示例#1
0
//Entry point
//Configure log
//Read config file
int main(int argc, const char** argv)
{
	char str[1];
	setupLog();

	ConfigLoader::init("config.ini");

	physicsWorker = new PhysicsWorker(new RakNet::RPC4());
	databaseWorker = new DatabaseWorker(new RakNet::RPC4());
	syncWorker = new SyncWorker(new RakNet::RPC4());
	pPooler = new PacketsPooler();

	//Server init	
	NetworkListener *listen = new NetworkListener();
	listen->add((short)ID_NEW_INCOMING_CONNECTION, handleconn); // Server conenct handler
	listen->add((short)ID_CONNECTION_LOST, handledisconn); // Server disconnect handler
	listen->add((short)VERIFY_ACCOUNT, handleVerify); // Server data verification handler
	listen->add((short)SELECT_CHARACTER, handleCharSelect); // Character choose handler

	mainServer = new Server(listen);

	mainServer->setThread(new std::thread(mainServer->startMainNetworkThread, mainServer, ConfigLoader::getIntVal("Network-ServerPort"), ConfigLoader::getIntVal("Network-MaxPlayers")));
	//Server end

	//Client init
	NetworkListener* clientListen = new NetworkListener();
	clientListen->add((short)ID_CONNECTION_REQUEST_ACCEPTED, registerServer); // PoolerClientConnectHandler.h
	clientListen->add((short)VERIFY_RESPONSE, verifyResultHandler); // VerifyResponseHandler.h
	clientListen->add((short)ID_CONNECTION_ATTEMPT_FAILED, authConnFail); // ConnToAuthFailHandler.h


	poolerClient = new Client(clientListen);
	poolerClient->connect(ConfigLoader::getVal("Network-PoolerAddress"), ConfigLoader::getIntVal("Network-PoolerPort"));
	//Client end

	physicsWorker->start(ConfigLoader::getVal("PhysicsWorker-Address"), ConfigLoader::getIntVal("PhysicsWorker-Port"));
	databaseWorker->start(ConfigLoader::getVal("DatabaseWorker-Address"), ConfigLoader::getIntVal("DatabaseWorker-Port"));
	syncWorker->start(ConfigLoader::getVal("SyncWorker-Address"), ConfigLoader::getIntVal("SyncWorker-Port"));

	//TODO: start command reader loop
	cin >> str;//Just for blocking

	poolerClient->setRunning(false);
	poolerClient->getThread()->join();

	mainServer->setRunning(false);
	mainServer->getThread()->join();

	//Cleaning 
	delete pPooler;
	delete databaseWorker;
	delete physicsWorker;
	delete syncWorker;

	return 0;
}
示例#2
0
文件: main.cpp 项目: Cyph3r/IntWars
int main(int argc, char ** argv) 
{
	Logging->writeLine("IntWars %s\n",SERVER_VERSION);
	NetworkListener *listener = new NetworkListener();
	ENetAddress address;
	address.host = SERVER_HOST;
	address.port = SERVER_PORT;

	listener->initialize(&address, SERVER_KEY);
	Logging->writeLine("Starting net loop\n");
	listener->netLoop();
	delete listener;

	Logging->writeLine("Goodbye\n");
}
示例#3
0
文件: RakAuth.cpp 项目: SKDS/Server
//Entry point for server
//Init log
//Init configuration
//Init SSH tunnel
//Init auth server(for players)
//Init pooler server(for registering servers)
int _tmain(int argc, _TCHAR* argv[])
{
	char str[23];
	setupLog();
	LOG(INFO) << "Log was initialized...";
	ConfigLoader::init();
	LOG(INFO) << "Configuration loaded...";
	
	//dbWorker = &DatabaseWorker();
	//dbWorker->init();

	//Auth server
	NetworkListener listen;
	listen.add((short)ID_NEW_INCOMING_CONNECTION, handleAuthconn);
	listen.add((short)ID_CONNECTION_LOST, handleDisconnectFromAuth);
	listen.add((short)ACCOUNT_AUTH, handleAuth);

	Server authSrv(&listen);

	authServer = &authSrv;
	std::thread trd1(authServer->startNetworkTrd, authServer, ConfigLoader::getIntVal("Auth-Port"), ConfigLoader::getIntVal("Auth-MaxCons"));
	authServer->networkTrd = &trd1;
	//Auth server end
	
	LOG(INFO) << "Auth server was started!";

	//Pooler server
	NetworkListener plisten;
	plisten.add((short)ID_NEW_INCOMING_CONNECTION, handleconn);
	plisten.add((short)AUTH_TO_POOLER, handlePoolerAuth);
	plisten.add((short)ID_DISCONNECTION_NOTIFICATION, handleDisconnectFromPooler);
	//plisten.add((short)CHANGE_SERVER_STATE, handleChangeState); will be implemented in future
	//plisten.add((short)VERIFY_REQUEST, handleVerification); will be implemented in future

	Server poolSrv(&plisten);

	poolerServer = &poolSrv;
	std::thread trd2(poolerServer->startNetworkTrd, poolerServer, ConfigLoader::getIntVal("Pooler-Port"), ConfigLoader::getIntVal("Pooler-MaxCons"));
	poolerServer->networkTrd = &trd2;
	//Pooler server end
	
	LOG(INFO) << "Pooler server was started!";

	cin >> str;
	
	LOG(INFO) << "Stopping auth server...";
	authServer->running = false;
	authServer->networkTrd->join();

	LOG(INFO) << "Stopping pooler server...";
	poolerServer->running = false;
	poolerServer->networkTrd->join();
	
	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	char str[10];
	setupLog();
	ConfigLoader::init("config.ini");
	NetworkListener listen;

	listen.add((short)ID_CONNECTION_REQUEST_ACCEPTED, handleConnect);
	listen.add((short)ID_CONNECTION_LOST, handleDisconnect);
	listen.add((short)ID_DISCONNECTION_NOTIFICATION, handleDisconnect);
	listen.add((short)CREATE_WORLD, handleCreateWorld);
	listen.add((short)ADD_ENTITY, handleEntity);
	listen.add((short)REMOVE_ENTITY, handleRemoveEntity);

	Server authSrv(&listen);

	mainServer = &authSrv;
	std::thread trd1(mainServer->startNetworkTrd, mainServer, ConfigLoader::getIntVal("Network-Port"), ConfigLoader::getIntVal("Network-MaxCons"));
	mainServer->setThread(&trd1);
	
	gets(str);

	mainServer->setRunning(false);
	mainServer->getThread()->join();

	return 0;
}
示例#5
0
//Entry point for server
//Init log
//Init configuration
//Load security keys
//Init auth server(for players)
//Init pooler server(for registering servers)
int _tmain(int argc, _TCHAR* argv[])
{
	char str[23];
	setupLog();
	LOG(INFO) << "Log was initialized...";
	ConfigLoader::init("config.ini");
	LOG(INFO) << "Configuration loaded...";
	
	//Generating and saving public and private keys
	if (!loadKeys())
	{
		cat::EasyHandshake::Initialize();
		cat::EasyHandshake handshake;
		handshake.GenerateServerKey(public_key, private_key);
		FILE *fp;
		fp = fopen("private", "wb");
		fwrite(private_key, sizeof(private_key), 1, fp);
		fclose(fp);
		fp = fopen("public", "wb");
		fwrite(public_key, sizeof(public_key), 1, fp);
		fclose(fp);
		LOG(INFO) << "Security keys have generated!";
	//	loadKeys();
	}

	//Auth server
	NetworkListener listen;
	listen.add((short)ID_NEW_INCOMING_CONNECTION, handleAuthconn);
	listen.add((short)ID_CONNECTION_LOST, handleDisconnectFromAuth);
	listen.add((short)ID_CONNECTION_LOST, handleDisconnectFromAuth);
	listen.add((short)ACCOUNT_AUTH, handleAuth);
	listen.add((short)CHECK_NICKNAME, handleNickCheck);
	listen.add((short)CREATE_CHARACTER, handleCharacterCreation);
	listen.add((short)REQUEST_CHARACTER_INFO, charReqHandler);
	listen.add((short)DELETE_CHARACTER, charDelHandle);

	//Debug connection
	listen.add((short)ID_CONNECTION_ATTEMPT_FAILED, handlefail);
	listen.add((short)ID_CONNECTION_REQUEST, handleReq);
	listen.add((short)ID_CONNECTION_REQUEST_ACCEPTED, handleReqAcc);
	listen.add((short)ID_REMOTE_SYSTEM_REQUIRES_PUBLIC_KEY, handlePubKey);
	listen.add((short)ID_PUBLIC_KEY_MISMATCH, handleWrgKey);
	listen.add((short)ID_OUR_SYSTEM_REQUIRES_SECURITY, handleInitSec);

	Server authSrv(&listen);

	authServer = &authSrv;
	authServer->initSecurity(public_key, private_key);//Must be called before starting network thread! (See RakPeerInterface.h for info)
	std::thread trd1(authServer->startNetworkTrd, authServer, ConfigLoader::getIntVal("Auth-Port"), ConfigLoader::getIntVal("Auth-MaxCons"));
	authServer->setThread(&trd1);
	//Auth server end
	
	LOG(INFO) << "Auth server was started!";

	//Pooler server
	NetworkListener plisten;
	plisten.add((short)ID_NEW_INCOMING_CONNECTION, handleconn);
	plisten.add((short)AUTH_TO_POOLER, handlePoolerAuth);
	plisten.add((short)ID_CONNECTION_LOST, handleDisconnectFromPooler);
	plisten.add((short)ID_DISCONNECTION_NOTIFICATION, handleDisconnectFromPooler);
	plisten.add((short)VERIFY_ACCOUNT, handleVerifyRequest);

	
	//plisten.add((short)CHANGE_SERVER_STATE, handleChangeState); will be implemented in future
	//plisten.add((short)VERIFY_REQUEST, handleVerification); will be implemented in future

	Server poolSrv(&plisten);

	poolerServer = &poolSrv;
	std::thread trd2(poolerServer->startNetworkTrd, poolerServer, ConfigLoader::getIntVal("Pooler-Port"), ConfigLoader::getIntVal("Pooler-MaxCons"));
	poolerServer->setThread(&trd2);
	//Pooler server end
	
	LOG(INFO) << "Pooler server was started!";

	//TODO: start command reader loop
	cin >> str; // just for blocking
	
	LOG(INFO) << "Stopping auth server...";
	authServer->setRunning(false);
	authServer->getThread()->join();

	LOG(INFO) << "Stopping pooler server...";
	poolerServer->setRunning(false);
	poolerServer->getThread()->join();
	
	return 0;
}