예제 #1
0
int main(int argc, const char **argv)
{

	//////////////////////////////////////////////////////////////////////////
	//set up logging : 
	TNLLogEnable(LogGhostConnection, true);
	TNLLogEnable(LogNetInterface,true);

	//////////////////////////////////////////////////////////////////////////
	//create a server : 
	//xNetworkFactory::xSCreateServerInterface(m_NetInterfaceServer,localServerAddress,localBroadcastAddress);
	TNL::Address *add = new TNL::Address("IP:Any:28999");
	TNL::Address *addBC=new TNL::Address("IP:broadcast:28999");
	m_NetInterfaceServer =  new xNetInterface(false,*add,*addBC);
	TNL::AsymmetricKey *theKey = new TNL::AsymmetricKey(32);
	m_NetInterfaceServer->setPrivateKey(theKey);
	m_NetInterfaceServer->setRequiresKeyExchange(false);
//	m_NetInterfaceServer->GetDistObjectInterface()->SetNetworkInterface(m_NetInterfaceServer);

	if (m_NetInterfaceServer)
	{
		m_NetInterfaceServer->setAllowsConnections(true);
		m_NetInterfaceServer->setConnection(new vtConnection());
		TNL::Address address = TNL::Address("IP:192.168.1.104:28999");
		m_NetInterfaceServer->getConnection()->connect(m_NetInterfaceServer,address,true,false);


		//m_NetInterfaceServer->GetDistObjectInterface()->SetNetworkInterface(m_NetInterfaceServer);
	}

	//Sleep(2000);
	if (GetServerInterface())
	{
		logprintf("\t Server Created");
	}
	
	for (;;)
	{

		GetServerInterface()->tick();
		TNL::Platform::sleep(1);
	}


	return 0;
}
예제 #2
0
int main(int argc, const char **argv)
{


	xLogger::GetInstance()->addLogItem(E_LI_SESSION);
	//xLogger::GetInstance()->enableLoggingLevel(E_LI_SESSION,ELOGINFO,1);
	
	xLogger::GetInstance()->addLogItem(E_LI_CLIENT);
	xLogger::GetInstance()->addLogItem(E_LI_3DOBJECT);
	xLogger::GetInstance()->addLogItem(E_LI_2DOBJECT);
	xLogger::GetInstance()->addLogItem(E_LI_DISTRIBUTED_BASE_OBJECT);
	xLogger::GetInstance()->addLogItem(E_LI_DISTRIBUTED_CLASS_DESCRIPTORS);
	xLogger::GetInstance()->addLogItem(E_LI_MESSAGES);
	xLogger::GetInstance()->addLogItem(E_LI_ARRAY_MESSAGES);
	xLogger::GetInstance()->addLogItem(E_LI_CONNECTION);
	xLogger::GetInstance()->addLogItem(E_LI_NET_INTERFACE);
	xLogger::GetInstance()->addLogItem(E_LI_GHOSTING);
	xLogger::GetInstance()->addLogItem(E_LI_STATISTICS);
	xLogger::GetInstance()->addLogItem(E_LI_BUILDINGBLOCKS);
	xLogger::GetInstance()->addLogItem(E_LI_VSL);
	xLogger::GetInstance()->addLogItem(E_LI_CPP);
	xLogger::GetInstance()->enableLoggingLevel(E_LI_CPP,ELOGINFO,1);
	xLogger::GetInstance()->addLogItem(E_LI_ASSERTS);
	xLogger::GetInstance()->addLogItem(E_LI_PREDICTION);
	xLogger::GetInstance()->addLogItem(E_LI_SERVER_MESSAGES);

	xLogger::GetInstance()->addItemDescription("Session");
	xLogger::GetInstance()->addItemDescription("Client");
	xLogger::GetInstance()->addItemDescription("3dObject");
	xLogger::GetInstance()->addItemDescription("2dObject");
	xLogger::GetInstance()->addItemDescription("DistBase Object");
	xLogger::GetInstance()->addItemDescription("DistClassDescr");
	xLogger::GetInstance()->addItemDescription("Messages");
	xLogger::GetInstance()->addItemDescription("ArrayMessages");
	xLogger::GetInstance()->addItemDescription("Connection");
	xLogger::GetInstance()->addItemDescription("NetInterface");
	xLogger::GetInstance()->addItemDescription("Ghosting");
	xLogger::GetInstance()->addItemDescription("Stats");
	xLogger::GetInstance()->addItemDescription("BB");
	xLogger::GetInstance()->addItemDescription("VSL");
	xLogger::GetInstance()->addItemDescription("CPP");
	xLogger::GetInstance()->addItemDescription("Asserts");
	xLogger::GetInstance()->addItemDescription("Prediction");
	xLogger::GetInstance()->addItemDescription("ServerMsg");


	TNLLogEnable(LogNetInterface,true);




	//////////////////////////////////////////////////////////////////////////
	//create a server : 
	
	TNL::Address *add = new TNL::Address("IP:Any:28999");
	TNL::Address *addBC=new TNL::Address("IP:broadcast:28999");
	m_NetInterfaceServer =  new xNetInterface(true,*add,*addBC);
	TNL::AsymmetricKey *theKey = new TNL::AsymmetricKey(32);
	m_NetInterfaceServer->setPrivateKey(theKey);
	m_NetInterfaceServer->setRequiresKeyExchange(false);

	if (m_NetInterfaceServer)
	{
		m_NetInterfaceServer->setAllowsConnections(true);
		
	}

	//Sleep(2000);
	if (GetServerInterface() && GetServerInterface()->getSocket().isValid() )
	{
		
		//logprintf("\t Server Created");
		xLogger::xLog(ELOGINFO,E_LI_CPP,"Server created");
		xLogger::xLog(ELOGINFO,E_LI_CPP,"enter '?' for available commands !" );


	}else{
        xLogger::xLog(ELOGERROR,E_LI_CPP,"Couldn't create socket");
	}

	
	UINT dwPromptThreadID;
	m_hPromptThread = (HANDLE)_beginthreadex( NULL, 0, StaticPromptThread, NULL, 0, &dwPromptThreadID );
	for (;;)
	{

		TNL::U32 currentTime = TNL::Platform::getRealMilliseconds();

		float timeDelta = (currentTime - mLastTime);
		mLastTime = (float)currentTime;
		GetServerInterface()->getMessagesInterface()->advanceTime(timeDelta);
		GetServerInterface()->tick();
		GetServerInterface()->getMessagesInterface()->checkMessages();
		GetServerInterface()->getMessagesInterface()->deleteAllOldMessages();
		if (m_bQuitThread)
		{
			GetServerInterface()->destroy();
			break;
		}
		/*char message[400];
		gets(message);
		if (!strcmp(message,"exit"))
		{
			break;
		}
		

		while (kbhit()){
			getch();
		}*/
		TNL::Platform::sleep(1);
	}


	return 0;
}