27 for (
LI li = allClients.begin(); li != allClients.end(); li++) {
29 Unit *un = clt->game_unit.GetUnit();
42 bool NetServer::loginAccept(
const string &_inetbuf,
ClientPtr clt,
int newacct,
char flags )
44 COUT<<
"enter "<<__PRETTY_FUNCTION__<<endl;
46 string inetbuf = _inetbuf;
64 COUT<<
"Error creating new client connection"<<endl;
68 clt->savegame.resize( 0 );
70 clt->savegame.push_back( savestr );
71 clt->savegame.push_back( xmlstr );
72 Cockpit *cp = loadCockpit( clt );
89 COUT<<
"LOGIN REQUEST SUCCESS for <"<<callsign<<
">"<<endl;
91 COUT<<
"This account has no ship/char so create one"<<
"(UNIMPLEMENTED)"<<endl;
92 sendLoginError( clt );
97 if ( loadFromSavegame( clt, cp ) ) {
98 sendLoginAccept( clt, cp );
99 COUT<<
"<<< SENT LOGIN ACCEPT -----------------------------------------------------------------------"<<endl;
106 COUT<<
"enter "<<__PRETTY_FUNCTION__<<endl;
111 sendLoginError( clt );
127 COUT<<
">>> SEND LOGIN ACCEPT =( serial #"<<cltserial<<
" )= --------------------------------------"<<endl;
128 COUT<<
"SAVE="<<clt->savegame[0].length()<<
" bytes - XML="<<clt->savegame[1].length()<<
" bytes"<<endl;
129 cerr<<
"SENDING STARDATE : "<<datestr<<endl;
132 string relsys = sysname+
".system";
139 unsigned char *digest =
new unsigned char[FileUtil::Hash.DigestSize()];
143 else if ( !sysname.empty() )
145 netbuf.
addShort( FileUtil::Hash.DigestSize() );
146 netbuf.
addBuffer( digest, FileUtil::Hash.DigestSize() );
178 for (vector< Cargo >::const_iterator iter = mpl->
pImage->
cargo.begin(); iter != mpl->
pImage->
cargo.end(); iter++)
179 if ( (*iter).GetCategory().substr( 0, 10 ) ==
"starships/" ) {
180 std::string content = (*iter).GetContent();
181 std::string::size_type dot = content.find(
'.' );
183 ships.push_back( content );
191 if ( clt->callsign.empty() ) {
192 sendLoginError( clt );
195 vector< string >ships;
199 unsigned short selection = netbuf.
getShort();
201 if ( selection >= ships.size() ) {
202 sendLoginError( clt );
205 string fighter = ships[selection];
206 Cockpit *cp = loadCockpit( clt );
208 if ( loadFromNewGame( clt, cp, fighter ) )
209 sendLoginAccept( clt, cp );
218 if (!this->server_password.empty() && passwd != this->server_password) {
219 this->sendLoginError( clt );
225 COUT<<
"Cannot login player "<<clt->callsign<<
": already exists on this server!";
226 sendLoginAlready( clt );
231 vector< string >ships;
234 for (vector< string >::const_iterator iter = ships.begin(); iter != ships.end(); ++iter)
248 sendLoginAlready( clt );
257 fprintf( stderr,
"======= Creating Cockpit 0 for universe save data! =======\n" );
261 if ( !unused_players.empty() ) {
263 unused_players.pop();
273 bool NetServer::loadFromNewGame(
ClientPtr clt,
Cockpit *cp,
string fighter )
276 string PLAYER_SHIPNAME =
fighter;
281 COUT<<
"Cannot login player without acctserver: No missions available";
282 sendLoginError( clt );
285 int saved_faction = 0;
292 COUT<<
"-> SAVE LOADED"<<endl;
296 COUT<<
"-> UNIT FACTORY WITH XML"<<endl;
302 static std::string loadfailed(
"LOAD_FAILED" );
304 if ( !PLAYER_SHIPNAME.empty() ) {
310 "default", 1, 1,
"",
"", mission ),
315 }
else if (un->
name == loadfailed) {
321 this->sendLoginError( clt );
322 cerr<<
"WARNING : Unit file ("<<PLAYER_SHIPNAME<<
") not found for "<<clt->callsign<<endl;
325 COUT<<
"\tAFTER UNIT FACTORY WITH XML"<<endl;
326 clt->game_unit.SetUnit( un );
332 COUT<<
"-> UNIT LOADED"<<endl;
335 cp->
SetParent( un, PLAYER_SHIPNAME.c_str(),
"", tmpvec );
336 COUT<<
"-> COCKPIT AFFECTED TO UNIT"<<endl;
338 string savestr, xmlstr;
339 clt->savegame.resize( 0 );
343 clt->savegame.push_back( savestr );
344 clt->savegame.push_back( xmlstr );
355 vector< string >savedships;
358 COUT<<
"-> LOADING SAVE FROM NETWORK"<<endl;
360 cp->
savegame->
ParseSaveGame(
"", str,
"", tmpvec, update, credits, savedships, cltserial, clt->savegame[0],
false );
362 if ( savedships.empty() ) {
363 COUT<<
"There are no saved ships... corrupted save file for "<<clt->callsign<<endl;
364 std::string logoutnetbuf;
372 COUT<<
"\tcredits = "<<credits<<endl;
374 COUT<<
"-> SAVE LOADED"<<endl;
377 COUT<<
"-> UNIT FACTORY WITH XML"<<endl;
379 string PLAYER_SHIPNAME = savedships[0];
385 static std::string loadfailed(
"LOAD_FAILED" );
387 if ( !PLAYER_SHIPNAME.empty() ) {
393 "default", 1, 1,
"",
"", mission ),
394 0, &clt->savegame[1] );
398 }
else if (un->
name == loadfailed) {
403 unsigned short serial = cltserial;
404 std::string logoutnetbuf;
412 if ( !acct_sock->
sendstr( logoutnetbuf ) )
413 COUT<<
"ERROR sending LOGOUT to account server"<<endl;
414 cerr<<
"WARNING : Unit file ("<<savedships[0]<<
") not found for "<<clt->callsign<<endl;
417 COUT<<
"\tAFTER UNIT FACTORY WITH XML"<<endl;
418 clt->game_unit.SetUnit( un );
424 COUT<<
"-> UNIT LOADED"<<endl;
426 cp->
SetParent( un, PLAYER_SHIPNAME.c_str(),
"", tmpvec );
427 COUT<<
"-> COCKPIT AFFECTED TO UNIT"<<endl;
429 COUT<<
"SHIP -- "<<savedships[0]<<
" -- LOCATION: x="<<tmpvec.i<<
",y="<<tmpvec.j<<
",z="<<tmpvec.k<<endl;
433 void NetServer::sendLoginError(
ClientPtr clt )
438 COUT<<
">>> SEND LOGIN ERROR -----------------------------------------------------------------"<<endl;
440 COUT<<
"<<< SENT LOGIN ERROR -----------------------------------------------------------------------"<<endl;
443 void NetServer::sendLoginUnavailable(
ClientPtr clt )
448 COUT<<
">>> SEND LOGIN UNAVAILABLE -----------------------------------------------------------------"<<endl;
450 COUT<<
"<<< SENT LOGIN UNAVAILABLE -----------------------------------------------------------------------"<<endl;
452 discList.push_back( clt );
455 void NetServer::sendLoginAlready(
ClientPtr clt )
462 COUT<<
">>> SEND LOGIN ALREADY =( serial #"<<packet.
getSerial()<<
" )= --------------------------------------"<<endl;
464 COUT<<
"<<< SENT LOGIN ALREADY -----------------------------------------------------------------------"<<endl;
465 discList.push_back( clt );