コード例 #1
0
void TServerConnectState::Update(nel::TGameTime deltaTime)
{
	TGameState::Update(deltaTime);

	IClient* client = (IClient*)Application->RetrieveInterface(IID_IClient);
	assert(client);
	client->Process();

	switch (progress)
	{
		case SHOULDCONNECT:		
			ConnectToServer();
			progress = CONNECTING;
			break;
		case CONNECTING:	
			if (client->IsConnected()) 
				progress = CONNECTED; 
			break;
		case CONNECTED:
			if (client->IsInLobby())
			{
				progress = INLOBBY;
				Owner->SetNextState(SID_Lobby);
			}
			break;
		case INLOBBY:			
			break;
	};
}
コード例 #2
0
static cell_t smn_InactivateClient(IPluginContext *pContext, const cell_t *params)
{
	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
	
	if (player == NULL)
	{
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
	}


	if (!iserver)
	{
		pContext->ThrowNativeError("IServer is null");
	}

	IClient* pClient = iserver->GetClient(params[1] - 1);
	if (pClient)
	{
		pClient->Inactivate();
	}
	else
	{
		pContext->ThrowNativeError("Could not get IClient for client %d", params[1]);
	}

	return 1;
}
コード例 #3
0
static cell_t smn_ReconnectClient(IPluginContext *pContext, const cell_t *params)
{
	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
	
	if (player == NULL)
	{
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
	}

	if (!iserver)
	{
		return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
	}

	IClient* pClient = iserver->GetClient(params[1] - 1);
	if (pClient)
	{
		pClient->Reconnect();
	}
	else
	{
		pContext->ThrowNativeError("Could not get IClient for client %d", params[1]);
	}
	return 1;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: cintiaf/LittleThumb
int		main(int ac, char **av)
{
	(void)ac;
	(void)av;
	IClient	*co = NULL;
	HandleConnection hc;


#ifdef _WIN32
	co = new Connection_Win();
	std::cout << "* Running in Windows env *" << std::endl;
#else
	co = new Connection_Lin();
	std::cout << "* Running in UNIX env *" << std::endl;
#endif
	if (co->connection(atoi(av[1]), IPS) == true)
		std::cout << "Worked" << std::endl;
	else
		std::cout << "blop" << std::endl;

	// PortAudio 	audio(co);
	// audio.initialize();
	// audio.initInputDevice();
	// audio.openRecordStream();
	// audio.initOutputDevice();
	// audio.openPlayStream();
	// audio.recordSound();
	// audio.playSound();
	hc.handle(co);
	//co->connectionHost(atoi(av[1]), IP);
	//co->handle_connection();
	//std::cout << "not good" << std::endl;
	//while (1);
	// if (ac == 2)
	//   {
	//     if (co->connection(atoi(av[1]), IP) == true)
	//       std::cout << "Worked" << std::endl;
	//     else
	//       {
	// 	std::cout << "blop" << std::endl;
	// 	return (1);
	//       }
	//     b = co;
	//     // co->create_server(atoi(av[1]));
	//     //std::cout << "not good" << std::endl;
	//     std::cout << "aeza" << std::endl;
	//     std::thread th1 (init_server);
	//     std::thread th2 (init_server);
	//     std::cout << "azeaze" << std::endl;
	//     th1.join();
	//     th2.join();
	//     //std::thread th2 (init_server);
	//     // while (1)
	//     //   {
	//     // 	read(0, buff, 500);
	//     // 	std::string b(buff);
	//     // 	co->write_to_server(b);
	//     //   }
	//   }
}
コード例 #5
0
void CPlayer::Kick(const char *str)
{
	MarkAsBeingKicked();
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(m_iIndex));
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
	pClient->Disconnect("%s", str);
}
コード例 #6
0
ファイル: SmartClient.cpp プロジェクト: XeanoRRR/mmo-resourse
IClient* CSmartClient::_Connect()
{
	if ( !IsConnecting() )
		return NULL;

#ifdef	CONSOLE_DEBUG
					cprintf( "Begin connect\n");
#endif	

	IClient *pClient = NULL;
	/*
	 * There is connectted the heaven by the rainbow
	 */

	pfnCreateClientInterface pClientFactroyFun = ( pfnCreateClientInterface )( m_theRainbowLib.GetProcAddress( _T( "CreateInterface" ) ) );
	IClientFactory *pClientFactory = NULL;
	
	if ( pClientFactroyFun && SUCCEEDED( pClientFactroyFun( IID_IClientFactory, reinterpret_cast< void ** >( &pClientFactory ) ) ) )
	{
		pClientFactory->SetEnvironment( 1024 * 1024 );
		
		pClientFactory->CreateClientInterface( IID_IESClient, reinterpret_cast< void ** >( &pClient ) );
		
		SAFE_RELEASE( pClientFactory );
	}
	
	if ( pClient )
	{
		pClient->Startup();
		
		pClient->RegisterMsgFilter( reinterpret_cast< void * >( this ), EventNotify );
		
		if ( FAILED( pClient->ConnectTo( m_sSvrIP.c_str(), m_nSvrPort ) ) )
		{
			pClient->Cleanup();
			
			SAFE_RELEASE( pClient );
				
#ifdef	CONSOLE_DEBUG
					cprintf( "Reconnect Failed\n");
#endif	
			::Sleep( 5000 );
			
			return NULL;
		}
		else
		{
			SetClientStatus(enumClientVerify);	
		}
	}
	
	return pClient;
}
コード例 #7
0
void TServerConnectState::Finalize()
{
	IClient* client = (IClient*)Application->RetrieveInterface(IID_IClient);
	assert(client);
	client->Disconnect();

	IServer* server = (IServer*)Application->RetrieveInterface(IID_IServer);
	assert(server);
	server->Stop();

	TGameState::Finalize();
}
コード例 #8
0
void CForwardManager::OnSpectatorPutInServer()
{
	void *pGameClient = META_IFACEPTR(void);
	if (!pGameClient)
		RETURN_META(MRES_IGNORED);

	// The IClient vtable is + 4 from the CBaseClient vtable due to multiple inheritance.
	IClient *client = (IClient *)((intptr_t)pGameClient + 4);

	m_SpectatorPutInServerFwd->PushCell(client->GetPlayerSlot() + 1);
	m_SpectatorPutInServerFwd->Execute();

	RETURN_META(MRES_IGNORED);
}
コード例 #9
0
int main()
{
    IClient *client = new Client("127.0.0.1", 12321);
    std::string msg = "Hello world !";

    if (client->connection(AF_INET, SOCK_STREAM, "TCP") == 0) {
        client->sendMessage(msg.c_str(), msg.size());

        client->disconnection();
    }

    delete client;

    return 0;
}
コード例 #10
0
bool HLTVServerWrapperManager::OnHLTVBotNetChanSendNetMsg(INetMessage &msg, bool bForceReliable, bool bVoice)
{
	// No need to worry about the right selected hltvserver, because there can only be one.
	IClient *pClient = iserver->GetClient(hltvserver->GetHLTVServer()->GetHLTVSlot());
	if (!pClient)
		RETURN_META_VALUE(MRES_SUPERCEDE, false);

	// Let the message flow through the intended path like CGameClient::SendNetMsg wants to.
	bool bRetSent = pClient->SendNetMsg(msg, bForceReliable);

	// It's important to supercede, because there is no original function to call.
	// (the "vtable" was empty before hooking it)
	// See FakeNetChan variable at the top.
	RETURN_META_VALUE(MRES_SUPERCEDE, bRetSent);
}
コード例 #11
0
void CForwardManager::CallOnSpectatorChatMessage_Post(HLTVServerWrapper *server, const char *msg, const char *chatgroup)
{
	int clientIndex = 0;
	if (server)
	{
		IClient *client = server->GetLastChatClient();
		if (client)
			clientIndex = client->GetPlayerSlot() + 1;
	}

	m_SpectatorChatMessagePostFwd->PushCell(clientIndex);
	m_SpectatorChatMessagePostFwd->PushString(msg);
	m_SpectatorChatMessagePostFwd->PushString(chatgroup);
	m_SpectatorChatMessagePostFwd->Execute();
}
コード例 #12
0
void CForwardManager::UnhookServer(HLTVServerWrapper *wrapper)
{
	IServer *server = wrapper->GetBaseServer();
	if (m_bHasClientConnectOffset)
		SH_REMOVE_MANUALHOOK(CHLTVServer_ConnectClient, server, SH_MEMBER(this, &CForwardManager::OnSpectatorConnect), false);

	if (m_bHasGetChallengeTypeOffset)
		SH_REMOVE_MANUALHOOK(CHLTVServer_GetChallengeType, server, SH_MEMBER(this, &CForwardManager::OnGetChallengeType), false);

	// Unhook all connected clients as well.
	for (int i = 0; i < server->GetClientCount(); i++)
	{
		IClient *client = server->GetClient(i);
		if (client->IsConnected())
			UnhookClient(client);
	}
}
コード例 #13
0
unsigned __stdcall ThreadFunction( void *pParam )
{
	IClient *pClient = ( IClient * )pParam;

	ASSERT( pClient );

	while ( !m_theQuitThreadEvent.Wait( 0 ) )
	{
		size_t dataLength = 0;

		const void *pData = pClient->GetPackFromServer( dataLength );

		if ( !pData || 0 == dataLength )
		{
			Sleep( 1 );
			continue;
		}

		EXTEND_HEADER* pHeader = (EXTEND_HEADER*)pData;
		if (pHeader->ProtocolFamily == pf_relay)
		{
			if (pHeader->ProtocolID == relay_c2c_data)
			{
				RELAY_DATA* pRelayCmd = (RELAY_DATA*)pData;

				in_addr ia;
				ia.s_addr = pRelayCmd->nFromIP;
				cout << "relaydata: " << inet_ntoa(ia) << '(' << pRelayCmd->nFromRelayID << ')' << " -- recv size: " << dataLength << endl;
			}
			if (pHeader->ProtocolID == relay_s2c_loseway)
			{
				RELAY_DATA* pRelayCmd = (RELAY_DATA*)pData;

				in_addr ia;
				ia.s_addr = pRelayCmd->nFromIP;
				cout << "loseway: " << inet_ntoa(ia) << '(' << pRelayCmd->nFromRelayID << ')' << " -- recv size: " << dataLength << endl;
			}
		}
	}

	cout << "The read thread was killed safely!" << endl;
	m_theAfirmThreadQuitEvent.Set();

	return 0;
}
コード例 #14
0
ファイル: NetworkEvent.cpp プロジェクト: athomaj/RType
void* launchTcpServer(void* param)
{
    IClient *clientTCP = new ClientTCP();
    MenuWindow *win = reinterpret_cast<MenuWindow*>(param);
    clientTCP->setMenuWindow(win);
    
    win->setTcpClient(clientTCP);
    try
    {
        clientTCP->run(win->getNetEvent()->getIp(), 4242);
    }
    catch (std::exception const& e)
    {
        std::cerr << e.what() << std::endl;
    }
    win->getMutex()->lock();
    win->setConnected(false);
    win->getMutex()->unlock();
    return (NULL);
}
コード例 #15
0
bool CForwardManager::CallOnSpectatorChatMessage(HLTVServerWrapper *server, char *msg, int msglen, char *chatgroup, int grouplen)
{
	int clientIndex = 0;
	if (server)
	{
		IClient *client = server->GetLastChatClient();
		if (client)
			clientIndex = client->GetPlayerSlot() + 1;
	}

	m_SpectatorChatMessageFwd->PushCell(clientIndex);
	m_SpectatorChatMessageFwd->PushStringEx(msg, msglen, SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
	m_SpectatorChatMessageFwd->PushStringEx(chatgroup, grouplen, SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);

	cell_t res = Pl_Continue;
	m_SpectatorChatMessageFwd->Execute(&res);
	if (res >= Pl_Handled)
		return true;
	return false;
}
コード例 #16
0
    void CBaseServer::OnFillServerInfo(int SVC_ServerInfo)
    {
        cell_t result = Pl_Continue;
    
        if (g_pFwdAddonsDisabler && AddonsDisabler::AddonsEclipse > 0 && vanillaModeSig)
        {
            int m_nPlayerSlot = *(int *)((unsigned char *)SVC_ServerInfo + 48);
            IClient *pClient = g_pServer->GetClient(m_nPlayerSlot);

            L4D_DEBUG_LOG("ADDONS DISABLER: Eligible client '%s' connected[%s]", pClient->GetClientName(), pClient->GetNetworkIDString());
            
            g_pFwdAddonsDisabler->PushString(pClient->GetNetworkIDString());
            g_pFwdAddonsDisabler->Execute(&result);
            
            /* uint8_t != unsigned char in terms of type */
            uint8_t disableAddons = result == Pl_Handled ? 0 : 1;
            memset((unsigned char *)SVC_ServerInfo + 25, disableAddons, sizeof(uint8_t));
        }

        (this->*(GetTrampoline()))(SVC_ServerInfo);
    }
コード例 #17
0
void CForwardManager::HookServer(HLTVServerWrapper *wrapper)
{
	IServer *server = wrapper->GetBaseServer();
	if (m_bHasClientConnectOffset)
		SH_ADD_MANUALHOOK(CHLTVServer_ConnectClient, server, SH_MEMBER(this, &CForwardManager::OnSpectatorConnect), false);
	
	if (m_bHasGetChallengeTypeOffset)
		SH_ADD_MANUALHOOK(CHLTVServer_GetChallengeType, server, SH_MEMBER(this, &CForwardManager::OnGetChallengeType), false);

	// Hook all already connected clients as well for late loading
	for (int i = 0; i < server->GetClientCount(); i++)
	{
		IClient *client = server->GetClient(i);
		if (client->IsConnected())
		{
			HookClient(client);
			// Ip and password unknown :(
			// Could add more gamedata to fetch it if people really lateload the extension and expect it to work :B
			wrapper->GetClient(i + 1)->Initialize("", "", client);
		}
	}
}
コード例 #18
0
ファイル: lac.cpp プロジェクト: Leystryku/lac
bool __stdcall hooked_ExecuteStringCmd( const char* cmd)
{
	IClient *ply = 0;
	__asm mov ply, ecx;

	if (!ply || !cmd || !Lua||!ply->GetNetworkIDString())
		return ExecuteStringCmd(cmd);

	Lua->PushSpecial(SPECIAL_GLOB);
	Lua->GetField(-1, "hook");
	Lua->GetField(-1, "Call");
	Lua->PushString("LAC.ExecuteStringCmd");
	Lua->PushNil();
	Lua->PushString(ply->GetNetworkIDString());
	Lua->PushString(cmd);
	int error = Lua->PCall(4, 1, 0);
	if (error)
	{
		Msg("!LAC ERROR! - ExecuteStringCmd: %s\n", Lua->GetString(-1));
		Lua->Pop();
	}

	if (Lua->IsType(-1, GarrysMod::Lua::Type::BOOL))
	{
		if (Lua->GetBool(-1))
		{
			Lua->Pop(3);
			return true;
		}
			
	}

	Lua->Pop(3);

	return ExecuteStringCmd( cmd);
}
コード例 #19
0
void TServerConnectState::ConnectToServer()
{	
	IClient* client = (IClient*)Application->RetrieveInterface(IID_IClient);
	assert(client);
	client->Connect("127.0.0.1", ServerPortConst);	
}
コード例 #20
0
IClient *CForwardManager::OnSpectatorConnect(netadr_t & address, int nProtocol, int iChallenge, int iClientChallenge, int nAuthProtocol, const char *pchName, const char *pchPassword, const char *pCookie, int cbCookie)
#endif
{
	if (!pCookie || (size_t)cbCookie < sizeof(uint64))
		RETURN_META_VALUE(MRES_IGNORED, nullptr);

#if SOURCE_ENGINE == SE_CSGO
	// CS:GO doesn't send the player name in pchName, but only in the client info convars.
	// Try to extract the name from the protobuf msg.
	char playerName[MAX_PLAYER_NAME_LENGTH];
	if (ExtractPlayerName(pSplitPlayerConnectVector, playerName, sizeof(playerName)))
		pchName = playerName;
#endif

	char ipString[16];
	V_snprintf(ipString, sizeof(ipString), "%u.%u.%u.%u", address.ip[0], address.ip[1], address.ip[2], address.ip[3]);
	V_strncpy(passwordBuffer, pchPassword, 255);

	// SourceTV doesn't validate steamids?!

	char rejectReason[255];

	m_SpectatorPreConnectFwd->PushString(pchName);
	m_SpectatorPreConnectFwd->PushStringEx(passwordBuffer, 255, SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
	m_SpectatorPreConnectFwd->PushString(ipString);
	m_SpectatorPreConnectFwd->PushStringEx(rejectReason, 255, SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);

	cell_t retVal = 1;
	m_SpectatorPreConnectFwd->Execute(&retVal);

	IServer *server = META_IFACEPTR(IServer);
	if (retVal == 0)
	{
		if (m_bHasRejectConnectionOffset)
		{
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_LEFT4DEAD || SOURCE_ENGINE == SE_LEFT4DEAD2
			SH_MCALL(server, CHLTVServer_RejectConnection)(address, rejectReason);
#else
			SH_MCALL(server, CHLTVServer_RejectConnection)(address, iClientChallenge, rejectReason);
#endif
		}
		RETURN_META_VALUE(MRES_SUPERCEDE, nullptr);
	}

	// Call the original function.
#if SOURCE_ENGINE == SE_CSGO
	IClient *client = SH_MCALL(server, CHLTVServer_ConnectClient)(address, nProtocol, iChallenge, nAuthProtocol, pchName, passwordBuffer, pCookie, cbCookie, pSplitPlayerConnectVector, bUnknown, platform, pUnknown, iUnknown);
#elif SOURCE_ENGINE == SE_LEFT4DEAD || SOURCE_ENGINE == SE_LEFT4DEAD2
	IClient *client = SH_MCALL(server, CHLTVServer_ConnectClient)(address, nProtocol, iChallenge, nAuthProtocol, pchName, passwordBuffer, pCookie, cbCookie, pSplitPlayerConnectVector, bUnknown);
#else
	IClient *client = SH_MCALL(server, CHLTVServer_ConnectClient)(address, nProtocol, iChallenge, iClientChallenge, nAuthProtocol, pchName, passwordBuffer, pCookie, cbCookie);
#endif

	if (!client)
		RETURN_META_VALUE(MRES_SUPERCEDE, nullptr);

	HookClient(client);

	HLTVServerWrapper *wrapper = g_HLTVServers.GetWrapper(server);
	if (wrapper)
	{
		HLTVClientWrapper *clientWrapper = wrapper->GetClient(client->GetPlayerSlot() + 1);
		clientWrapper->Initialize(ipString, pchPassword, client);
	}

	m_SpectatorConnectedFwd->PushCell(client->GetPlayerSlot() + 1);
	m_SpectatorConnectedFwd->Execute();

	// Don't call the hooked function again, just return its value.
	RETURN_META_VALUE(MRES_SUPERCEDE, client);
}
コード例 #21
0
/*
 * main
 */
int main(int argc, char* argv[])
{
	setcolor( enumCyanonBlack );

	cout << "Welcome to the example that it can be to test relay server." << endl << endl;

	setcolor( enumDefault );

	IClient *pClient = NULL;

	pfnCreateClientInterface pFactroyFun = 
		(pfnCreateClientInterface)g_theRainbowDll.GetProcAddress("CreateInterface");

	IClientFactory *pClientFactory = NULL;
 
	ASSERT(pFactroyFun);

	if (SUCCEEDED(pFactroyFun(IID_IClientFactory, reinterpret_cast< void ** >(&pClientFactory))))
	{
		pClientFactory->SetEnvironment(8192);
		
		pClientFactory->CreateClientInterface(IID_IESClient, reinterpret_cast< void ** >(&pClient ));
		
		pClientFactory->Release();
	}

	ASSERT(pClient);

	pClient->Startup();

	pClient->RegisterMsgFilter( reinterpret_cast< void * >( pClient ), ClientEventNotify );

	//cout << "Relay Server IP: ";
	string relayip = "192.168.20.15";
	//cin >> relayip;

	if ( FAILED( pClient->ConnectTo( relayip.c_str(), 7777 ) ) )
	{
		cout << "To connect the account server is failed!" << endl;

		exit( -1 );
	}

	IClient *pClonClient = NULL;
	pClient->QueryInterface( IID_IESClient, reinterpret_cast< void ** >( &pClonClient ) );

	unsigned int threadID = 0;
	
	HANDLE hThread = (HANDLE)::_beginthreadex(0,
		0, 
		ThreadFunction,
		( void * )pClonClient,
		0, 
		&threadID );

	ASSERT( hThread );
	
	SAFE_CLOSEHANDLE( hThread );		

	//m_theTaskEvent.Wait();

	/*
	 * System command
	 */
_TRY_AGAIN:
	if (argc == 1)
	{
		string sInfo;
		cout << "Command:" << endl;

		cin >> sInfo;
		if (0 == sInfo.compare( "relayto" ))
		{
			cout << "IP:";
			string sip;
			cin >> sip;
			cout << "id:";
			unsigned long id;
			cin >> id;

			for (int i = 0; i < 1000; i++)
				RelayTo(pClient, inet_addr(sip.c_str()), id);
		}