So i looked into the db.py , and found that the account table is updated here :
def modify_account(self, username, type="llama.begin", faction="confed"):
self.save_account(username, self.get_default_save(type, faction),
self.get_default_csv(type))
with details implemented here :
def save_account(self, username, save, csv):
#print save
#print csv
if not save:
raise DBError('Empty save file')
elif not csv:
raise DBError('Empty csv file')
c = self.conn.cursor()
whereadd=''
username=username.replace(' ','_')
if self.user_table != self.account_table:
c.execute('SELECT logged_in_server FROM '+self.account_table +
' WHERE username=%s AND modname=%s',
(username, self.modkey))
row = c.fetchone()
if not row:
c.execute('INSERT INTO '+self.account_table +
' (username, modname, csv, savegame, logged_in_server)'+
' VALUES (%s, %s, %s, %s, 0)',
(username, self.modkey, csv, save))
else:
#print ('UPDATE ' + self.account_table +
# ' SET savegame=%s, csv=%s WHERE username=%s AND modname=%s' %
# (save, csv, username, self.modkey))
c.execute('UPDATE ' + self.account_table +
' SET savegame=%s, csv=%s WHERE username=%s AND modname=%s',
(save, csv, username, self.modkey))
else:
c.execute('UPDATE ' +self.user_table+
'SET savegame=%s, csv=%s WHERE username=%s',
(save, csv, username))
3 different queries , 1 create and 2 updates .
We could make that in php , with respect with the conditions .
I don't have checked yet if the VS server is calling save_account , i guess he does .
So php could be used at registration time , then VS server will do the updates , with his connection
to the account server . tho' I need to verify that point .
EDIT :
VERIFIED :
in netserver_accnt.cpp :
bool NetServer::saveAccount( int i )
{
string xmlstr, savestr;
//unsigned int xmllen, savelen, nxmllen, nsavelen;
Cockpit *cp = _Universe->AccessCockpit( i );
//Write the save and xml unit
//FileUtil::WriteSaveFiles( savestr, xmlstr, VSFileSystem::datadir+"/serversaves", cp->savegame->GetCallsign());
//SEND THE BUFFERS TO ACCOUNT SERVER
if (cp && acctserver && acct_con) {
Unit *un = cp->GetParent();
ClientPtr clt;
if (un)
clt = getClientFromSerial( un->GetSerial() );
if (!clt || !un) {
cerr<<"Error client/unit for "<<(clt ? clt->callsign : "")<<", serial "<<(un ? un->GetSerial() : 0)
<<" not found in save process !!!!"<<endl;
return false;
}
if (clt->loginstate < Client::INGAME)
return false; //Cannot save at this point.
SaveNetUtil::GetSaveStrings( i, savestr, xmlstr, true );
if ( savestr.empty() || xmlstr.empty() )
//cerr<<"Unable to generate CSV and Save data for player."<<endl;
return false;
std::string snetbuf;
//Loop through clients to find the one corresponding to the unit (we need its serial)
//Fix CMD_RESPAWN. I expect the client to do the same thing here.
clt->savegame.clear();
clt->savegame.push_back( savestr );
clt->savegame.push_back( xmlstr );
addSimpleChar( snetbuf, ACCT_SAVE );
addSimpleString( snetbuf, clt->callsign );
addSimpleString( snetbuf, clt->passwd );
addSimpleString( snetbuf, savestr );
addSimpleString( snetbuf, xmlstr );
if ( !acct_sock->sendstr( snetbuf ) ) {
COUT<<"ERROR sending SAVE to account server for "<<clt->callsign<<" ("<<un->GetSerial()<<")"<<endl;
return false;
}
{
//Tell client that we saved the game.
Packet p1;
NetBuffer netbuf;
p1.send( CMD_SAVEACCOUNTS, un->GetSerial(), netbuf.getData(), netbuf.getDataLength(),
SENDRELIABLE, NULL, clt->tcp_sock, __FILE__, __LINE__ );
}
return true;
}
return false;
}
In red , the command sent to the account server .
Accountserver.py is listening and react to that command ( line 205 ) :
elif command==ACCT_SAVE:
username=packet.getCheckedString()
password=packet.getCheckedString()
save=packet.getString()
xml=packet.getString()
if conn.check_password(username, password):
conn.save_account(username,save,xml)
printACCT_SUCCESS(conn, username, save)
So yeah , the updates of the accounts are done when clients logout from VS server .
So it seem to me that we can make the first account write in the database with php ,
then let the VS server+Account server do the updates .
We could at any time write to the accounts with php ( superuser ? ), directly to the database , or even by using php sockets and sending a string that contains the ACCT_SAVE:
We just have to do the same than the c++ code :
std::string snetbuf; <---- Standard string
addSimpleChar( snetbuf, ACCT_SAVE );
input += std::string( add, 1 );
addSimpleString( snetbuf, clt->callsign );
addSimpleString( snetbuf, clt->passwd );
addSimpleString( snetbuf, savestr );
addSimpleString( snetbuf, xmlstr );
if ( !acct_sock->sendstr( snetbuf ) ) {
COUT<<"ERROR sending SAVE to account server for "<<clt->callsign<<" ("<<un->GetSerial()<<")"<<endl;
return false;
}
not so complicated .
( in theory
)
Ah , and you need that to compose your messages :
enum accountServerCommands
{
ACCT_LOGIN ='l',
ACCT_NEWCHAR ='c',
ACCT_NEWSUBSCRIBE ='u',
ACCT_LOGIN_DATA ='d',
ACCT_LOGIN_ERROR ='e',
ACCT_LOGIN_ALREADY='f',
ACCT_LOGIN_NEW ='n',
ACCT_LOGIN_ACCEPT ='a',
ACCT_LOGOUT ='o',
ACCT_RESYNC ='r',
ACCT_SAVE='s',
ACCT_SAVE_LOGOUT ='S',
ACCT_SUCCESS ='!',
};