void CArtefact::OnAnimationEnd(u32 state) { switch (state) { case eHiding: { SwitchState(eHidden); }break; case eShowing: { SwitchState(eIdle); }break; case eActivating: { if(Local()) { SwitchState (eHiding); NET_Packet P; u_EventGen (P, GEG_PLAYER_ACTIVATEARTEFACT, H_Parent()->ID()); P.w_u16 (ID()); u_EventSend (P); } }break; }; }
void CUIInventoryWnd::SendEvent_Item_Eat (PIItem pItem) { NET_Packet P; pItem->object().u_EventGen (P, GEG_PLAYER_ITEM_EAT, pItem->object().H_Parent()->ID()); P.w_u16 (pItem->object().ID()); pItem->object().u_EventSend (P); };
void CUIInventoryWnd::SendEvent_ActivateArtefact (PIItem pItem) { NET_Packet P; pItem->object().u_EventGen (P, GEG_PLAYER_ACTIVATEARTEFACT, pItem->object().H_Parent()->ID()); P.w_u16 (pItem->object().ID()); pItem->object().u_EventSend (P); };
void CEntity::KillEntity(u16 whoID) { if (whoID != ID()) { #ifdef DEBUG if (m_killer_id != ALife::_OBJECT_ID(-1)) { Msg ("! Entity [%s][%s] already has killer with id %d, but new killer id arrived - %d",*cNameSect(),*cName(),m_killer_id,whoID); CObject *old_killer = Level().Objects.net_Find(m_killer_id); Msg ("! Old killer is %s",old_killer ? *old_killer->cName() : "unknown"); CObject *new_killer = Level().Objects.net_Find(whoID); Msg ("! New killer is %s",new_killer ? *new_killer->cName() : "unknown"); VERIFY (m_killer_id == ALife::_OBJECT_ID(-1)); } #endif } else { if (m_killer_id != ALife::_OBJECT_ID(-1)) return; } m_killer_id = whoID; set_death_time (); if (!getDestroy()){ NET_Packet P; u_EventGen (P,GE_DIE,ID()); P.w_u16 (u16(whoID)); P.w_u32 (0); if (OnServer()) u_EventSend (P, net_flags(TRUE, TRUE, FALSE, TRUE)); } };
void CCar::SaveNetState(NET_Packet& P) { CPHSkeleton::SaveNetState (P); P.w_vec3(Position()); Fvector Angle; XFORM().getXYZ(Angle); P.w_vec3(Angle); { xr_map<u16,SDoor>::iterator i,e; i=m_doors.begin(); e=m_doors.end(); P.w_u16(u16(m_doors.size())); for(;i!=e;++i) i->second.SaveNetState(P); } { xr_map<u16,SWheel>::iterator i,e; i=m_wheels_map.begin(); e=m_wheels_map.end(); P.w_u16(u16(m_wheels_map.size())); for(;i!=e;++i) i->second.SaveNetState(P); } P.w_float(GetfHealth()); }
//передаче вещи из своего инвентаря в инвентарь партнера void CScriptGameObject::TransferItem(CScriptGameObject* pItem, CScriptGameObject* pForWho) { if (!pItem || !pForWho) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"cannot transfer NULL item"); return; } CInventoryItem* pIItem = smart_cast<CInventoryItem*>(&pItem->object()); if (!pIItem) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"Cannot transfer not CInventoryItem item"); return ; } // выбросить у себя NET_Packet P; CGameObject::u_EventGen (P,GE_TRADE_SELL, object().ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); // отдать партнеру CGameObject::u_EventGen (P,GE_TRADE_BUY, pForWho->object().ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); }
void CInventoryItem::OnEvent (NET_Packet& P, u16 type) { switch (type) { case GE_ADDON_ATTACH: { u16 ItemID; P.r_u16 (ItemID); CInventoryItem* ItemToAttach = smart_cast<CInventoryItem*>(Level().Objects.net_Find(ItemID)); if (!ItemToAttach) break; Attach(ItemToAttach,true); }break; case GE_ADDON_DETACH: { string64 i_name; P.r_stringZ (i_name); Detach(i_name, true); }break; case GE_CHANGE_POS: { Fvector p; P.r_vec3(p); CPHSynchronize* pSyncObj = NULL; pSyncObj = object().PHGetSyncItem(0); if (!pSyncObj) return; SPHNetState state; pSyncObj->get_State(state); state.position = p; state.previous_position = p; pSyncObj->set_State(state); }break; } }
bool CInventory::Eat(PIItem pIItem) { R_ASSERT(pIItem->m_pCurrentInventory==this); //устанаовить съедобна ли вещь CEatableItem* pItemToEat = smart_cast<CEatableItem*>(pIItem); R_ASSERT (pItemToEat); CEntityAlive *entity_alive = smart_cast<CEntityAlive*>(m_pOwner); R_ASSERT (entity_alive); pItemToEat->UseBy (entity_alive); if(IsGameTypeSingle() && Actor()->m_inventory == this) Actor()->callback(GameObject::eUseObject)((smart_cast<CGameObject*>(pIItem))->lua_game_object()); if(pItemToEat->Empty() && entity_alive->Local()) { NET_Packet P; CGameObject::u_EventGen (P,GE_OWNERSHIP_REJECT,entity_alive->ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); CGameObject::u_EventGen (P,GE_DESTROY,pIItem->object().ID()); CGameObject::u_EventSend (P); return false; } return true; }
void game_cl_TeamDeathmatch::net_import_state (NET_Packet& P) { bool teamsEqual = (!teams.empty())?(teams[0].score == teams[1].score) : false; inherited::net_import_state (P); m_bFriendlyIndicators = !!P.r_u8(); m_bFriendlyNames = !!P.r_u8(); if (!teams.empty()) { if (teamsEqual) { if (teams[0].score != teams[1].score) { if (Level().CurrentViewEntity()) { if (teams[0].score > teams[1].score) PlaySndMessage(ID_TEAM1_LEAD); else PlaySndMessage(ID_TEAM2_LEAD); } } } else { if (teams[0].score == teams[1].score) if (Level().CurrentViewEntity()) PlaySndMessage(ID_TEAMS_EQUAL); } }; }
void game_cl_GameState::sv_GameEventGen(NET_Packet& P) { P.w_begin (M_EVENT); P.w_u32 (Level().timeServer()); P.w_u16 ( u16(GE_GAME_EVENT&0xffff) ); P.w_u16 (0);//dest==0 }
void CInventoryItem::net_Export (NET_Packet& P) { P.w_float (m_fCondition); P.w_u32 (Level().timeServer()); /////////////////////////////////////// CPHSynchronize* pSyncObj = NULL; SPHNetState State; pSyncObj = object().PHGetSyncItem (0); if (pSyncObj && !object().H_Parent()) pSyncObj->get_State(State); else State.position.set(object().Position()); /////////////////////////////////////// u16 NumItems = object().PHGetSyncItemsNumber(); if (object().H_Parent()) NumItems = CSE_ALifeInventoryItem::FLAG_NO_POSITION; else if (IsGameTypeSingle()) NumItems = 0; P.w_u16 ( NumItems ); if (NumItems != CSE_ALifeInventoryItem::FLAG_NO_POSITION) P.w_vec3 ( State.position); if (!NumItems || (NumItems == CSE_ALifeInventoryItem::FLAG_NO_POSITION)) return; position_Export(P,State); };
void CActor::PickupModeUpdate() { if(!m_bPickupMode) return; if (GameID() != GAME_SINGLE) return; //подбирание объекта if(inventory().m_pTarget && inventory().m_pTarget->Useful() && m_pUsableObject && m_pUsableObject->nonscript_usable() && !Level().m_feel_deny.is_object_denied(smart_cast<CGameObject*>(inventory().m_pTarget)) ) { NET_Packet P; u_EventGen(P, GE_OWNERSHIP_TAKE, ID()); P.w_u16(inventory().m_pTarget->object().ID()); u_EventSend(P); } //. ????? GetNearest ????? feel_touch_update (Position(), /*inventory().GetTakeDist()*/m_fPickupInfoRadius); CFrustum frustum; frustum.CreateFromMatrix(Device.mFullTransform,FRUSTUM_P_LRTB|FRUSTUM_P_FAR); //. slow (ray-query test) for(xr_vector<CObject*>::iterator it = feel_touch.begin(); it != feel_touch.end(); it++) if (CanPickItem(frustum,Device.vCameraPosition,*it)) PickupInfoDraw(*it); }
void CLevel__cl_Process_CustomEventServer(NET_Packet& pack) { if (HookHandle->IsServer()) { unsigned char type = 0; pack.r_u8(type); if (type == e_so_engine_packet) { unsigned char e; pack.r_u8(e); switch (e) { case e_add_money: { LogHandle->Write("CLevel__cl_Process_CustomEventServer add money event"); ClientID cl_id; pack.r_clientID(cl_id); HookHandle->Add_money_mp(cl_id); }break; default: LogHandle->Write("CLevel__cl_Process_CustomEventServer unknown event %d",e); break; } } else if (type == e_so_script_packet) { char data[2048]; pack.r_stringZ(data); LogHandle->Write("Recieved data at server side '%s'",data); HookHandle->messanges_sv.push_back(data); } else { LogHandle->Write("ERROR: CLevel__cl_Process_CustomEventServer unknown type"); } } }
void CInventoryBox::OnEvent(NET_Packet& P, u16 type) { inherited::OnEvent (P, type); switch (type) { case GE_OWNERSHIP_TAKE: { u16 id; P.r_u16(id); CObject* itm = Level().Objects.net_Find(id); VERIFY(itm); m_items.push_back (id); itm->H_SetParent (this); itm->setVisible (FALSE); itm->setEnabled (FALSE); }break; case GE_OWNERSHIP_REJECT: { u16 id; P.r_u16(id); CObject* itm = Level().Objects.net_Find(id); VERIFY(itm); xr_vector<u16>::iterator it; it = std::find(m_items.begin(),m_items.end(),id); VERIFY(it!=m_items.end()); m_items.erase (it); itm->H_SetParent (NULL,!P.r_eof() && P.r_u8()); if( m_in_use ) { CGameObject* GO = smart_cast<CGameObject*>(itm); Actor()->callback(GameObject::eInvBoxItemTake)( this->lua_game_object(), GO->lua_game_object() ); } }break; }; }
void CUIInventoryWnd::SendEvent_ActivateSlot (PIItem pItem) { NET_Packet P; pItem->object().u_EventGen (P, GEG_PLAYER_ACTIVATE_SLOT, pItem->object().H_Parent()->ID()); P.w_u32 (pItem->GetSlot()); pItem->object().u_EventSend (P); }
void CGameObject::net_Save (NET_Packet &net_packet) { u32 position; net_packet.w_chunk_open16 (position); save (net_packet); // Script Binder Save --------------------------------------- #ifdef DEBUG if (psAI_Flags.test(aiSerialize)) { Msg(">> **** Save script object [%s] *****", *cName()); Msg(">> Before save :: packet position = [%u]", net_packet.w_tell()); } #endif CScriptBinder::save (net_packet); #ifdef DEBUG if (psAI_Flags.test(aiSerialize)) { Msg(">> After save :: packet position = [%u]", net_packet.w_tell()); } #endif // ---------------------------------------------------------- net_packet.w_chunk_close16 (position); }
void game_cl_Deathmatch::SendPickUpEvent(u16 ID_who, u16 ID_what) { NET_Packet P; u_EventGen (P, GE_OWNERSHIP_TAKE_MP_FORCED, ID_who); P.w_u16 (ID_what); u_EventSend (P); };
void game_cl_Deathmatch::OnSkinMenu_Ok () { CObject *l_pObj = Level().CurrentEntity(); CGameObject *l_pPlayer = smart_cast<CGameObject*>(l_pObj); if(!l_pPlayer) return; NET_Packet P; l_pPlayer->u_EventGen (P, GE_GAME_EVENT, l_pPlayer->ID() ); P.w_u16(GAME_EVENT_PLAYER_GAME_MENU); P.w_u8(PLAYER_CHANGE_SKIN); P.w_s8 ((u8)pCurSkinMenu->GetActiveIndex()); l_pPlayer->u_EventSend (P); //----------------------------------------------------------------- m_bSkinSelected = TRUE; // second stub here if (pCurBuyMenu) { if (-1 == pCurSkinMenu->GetActiveIndex()) pCurBuyMenu->SetSkin(0); else pCurBuyMenu->SetSkin((u8)pCurSkinMenu->GetActiveIndex()); } };
void CInventoryItem::net_Import (NET_Packet& P) { P.r_float (m_fCondition) ; net_update_IItem N ; N.dwTimeStamp=P.r_u32 ( ); u16 NumItems = 0; NumItems=P.r_u16 ( ); if (CSE_ALifeInventoryItem::FLAG_NO_POSITION != NumItems) N.State.position=P.r_vec3 (); if (!NumItems || (CSE_ALifeInventoryItem::FLAG_NO_POSITION == NumItems)) return; position_Import (P,N) ; net_updateData *p = NetSync() ; if ( !p->NET_IItem.empty() && (p->NET_IItem.back().dwTimeStamp>=N.dwTimeStamp)) return; if (!p->NET_IItem.empty()){ m_flags.set (FInInterpolate, TRUE); // m_bInterpolate = true; } Level().AddObject_To_Objects4CrPr (m_object); object().CrPr_SetActivated (false); object().CrPr_SetActivationStep (0); p->NET_IItem.push_back (N); while (p->NET_IItem.size() > 2) { p->NET_IItem.pop_front (); }; };
void game_cl_GameState::u_EventGen(NET_Packet& P, u16 type, u16 dest) { P.w_begin (M_EVENT); P.w_u32 (Level().timeServer()); P.w_u16 (type); P.w_u16 (dest); }
void game_cl_GameState::SendPickUpEvent (u16 ID_who, u16 ID_what) { NET_Packet P; u_EventGen(P,GE_OWNERSHIP_TAKE, ID_who); P.w_u16(ID_what); u_EventSend(P); };
void CActorCondition::save(NET_Packet &output_packet) { inherited::save (output_packet); save_data (m_fAlcohol, output_packet); save_data (m_condition_flags, output_packet); save_data (m_fSatiety, output_packet); save_data (m_curr_medicine_influence.fHealth, output_packet); save_data (m_curr_medicine_influence.fPower, output_packet); save_data (m_curr_medicine_influence.fSatiety, output_packet); save_data (m_curr_medicine_influence.fRadiation, output_packet); save_data (m_curr_medicine_influence.fWoundsHeal, output_packet); save_data (m_curr_medicine_influence.fMaxPowerUp, output_packet); save_data (m_curr_medicine_influence.fAlcohol, output_packet); save_data (m_curr_medicine_influence.fTimeTotal, output_packet); save_data (m_curr_medicine_influence.fTimeCurrent, output_packet); output_packet.w_u8((u8)m_booster_influences.size()); BOOSTER_MAP::iterator b = m_booster_influences.begin(), e = m_booster_influences.end(); for(; b!=e; b++) { output_packet.w_u8((u8)b->second.m_type); output_packet.w_float(b->second.fBoostValue); output_packet.w_float(b->second.fBoostTime); } }
//передаче вещи из своего инвентаря в инвентарь партнера void CScriptGameObject::TransferItem(CScriptGameObject* pItem, CScriptGameObject* pForWho) { if (!pItem || !pForWho) { ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "cannot transfer NULL item"); return; } CInventoryItem* pIItem = smart_cast<CInventoryItem*>(&pItem->object()); if (!pIItem) { ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "Cannot transfer not CInventoryItem item"); return; } NET_Packet P; // выбросить у себя if (NULL != pItem->object().H_Parent() && this != pItem) // из скриптов часто подбираются "независимые" предметы { CGameObject::u_EventGen(P, GE_OWNERSHIP_REJECT, object().ID()); P.w_u16(pIItem->object().ID()); CGameObject::u_EventSend(P); } // отдать партнеру CGameObject::u_EventGen (P,GE_OWNERSHIP_TAKE, pForWho->object().ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); }
void CGameObject::u_EventGen(NET_Packet& P, u32 type, u32 dest) { P.w_begin (M_EVENT); P.w_u32 (Level().timeServer()); P.w_u16 (u16(type&0xffff)); P.w_u16 (u16(dest&0xffff)); }
void game_sv_GameState::u_EventGen(NET_Packet& P, u16 type, u16 dest) { P.w_begin (M_EVENT); P.w_u32 (Level().timeServer());//Device.TimerAsync()); P.w_u16 (type); P.w_u16 (dest); }
void CWeaponMagazinedWGrenade::OnEvent(NET_Packet& P, u16 type) { inherited::OnEvent(P,type); u16 id; switch (type) { case GE_OWNERSHIP_TAKE: { P.r_u16(id); CRocketLauncher::AttachRocket(id, this); } break; case GE_OWNERSHIP_REJECT : case GE_LAUNCH_ROCKET : { bool bLaunch = (type==GE_LAUNCH_ROCKET); P.r_u16 (id); CRocketLauncher::DetachRocket(id, bLaunch); if(bLaunch) { PlayAnimShoot (); PlaySound ("sndShotG", get_LastFP2()); AddShotEffector (); StartFlameParticles2(); } break; } } }
void CHelicopter::startRocket(u16 idx) { if((getRocketCount()>=1)&&m_use_rocket_on_attack) { CExplosiveRocket* pGrenade = smart_cast<CExplosiveRocket*>(getCurrentRocket()); VERIFY(pGrenade); pGrenade->SetInitiator(this->ID()); Fmatrix rocketXFORM; (idx==1)?rocketXFORM=m_left_rocket_bone_xform:rocketXFORM=m_right_rocket_bone_xform; Fvector vel; Fvector dir; dir.sub(m_enemy.destEnemyPos, rocketXFORM.c ).normalize_safe(); vel.mul(dir,CRocketLauncher::m_fLaunchSpeed); Fmatrix xform; xform.identity(); xform.k.set(dir); Fvector::generate_orthonormal_basis(xform.k,xform.j,xform.i); xform.c = rocketXFORM.c; VERIFY2(_valid(xform),"CHelicopter::startRocket. Invalid xform"); LaunchRocket(xform, vel, zero_vel); NET_Packet P; u_EventGen(P,GE_LAUNCH_ROCKET,ID()); P.w_u16(u16( getCurrentRocket()->ID())); u_EventSend(P); dropCurrentRocket(); m_last_launched_rocket = idx; HUD_SOUND_ITEM::PlaySound(m_sndShotRocket, xform.c, this, false); } }
void CArtefact::OnAnimationEnd (u32 state) { switch (state) { case eHiding: { SwitchState(eHidden); //. if(m_pInventory->GetNextActiveSlot()!=NO_ACTIVE_SLOT) //. m_pInventory->Activate(m_pInventory->GetPrevActiveSlot()); }break; case eShowing: { SwitchState(eIdle); }break; case eActivating: { if(Local()){ SwitchState (eHiding); NET_Packet P; u_EventGen (P, GEG_PLAYER_ACTIVATEARTEFACT, H_Parent()->ID()); P.w_u16 (ID()); u_EventSend (P); } }break; }; }
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; u32 EndTime = GetTickCount() + ConnectionTimeOut; while (!m_bConnectResultReceived) { ClientReceive (); Sleep (5); if(Server) Server->Update() ; //----------------------------------------- u32 CurTime = GetTickCount(); if (CurTime > EndTime) { NET_Packet P; P.B.count = 0; P.r_pos = 0; P.w_u8(0); P.w_u8(0); P.w_stringZ("Data verification failed. Cheater? [1]"); OnConnectResult(&P); } if (net_isFails_Connect()) { OnConnectRejected (); Disconnect () ; return FALSE; } //----------------------------------------- } 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, net_flags(TRUE, TRUE, TRUE, TRUE)); //--------------------------------------------------------------------------- return TRUE; };
void CLevel::ClientSend() { if ((GameID() != eGameIDSingle) || OnClient()) // fixed by Shoker { if ( !net_HasBandwidth() ) return; }; NET_Packet P; u32 start = 0; //----------- for E3 ----------------------------- // if () { // if (!(Game().local_player) || Game().local_player->testFlag(GAME_PLAYER_FLAG_VERY_VERY_DEAD)) return; if (CurrentControlEntity()) { CObject* pObj = CurrentControlEntity(); if (!pObj->getDestroy() && pObj->net_Relevant()) { P.w_begin (M_CL_UPDATE); P.w_u16 (u16(pObj->ID()) ); P.w_u32 (0); //reserved place for client's ping pObj->net_Export (P); if (P.B.count>9) { if (!OnServer()) Send (P, net_flags(FALSE)); } } } }; if (m_file_transfer) { m_file_transfer->update_transfer(); m_file_transfer->stop_obsolete_receivers(); } if (OnClient()) { Flush_Send_Buffer(); return; } //------------------------------------------------- while (1) { P.w_begin (M_UPDATE); start = Objects.net_Export (&P, start, max_objects_size); if (P.B.count>2) { Device.Statistic->TEST3.Begin(); Send (P, net_flags(FALSE)); Device.Statistic->TEST3.End(); }else break; } }