Пример #1
0
	ShutDownType Master::Run(int argc, char **argv)
	{
		new Config;
		std::vector<const char*> files;
		files.push_back("server.properties"), files.push_back("misc.properties"),
			files.push_back("character.properties");
		std::string path = "./config";
		if(argc >= 2)
			path = argv[1];
		Config::Instance().Init(path, files);

		new Log(m_service);
		Log::Instance().Init(Config::Instance().GetParam<std::string>(LOGS_PATH_STRING, LOGS_PATH_DEFAULT).c_str(),
			Config::Instance().GetParam<uint8>(LOGS_LEVEL_STRING, LOGS_LEVEL_DEFAULT));

		SetApplicationTitle("Desperion GameServer v%u.%u.%u", GAME_VERSION_MAJOR, GAME_VERSION_MINOR, GAME_VERSION_REVISION);
		Log::Instance().OutColor(TBLUE, 	",------,  ,-----. ,-----, ,------. ,-----. ,------.  ,------. ,------, ,,    ,,");
		Log::Instance().OutColor(TBLUE, 	"| ,--,  ` | .---' |  ,--` | ,--, | | .---' | ,--, |  `--||--' | ,--, | ||\\   ||");
		Log::Instance().OutColor(TBLUE, 	"| |  |  | | |--.  |  `--, | |  | | | |--.  | |  | |     ||    | |  | | || \\  ||");
		Log::Instance().OutColor(TBLUE, 	"| |  |  | | |--'  `---, | | `--` | | |--'  | `--` ,     ||    | |  | | ||  \\ ||");
		Log::Instance().OutColor(TBLUE, 	"| '--'  , | '---, ,---| | | ,----` | '---, | ,-\\  \\  .--||--, | '--' | ||   \\||");
		Log::Instance().OutColor(TBLUE, 	"`------`  `-----' `-----` `-`      `-----' `-`  '--' `------` `------` ``    `'\n");
		Log::Instance().OutColor(TWHITE, "Dofus v%u.%u.%u.%u.%u.%u, protocol %u/%u", DOFUS_VERSION_MAJOR, 
			DOFUS_VERSION_MINOR, DOFUS_VERSION_RELEASE, DOFUS_VERSION_REVISION, DOFUS_VERSION_PATCH, DOFUS_VERSION_BUILD_TYPE,
			PROTOCOL_BUILD, PROTOCOL_REQUIRED_BUILD);
		Log::Instance().OutColor(TWHITE, "GameServer v%u.%u.%u", GAME_VERSION_MAJOR, GAME_VERSION_MINOR, GAME_VERSION_REVISION);
		Log::Instance().OutColor(TWHITE, "Shared v%u.%u.%u\n\n", SHARED_VERSION_MAJOR, SHARED_VERSION_MINOR, SHARED_VERSION_REVISION);

		if(!StartUpDatabase())
			return SHUTDOWN_NORMAL;

		/*ResultPtr QR = sDatabase->Query("SELECT id, effects FROM d2o_item_set;");
		barGoLink go(QR->GetRowCount());
		while(QR->NextRow())
		{
			Field* fields = QR->Fetch();
			std::vector<std::string> table;
			std::ostringstream effects;
			Desperion::FastSplitString<':'>(table, std::string(fields[1].GetString()));
			effects<<table.size();
			for(size_t a = 0; a < table.size(); ++a)
			{
				effects<<":";
				std::vector<std::string> table2;
				Desperion::FastSplitString<';'>(table2, table[a]);
				effects<<table2.size();
				for(size_t b = 0; b < table2.size(); ++b)
				{
					effects<<";";
					std::vector<int> table3;
					Desperion::FastSplit<','>(table3, table2[b], Desperion::SplitInt);
					effects<<3<<","<<OBJECT_EFFECT_INTEGER<<","<<table3[2]<<","<<table3[6];
				}
			}
			sDatabase->Execute("UPDATE d2o_item_set SET effects='%s' WHERE id=%u;", effects.str().c_str(),
				fields[0].GetInt32());
			go.step();
		}
		return SHUTDOWN_NORMAL;*/

		new World;
		World::Instance().Init();
		
		SocketListener<Session> sListener(ThreadPool::Instance().GetService(),
			Config::Instance().GetParam(LOCAL_SERVER_PORT_STRING, LOCAL_SERVER_PORT_DEFAULT));
		Log::Instance().OutNotice("Network", "Listening for Dofus clients on port %u",
			Config::Instance().GetParam(LOCAL_SERVER_PORT_STRING, LOCAL_SERVER_PORT_DEFAULT));

		new GameClient(ThreadPool::Instance().GetService());
		GameClient::Instance().Launch();

		std::cout<<std::endl;
		Log::Instance().OutString("Uptime: %ums", GetUpTime());
		Log::Instance().OutColor(TBLUE, "Type Ctrl+C to safely shutdown the server.\n");

		HookSignals();
		HookSignals();
		while(m_shutdown == SHUTDOWN_NOT_REQUESTED)
		{
			m_service.reset();
			ThreadPool::Instance().SpawnWorkerThreads();
			m_service.run();
			ThreadPool::Instance().ClearWorkerThreads();
		}
		UnHookSignals();
		return m_shutdown;
	}
Пример #2
0
int main(int argc, char * argv[])
{
	ParseArg(argc,argv);

	if (gDaemonFlag)
	{
		CUtil::DaemonInit();
	}
	
	sSessCtrl;
	sLog->Initialize();

	//if (!CUtil::SetRLimit())
	//	return 0;

	if (!g_serverIni.OpenFile("server.ini"))
	{
		IME_ERROR("Cannot open server.ini");
		return 0;
	}

	if (!InitServer())
	{
		IME_ERROR("InitServer failed");
		return 0;
	}

//	//do many init db here
//	if (!StartDB())
//	{
//		IME_ERROR("StartDB failed");
//		return 0;
//	}

	IME_LOG("GameServer Start!");
	
	//todo 
	//hooksignal
	HookSignals();

	///- Launch CNetRunnable thread
	CNetRunnable * pNetRunnable = new CNetRunnable;
	ZThread::Thread netThread(pNetRunnable);
	netThread.setPriority((ZThread::Priority)1);

	ZThread::Thread *pRelayClientThread = NULL;
	if (CSet::ClientSessionRun)
	{
		///- Launch CRelayClientRunnable thread
		CRelayClientRunnable * pRelayClientRunnable = new CRelayClientRunnable;
//		ZThread::Thread relayClientThread(pRelayClientRunnable);
//		relayClientThread.setPriority((ZThread::Priority)1);
		pRelayClientThread = new ZThread::Thread(pRelayClientRunnable);
		pRelayClientThread->setPriority((ZThread::Priority)1);
	}

	///- Launch CWorldRunnable thread
	ZThread::Thread worldThread(new CWorldRunnable);
	worldThread.setPriority((ZThread::Priority)1);

	worldThread.wait();
	netThread.wait();
	//relayClientThread.wait();
	if (pRelayClientThread != NULL)
		pRelayClientThread->wait();

	//unhooksignal	
	UnHookSignals();
	EndServer();
	IME_LOG("GameServer End!");

	return 0;
}