void LogicSystem::dismantleCharacter(int cn) { #ifndef SERVER if (cn == ClientSystem::playerNumber) logger::log(logger::DEBUG, "Not dismantling own client\r\n", cn); else #endif { logger::log(logger::DEBUG, "Dismantling other client %d\r\n", cn); #ifdef SERVER gameent* gameEntity = game::getclient(cn); bool isNPC = gameEntity->serverControlled; #endif game::clientdisconnected(cn); #ifdef SERVER if (isNPC) { /* The server connections of NPCs are removed when they are dismantled - * they must be re-created manually in the new scenario, unlike players */ localdisconnect(true, cn); } #endif } }
void gets2c() // get updates from the server { ENetEvent event; if(!clienthost) return; if(connpeer && totalmillis/3000 > connmillis/3000) { conoutf("attempting to connect..."); connmillis = totalmillis; ++connattempts; if(connattempts > 3) { conoutf("\f3could not connect to server"); abortconnect(); return; } } while(clienthost && enet_host_service(clienthost, &event, 0)>0) switch(event.type) { case ENET_EVENT_TYPE_CONNECT: disconnect(false, false); localdisconnect(false); curpeer = connpeer; connpeer = NULL; conoutf("connected to server"); throttle(); if(rate) setrate(rate); game::gameconnect(true); break; case ENET_EVENT_TYPE_RECEIVE: if(discmillis) conoutf("attempting to disconnect..."); else localservertoclient(event.channelID, event.packet); enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: extern const char *disc_reasons[10]; /* because gcc 4.2 is retarded */ if(event.data>=DISC_NUM) event.data = DISC_NONE; if(event.peer==connpeer) { conoutf("\f3could not connect to server"); abortconnect(); } else { if(!discmillis || event.data) conoutf("\f3server network error, disconnecting (%s) ...", disc_reasons[event.data]); disconnect(); } return; default: break; } }
void quit() // normal exit { extern void writeinitcfg(); writeinitcfg(); writeservercfg(); abortconnect(); disconnect(); localdisconnect(); writecfg(); cleanup(); exit(EXIT_SUCCESS); }
/// normal game quit /// @see fatal /// @see cleanup void quit() { delete metapp; // CefShutdown(); writeinitcfg(); writeservercfg(); writehistory(); abortconnect(); disconnect(); localdisconnect(); writecfg(); cleanup(); exit(EXIT_SUCCESS); }
void trydisconnect(bool local) { if(connpeer) { conoutf("aborting connection attempt"); abortconnect(); } else if(curpeer) { conoutf("attempting to disconnect..."); disconnect(!discmillis); } else if(local && haslocalclients()) localdisconnect(); else conoutf("not connected"); }
void quit() // normal exit { extern void writeinitcfg(); writeinitcfg(); abortconnect(); disconnect(); localdisconnect(); tools::writecfg(); cleanup(); varsys::flush(); exit(EXIT_SUCCESS); }
void disconnect(int onlyclean, int async) { bool cleanup = onlyclean!=0; if(curpeer || connectedlocally) { if(curpeer) { if(!discmillis) { enet_peer_disconnect(curpeer, DISC_NONE); if(clienthost) enet_host_flush(clienthost); discmillis = totalmillis; } if(curpeer->state!=ENET_PEER_STATE_DISCONNECTED) { if(async) return; enet_peer_reset(curpeer); } curpeer = NULL; } discmillis = 0; conoutft(CON_MESG, "\frdisconnected"); cleanup = true; } if(!connpeer && clienthost) { enet_host_destroy(clienthost); clienthost = NULL; } if(cleanup) { client::gamedisconnect(onlyclean); localdisconnect(); } if(!onlyclean) localconnect(false); }
void gets2c() // get updates from the server { ENetEvent event; if(!clienthost) return; if(connpeer && totalmillis/3000 > connmillis/3000) { conoutf("attempting to connect..."); connmillis = totalmillis; ++connattempts; if(connattempts > 3) { conoutf("\f3could not connect to server"); abortconnect(); return; } } while(clienthost && enet_host_service(clienthost, &event, 0)>0) switch(event.type) { case ENET_EVENT_TYPE_CONNECT: disconnect(false, false); localdisconnect(false); curpeer = connpeer; connpeer = NULL; conoutf("connected to server"); throttle(); if(GETIV(rate)) setrate(GETIV(rate)); game::gameconnect(true); break; case ENET_EVENT_TYPE_RECEIVE: #if CLIENT // INTENSITY if(discmillis) conoutf("attempting to disconnect..."); else localservertoclient(event.channelID, event.packet); enet_packet_destroy(event.packet); #else // SERVER assert(0); #endif break; case ENET_EVENT_TYPE_DISCONNECT: // LogicSystem::init(); // INTENSITY: Not sure about this...? extern const char *disc_reasons[]; if(event.data>=DISC_NUM) event.data = DISC_NONE; if(event.peer==connpeer) { conoutf("\f3could not connect to server"); abortconnect(); } else { if(!discmillis || event.data) conoutf("\f3server network error, disconnecting (%s) ...", disc_reasons[event.data]); disconnect(); } return; default: break; } }