void CLevel::OnBuildVersionChallenge () { NET_Packet P; P.w_begin (M_CL_AUTH); u64 auth = FS.auth_get(); P.w_u64 (auth); Send (P, net_flags(TRUE, TRUE, TRUE, TRUE)); };
void BattlEyeServer::SendPacket( int player, void* packet, int len ) { NET_Packet P; P.w_begin( M_BATTLEYE ); P.w_u32( len ); P.w( packet, len ); Level().Server->SendTo( (u32)player, P, net_flags() ); }
void WeaponUsageStatistic::Send_Check_Respond() { if (!OnServer()) return; NET_Packet P; string1024 STrue, SFalse; for (u32 i=0; i<m_Requests.size(); i++) { Bullet_Check_Array& BChA_Request = m_Requests[i]; if (BChA_Request.Requests.empty()) continue; Bullet_Check_Respond_True* pSTrue = (Bullet_Check_Respond_True*) STrue; u32* pSFalse = (u32*) SFalse; //----------------------------------------------------- u32 NumFalse = 0; u32 NumTrue = 0; u32 j=0; while (j<BChA_Request.Requests.size()) { Bullet_Check_Request& curBChR = BChA_Request.Requests[j]; if (!curBChR.Processed) { j++; continue; } else { if (curBChR.Result) { pSTrue->BulletID = curBChR.BulletID; pSTrue->BoneID = curBChR.BoneID; pSTrue++; // HitChecksRespondedTrue++; NumTrue++; } else { *(pSFalse++) = curBChR.BulletID; // HitChecksRespondedFalse++; NumFalse++; }; // HitChecksResponded++; //----------------------------------------------------- *(BChA_Request.Requests.begin()+j) = BChA_Request.Requests.back(); BChA_Request.Requests.pop_back(); } } //----------------------------------------------------- P.w_begin(M_BULLET_CHECK_RESPOND); // Msg("%d-%d || %d-%d", NumFalse, BChA_Request.NumFalse, NumTrue, BChA_Request.NumTrue); P.w_u8(BChA_Request.NumFalse); BChA_Request.NumFalse = 0; P.w_u8(BChA_Request.NumTrue); BChA_Request.NumTrue = 0; if ((char*)pSFalse != (char*)SFalse) P.w(SFalse, u32((char*)pSFalse-(char*)SFalse)); if ((char*)pSTrue != (char*)STrue) P.w(STrue, u32((char*)pSTrue-(char*)STrue)); //----------------------------------------------------- ClientID ClID; ClID.set(BChA_Request.SenderID); if(Level().Server) Level().Server->SendTo(ClID, P); }; }
void SHit::Write_Packet (NET_Packet &Packet) { Packet.w_begin (M_EVENT); Packet.w_u32 (Time); Packet.w_u16 (u16(PACKET_TYPE&0xffff)); Packet.w_u16 (u16(DestID&0xffff)); Write_Packet_Cont (Packet); };
void CSE_Abstract::Spawn_Write (NET_Packet &tNetPacket, BOOL bLocal) { // generic tNetPacket.w_begin (M_SPAWN); tNetPacket.w_stringZ (s_name ); tNetPacket.w_stringZ (s_name_replace ? s_name_replace : ""); tNetPacket.w_u8 (s_gameid ); tNetPacket.w_u8 (s_RP ); tNetPacket.w_vec3 (o_Position ); tNetPacket.w_vec3 (o_Angle ); tNetPacket.w_u16 (RespawnTime ); tNetPacket.w_u16 (ID ); tNetPacket.w_u16 (ID_Parent ); tNetPacket.w_u16 (ID_Phantom ); s_flags.set (M_SPAWN_VERSION,TRUE); if (bLocal) tNetPacket.w_u16 (u16(s_flags.flags|M_SPAWN_OBJECT_LOCAL) ); else tNetPacket.w_u16 (u16(s_flags.flags&~(M_SPAWN_OBJECT_LOCAL|M_SPAWN_OBJECT_ASPLAYER))); tNetPacket.w_u16 (SPAWN_VERSION); tNetPacket.w_u16 (script_server_object_version()); //client object custom data serialization SAVE u16 client_data_size = (u16)client_data.size(); //не может быть больше 256 байт tNetPacket.w_u16 (client_data_size); // Msg ("SERVER:saving:save:%d bytes:%d:%s",client_data_size,ID,s_name_replace ? s_name_replace : ""); if (client_data_size > 0) { tNetPacket.w (&*client_data.begin(),client_data_size); } tNetPacket.w (&m_tSpawnID, sizeof(m_tSpawnID)); // tNetPacket.w_float (m_spawn_probability); // tNetPacket.w_u32 (m_spawn_flags.get()); // tNetPacket.w_stringZ (m_spawn_control); // tNetPacket.w_u32 (m_max_spawn_count); // tNetPacket.w_u64 (m_min_spawn_interval); // tNetPacket.w_u64 (m_max_spawn_interval); #ifdef XRSE_FACTORY_EXPORTS CScriptValueContainer::assign(); #endif // write specific data u32 position = tNetPacket.w_tell(); tNetPacket.w_u16 (0); STATE_Write (tNetPacket); u16 size = u16(tNetPacket.w_tell() - position); //#ifdef XRSE_FACTORY_EXPORTS R_ASSERT3 ((m_tClassID == CLSID_SPECTATOR) || (size > sizeof(size)),"object isn't successfully saved, get your backup :(",name_replace()); //#endif tNetPacket.w_seek (position,&size,sizeof(u16)); }
void CChangeLevelWnd::OnOk() { Game().StartStopMenu (this, true); NET_Packet p; p.w_begin (M_CHANGE_LEVEL); p.w (&m_game_vertex_id,sizeof(m_game_vertex_id)); p.w (&m_level_vertex_id,sizeof(m_level_vertex_id)); p.w_vec3 (m_position); p.w_vec3 (m_angles); Level().Send (p,net_flags(TRUE)); }
void CLevel::OnBuildVersionChallenge () { NET_Packet P; P.w_begin (M_CL_AUTH); #ifdef DEBUG u64 auth = MP_DEBUG_AUTH; #else u64 auth = FS.auth_get(); #endif //#ifdef DEBUG P.w_u64 (auth); SecureSend (P, net_flags(TRUE, TRUE, TRUE, TRUE)); };
void CLevel::SendPingMessage () { u32 CurTime = timeServer_Async(); if (CurTime < (m_dwCL_PingLastSendTime + m_dwCL_PingDeltaSend)) return; u32 m_dwCL_PingLastSendTime = CurTime; NET_Packet P; P.w_begin (M_CL_PING_CHALLENGE); P.w_u32 (m_dwCL_PingLastSendTime); P.w_u32 (m_dwCL_PingLastSendTime); P.w_u32 (m_dwRealPing); Send (P, net_flags(FALSE)); };
void WeaponUsageStatistic::OnUpdateRequest(NET_Packet*) { if (aPlayersStatistic.empty()) return; Player_Statistic& PS = aPlayersStatistic.front(); //------------------------------------------------- NET_Packet P; P.w_begin(M_STATISTIC_UPDATE_RESPOND); //------------------------------------------------- P.w_stringZ(PS.PName); PS.net_save(&P); //------------------------------------------------- Level().Send(P); };
void xrGameSpyServer::OnCDKey_ReValidation (int LocalID, int hint, char* challenge) { ClientID ID; ID.set(u32(LocalID)); xrGameSpyClientData* CL = (xrGameSpyClientData*) ID_to_client(ID); if (!CL) return; strcpy_s(CL->m_pChallengeString, challenge); CL->m_iCDKeyReauthHint = hint; //--------- Send Respond --------------------------------------------- NET_Packet P; P.w_begin (M_GAMESPY_CDKEY_VALIDATION_CHALLENGE); P.w_u8(1); P.w_stringZ(CL->m_pChallengeString); SendTo(CL->ID, P); }
void WeaponUsageStatistic::Update() { if (!CollectData()) return; if (Level().timeServer() < (m_dwLastUpdateTime + m_dwUpdateTimeDelta)) { //--------------------------------------------- m_dwLastUpdateTime = Level().timeServer(); //--------------------------------------------- NET_Packet P; P.w_begin (M_STATISTIC_UPDATE); P.w_u32 (Level().timeServer()); Level().Send(P); } };
void xrGameSpyServer::SendChallengeString_2_Client (IClient* C) { if (!C) return; xrGameSpyClientData* pClient = (xrGameSpyClientData*) C; m_GCDServer.CreateRandomChallenge(pClient->m_pChallengeString, 8); //--------- Send Respond --------------------------------------------- NET_Packet P; P.w_begin (M_GAMESPY_CDKEY_VALIDATION_CHALLENGE); P.w_u8(0); P.w_stringZ(pClient->m_pChallengeString); SendTo(pClient->ID, P); }
void xrServer::SendConnectionData(IClient* _CL) { g_perform_spawn_ids.clear_not_free(); xrClientData* CL = (xrClientData*)_CL; NET_Packet P; u32 mode = net_flags(TRUE,TRUE); // Replicate current entities on to this client xrS_entities::iterator I=entities.begin(),E=entities.end(); for (; I!=E; ++I) I->second->net_Processed = FALSE; for (I=entities.begin(); I!=E; ++I) Perform_connect_spawn (I->second,CL,P); // Send "finished" signal P.w_begin (M_SV_CONFIG_FINISHED); SendTo (CL->ID,P,mode); };
bool xrServer::NeedToCheckClient_BuildVersion (IClient* CL) { //#ifdef DEBUG //return false; //#else if (g_SV_Disable_Auth_Check) return false; CL->flags.bVerified = FALSE; NET_Packet P; P.w_begin (M_AUTH_CHALLENGE); SendTo (CL->ID, P); return true; //#endif };
virtual void Execute(LPCSTR args) { if ((GameID() == GAME_SINGLE) &&ai().get_alife()) { float id1 = 0.0f; sscanf(args ,"%f",&id1); if (id1 < 2.0f) Msg("Invalid online distance! (%.4f)",id1); else { NET_Packet P; P.w_begin (M_SWITCH_DISTANCE); P.w_float (id1); Level().Send (P,net_flags(TRUE,TRUE)); } } else Log("!Not a single player game!"); }
void CLevel::ClientSave () { NET_Packet P; u32 start = 0; for (;;) { P.w_begin (M_SAVE_PACKET); start = Objects_net_Save(&P, start, max_objects_size_in_save); if (P.B.count>2) Send (P, net_flags(FALSE)); else break; } }
void CALifeSimulatorBase::create(CSE_ALifeDynamicObject *&i, CSE_ALifeDynamicObject *j, const _SPAWN_ID &tSpawnID) { CSE_Abstract *tpSE_Abstract = F_entity_Create(*j->s_name); R_ASSERT3 (tpSE_Abstract,"Cannot find item with section",*j->s_name); i = smart_cast<CSE_ALifeDynamicObject*>(tpSE_Abstract); R_ASSERT2 (i,"Non-ALife object in the 'game.spawn'"); NET_Packet tNetPacket; j->Spawn_Write (tNetPacket,TRUE); i->Spawn_Read (tNetPacket); tNetPacket.w_begin (M_UPDATE); j->UPDATE_Write (tNetPacket); u16 id; tNetPacket.r_begin (id); i->UPDATE_Read (tNetPacket); R_ASSERT3 (!(i->used_ai_locations()) || (i->m_tNodeID != u32(-1)),"Invalid vertex for object ",i->name_replace()); i->m_tSpawnID = tSpawnID; if (!graph().actor() && smart_cast<CSE_ALifeCreatureActor*>(i)) i->ID = 0; else i->ID = server().PerformIDgen(0xffff); register_object (i,true); i->m_bALifeControl = true; CSE_ALifeMonsterAbstract *monster = smart_cast<CSE_ALifeMonsterAbstract*>(i); if (monster) graph().assign (monster); CSE_ALifeGroupAbstract *group = smart_cast<CSE_ALifeGroupAbstract*>(i); if (group) { group->m_tpMembers.resize(group->m_wCount); OBJECT_IT I = group->m_tpMembers.begin(); OBJECT_IT E = group->m_tpMembers.end(); for ( ; I != E; ++I) { CSE_Abstract *object = create (group,j); *I = object->ID; } } else i->spawn_supplies (); i->on_spawn (); }
void xrServer::Perform_reject(CSE_Abstract* what, CSE_Abstract* from, int delta) { R_ASSERT (what && from); R_ASSERT (what->ID_Parent == from->ID); NET_Packet P; u32 time = Device.dwTimeGlobal - delta; P.w_begin (M_EVENT); P.w_u32 (time); P.w_u16 (GE_OWNERSHIP_REJECT); P.w_u16 (from->ID); P.w_u16 (what->ID); P.w_u8 (1); Process_event_reject (P,BroadcastCID,time,from->ID,what->ID); }
void xrServer::SendConnectResult(IClient* CL, u8 res, u8 res1, char* ResultStr) { NET_Packet P; P.w_begin (M_CLIENT_CONNECT_RESULT); P.w_u8 (res); P.w_u8 (res1); P.w_stringZ (ResultStr); if (SV_Client && SV_Client == CL) P.w_u8(1); else P.w_u8(0); P.w_stringZ(Level().m_caServerOptions); SendTo (CL->ID, P); };
void xrServer::Perform_destroy (CSE_Abstract* object, u32 mode) { R_ASSERT (object); R_ASSERT (object->ID_Parent == 0xffff); #ifdef DEBUG # ifdef SLOW_VERIFY_ENTITIES verify_entities (); # endif #endif while (!object->children.empty()) { CSE_Abstract *child = game->get_entity_from_eid(object->children.back()); R_ASSERT2 (child, make_string("child registered but not found [%d]",object->children.back())); // Msg ("SLS-CLEAR : REJECT [%s][%s] FROM [%s][%s]",child->name(),child->name_replace(),object->name(),object->name_replace()); Perform_reject (child,object,2*NET_Latency); #ifdef DEBUG # ifdef SLOW_VERIFY_ENTITIES verify_entities (); # endif #endif Perform_destroy (child,mode); } // Msg ("SLS-CLEAR : DESTROY [%s][%s]",object->name(),object->name_replace()); u16 object_id = object->ID; entity_Destroy (object); #ifdef DEBUG # ifdef SLOW_VERIFY_ENTITIES verify_entities (); # endif #endif NET_Packet P; P.w_begin (M_EVENT); P.w_u32 (Device.dwTimeGlobal - 2*NET_Latency); P.w_u16 (GE_DESTROY); P.w_u16 (object_id); ClientID clientID; clientID.setBroadcast (); SendBroadcast (clientID,P,mode); }
void CLevel::OnGameSpyChallenge (NET_Packet* P) { Msg("xrGS::CDKey::Level : Responding on Challenge"); u8 Reauth = P->r_u8(); string64 ChallengeStr; P->r_stringZ(ChallengeStr); //-------------------------------------------------------------------- string128 ResponseStr=""; CGameSpy_GCD_Client GCD; GCD.CreateRespond(ResponseStr, ChallengeStr, Reauth); //--------- Send Respond --------------------------------------------- NET_Packet newP; newP.w_begin (M_GAMESPY_CDKEY_VALIDATION_CHALLENGE_RESPOND); newP.w_stringZ(ResponseStr); Send(newP, net_flags(TRUE, TRUE, TRUE, TRUE)); // g_pGamePersistent->LoadTitle("st_validating_cdkey"); };
void BattlEyeServer::KickPlayer( int player, char* reason ) { xrClientData* tmp_client = static_cast<xrClientData*>( Level().Server->GetClientByID(static_cast<ClientID>(player)) ); if (!tmp_client) { Msg( "! No such player found : %i", player ); return; } LPCSTR reason2; STRCONCAT( reason2, "@", tmp_client->ps->getName(), " ", CStringTable().translate("ui_st_kicked_by_battleye").c_str(), " ", reason ); Msg( reason2 ); if( g_be_message_out )// self { if ( Level().game ) { Level().game->CommonMessageOut( reason2 + 1 ); } } if (Level().Server->GetServerClient() == tmp_client) { // " Disconnecting : %s ! Server's Client kicked by BattlEye Server. Reason: %s", NET_Packet P; P.w_begin ( M_GAMEMESSAGE ); P.w_u32 ( GAME_EVENT_SERVER_DIALOG_MESSAGE ); P.w_stringZ ( reason2 ); Level().Server->SendBroadcast( tmp_client->ID, P ); // to all, except self Level().OnSessionTerminate( reason2 ); //to self Engine.Event.Defer("KERNEL:disconnect"); return; } Level().Server->AddCheater(shared_str(reason2), tmp_client->ID); }
CSE_Abstract *CALifeSimulatorBase::create(CSE_ALifeGroupAbstract *tpALifeGroupAbstract, CSE_ALifeDynamicObject *j) { NET_Packet tNetPacket; LPCSTR S = pSettings->r_string(tpALifeGroupAbstract->base()->s_name,"monster_section"); CSE_Abstract *l_tpAbstract = F_entity_Create(S); R_ASSERT2 (l_tpAbstract,"Can't create entity."); CSE_ALifeDynamicObject *k = smart_cast<CSE_ALifeDynamicObject*>(l_tpAbstract); R_ASSERT2 (k,"Non-ALife object in the 'game.spawn'"); j->Spawn_Write (tNetPacket,TRUE); k->Spawn_Read (tNetPacket); tNetPacket.w_begin (M_UPDATE); j->UPDATE_Write (tNetPacket); u16 id; tNetPacket.r_begin (id); k->UPDATE_Read (tNetPacket); k->s_name = S; k->m_tSpawnID = j->m_tSpawnID; k->ID = server().PerformIDgen(0xffff); k->m_bDirectControl = false; k->m_bALifeControl = true; string256 s_name_replace; strcpy_s (s_name_replace,*k->s_name); if (k->ID < 1000) strcat (s_name_replace,"0"); if (k->ID < 100) strcat (s_name_replace,"0"); if (k->ID < 10) strcat (s_name_replace,"0"); string16 S1; strcat (s_name_replace,itoa(k->ID,S1,10)); k->set_name_replace (s_name_replace); register_object (k,true); k->spawn_supplies (); k->on_spawn (); return (k); }
BOOL CLevel::Connect2Server (LPCSTR options) { NET_Packet P; m_bConnectResultReceived = false ; m_bConnectResult = true ; if (!Connect(options)) return FALSE; //--------------------------------------------------------------------------- if(psNET_direct_connect) m_bConnectResultReceived = true; while (!m_bConnectResultReceived) { ClientReceive (); Sleep (5); if(Server) Server->Update() ; } Msg ("%c client : connection %s - <%s>", m_bConnectResult ?'*':'!', m_bConnectResult ? "accepted" : "rejected", m_sConnectResult.c_str()); if (!m_bConnectResult) { OnConnectRejected (); Disconnect () ; return FALSE ; }; if(psNET_direct_connect) net_Syncronised = TRUE; else net_Syncronize (); while (!net_IsSyncronised()) { }; //--------------------------------------------------------------------------- P.w_begin (M_CLIENT_REQUEST_CONNECTION_DATA); Send (P); //--------------------------------------------------------------------------- return TRUE; };
void CLevelChanger::feel_touch_new (CObject *tpObject) { CActor* l_tpActor = smart_cast<CActor*>(tpObject); VERIFY (l_tpActor); if(m_bSilentMode) { NET_Packet p; p.w_begin (M_CHANGE_LEVEL); p.w (&m_game_vertex_id,sizeof(m_game_vertex_id)); p.w (&m_level_vertex_id,sizeof(m_level_vertex_id)); p.w_vec3 (m_position); p.w_vec3 (m_angles); Level().Send (p,net_flags(TRUE)); }else{ Fvector p,r; bool b = get_reject_pos(p,r); CUIGameSP* pGameSP = smart_cast<CUIGameSP*>(HUD().GetUI()->UIGame()); if(pGameSP)pGameSP->ChangeLevel(m_game_vertex_id,m_level_vertex_id,m_position,m_angles,p,r,b); m_entrance_time = Device.fTimeGlobal; } }
void CLevel::ClearAllObjects () { bool ParentFound = true; while (ParentFound) { ProcessGameEvents (); u32 CLObjNum = Level().Objects.o_count(); ParentFound = false; for (u32 i=0; i<CLObjNum; i++) { CObject* pObj = Level().Objects.o_get_by_iterator(i); if (!pObj->H_Parent()) continue; //----------------------------------------------------------- NET_Packet GEN; GEN.w_begin (M_EVENT); //------------------ --------------------------- GEN.w_u32 (Level().timeServer()); GEN.w_u16 (GE_OWNERSHIP_REJECT); GEN.w_u16 (pObj->H_Parent()->ID()); GEN.w_u16 (u16(pObj->ID())); game_events->insert (GEN); if (g_bDebugEvents) ProcessGameEvents (); //------------------------------------------------------------- ParentFound = true; //------------------------------------------------------------- #ifdef DEBUG Msg ("Rejection of %s[%d] from %s[%d]", *(pObj->cNameSect()), pObj->ID(), *(pObj->H_Parent()->cNameSect()), pObj->H_Parent()->ID()); #endif }; }; u32 CLObjNum = Level().Objects.o_count(); for (u32 i=0; i<CLObjNum; i++) { CObject* pObj = Level().Objects.o_get_by_iterator(i); R_ASSERT(pObj->H_Parent()==NULL); //----------------------------------------------------------- NET_Packet GEN; GEN.w_begin (M_EVENT); //--------------------------------------------- GEN.w_u32 (Level().timeServer()); GEN.w_u16 (GE_DESTROY); GEN.w_u16 (u16(pObj->ID())); game_events->insert (GEN); if (g_bDebugEvents) ProcessGameEvents(); //------------------------------------------------------------- ParentFound = true; //------------------------------------------------------------- #ifdef DEBUG Msg ("Destruction of %s[%d]", *(pObj->cNameSect()), pObj->ID()); #endif }; ProcessGameEvents(); };
void CLevel::ProcessGameEvents () { // Game events { NET_Packet P; u32 svT = timeServer()-NET_Latency; /* if (!game_events->queue.empty()) Msg("- d[%d],ts[%d] -- E[svT=%d],[evT=%d]",Device.dwTimeGlobal,timeServer(),svT,game_events->queue.begin()->timestamp); */ #ifdef SPAWN_ANTIFREEZE while (spawn_events->available(svT)) { u16 ID, dest, type; spawn_events->get(ID, dest, type, P); game_events->insert(P); } u32 avail_time = 5; u32 elps = Device.frame_elapsed(); if (elps < 30) avail_time = 33 - elps; u32 work_limit = elps + avail_time; #endif while (game_events->available(svT)) { u16 ID,dest,type; game_events->get (ID,dest,type,P); #ifdef SPAWN_ANTIFREEZE // не отправлять события не заспавненным объектам if (g_bootComplete && M_EVENT == ID && PostponedSpawn(dest)) { spawn_events->insert(P); continue; } if (g_bootComplete && M_SPAWN == ID && Device.frame_elapsed() > work_limit) // alpet: позволит плавнее выводить объекты в онлайн, без заметных фризов { u16 parent_id; GetSpawnInfo(P, parent_id); //------------------------------------------------- if (parent_id < 0xffff) // откладывать спавн только объектов в контейнеры { //if (!spawn_events->available(svT)) //Msg("* ProcessGameEvents, spawn event postponed. Events rest = %d", game_events->queue.size()); spawn_events->insert(P); continue; } } #endif switch (ID) { case M_SPAWN: { u16 dummy16; P.r_begin(dummy16); cl_Process_Spawn(P); }break; case M_EVENT: { cl_Process_Event(dest, type, P); }break; case M_MOVE_PLAYERS: { u8 Count = P.r_u8(); for (u8 i=0; i<Count; i++) { u16 ID = P.r_u16(); Fvector NewPos, NewDir; P.r_vec3(NewPos); P.r_vec3(NewDir); CActor* OActor = smart_cast<CActor*>(Objects.net_Find (ID)); if (0 == OActor) break; OActor->MoveActor(NewPos, NewDir); }; NET_Packet PRespond; PRespond.w_begin(M_MOVE_PLAYERS_RESPOND); Send(PRespond, net_flags(TRUE, TRUE)); }break; case M_STATISTIC_UPDATE: { if (GameID() != eGameIDSingle) Game().m_WeaponUsageStatistic->OnUpdateRequest(&P); }break; case M_FILE_TRANSFER: { if (m_file_transfer) //in case of net_Stop m_file_transfer->on_message(&P); }break; case M_GAMEMESSAGE: { Game().OnGameMessage(P); }break; default: { VERIFY(0); }break; } } } if (OnServer() && GameID()!= eGameIDSingle) Game().m_WeaponUsageStatistic->Send_Check_Respond(); }
void CActor::IR_OnKeyboardPress(int cmd) { if(hud_adj_mode && pInput->iGetAsyncKeyState(DIK_LSHIFT)) return; if (Remote()) return; if (IsTalking()) return; if (m_input_external_handler && !m_input_external_handler->authorized(cmd)) return; switch (cmd) { case kWPN_FIRE: { /* XEM #95 */ //if( (mstate_wishful & mcLookout) && !IsGameTypeSingle() ) return; u16 slot = inventory().GetActiveSlot(); if(inventory().ActiveItem() && (slot==INV_SLOT_3 || slot==INV_SLOT_2) ) mstate_wishful &=~mcSprint; //----------------------------- if (OnServer()) { NET_Packet P; P.w_begin(M_PLAYER_FIRE); P.w_u16(ID()); u_EventSend(P); } }break; default: { }break; } if (!g_Alive()) return; if(m_holder && kUSE != cmd) { m_holder->OnKeyboardPress (cmd); if(m_holder->allowWeapon() && inventory().Action((u16)cmd, CMD_START)) return; return; }else if(inventory().Action((u16)cmd, CMD_START)) return; #ifdef DEBUG if(psActorFlags.test(AF_NO_CLIP)) { NoClipFly(cmd); return; } #endif //DEBUG switch(cmd) { case kJUMP: { mstate_wishful |= mcJump; }break; case kSPRINT_TOGGLE: { mstate_wishful ^= mcSprint; }break; case kCROUCH: { if( psActorFlags.test(AF_CROUCH_TOGGLE) ) mstate_wishful ^= mcCrouch; }break; case kCAM_1: cam_Set (eacFirstEye); break; case kCAM_2: cam_Set (eacLookAt); break; case kCAM_3: cam_Set (eacFreeLook); break; case kNIGHT_VISION: { SwitchNightVision(); break; } case kTORCH: { SwitchTorch(); break; } case kDETECTOR: { PIItem det_active = inventory().ItemFromSlot(DETECTOR_SLOT); if(det_active) { CCustomDetector* det = smart_cast<CCustomDetector*>(det_active); det->ToggleDetector (g_player_hud->attached_item(0)!=NULL); return; } }break; /* case kFLARE:{ PIItem fl_active = inventory().ItemFromSlot(FLARE_SLOT); if(fl_active) { CFlare* fl = smart_cast<CFlare*>(fl_active); fl->DropFlare (); return ; } PIItem fli = inventory().Get(CLSID_DEVICE_FLARE, true); if(!fli) return; CFlare* fl = smart_cast<CFlare*>(fli); if(inventory().Slot(fl)) fl->ActivateFlare (); }break; */ case kUSE: ActorUse(); break; case kDROP: b_DropActivated = TRUE; f_DropPower = 0; break; case kNEXT_SLOT: { OnNextWeaponSlot(); }break; case kPREV_SLOT: { OnPrevWeaponSlot(); }break; case kQUICK_USE_1: case kQUICK_USE_2: case kQUICK_USE_3: case kQUICK_USE_4: { const shared_str& item_name = g_quick_use_slots[cmd-kQUICK_USE_1]; if(item_name.size()) { PIItem itm = inventory().GetAny(item_name.c_str()); if(itm) { if (IsGameTypeSingle()) { inventory().Eat (itm); } else { inventory().ClientEat (itm); } StaticDrawableWrapper* _s = CurrentGameUI()->AddCustomStatic("item_used", true); string1024 str; strconcat (sizeof(str),str,*CStringTable().translate("st_item_used"),": ", itm->NameItem()); _s->wnd()->TextItemControl()->SetText(str); CurrentGameUI()->GetActorMenu().m_pQuickSlot->ReloadReferences(this); } } }break; } }
void game_sv_GameState::GenerateGameMessage (NET_Packet &P) { P.w_begin(M_GAMEMESSAGE); };
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; } }