void UITeamState::AddPlayer(ClientID const & clientId) { game_cl_GameState::PLAYERS_MAP & playersMap = Game().players; game_cl_GameState::PLAYERS_MAP::iterator pi = playersMap.find(clientId); VERIFY(pi != playersMap.end()); /*if (pi == playersMap.end()) { Msg("--- Player not found by ClientID = 0x%08x", clientId.value()); return; }*/ game_PlayerState *ps = pi->second; VERIFY(ps); /*if (!ps) { return; }*/ // if player not in my team... if (Game().IsPlayerInTeam(ps, myTeam) == false) { return; } #ifdef DEBUG Msg("--- UITeamState: adding player (ClientID = 0x%08x) to %d team (0x%08x)", clientId.value(), myTeam, this); #endif // #ifdef DEBUG UIPlayerItem* tempPlayerItem = xr_new<UIPlayerItem>(static_cast<ETeam>(ps->team), clientId, this, m_teamPanels); VERIFY2(tempPlayerItem, make_string("failed to create player with ClientID = 0x%08x", clientId.value()).c_str()); TScrollPanels::size_type panel_index = GetNeedScrollPanelIndex(); VERIFY(panel_index < m_scroll_panels.size()); m_scroll_panels[panel_index].first->AddWindow(tempPlayerItem, false); VERIFY2(mainUiXml, "main UI XML not initialized"); XML_NODE* tempRoot = mainUiXml->GetLocalRoot(); mainUiXml->SetLocalRoot(teamXmlNode); if (clientId == Game().local_svdpnid) { tempPlayerItem->Init(*mainUiXml, "local_player_item", 0); } else { tempPlayerItem->Init(*mainUiXml, "player_item", 0); } mainUiXml->SetLocalRoot(tempRoot); myPlayers.insert(std::make_pair(clientId, TPlayerItem(tempPlayerItem, panel_index))); }
void clientdata_proxy::make_config_dump(ClientID const & admin_id, ClientID const & cheater_id) { m_admin_id = admin_id; m_chearer_id = cheater_id; xrClientData* tmp_cheater = static_cast<xrClientData*>( Level().Server->GetClientByID(m_chearer_id)); if (!tmp_cheater) { Msg("! ERROR: SV: client [%u] not found ...", cheater_id.value()); return; } if (m_ft_server->is_receiving_active(cheater_id)) { Msg("! Receiving from client [%u] already active, please try later", cheater_id.value()); return; } m_cheater_digest = tmp_cheater->m_cdkey_digest; m_cheater_name = tmp_cheater->ps ? tmp_cheater->ps->getName() : "unknown"; NET_Packet ssr_packet; ssr_packet.w_begin (M_GAMEMESSAGE); ssr_packet.w_u32 (GAME_EVENT_MAKE_DATA); ssr_packet.w_u8 (e_configs_request); //make screenshot //alligning size to GAME_EVENT_PLAYER_KILLED message size ssr_packet.w_u16 (u16(Random.randI(2))); //food for thought for crackers :) ssr_packet.w_u16 (u16(Random.randI(2))); ssr_packet.w_u16 (u16(Random.randI(2))); ssr_packet.w_u8 (u8(Random.randI(2))); Level().Server->SecureSendTo (tmp_cheater, ssr_packet, net_flags(TRUE, TRUE)); file_transfer::receiving_state_callback_t receiving_cb = fastdelegate::MakeDelegate(this, &clientdata_proxy::download_config_callback); if (my_proxy_mem_file.size()) my_proxy_mem_file.clear(); m_first_receive = true; m_receiver = m_ft_server->start_receive_file(my_proxy_mem_file, m_chearer_id, receiving_cb); }
void game_sv_GameState::OnEvent (NET_Packet &tNetPacket, u16 type, u32 time, ClientID sender ) { switch (type) { case GAME_EVENT_PLAYER_CONNECTED: { ClientID ID; tNetPacket.r_clientID(ID); OnPlayerConnect(ID); }break; case GAME_EVENT_PLAYER_DISCONNECTED: { ClientID ID; tNetPacket.r_clientID(ID); string1024 PlayerName; tNetPacket.r_stringZ(PlayerName); u16 GameID = tNetPacket.r_u16(); OnPlayerDisconnect(ID, PlayerName, GameID); }break; case GAME_EVENT_PLAYER_KILLED: { }break ; case GAME_EVENT_ON_HIT: { u16 id_dest = tNetPacket.r_u16(); u16 id_src = tNetPacket.r_u16(); CSE_Abstract* e_src = get_entity_from_eid (id_src ); if(!e_src) // && !IsGameTypeSingle() added by andy because of Phantom does not have server entity { if( IsGameTypeSingle() ) break; game_PlayerState* ps = get_eid(id_src); if (!ps) break; id_src = ps->GameID; } OnHit(id_src, id_dest, tNetPacket); m_server->SendBroadcast (BroadcastCID,tNetPacket,net_flags(TRUE,TRUE)); }break; case GAME_EVENT_CREATE_CLIENT: { IClient* CL = (IClient*)m_server->ID_to_client(sender); VERIFY2(CL, "bad create client message GAME_EVENT_CREATE_CLIENT"); if ( CL == NULL ) { break; } CL->flags.bConnected = TRUE; m_server->AttachNewClient (CL); }break; case GAME_EVENT_PLAYER_AUTH: { IClient* CL = m_server->ID_to_client (sender); m_server->OnBuildVersionRespond(CL, tNetPacket); }break; case GAME_EVENT_CREATE_PLAYER_STATE: { xrClientData* CL = m_server->ID_to_client(sender); R_ASSERT2(CL, make_string("M_CREATE_PLAYER_STATE: client 0x%08x not found", sender.value() ).c_str() ); CL->ps = createPlayerState(&tNetPacket); CL->ps->m_online_time = Level().timeServer(); CL->ps->DeathTime = Device.dwTimeGlobal; if (psNET_direct_connect) //IsGameTypeSingle()) break; if (Level().IsDemoPlay()) break; if (g_dedicated_server && (CL == m_server->GetServerClient())) break; CheckNewPlayer(CL); }break; default: { string16 tmp; R_ASSERT3 (0,"Game Event not implemented!!!", itoa(type, tmp, 10)); }; }; }
void xrServer::Process_event (NET_Packet& P, ClientID sender) { # ifdef SLOW_VERIFY_ENTITIES VERIFY (verify_entities()); # endif u32 timestamp; u16 type; u16 destination; u32 MODE = net_flags(TRUE,TRUE); // correct timestamp with server-unique-time (note: direct message correction) P.r_u32 (timestamp ); // read generic info P.r_u16 (type ); P.r_u16 (destination); CSE_Abstract* receiver = game->get_entity_from_eid (destination); if (receiver) { R_ASSERT(receiver->owner); receiver->OnEvent (P,type,timestamp,sender); }; switch (type) { case GE_GAME_EVENT: { u16 game_event_type; P.r_u16(game_event_type); game->AddDelayedEvent(P,game_event_type,timestamp,sender); }break; case GE_INFO_TRANSFER: case GE_WPN_STATE_CHANGE: case GE_ZONE_STATE_CHANGE: case GE_ACTOR_JUMPING: case GEG_PLAYER_PLAY_HEADSHOT_PARTICLE: case GEG_PLAYER_ATTACH_HOLDER: case GEG_PLAYER_DETACH_HOLDER: case GEG_PLAYER_ITEM2SLOT: case GEG_PLAYER_ITEM2BELT: case GEG_PLAYER_ITEM2RUCK: case GE_GRENADE_EXPLODE: { SendBroadcast (BroadcastCID,P,MODE); }break; case GEG_PLAYER_ACTIVATEARTEFACT: { Process_event_activate (P,sender,timestamp,destination,P.r_u16(), true); break; }; case GE_INV_ACTION: { xrClientData* CL = ID_to_client(sender); if (CL) CL->net_Ready = TRUE; if (SV_Client) SendTo(SV_Client->ID, P, net_flags(TRUE, TRUE)); }break; case GE_RESPAWN: { CSE_Abstract* E = receiver; if (E) { R_ASSERT (E->s_flags.is(M_SPAWN_OBJECT_PHANTOM)); svs_respawn R; R.timestamp = timestamp + E->RespawnTime*1000; R.phantom = destination; q_respawn.insert (R); } } break; case GE_TRADE_BUY: case GE_OWNERSHIP_TAKE: { Process_event_ownership (P,sender,timestamp,destination); VERIFY (verify_entities()); }break; case GE_OWNERSHIP_TAKE_MP_FORCED: { Process_event_ownership (P,sender,timestamp,destination,TRUE); VERIFY (verify_entities()); }break; case GE_TRADE_SELL: case GE_OWNERSHIP_REJECT: case GE_LAUNCH_ROCKET: { Process_event_reject (P,sender,timestamp,destination,P.r_u16()); VERIFY (verify_entities()); }break; case GE_DESTROY: { Process_event_destroy (P,sender,timestamp,destination, NULL); VERIFY (verify_entities()); } break; case GE_TRANSFER_AMMO: { u16 id_entity; P.r_u16 (id_entity); CSE_Abstract* e_parent = receiver; // кто забирает (для своих нужд) CSE_Abstract* e_entity = game->get_entity_from_eid (id_entity); // кто отдает if (!e_entity) break; if (0xffff != e_entity->ID_Parent) break; // this item already taken xrClientData* c_parent = e_parent->owner; xrClientData* c_from = ID_to_client (sender); R_ASSERT (c_from == c_parent); // assure client ownership of event // Signal to everyone (including sender) SendBroadcast (BroadcastCID,P,MODE); // Perfrom real destroy entity_Destroy (e_entity ); VERIFY (verify_entities()); } break; case GE_HIT: case GE_HIT_STATISTIC: { P.r_pos -=2; if (type == GE_HIT_STATISTIC) { P.B.count -= 4; P.w_u32(sender.value()); }; game->AddDelayedEvent(P,GAME_EVENT_ON_HIT, 0, ClientID() ); } break; case GE_ASSIGN_KILLER: { u16 id_src; P.r_u16 (id_src); CSE_Abstract *e_dest = receiver; // кто умер // this is possible when hit event is sent before destroy event if (!e_dest) break; CSE_ALifeCreatureAbstract *creature = smart_cast<CSE_ALifeCreatureAbstract*>(e_dest); if (creature) creature->set_killer_id( id_src ); // Msg ("[%d][%s] killed [%d][%s]",id_src,id_src==u16(-1) ? "UNKNOWN" : game->get_entity_from_eid(id_src)->name_replace(),id_dest,e_dest->name_replace()); break; } case GE_CHANGE_VISUAL: { CSE_Visual* visual = smart_cast<CSE_Visual*>(receiver); VERIFY(visual); string256 tmp; P.r_stringZ (tmp); visual->set_visual (tmp); }break; case GE_DIE: { // Parse message u16 id_dest = destination, id_src; P.r_u16 (id_src); xrClientData *l_pC = ID_to_client(sender); VERIFY (game && l_pC); #ifndef MASTER_GOLD if ((game->Type() != eGameIDSingle) && l_pC && l_pC->owner) { Msg ("* [%2d] killed by [%2d] - sended by [%s:%2d]", id_dest, id_src, game->get_option_s(*l_pC->name,"name","Player"), l_pC->owner->ID); } #endif // #ifndef MASTER_GOLD CSE_Abstract* e_dest = receiver; // кто умер // this is possible when hit event is sent before destroy event if (!e_dest) break; #ifndef MASTER_GOLD if (game->Type() != eGameIDSingle) Msg ("* [%2d] is [%s:%s]", id_dest, *e_dest->s_name, e_dest->name_replace()); #endif // #ifndef MASTER_GOLD CSE_Abstract* e_src = game->get_entity_from_eid (id_src ); // кто убил if (!e_src) { xrClientData* C = (xrClientData*) game->get_client(id_src); if (C) e_src = C->owner; }; VERIFY (e_src); if (!e_src) { Msg("! ERROR: SV: src killer not exist."); return; } // R_ASSERT2 (e_dest && e_src, "Killer or/and being killed are offline or not exist at all :("); #ifndef MASTER_GOLD if (game->Type() != eGameIDSingle) Msg ("* [%2d] is [%s:%s]", id_src, *e_src->s_name, e_src->name_replace()); #endif // #ifndef MASTER_GOLD game->on_death (e_dest,e_src); xrClientData* c_src = e_src->owner; // клиент, чей юнит убил if (c_src->owner->ID == id_src) { // Main unit P.w_begin (M_EVENT); P.w_u32 (timestamp); P.w_u16 (type); P.w_u16 (destination); P.w_u16 (id_src); P.w_clientID (c_src->ID); } SendBroadcast (BroadcastCID,P,MODE); ////////////////////////////////////////////////////////////////////////// // if (game->Type() == eGameIDSingle) { P.w_begin (M_EVENT); P.w_u32 (timestamp); P.w_u16 (GE_KILL_SOMEONE); P.w_u16 (id_src); P.w_u16 (destination); SendTo (c_src->ID, P, net_flags(TRUE, TRUE)); } ////////////////////////////////////////////////////////////////////////// VERIFY (verify_entities()); } break; case GE_ADDON_ATTACH: case GE_ADDON_DETACH: case GE_CHANGE_POS: { SendTo(SV_Client->ID, P, net_flags(TRUE, TRUE)); }break; case GE_INSTALL_UPGRADE: { shared_str upgrade_id; P.r_stringZ ( upgrade_id ); CSE_ALifeInventoryItem* iitem = smart_cast<CSE_ALifeInventoryItem*>( receiver ); if ( !iitem ) { break; } iitem->add_upgrade ( upgrade_id ); }break; case GEG_PLAYER_DISABLE_SPRINT: case GEG_PLAYER_WEAPON_HIDE_STATE: { SendTo (SV_Client->ID, P, net_flags(TRUE, TRUE)); # ifdef SLOW_VERIFY_ENTITIES VERIFY (verify_entities()); # endif }break; case GEG_PLAYER_ACTIVATE_SLOT: case GEG_PLAYER_ITEM_EAT: { SendTo(SV_Client->ID, P, net_flags(TRUE, TRUE)); # ifdef SLOW_VERIFY_ENTITIES VERIFY (verify_entities()); # endif }break; case GEG_PLAYER_ITEM_SELL: { game->OnPlayer_Sell_Item(sender, P); }break; case GE_TELEPORT_OBJECT: { game->teleport_object (P,destination); }break; case GE_ADD_RESTRICTION: { game->add_restriction (P,destination); }break; case GE_REMOVE_RESTRICTION: { game->remove_restriction(P,destination); }break; case GE_REMOVE_ALL_RESTRICTIONS: { game->remove_all_restrictions(P,destination); }break; case GE_MONEY: { CSE_Abstract *e_dest = receiver; CSE_ALifeTraderAbstract* pTa = smart_cast<CSE_ALifeTraderAbstract*>(e_dest); pTa->m_dwMoney = P.r_u32(); }break; case GE_FREEZE_OBJECT: break; default: R_ASSERT2 (0,"Game Event not implemented!!!"); break; } }
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); }