void CLevelChanger::feel_touch_new (CObject *tpObject) { CActor* l_tpActor = smart_cast<CActor*>(tpObject); VERIFY (l_tpActor); if (!l_tpActor->g_Alive()) return; 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)); return; } 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 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 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 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 CAI_Stalker::net_Export (NET_Packet& P) { R_ASSERT (Local()); // export last known packet R_ASSERT (!NET.empty()); net_update& N = NET.back(); // P.w_float (inventory().TotalWeight()); // P.w_u32 (m_dwMoney); P.w_float (GetfHealth()); P.w_u32 (N.dwTimeStamp); P.w_u8 (0); P.w_vec3 (N.p_pos); P.w_float /*w_angle8*/ (N.o_model); P.w_float /*w_angle8*/ (N.o_torso.yaw); P.w_float /*w_angle8*/ (N.o_torso.pitch); P.w_float /*w_angle8*/ (N.o_torso.roll); P.w_u8 (u8(g_Team())); P.w_u8 (u8(g_Squad())); P.w_u8 (u8(g_Group())); float f1 = 0; GameGraph::_GRAPH_ID l_game_vertex_id = ai_location().game_vertex_id(); P.w (&l_game_vertex_id, sizeof(l_game_vertex_id)); P.w (&l_game_vertex_id, sizeof(l_game_vertex_id)); // P.w (&f1, sizeof(f1)); // P.w (&f1, sizeof(f1)); if (ai().game_graph().valid_vertex_id(l_game_vertex_id)) { f1 = Position().distance_to (ai().game_graph().vertex(l_game_vertex_id)->level_point()); P.w (&f1, sizeof(f1)); f1 = Position().distance_to (ai().game_graph().vertex(l_game_vertex_id)->level_point()); P.w (&f1, sizeof(f1)); } else { P.w (&f1, sizeof(f1)); P.w (&f1, sizeof(f1)); } P.w_stringZ (m_sStartDialog); }
void CAI_Rat::net_Export(NET_Packet& P) { R_ASSERT (Local()); // export last known packet R_ASSERT (!NET.empty()); net_update& N = NET.back(); P.w_float (GetfHealth()); P.w_u32 (N.dwTimeStamp); P.w_u8 (0); P.w_vec3 (N.p_pos); P.w_float (N.o_model); P.w_float (N.o_torso.yaw); P.w_float (N.o_torso.pitch); P.w_float (N.o_torso.roll); P.w_u8 (u8(g_Team())); P.w_u8 (u8(g_Squad())); P.w_u8 (u8(g_Group())); GameGraph::_GRAPH_ID l_game_vertex_id = ai_location().game_vertex_id(); P.w (&l_game_vertex_id, sizeof(l_game_vertex_id)); P.w (&l_game_vertex_id, sizeof(l_game_vertex_id)); // P.w (&m_fGoingSpeed, sizeof(m_fGoingSpeed)); // P.w (&m_fGoingSpeed, sizeof(m_fGoingSpeed)); float f1 = 0; if (ai().game_graph().valid_vertex_id(l_game_vertex_id)) { f1 = Position().distance_to (ai().game_graph().vertex(l_game_vertex_id)->level_point()); P.w (&f1, sizeof(f1)); f1 = Position().distance_to (ai().game_graph().vertex(l_game_vertex_id)->level_point()); P.w (&f1, sizeof(f1)); } else { P.w (&f1, sizeof(f1)); P.w (&f1, sizeof(f1)); } CEatableItem::net_Export(P); }
void CSE_ALifeItemPDA::STATE_Write (NET_Packet &tNetPacket) { inherited::STATE_Write (tNetPacket); tNetPacket.w (&m_original_owner,sizeof(m_original_owner)); #ifdef XRGAME_EXPORTS tNetPacket.w_stringZ (m_specific_character); tNetPacket.w_stringZ (m_info_portion); #else shared_str tmp_1 = NULL; shared_str tmp_2 = NULL; tNetPacket.w_stringZ (tmp_1); tNetPacket.w_stringZ (tmp_2); #endif }
void xrServer::Update () { NET_Packet Packet; u32 position; csPlayers.Enter (); VERIFY (verify_entities()); // game update game->ProcessDelayedEvent(); game->Update (); // spawn queue u32 svT = Device.TimerAsync(); while (!(q_respawn.empty() || (svT<q_respawn.begin()->timestamp))) { // get svs_respawn R = *q_respawn.begin(); q_respawn.erase (q_respawn.begin()); // CSE_Abstract* E = ID_to_entity(R.phantom); E->Spawn_Write (Packet,FALSE); u16 ID; Packet.r_begin (ID); R_ASSERT(M_SPAWN==ID); ClientID clientID; clientID.set(0xffff); Process_spawn (Packet,clientID); } // for (u32 client=0; client<net_Players.size(); ++client) { // Initialize process and check for available bandwidth xrClientData* Client = (xrClientData*) net_Players [client]; if (!Client->net_Ready) continue; if (!HasBandwidth(Client) #ifdef DEBUG && !g_sv_SendUpdate #endif ) continue; // Send relevant entities to client // CSE_Abstract* Base = Client->owner; u16 PacketType = M_UPDATE; Packet.w_begin (PacketType); // GameUpdate ++(Client->game_replicate_id); u32 g_it = (Client->game_replicate_id % client_Count()); // u32 g_id = net_Players[g_it]->ID; ClientID g_id = net_Players[g_it]->ID; game->net_Export_Update (Packet,Client->ID,g_id); // if (!Client->flags.bLocal) game->net_Export_GameTime(Packet); if (!Client->flags.bLocal || client_Count() == 1) { #ifdef DEBUG if (g_Dump_Update_Write) Msg("---- UPDATE_Write to %s --- ", *(Client->Name)); #endif // Entities NET_Packet tmpPacket; xrS_entities::iterator I=entities.begin(),E=entities.end(); for (; I!=E; ++I) { CSE_Abstract& Test = *(I->second); if (0==Test.owner) continue; // Phantom(?) if (!Test.net_Ready) continue; if (Test.owner == Client && Client->flags.bLocal) continue; // Can't be relevant if (Test.s_flags.is(M_SPAWN_OBJECT_PHANTOM)) continue; // Surely: phantom tmpPacket.B.count = 0; // write specific data { tmpPacket.w_u16 (Test.ID ); tmpPacket.w_chunk_open8 (position ); Test.UPDATE_Write (tmpPacket ); #ifdef DEBUG if (g_Dump_Update_Write) Msg("* %s : %d", Test.name(), u32(tmpPacket.w_tell()-position)-sizeof(u8)); #endif tmpPacket.w_chunk_close8 (position ); if (Packet.B.count + tmpPacket.B.count < NET_PacketSizeLimit) { Packet.w(tmpPacket.B.data, tmpPacket.B.count); } else { if (Packet.B.count > 2) { // if (!Client->flags.bLocal) // Msg ("- Server Update[%d] to Client : %d", PacketType, Packet.B.count); SendTo (Client->ID,Packet,net_flags(FALSE,TRUE)); } PacketType = M_UPDATE_OBJECTS; Packet.w_begin(PacketType); } } } #ifdef DEBUG if (g_Dump_Update_Write) Msg("----------------------- "); #endif }; if (Packet.B.count > 2) { // if (!Client->flags.bLocal) // Msg ("- Server Update[%d] to Client : %d", PacketType, Packet.B.count); SendTo (Client->ID,Packet,net_flags(FALSE,TRUE)); } } #ifdef DEBUG g_sv_SendUpdate = 0; #endif if (game->sv_force_sync) Perform_game_export(); VERIFY (verify_entities()); //----------------------------------------------------- //Remove any of long time disconnected players for (u32 DI = 0; DI<net_Players_disconnected.size(); DI++) { IClient* CL = net_Players_disconnected[DI]; if (CL->dwTime_LastUpdate+g_sv_Client_Reconnect_Time*60000<Device.dwTimeGlobal) client_Destroy(CL); } //----------------------------------------------------- csPlayers.Leave (); }