15 using namespace VSFileSystem;
27 cout<<
"AccountServer init"<<endl;
54 cout<<endl<<
"Vegastrike Account Server version 0.0.1"<<endl;
55 cout<<
"Written by Stephane Vaxelaire"<<endl<<endl;
69 cout<<
"Loading config file...";
82 period = atoi( strperiod.c_str() );
85 cout<<
"Loading accounts data... ";
90 cout<<
"Initializing network..."<<endl;
91 unsigned short tmpport;
98 cout<<
"Error cannot start server... quitting."<<endl;
110 comsock = Network->acceptNewConn();
111 if ( comsock.
valid() ) {
112 Socks.push_back( comsock );
113 COUT<<
"New connection - socket allocated : "<<comsock<<endl;
116 list< SOCKETALT >::iterator
i;
117 for (i = Socks.begin(); i != Socks.end(); i++) {
132 Network->disconnect(
"Shutting down." );
137 string callsign, passwd;
141 int found = 0, connected = 0;
146 if ( ( recvcount = sock.
recvbuf( &p, &ipadr ) ) > 0 ) {
147 cout<<
"Socket : "<<endl<<sock<<endl;
152 cout<<
"Buffer => "<<p.
getData()<<endl;
158 callsign = netbuf.getString();
159 passwd = netbuf.getString();
160 cout<<
">>> SERVER REQUEST =( "<<callsign<<
":"<<passwd<<
" )= --------------------------------------"<<endl;
163 if (elem->
passwd != passwd)
166 COUT<<
"Login/passwd not found"<<endl;
167 Account elt( callsign, passwd );
171 COUT<<
"Login already connected !"<<endl;
175 COUT<<
"Login accepted send server ip !"<<endl;
184 char flags = netbuf.getChar();
185 callsign = netbuf.getString();
186 passwd = netbuf.getString();
187 cout<<
">>> LOGIN REQUEST =( "<<callsign<<
":"<<passwd<<
" )= --------------------------------------"<<endl;
190 if (elem->
passwd != passwd)
193 Account elt( callsign, passwd );
197 cout<<
"Client already connected"<<endl;
201 cout<<
"Login accepted !"<<endl;
206 cout<<
"<<< LOGIN REQUEST ------------------------------------------"<<endl;
210 callsign = netbuf.getString();
211 passwd = netbuf.getString();
212 cout<<
">>> LOGOUT REQUEST =( "<<callsign<<
":"<<passwd<<
" )= --------------------------------------"<<endl;
217 if (elem->
passwd != passwd)
224 cout<<
"ERROR LOGOUT -> didn't find player to disconnect = <"<<callsign<<
">:<"<<passwd<<
">"<<endl;
228 cout<<
"-= "<<callsign<<
" =- Disconnected"<<endl;
230 cout<<
"ERROR LOGOUT -> player exists but wasn't connected ?!?!"<<endl;
233 cout<<
"<<< LOGOUT REQUEST ---------------------------------------"<<endl;
237 cout<<
">>> SUBSRIBE REQUEST =( "<<callsign<<
" )= --------------------------------------"<<endl;
240 callsign = netbuf.getString();
241 passwd = netbuf.getString();
249 cout<<
"ERROR sending authorization"<<endl;
258 cout<<
"ERROR opening accounts file";
261 cout<<
"ERROR sending errormsg to subscription website"<<endl;
264 cout<<
"Account file opened"<<endl;
267 vector< string >acctlines;
270 acctlines.push_back( fbuf );
271 cout<<
"Read line : "<<fbuf<<endl;
276 cerr<<
"!!! ERROR : opening account file in write mode !!!"<<endl;
279 acctlines.push_back(
"\t<PLAYER name=\""+callsign+
"\"\tpassword=\""+passwd+
"\" />\n" );
280 acctlines.push_back(
"</ACCOUNTS>\n" );
282 for (
size_t i = 0;
i < acctlines.size();
i++)
283 if (f.
WriteLine( acctlines[
i].c_str() ) < 0) {
285 cout<<
"!!! ERROR : writing to account file !!!"<<endl;
299 __FILE__, __LINE__ ) < 0) {
300 cout<<
"ERROR sending authorization"<<endl;
305 cout<<
"<<< SUBSRIBE REQUEST --------------------------------------"<<endl;
310 cout<<
">>> RESYNC ACCOUNTS --------------------------------------"<<endl;
313 cout<<
">>>>>>>>> SYNC RECEIVED FOR "<<nbclients<<
" CLIENTS <<<<<<<<<<<<"<<endl;
320 for (i = 0; i < nbclients; i++) {
321 nameTmp = netbuf.getString();
331 cout<<
"<<< RESYNC'ED ACCOUNTS --------------------------------------"<<endl;
335 cout<<
">>> SAVING ACCOUNT #"<<packet.
getSerial()<<
"-----------------------------"<<endl;
337 cout<<
"<<< ACCOUNT SAVED --------------------------------------"<<endl;
340 cout<<
">>> UNKNOWN command =( "<<cmd<<
" )= ---------------------------------";
352 cout<<
"Received failed or socket closed"<<endl;
353 DeadSocks.push_back( sock );
363 cout<<
"\tLOGIN REQUEST SUCCESS for <"<<acct->
callsign<<
">:<"<<acct->
passwd<<
">"<<endl;
367 if ( acct->
isNew() ) {
372 cout<<
"ERROR sending authorization"<<endl;
381 string acctfile = acct->
callsign+
".save";
382 cerr<<
"Trying to open : "<<acctfile<<endl;
386 cerr<<
"Account save file does not exists... sending default one to game server"<<endl;
387 acctfile =
"default.save";
388 cerr<<
"Trying to open : "<<acctfile<<endl;
391 cout<<
"Error, default save not found"<<endl;
395 cout<<
"... done !"<<endl;
400 if (acctfile ==
"default.save")
401 acctsave =
"default.xml";
404 cerr<<
"Trying to open : "<<acctsave<<endl;
408 cout<<
"XML save file does not exists... sending default one to game server"<<endl;
409 acctsave =
"default.xml";
410 cerr<<
"Trying to open : "<<acctsave<<endl;
411 if (acctfile !=
"default.save") {
414 cerr<<
"Default XML Loaded -> reload the default save !"<<endl;
415 acctfile =
"default.save";
416 cerr<<
"Trying to open : "<<acctfile<<endl;
421 cout<<
"... done !"<<endl;
426 cout<<
"Save size = "<<f.
Size()<<
" - XML size = "<<f2.
Size()<<endl;
427 cout<<
"Loaded -= "<<acct->
callsign<<
" =- save files ("<<( f.
Size()+f2.
Size() )<<
")"<<endl;
433 cout<<
"Error, default save not found"<<endl;
448 cout<<
"Error, default xml not found"<<endl;
457 NULL, sock, __FILE__, __LINE__ ) < 0) {
458 cout<<
"ERROR sending authorization"<<endl;
468 cout<<
"\tLOGIN REQUEST FAILED for <"<<acct->
callsign<<
">:<"<<acct->
passwd<<
">"<<endl;
476 cout<<
"\tLOGIN REQUEST FAILED for <"<<acct->
callsign<<
">:<"<<acct->
passwd<<
"> -> ALREADY LOGGED IN"<<endl;
485 cout<<
"-- sending SERVERIP="<<acct->
serverip<<
" - SERVERPORT="<<acct->
serverport<<endl;
487 cout<<
"\tLOGIN DATA SENT for <"<<acct->
callsign<<
">:<"<<acct->
passwd<<
">"<<endl;
503 if ( DeadSocks.empty() )
return;
506 list< SOCKETALT >::iterator
j;
508 for (j = DeadSocks.begin(); j != DeadSocks.end(); j++) {
510 COUT<<
">>>>>>> Closing socket number "<<(*j)<<endl;
521 j->disconnect(
"\tclosing socket" );
522 Socks.remove( (*j) );
524 cout<<
"\tDisconnected "<<nbc_disc<<
" clients associated with that server socket"<<endl;
525 cout<<
"\tDisconnected "<<nbs_disc<<
" non-clients sockets"<<endl;
533 string xmlstr = saves[0];
534 string savestr = saves[1];