예제 #1
0
bool ScmdServer_Impl::HandleListClients( HCLIENT hClient, ILTMessage_Read& msg )
{
	float fPing = 0.0f;
    uint16 nClientID = 0;
	uint8 aClientIP[4];
	uint16 nPort;
	std::string sPlayerHandle = "";

	// Write out the message header.
	CAutoMessage cMsg;
	cMsg.Writeuint8( MID_SCMD );
	cMsg.Writeuint8( kScmdCommandListClients );
	cMsg.Writeuint8( kScmdCommandStatusOk );

	// Iterate over all the clients and put their id, ping, ip and name in the message.
    HCLIENT hIterClient = g_pLTServer->GetNextClient( NULL );
    while( hIterClient )
	{
        nClientID = ( uint16 )g_pLTServer->GetClientID( hIterClient );
        g_pLTServer->GetClientPing( hIterClient, fPing );
		g_pLTServer->GetClientAddr( hIterClient, aClientIP, &nPort );

		cMsg.Writeuint16(( uint16 )nClientID );
		cMsg.Writeuint16(( uint16 )( fPing + 0.5f ));
		cMsg.Writeuint8( aClientIP[0] );
		cMsg.Writeuint8( aClientIP[1] );
		cMsg.Writeuint8( aClientIP[2] );
		cMsg.Writeuint8( aClientIP[3] );

		// Get the player for this client.  If there is none,
		// then we can't determine the name.
		CPlayerObj* pPlayerObj = ( CPlayerObj* )g_pLTServer->GetClientUserData( hIterClient );
		if( !pPlayerObj )
		{
			sPlayerHandle = "";
		}
		else
		{
			sPlayerHandle = pPlayerObj->GetNetUniqueName( );
		}
		cMsg.WriteString( sPlayerHandle.c_str( ));

	    hIterClient = g_pLTServer->GetNextClient( hIterClient );
	}

	// Write out the the list terminator.
	cMsg.Writeuint16(0xFFFF);
	SendMessage( hClient, *cMsg );

	return true;
}
예제 #2
0
static bool BootClient( bool bById, uint16 nBootClientId, char const* pszBootName )
{
    uint32 nClientId = 0;
	std::string sPlayerHandle = "";
	bool bBooted = false;

	// Iterate over all the clients and put their id, ping, ip and name in the message.
    HCLIENT hIterClient = NULL;
    for( hIterClient = g_pLTServer->GetNextClient( NULL ); hIterClient; 
		hIterClient = g_pLTServer->GetNextClient( hIterClient ))
	{
        nClientId = g_pLTServer->GetClientID( hIterClient );

		// Check if we're booting by ID.
		if( bById )
		{
			if( nClientId == nBootClientId )
			{
				g_pLTServer->KickClient( hIterClient );
				bBooted = true;
				break;
			}
		}
		else
		{
			// Get the player for this client.  If there is none,
			// then we can't determine the name.
			CPlayerObj* pPlayerObj = ( CPlayerObj* )g_pLTServer->GetClientUserData( hIterClient );
			if( !pPlayerObj )
			{
				continue;
			}
			else
			{
				sPlayerHandle = pPlayerObj->GetNetUniqueName( );
			}

			// See if this matches the name we want to boot.
			if( stricmp( pszBootName, sPlayerHandle.c_str( )) == 0 )
			{
				bBooted = ( g_pLTServer->KickClient( hIterClient ) == LT_OK );
				break;
			}
		}
	}

	return bBooted;
}
예제 #3
0
void CTO2GameServerShell::Update(LTFLOAT timeElapsed)
{
	// Update the main server first
	CGameServerShell::Update(timeElapsed);

	m_VersionMgr.Update();

	if (!GetServerDir())
		return;

	//if we're hosting LANOnly game, don't publish the server
	if( m_ServerGameOptions.m_bLANOnly )
		return;

	// Are we still waiting?
	static std::string status;
	switch (GetServerDir()->GetCurStatus())
	{
		case IServerDirectory::eStatus_Processing : 
			status ="";
			break;
		case IServerDirectory::eStatus_Waiting : 
			if (status.empty())
				status = GetServerDir()->GetLastRequestResultString();
			break;
		case IServerDirectory::eStatus_Error : 
			{
				
				IServerDirectory::ERequest eErrorRequest = GetServerDir()->GetLastErrorRequest();
				status = GetServerDir()->GetLastRequestResultString();
				GetServerDir()->ProcessRequestList();
			}
			break;
	};



	// Publish the server if we've waited long enough since the last directory update
	uint32 nCurTime = (uint32)GetTickCount();
	if ((m_nLastPublishTime == 0) || 
		((nCurTime - m_nLastPublishTime) > k_nRepublishDelay))
	{
		status = "";
		m_nLastPublishTime = nCurTime;
		uint32 nMax = 0;
		g_pLTServer->GetMaxConnections(nMax);

		// If not run by a dedicated server, we need to add one connection
		// for the local host.
		if( !m_ServerGameOptions.m_bDedicated )
			nMax++;

		GetServerDir()->SetActivePeer(0);

		CAutoMessage cMsg;

		// Update the summary info
		cMsg.WriteString(GetHostName());
		GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Name, *cMsg.Read());

		char fname[_MAX_FNAME] = "";
		_splitpath( GetCurLevel(), NULL, NULL, fname, NULL );

		// Update the summary info
		cMsg.WriteString(g_pVersionMgr->GetBuild());
		cMsg.WriteString( fname );
		cMsg.Writeuint8(GetNumPlayers());
		cMsg.Writeuint8(nMax);
		cMsg.Writebool(m_ServerGameOptions.m_bUsePassword);
		cMsg.Writeuint8((uint8)GetGameType());
		cMsg.WriteString( m_ServerGameOptions.m_sModName.c_str() );

		GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Summary, *cMsg.Read());


		// Update the details
		ServerMissionSettings sms = g_pServerMissionMgr->GetServerSettings();
		cMsg.Writebool(sms.m_bUseSkills);
		cMsg.Writebool(sms.m_bFriendlyFire);
		cMsg.Writeuint8(sms.m_nMPDifficulty);
		cMsg.Writefloat(sms.m_fPlayerDiffFactor);

		CPlayerObj* pPlayer = GetFirstNetPlayer();
	    while (pPlayer)
		{
			//has player info
			cMsg.Writebool(true);
			cMsg.WriteString(pPlayer->GetNetUniqueName());
			cMsg.Writeuint16( Min( GetPlayerPing(pPlayer), ( uint32 )65535 ));
			pPlayer = GetNextNetPlayer();
		};

		//end of player info
		cMsg.Writebool(false);

	
		cMsg.Writeuint8(sms.m_nRunSpeed);
		cMsg.Writeuint8(sms.m_nScoreLimit);
		cMsg.Writeuint8(sms.m_nTimeLimit);

		GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Details, *cMsg.Read());

		// Update the port
		char aHostAddr[16];
		uint16 nHostPort;
		g_pLTServer->GetTcpIpAddress(aHostAddr, sizeof(aHostAddr), nHostPort);
		cMsg.Writeuint16(nHostPort);
		GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Port, *cMsg.Read());
		
		// Tell serverdir again about info, but in service specific manner.
		PeerInfo_Service_Titan peerInfo;
		peerInfo.m_sHostName = GetHostName( );
		peerInfo.m_sCurWorld = fname; 
		peerInfo.m_nCurNumPlayers = GetNumPlayers( );
		peerInfo.m_nMaxNumPlayers = nMax;
		peerInfo.m_bUsePassword = m_ServerGameOptions.m_bUsePassword;
		peerInfo.m_sGameType = GameTypeToString( GetGameType( ));
		peerInfo.m_nScoreLimit = sms.m_nScoreLimit;
		peerInfo.m_nTimeLimit = sms.m_nTimeLimit;

		PeerInfo_Service_Titan::Player player;
		CPlayerObj::PlayerObjList::const_iterator iter = CPlayerObj::GetPlayerObjList( ).begin( );
		while( iter != CPlayerObj::GetPlayerObjList( ).end( ))
		{
			CPlayerObj* pPlayerObj = *iter;

			player.m_sName = pPlayerObj->GetNetUniqueName( );
			player.m_nScore = pPlayerObj->GetPlayerScore()->GetScore( );

			float fPing;
			g_pLTServer->GetClientPing( pPlayerObj->GetClient( ), fPing );
			player.m_nPing = ( uint16 )( fPing + 0.5f );

			peerInfo.m_PlayerList.push_back( player );

			iter++;
		}


		cMsg.Writeuint32(( uint32 )&peerInfo );
		GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Service, *cMsg.Read());

		// Tell the world about me...
		GetServerDir()->QueueRequest(IServerDirectory::eRequest_Publish_Server);
	}
}