24 static std::string enterclientani =
vs_config->
getVariable(
"graphics",
"enter_client_ani",
"warp.ani" );
25 static std::string exitclientani =
vs_config->
getVariable(
"graphics",
"enter_client_ani",
"warp.ani" );
26 std::string tmp = enter ? enterclientani : exitclientani;
42 if (NULL != shouldbenull) {
43 cout<<
" not adding unit with serial number "<<cltserial<<
" named "<<shouldbenull->
name.get()<<
" to system .";
54 vector< string >savedships;
55 string PLAYER_FACTION_STRING;
56 string *savegamestr = NULL;
57 if ( cltname.length() ) {
59 if (savestr.length() == 0) {
60 if (this->lastsave.size() && this->lastsave[0].length()
61 && this->callsign == cltname)
62 savestr = this->lastsave[0];
65 save.ParseSaveGame(
"", starsys,
"", pos, update, creds, savedships, 0, savestr,
false );
67 PLAYER_FACTION_STRING = save.GetPlayerFaction();
71 if ( savedships.empty() ) {
72 cerr<<
"savedships is empty!!!"<<endl;
73 cerr<<
"SAVEGAME: "<<endl<<savestr<<
"-------"<<endl;
74 cerr<<
"SHIPCSV: "<<endl<<xmlstr<<
"-------"<<endl;
77 cerr<<
"Found saveship[0] = "<<savedships[0]<<endl;
79 cerr<<
"NEW PLAYER POSITION : x="<<pos.i<<
",y="<<pos.j<<
"z="<<pos.k<<endl;
81 cerr<<
"SAFE PLATER POSITION: x="<<pos.i<<
",y="<<pos.j<<
"z="<<pos.k<<endl;
82 savegamestr = &xmlstr;
84 std::string::size_type wherepipe = xmlstr.find(
"|" );
85 PLAYER_FACTION_STRING = ( (wherepipe != string::npos) ? xmlstr.substr( 0, wherepipe ) : xmlstr );
86 if (savestr ==
"Pilot" || savestr ==
"pilot")
88 else if (savestr.find(
".cargo" ) == string::npos && PLAYER_FACTION_STRING ==
"upgrades")
89 savestr =
"generic_cargo";
90 savedships.push_back( savestr );
91 if (wherepipe != string::npos)
92 cltname = xmlstr.substr( wherepipe+1 );
93 if (wherepipe == string::npos || cltname.length() == 0)
101 "default", 1, 1,
"",
"",
mission ),
112 clt->prediction->InitInterpolation( un, un->
old_state, 0, this->deltatime );
116 clt->callsign = cltname;
117 string msg = clt->callsign+
" entered the system";
134 if (fg) fgname =
", fg "+fg->
name;
135 COUT<<
" >>> ENTERING CLIENT =( "<<cltserial
136 <<fgname<<
" )= -----------------"<<endl;
138 ClientPtr clt = Clients.get( cltserial );
141 COUT<<
"Existing client #"<<cltserial<<endl;
142 }
else if (!cltserial) {
146 clt = Clients.insert( cltserial,
new Client );
148 COUT<<
"New client #"<<cltserial<<
" - now "<<nbclients<<
" clients in system"<<endl;
151 clt->game_unit.SetUnit( un );
154 ::iterator
i = un->
mounts.begin();
155 for (; i != un->
mounts.end(); ++i)
162 clt->prediction->InitInterpolation( un, un->
old_state, 0, this->deltatime );
166 Unit *cltun = clt->game_unit.GetUnit();
167 if ( cltun == NULL || cltserial != cltun->
GetSerial() )
169 if ( myun == NULL || cltserial != myun->
GetSerial() )
184 sprintf( tbuf,
"%d", this->zone );
185 COUT<<__PRETTY_FUNCTION__<<
" zone: "<<tbuf<<endl;
187 _downloadManagerClient->addItem( &buf );
188 timeval timeout = {10, 0};
189 while ( !buf.
done() )
190 if (recvMsg( NULL, &timeout ) <= 0)
193 const char *tmp = (
char*) buf.
getBuffer().get();
212 if (noffset == offset) {
213 COUT<<
"ERROR Premature end of AddObjects buffer "<<std::hex
219 Unit *newunit = NULL;
226 newunit = this->enterClient( netbuf, serial );
254 cerr<<
"WARNING : Unknown sub "<<(
int) subcmd<<
" command in AddObjects"<<endl;
260 <<newunit->
name.get()<<endl;
284 void NetClient::removeClient(
const Packet *packet )
288 COUT<<
" & HTONS(Serial) = "<<cltserial<<endl;
290 if ( !( clt = Clients.get( cltserial ) ) ) {
291 cerr<<
"Error, client does not exists !!"<<endl;
295 Unit *un = clt->game_unit.GetUnit();
302 Clients.remove( cltserial );
305 COUT<<
"Leaving client #"<<cltserial<<
" - now "<<nbclients<<
" clients in system"<<endl;
306 string msg = clt->callsign+
" left the system";
325 if (debugPos)
COUT<<
"Sending ClientState == ";
326 if (debugPos) (*cs).display();
329 if (netversion > 4960)
349 void NetClient::receivePositions(
unsigned int numUnits,
unsigned int int_ts,
NetBuffer &netbuf,
double delta_t )
355 if (latest_timestamp <= int_ts) {
356 if (debugPos)
COUT<<
" *** SNAPSHOT is not late - evaluating"<<endl;
357 this->latest_timestamp = int_ts;
358 this->deltatime = delta_t;
361 unsigned int i = 0,
j = 0,
k = 0;
363 while ( (i+j+k) < numUnits ) {
366 bool localplayer =
false;
373 if (noffset == offset) {
374 COUT<<
"ERROR Premature end of Snapshot buffer "<<std::hex
383 if (sernum == this->
serial)
385 if ( !( clt = Clients.get( sernum ) ) ) {
388 COUT<<
"WARNING : No client, no unit found for this serial ("<<sernum<<
")"<<endl;
392 un = clt->game_unit.GetUnit();
397 if (debugPos)
COUT<<
" *** SubCommand is FullUpdate ser="<<sernum<<endl;
401 if (debugPos)
COUT<<
"Received ZoneMgr::FullUpdate ";
409 if (debugPos)
COUT<<
" *** cs="<<cs<<endl;
420 if ( clt->last_packet.getPosition() ==
QVector( 0, 0, 0 ) ) {
423 clt->last_packet = cs;
425 clt->setLatestTimestamp( int_ts );
426 clt->elapsed_since_packet = 0;
427 assert( clt->prediction );
428 clt->prediction->InitInterpolation( un,
431 clt->getNextDeltatime() );
432 clt->last_packet = cs;
436 if (debugPos) cerr<<
"Predicted location : x="<<predpos.i<<
",y="<<predpos.j<<
",z="<<predpos.k<<endl;
443 if (debugPos)
COUT<<
" *** SubCommand is PosUpdate ser="<<sernum<<endl;
445 if (debugPos)
COUT<<
" *** pos="<<pos.i<<
","<<pos.j<<
","<<pos.k<<endl;
446 if ( un && (!localplayer) ) {
452 if ( clt->last_packet.getPosition() ==
QVector( 0, 0, 0 ) ) {
455 clt->last_packet.setPosition( pos );
457 clt->setLatestTimestamp( int_ts );
458 clt->elapsed_since_packet = 0;
459 assert( clt->prediction );
460 clt->prediction->InitInterpolation( un,
463 clt->getNextDeltatime() );
468 }
else if (localplayer) {
469 if (debugPos) cerr<<
" IGNORING LOCAL PLAYER"<<endl;
476 receiveUnitDamage( netbuf, un );
485 COUT<<
" *** SNAPSHOT is late - ignoring"<<endl;
489 #define SETNOTNULL( un, param, val ) \
490 if (un) param = val; \
494 void NetClient::receiveUnitDamage(
NetBuffer &netbuf,
Unit *un )
497 unsigned short damages;
500 cerr<<
"Received Damage Update for null unit"<<endl;
501 if (un && un->
hull <= 0) {
502 cerr<<
"Received Damage Update for dead unit "<<un->
GetSerial()<<endl;
512 if (un && un->
hull < 0)
523 unsigned int numvdus = (
unsigned int)(
unsigned char)netbuf.
getChar();
524 for (it = 0; it < numvdus; ++it) {
532 unsigned int nummounts = (
unsigned int)(
unsigned short) netbuf.
getShort();
533 for (it = 0; it < nummounts; ++it) {
538 if ( un && it < un->mounts.size() ) {
540 un->
mounts[it].status = tmpstatus;
542 un->
mounts[it].ammo = ammo;
543 un->
mounts[it].time_to_lock = ttl;
544 un->
mounts[it].size = size;
605 cout<<
"Trying to ingame dead unit";
611 COUT<<
"Sending ingame with serial #"<<this->
serial<<endl;