Exemple #1
0
BOOL KNetConnectPlayer::KickOutPlayer( INT nPlayerIndex )
{
	INT nConnIdx = m_pnPlayerIndex2ConnId[nPlayerIndex];

	if (nConnIdx > 0)
		return g_piSocketServer->Disconnect(nConnIdx);

	// not attached
	return OnPlayerDisconnect(nPlayerIndex);
}
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));
		};
	};
}
Exemple #3
0
static cell AMX_NATIVE_CALL n_OnPlayerDisconnect( AMX* amx, cell* params )
{
	return OnPlayerDisconnect(params[1], params[2]);
}
Exemple #4
0
//-----------------------------------------------------------------------------
// Name: ProcessReliableMessage()
// Desc: First checks to see if any new connections have been attempted, and if
//		 we have room, accepts them.  Then, scans all reliable client 
//		 connections to see if any have messages pending.
//		 If a message is waiting, it is routed and processed.
//		 If no messages are waiting, the function returns immediately.
//-----------------------------------------------------------------------------
void CVoiceManager::ProcessReliableMessage()
{
	if( !m_ReliableSock.IsOpen() )
		return;

	if( com_sv_running->integer )
	{
		// Process any pending socket connections
		for( ; ; )
		{
			ClientSocket cs;
			cs.sock = m_ReliableSock.Accept( &cs.sa );
			if( cs.sock == INVALID_SOCKET )
				break;

			int cIdx;
			for( cIdx = 0; cIdx < MAX_CLIENTS; ++cIdx )
			{
				if( !m_ClientSockets[cIdx].inUse )
					break;
			}
			assert( cIdx != MAX_CLIENTS );
			m_ClientSockets[cIdx] = cs;
			m_ClientSockets[cIdx].inUse = true;
//			m_ClientSockets.push_back( cs );
		}

		// Poll each of our clients for messages and timeout
//		for( SocketList::iterator it = m_ClientSockets.begin();
//			it < m_ClientSockets.end();
//			++it )
		for( int i = 0; i < MAX_CLIENTS; ++i )
		{
			if( !m_ClientSockets[i].inUse )
				continue;
			ClientSocket *it = &m_ClientSockets[i];

			// Try to parse out a message from the socket.	If message was
			// completed, process the message
			HRESULT hr = it->msgPending.Read( it->sock );
			if( FAILED( hr ) )
			{
				// We lost a connection to a client.
				Com_Printf( "WARNING: Reliable voice cnxn was lost\n" );

				// VVFIXME - This code assumes that the xbPlayerInfo for the drop is
				// still valid. It might not be, in some really outrageous situation.
				// We should figure out a solution to that.

				// Remove them from the Voice System, but let the game logic handle
				// everything else (xbOnlineInfo).
				int idx;
				for( idx = 0; idx < MAX_ONLINE_PLAYERS; ++idx )
				{
					if( xbOnlineInfo.xbPlayerList[idx].isActive &&
						xbOnlineInfo.xbPlayerList[idx].inAddr.s_addr == it->sa.sin_addr.s_addr )
						break;
				}

				if( idx == MAX_ONLINE_PLAYERS )
				{
					// This shouldn't happen (but it can - see above)
					Com_Error( ERR_FATAL, "ERROR: Couldn't find user after reliable cnxn lost\n" );
				}

				OnPlayerDisconnect( &xbOnlineInfo.xbPlayerList[idx] );
				// OK. We found them in the playerlist. Take them out of the voice system
				// This function removes the socket from the vector. I don't care if SimpleVoice
				// isn't iterator safe - I will be. =) VVFIXME - I still don't like this.
/*
				int oldIndex = it - m_ClientSockets.begin();
				OnPlayerDisconnect( &xbOnlineInfo.xbPlayerList[idx] );
				it = m_ClientSockets.begin() + oldIndex;
*/
			}
			else if( S_OK == hr )
			{
				ProcessVoiceInfo( it->msgPending.m_msg.GetMsgVoiceInfo(), CXBSockAddr( it->sa ) );
				it->msgPending.Reset();
			}
		}
	}
	else
	{
		HRESULT hr = m_msgPending.Read( m_ReliableSock.GetSocket() );
		if( FAILED( hr ) )
		{
			// This leads to calling g_Voice.Shutdown(), let that handle cleanup
			Com_Error( ERR_DROP, "@MENUS_LOST_CONNECTION" );
		}
		else if( S_OK == hr )
		{
			ProcessVoiceInfo( m_msgPending.m_msg.GetMsgVoiceInfo(), CXBSockAddr( xbc.SrvAddr, RELIABLE_PORT ) );
			m_msgPending.Reset();
		}
	}

	return;
}