void xrServer::Process_save(NET_Packet& P, ClientID sender) { xrClientData* CL = ID_to_client(sender); if (CL) CL->net_Ready = TRUE; R_ASSERT(CL->flags.bLocal); // while has information while (!P.r_eof()) { // find entity u16 ID; u16 size; P.r_u16 (ID); P.r_u16 (size); s32 _pos_start = P.r_tell (); CSE_Abstract *E = ID_to_entity(ID); if (E) { E->net_Ready = TRUE; E->load (P); } else P.r_advance (size); s32 _pos_end = P.r_tell (); s32 _size = size; if (_size != (_pos_end-_pos_start)) { Msg ("! load/save mismatch, object: '%s'",E?E->name_replace():"unknown"); s32 _rollback = _pos_start+_size; P.r_seek (_rollback); } } }
void xrServer::Process_update(NET_Packet& P, ClientID sender) { xrClientData* CL = ID_to_client(sender); if (!CL) { return; } // if (CL) CL->net_Ready = TRUE; #ifdef DEBUG if (g_Dump_Update_Read) Msg("---- UPDATE_Read --- "); #endif // Entities R_ASSERT(CL->flags.bLocal); // while has information while (!P.r_eof()) { // find entity u16 ID; u8 size; P.r_u16 (ID); P.r_u8 (size); u32 _pos = P.r_tell(); CSE_Abstract *E = ID_to_entity(ID); if (E) { //Msg ("sv_import: %d '%s'",E->ID,E->name_replace()); E->net_Ready = TRUE; E->UPDATE_Read (P); #ifdef DEBUG if (g_Dump_Update_Read) Msg("* %s : %d - %d", E->name(), size, P.r_tell() - _pos); #endif if ((P.r_tell()-_pos) != size) { string16 tmp; CLSID2TEXT (E->m_tClassID,tmp); Debug.fatal (DEBUG_INFO,"Beer from the creator of '%s'",tmp); } } else P.r_advance (size); } #ifdef DEBUG if (g_Dump_Update_Read) Msg("-------------------- "); #endif // Entities }
void xrServer::Process_update(NET_Packet& P, ClientID sender) { xrClientData* CL = ID_to_client(sender); R_ASSERT2 (CL,"Process_update client not found"); if (g_Dump_Update_Read) Msg("---- UPDATE_Read --- "); R_ASSERT(CL->flags.bLocal); // while has information while (!P.r_eof()) { // find entity u16 ID; u8 size; P.r_u16 (ID); P.r_u8 (size); u32 _pos = P.r_tell(); CSE_Abstract *E = ID_to_entity(ID); if (E) { //Msg ("sv_import: %d '%s'",E->ID,E->name_replace()); E->net_Ready = TRUE; E->UPDATE_Read (P); u32 cp = P.r_tell(); if (g_Dump_Update_Read) Msg("* %s : %d - %d", E->name(), size, cp - _pos); if ((cp - _pos) != size) { string16 tmp; CLSID2TEXT (E->m_tClassID,tmp); Msg("* size = %d, start read = %d, end read = %d", size, _pos, cp); Debug.fatal (DEBUG_INFO,"Beer from the creator of '%s', version of object = %d", tmp, E->m_wVersion); } } else P.r_advance (size); } if (g_Dump_Update_Read) Msg("-------------------- "); }
void CLevel::cl_Process_Event (u16 dest, u16 type, NET_Packet& P) { // Msg ("--- event[%d] for [%d]",type,dest); CObject* O = Objects.net_Find (dest); if (0==O) { #ifdef DEBUG Msg("* WARNING: c_EVENT[%d] to [%d]: unknown dest",type,dest); #endif // DEBUG return; } CGameObject* GO = smart_cast<CGameObject*>(O); if (!GO) { Msg("! ERROR: c_EVENT[%d] : non-game-object",dest); return; } if (type != GE_DESTROY_REJECT) { if (type == GE_DESTROY) Game().OnDestroy(GO); GO->OnEvent (P,type); } else { // handle GE_DESTROY_REJECT here u32 pos = P.r_tell(); u16 id = P.r_u16(); P.r_seek (pos); bool ok = true; CObject *D = Objects.net_Find (id); if (0==D) { Msg ("! ERROR: c_EVENT[%d] : unknown dest",id); ok = false; } CGameObject *GD = smart_cast<CGameObject*>(D); if (!GD) { Msg ("! ERROR: c_EVENT[%d] : non-game-object",id); ok = false; } GO->OnEvent (P,GE_OWNERSHIP_REJECT); if (ok) { Game().OnDestroy(GD); GD->OnEvent (P,GE_DESTROY); }; } };
void message_filter::check_new_data (NET_Packet & packet) { u32 tmp_old_pos = packet.r_tell(); msg_type_subtype_t packet_mtype; packet_mtype.import (packet); if (packet_mtype.msg_type == M_EVENT_PACK) { NET_Packet tmp_packet; while (!packet.r_eof()) { tmp_packet.B.count = packet.r_u8(); packet.r (tmp_packet.B.data, tmp_packet.B.count); packet_mtype.import(tmp_packet); R_ASSERT2(packet_mtype.msg_type != M_EVENT_PACK, "M_EVENT_PACK in M_EVENT_PACK"); dbg_print_msg (tmp_packet, packet_mtype); filters_map_t::iterator tmp_iter = m_filters.find(packet_mtype); if (tmp_iter != m_filters.end()) { tmp_iter->second(packet_mtype.msg_type, packet_mtype.msg_subtype, tmp_packet); } } } else { dbg_print_msg (packet, packet_mtype); filters_map_t::iterator tmp_iter = m_filters.find(packet_mtype); if (tmp_iter != m_filters.end()) { tmp_iter->second(packet_mtype.msg_type, packet_mtype.msg_subtype, packet); } } packet.r_seek (tmp_old_pos); }
void CLevel::cl_Process_Event (u16 dest, u16 type, NET_Packet& P) { // Msg ("* event[%d] for [%d]",type,dest); CObject* O = Objects.net_Find (dest); if (0==O) { #ifdef DEBUG Msg("! WARNING: c_EVENT[%d] to [%d]: unknown dest",type,dest); #endif // DEBUG return; } CGameObject* GO = smart_cast<CGameObject*>(O); if (!GO) { #ifndef MASTER_GOLD Msg("! ERROR: c_EVENT[%d] : non-game-object",dest); #endif // #ifndef MASTER_GOLD return; } if (type != GE_DESTROY_REJECT) { if (type == GE_DESTROY) { Game().OnDestroy(GO); // if ( GO->H_Parent() ) // { // = GameObject.cpp (210) // Msg( "! ERROR (Level): GE_DESTROY arrived to object[%d][%s], that has parent[%d][%s], frame[%d]", // GO->ID(), GO->cNameSect().c_str(), // GO->H_Parent()->ID(), GO->H_Parent()->cName().c_str(), Device.dwFrame ); // } } GO->OnEvent (P,type); } else { // handle GE_DESTROY_REJECT here u32 pos = P.r_tell(); u16 id = P.r_u16(); P.r_seek (pos); bool ok = true; CObject *D = Objects.net_Find (id); if (0==D) { #ifndef MASTER_GOLD Msg ("! ERROR: c_EVENT[%d] : unknown dest",id); #endif // #ifndef MASTER_GOLD ok = false; } CGameObject *GD = smart_cast<CGameObject*>(D); if (!GD) { #ifndef MASTER_GOLD Msg ("! ERROR: c_EVENT[%d] : non-game-object",id); #endif // #ifndef MASTER_GOLD ok = false; } GO->OnEvent (P,GE_OWNERSHIP_REJECT); if (ok) { Game().OnDestroy(GD); GD->OnEvent (P,GE_DESTROY); }; } };
u32 xrServer::OnMessage (NET_Packet& P, ClientID sender) // Non-Zero means broadcasting with "flags" as returned { if (g_pGameLevel && Level().IsDemoSave()) Level().Demo_StoreServerData(P.B.data, P.B.count); u16 type; P.r_begin (type); csPlayers.Enter (); VERIFY (verify_entities()); xrClientData* CL = ID_to_client(sender); switch (type) { case M_UPDATE: { Process_update (P,sender); // No broadcast VERIFY (verify_entities()); }break; case M_SPAWN: { // R_ASSERT(CL->flags.bLocal); if (CL->flags.bLocal) Process_spawn (P,sender); VERIFY (verify_entities()); }break; case M_EVENT: { Process_event (P,sender); VERIFY (verify_entities()); }break; case M_EVENT_PACK: { NET_Packet tmpP; while (!P.r_eof()) { tmpP.B.count = P.r_u8(); P.r (&tmpP.B.data, tmpP.B.count); OnMessage (tmpP, sender); }; }break; case M_CL_UPDATE: { xrClientData* CL = ID_to_client (sender); if (!CL) break; CL->net_Ready = TRUE; if (!CL->net_PassUpdates) break; //------------------------------------------------------------------- u32 ClientPing = CL->stats.getPing(); P.w_seek(P.r_tell()+2, &ClientPing, 4); //------------------------------------------------------------------- if (SV_Client) SendTo (SV_Client->ID, P, net_flags(TRUE, TRUE)); VERIFY (verify_entities()); }break; case M_MOVE_PLAYERS_RESPOND: { xrClientData* CL = ID_to_client (sender); if (!CL) break; CL->net_Ready = TRUE; CL->net_PassUpdates = TRUE; }break; //------------------------------------------------------------------- case M_CL_PING_CHALLENGE: { P.r_u32(); u32 id = sender.value(); P.w_seek( P.r_tell(), &(id), 4); if (SV_Client) SendTo (SV_Client->ID, P, net_flags(FALSE)); }break; case M_CL_PING_CHALLENGE_RESPOND: { P.r_u32(); u32 id = P.r_u32(); ClientID clientID; clientID.set(id); u32 clLastPing = P.r_u32(); xrClientData* pCL = ID_to_client(clientID); pCL->ps->Rping = u16(clLastPing); SendTo (clientID, P, net_flags(FALSE)); }break; //------------------------------------------------------------------- case M_CL_INPUT: { xrClientData* CL = ID_to_client (sender); if (CL) CL->net_Ready = TRUE; if (SV_Client) SendTo (SV_Client->ID, P, net_flags(TRUE, TRUE)); VERIFY (verify_entities()); }break; case M_GAMEMESSAGE: { ClientID clientID;clientID.setBroadcast(); SendBroadcast (clientID,P,net_flags(TRUE,TRUE)); VERIFY (verify_entities()); }break; case M_CLIENTREADY: { xrClientData* CL = ID_to_client(sender); if (CL) { CL->net_Ready = TRUE; CL->ps->DeathTime = Device.dwTimeGlobal; game->OnPlayerConnectFinished(sender); }; game->signal_Syncronize (); VERIFY (verify_entities()); }break; case M_SWITCH_DISTANCE: { game->switch_distance (P,sender); VERIFY (verify_entities()); }break; case M_CHANGE_LEVEL: { if (game->change_level(P,sender)){ ClientID clientID;clientID.setBroadcast(); SendBroadcast (clientID,P,net_flags(TRUE,TRUE)); } VERIFY (verify_entities()); }break; case M_SAVE_GAME: { game->save_game (P,sender); VERIFY (verify_entities()); }break; case M_LOAD_GAME: { game->load_game (P,sender); ClientID clientID;clientID.setBroadcast(); SendBroadcast (clientID,P,net_flags(TRUE,TRUE)); VERIFY (verify_entities()); }break; case M_RELOAD_GAME: { ClientID clientID;clientID.setBroadcast(); SendBroadcast (clientID,P,net_flags(TRUE,TRUE)); VERIFY (verify_entities()); }break; case M_SAVE_PACKET: { Process_save (P,sender); VERIFY (verify_entities()); }break; case M_CLIENT_REQUEST_CONNECTION_DATA: { xrClientData* CL = ID_to_client (sender); OnCL_Connected (CL); }break; case M_CHAT_MESSAGE: { xrClientData *l_pC = ID_to_client(sender); OnChatMessage (&P, l_pC); }break; case M_CHANGE_LEVEL_GAME: { ClientID CID; CID.set (0xffffffff); SendBroadcast (CID,P,net_flags(TRUE,TRUE)); }break; case M_CL_AUTH: { game->AddDelayedEvent (P,GAME_EVENT_PLAYER_AUTH, 0, sender); }break; case M_PAUSE_GAME: { ClientID clientID;clientID.setBroadcast(); SendBroadcast (clientID,P,net_flags(TRUE,TRUE)); }break; case M_STATISTIC_UPDATE: { ClientID clientID;clientID.setBroadcast(); if (SV_Client) SendBroadcast (SV_Client->ID,P,net_flags(TRUE,TRUE)); else SendBroadcast (clientID,P,net_flags(TRUE,TRUE)); }break; case M_STATISTIC_UPDATE_RESPOND: { if (SV_Client) SendTo (SV_Client->ID, P, net_flags(TRUE, TRUE)); }break; case M_PLAYER_FIRE: { if (game) game->OnPlayerFire(sender, P); }break; } VERIFY (verify_entities()); csPlayers.Leave (); return IPureServer::OnMessage(P, sender); }