Example #1
0
bool ServerCore::Load(void)
{
	Log::SetState( LOG_INFO|LOG_ERROR|LOG_WARNING|LOG_DEBUG );
	Log::AddLogger(&logfile);
	Log::AddLogger(&logserver);
	concore.SetOutputFunction(Log::Info);
	concore.SetExecPath(L"cfg/");
	conscreen.SetCaption(L"FOUR-MP");
	//Core console functions
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"alias", ConCmdAlias, L"Alias a command.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"cvarlist", ConCmdCvarlist, L"Show the list of convars/concommands.", 0));
	hm.AddNewHandle(0, HandleTypeConVar, concore.AddConVar(L"developer", 0, L"Show developer messages.", 0, true, 0, true, 2));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"echo", ConCmdEcho, L"Echo text to console.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"exec", ConCmdExec, L"Execute script file.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"find", ConCmdFind, L"Find concommands with the specified string in their name/help text.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"help", ConCmdHelp, L"Find help about a convar/concommand.", 0));
	// FMP console functions
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"exit", ConCmdQuit, L"Exit the engine.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_list", ConCmdFsList, L"Prints details about loaded gamemode/filterscripts.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_load", ConCmdFsLoad, L"fs_load <filename> : loads a filterscript", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_load_all", ConCmdFsLoadAll, L"Loads all filterscripts", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_pause", ConCmdFsPause, L"fs_pause <index> : pauses a loaded filterscript", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_pause_all", ConCmdFsPauseAll, L"Pauses all loaded filterscripts", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_reload", ConCmdFsReload, L"fs_reload <index> : reloads a filterscript", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_reload_all", ConCmdFsReloadAll, L"Reloads all filterscripts", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_unload", ConCmdFsUnload, L"fs_unload <index> : unloads a filterscript", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_unload_all", ConCmdFsUnloadAll, L"Unloads all filterscripts", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_unpause", ConCmdFsUnpause, L"fs_unpause <index> : unpauses a loaded filterscript", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"fs_unpause_all", ConCmdFsUnpauseAll, L"Unpauses all disabled filterscripts", 0));
	ConVar *gamemodecvar = concore.AddConVar(L"host_gamemode", L"", L"Current gamemode name.", 0);
	gamemodecvar->HookChange(ConVarHookHostGamemode);
	hm.AddNewHandle(0, HandleTypeConVar, gamemodecvar);
	ConVar *hostnamecvar = concore.AddConVar(L"hostname", L"", L"Hostname for server.", 0);
	hostnamecvar->HookChange(ConVarHookHostname);
	hm.AddNewHandle(0, HandleTypeConVar, hostnamecvar);
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_list", ConCmdPluginList, L"Prints details about loaded plugins.", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_load", ConCmdPluginLoad, L"plugin_load <filename> : loads a plugin", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_load_all", ConCmdPluginLoadAll, L"Loads all plugins", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_pause", ConCmdPluginPause, L"plugin_pause <index> : pauses a loaded plugin", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_pause_all", ConCmdPluginPauseAll, L"Pauses all loaded plugins", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_reload", ConCmdPluginReload, L"fs_reload <index> : reloads a plugin", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_reload_all", ConCmdPluginReloadAll, L"Reloads all plugins", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_unload", ConCmdPluginUnload, L"fs_unload <index> : unloads a plugin", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_unload_all", ConCmdPluginUnloadAll, L"Unloads all plugins", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_unpause", ConCmdPluginUnpause, L"fs_unpause <index> : unpauses a loaded plugin", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"plugin_unpause_all", ConCmdPluginUnpauseAll, L"Unpauses all disabled plugins", 0));
	hm.AddNewHandle(0, HandleTypeConCmd, concore.AddConCmd(L"quit", ConCmdQuit, L"Exit the engine.", 0));
	ConVar *rconpasswordcvar = concore.AddConVar(L"rcon_password", L"", L"Remote console password.", 0);
	rconpasswordcvar->HookChange(ConVarHookRconPassword);
	hm.AddNewHandle(0, HandleTypeConVar, rconpasswordcvar);
	componentselectcvar = concore.AddConVar(L"sv_componentselect", 0, L"Enables component select", 0, true, 0, true, 1);
	componentselectcvar->HookChange(ConVarHookSvComponentselect);
	hm.AddNewHandle(0, HandleTypeConVar, componentselectcvar);
	ConVar *lancvar = concore.AddConVar(L"sv_lan", 1, L"Server is a lan server (no heartbeat, no authentication, no non-class C addresses).", 0, true, 0, true, 1);
	lancvar->HookChange(ConVarHookSvLan);
	hm.AddNewHandle(0, HandleTypeConVar, lancvar);
	ConVar *passwordcvar = concore.AddConVar(L"sv_password", L"", L"Server password for entry into multiplayer games", 0);
	passwordcvar->HookChange(ConVarHookSvPassword);
	hm.AddNewHandle(0, HandleTypeConVar, passwordcvar);
	ConVar *portcvar = concore.AddConVar(L"sv_port", 7777, L"Server port.", 0, true, 0, true, 65535);
	portcvar->HookChange(ConVarHookSvPort);
	hm.AddNewHandle(0, HandleTypeConVar, portcvar);
	Log::Void(L"FOUR-MP. Copyright 2009-2010 Four-mp team.");
	concore.InterpretLine(L"exec server.cfg");
	sleepcount = 1000 / SERVER_TICKRATE;
	gametime.ticksperminute = SERVER_TICKRATE * 2;
	nm.Load(playm.GetMaxPlayers(), port);
	maxplayers = playm.GetMaxPlayers();
	plugm.LoadPlugins();
	vmm.LoadFilterScripts();
	if (!vmm.LoadGameMode(gamemode))
	{
		Log::Error(L"Can't load gamemode.");
		return false;
	}
	gamemodename = vmm.GetGameModeName();
	if (!lan)
	{
		msm.Init();
	}
	this->UpdateServerInfo();
	this->UpdateCaption();
	isrunning = true;
	Log::Debug(L"Started");
	return true;
}