public static void initServer() { Global.echo("\n--------- Initializing " + Globals.GetString("appName") + ": Server Scripts ---------"); // Load prefs string prefPath = Core.HelperFunctions.getPrefpath(); if (Global.isFile(prefPath + "/serverPrefs.cs")) { Global.exec(prefPath + "/serverPrefs.cs"); } else { //todo exec server/defaults.cs Global.exec("data/clientServer/scripts/server/defaults.cs"); } Audio.Init(); Commands.Init(); Message.Init(); LevelDownload.Init(); LevelLoad.Init(); LevelInfo.Init(); GameConnectionToClient.Init(); // Server::Status is returned in the Game Info Query and represents the // current status of the server. This string sould be very short. Globals.SetString("Server::Status", "Unknown"); // Turn on testing/debug script functions Globals.SetBool("Server::TestCheats", false); // Specify where the mission files are. Globals.SetString("Server::MissionFileSpec", "data/levels/*.mis"); }
/// <summary> /// Create a server with either a "SinglePlayer" or "MultiPlayer" type /// Specify the level to load on the server /// </summary> /// <param name="serverType"></param> /// <param name="level"></param> /// <returns></returns> public static bool createServer(string serverType, string level) { // Increase the server session number. This is used to make sure we're // working with the server session we think we are. Globals.Increment("Server::Session"); if (string.IsNullOrEmpty(level)) { Global.error("createServer(): level name unspecified"); return(false); } // Make sure our level name is relative so that it can send // across the network correctly level = Global.makeRelativePath(level, Global.getWorkingDirectory()); destroyServer(); Globals.SetInt("missionSequence", 0); Globals.SetInt("Server::PlayerCount", 0); Globals.SetString("Server::ServerType", serverType); Globals.SetString("Server::LoadFailMsg", ""); Globals.SetBool("Physics::isSinglePlayer", true); // Setup for multi-player, the network must have been // initialized before now. if (serverType.Equals("MultiPlayer")) { Globals.SetBool("Physics::isSinglePlayer", false); Global.echo("Starting multiplayer mode"); // Make sure the network port is set to the correct pref. portInit(Globals.GetInt("Pref::Server::Port")); Global.allowConnections(true); if (!Globals.GetString("pref::Net::DisplayOnMaster").Equals("Never")) { Global.schedule("0", "0", Global.getTag("startHeartbeat")); } } // Let the game initialize some things now that the // the server has been created onServerCreated(); LevelLoad.loadMission(level, true); Globals.SetBool("Game::running", true); return(true); }