Ejemplo n.º 1
0
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");
		}
	}
}
Ejemplo n.º 2
0
void	game_cl_GameState::net_import_update(NET_Packet& P)
{
	// Read
	ClientID			ID;
	P.r_clientID		(ID);

	// Update
	PLAYERS_MAP_IT I	= players.find(ID);
	if (players.end()!=I)
	{
		game_PlayerState* IP		= I->second;
//		CopyMemory	(&IP,&PS,sizeof(PS));		
		//***********************************************
		u16 OldFlags = IP->flags__;
		u8 OldVote = IP->m_bCurrentVoteAgreed;
		//-----------------------------------------------
		IP->net_Import(P);
		//-----------------------------------------------
		if (OldFlags != IP->flags__)
			if (Type() != GAME_SINGLE) OnPlayerFlagsChanged(IP);
		if (OldVote != IP->m_bCurrentVoteAgreed)
			OnPlayerVoted(IP);
		//***********************************************
	}
	else
	{
		game_PlayerState*	PS = createPlayerState();
		PS->net_Import		(P);
		if (Type() != GAME_SINGLE) OnPlayerFlagsChanged(PS);
		xr_delete(PS);
	};

	//Syncronize GameTime
	net_import_GameTime (P);
}
Ejemplo n.º 3
0
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));
		};
	};
}
Ejemplo n.º 4
0
void	game_cl_GameState::net_import_state	(NET_Packet& P)
{
	// Generic
	P.r_clientID	(local_svdpnid);
	P.r_s32			(m_type);
	
	u16 ph;
	P.r_u16			(ph);
	
	if(Phase()!=ph)
		switch_Phase(ph);

	P.r_s32			(m_round);
	P.r_u32			(m_start_time);
	m_u16VotingEnabled = u16(P.r_u8());
	m_bServerControlHits = !!P.r_u8();	
	m_WeaponUsageStatistic->SetCollectData(!!P.r_u8());

	// Players
	u16	p_count;
	P.r_u16			(p_count);
	
	PLAYERS_MAP players_new;

/*
	players.clear	();
*/
	PLAYERS_MAP_IT I;
	for (u16 p_it=0; p_it<p_count; ++p_it)
	{
		ClientID			ID;
		P.r_clientID		(ID);
		
		game_PlayerState*   IP;
		I = players.find(ID);
		if( I!=players.end() )
		{
			IP = I->second;
			//***********************************************
			u16 OldFlags = IP->flags__;
			u8 OldVote = IP->m_bCurrentVoteAgreed;
			//-----------------------------------------------
			IP->net_Import(P);
			//-----------------------------------------------
			if (OldFlags != IP->flags__)
				if (Type() != GAME_SINGLE) OnPlayerFlagsChanged(IP);
			if (OldVote != IP->m_bCurrentVoteAgreed)
				OnPlayerVoted(IP);
			//***********************************************

			players_new.insert(mk_pair(ID,IP));
			players.erase(I);
		}else{
			IP = createPlayerState();
			IP->net_Import		(P);

			if (Type() != GAME_SINGLE) OnPlayerFlagsChanged(IP);

			players_new.insert(mk_pair(ID,IP));
		}
		if (IP->testFlag(GAME_PLAYER_FLAG_LOCAL) ) local_player = IP;
	}

	I	= players.begin();
	for(;I!=players.end(); ++I)
		xr_delete(I->second);
	players.clear();
	
	players = players_new;

	net_import_GameTime(P);
}