Beispiel #1
0
 public virtual void Init()
 {
     DirectoryInfo CodeBase = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath).Directory;
     Console.WriteLine("Code Base: " + CodeBase.FullName);
     DirectoryInfo FakeRoot = CodeBase.Parent;
     Console.WriteLine("Fake Root: " + FakeRoot.FullName);
     if(GameServer.Instance==null)
     {
         GameServerConfiguration config = new GameServerConfiguration();
         config.RootDirectory = FakeRoot.FullName;
         config.Port = 0; // Auto Choosing Listen Port
         config.UDPPort = 0; // Auto Choosing Listen Port
         config.IP = System.Net.IPAddress.Parse("127.0.0.1");
         config.UDPIP = System.Net.IPAddress.Parse("127.0.0.1");
         config.RegionIP = System.Net.IPAddress.Parse("127.0.0.1");
         GameServer.CreateInstance(config);
     }
     if (!GameServer.Instance.IsRunning)
     {
         Console.WriteLine("Starting GameServer");
         if (!GameServer.Instance.Start())
         {
             Console.WriteLine("Error init GameServer");
         }
     }
     else
     {
         Console.WriteLine("GameServer already running, skip init of Gameserver...");
     }
 }
Beispiel #2
0
 public virtual void Init()
 {
     Directory.SetCurrentDirectory("../../debug");
     string CD = Directory.GetCurrentDirectory();
     Console.WriteLine(CD);
     if (GameServer.Instance == null)
     {
         FileInfo configFile = new FileInfo("./config/serverconfig.xml");
         GameServerConfiguration config = new GameServerConfiguration();
         if (!configFile.Exists)
             config.SaveToXMLFile(configFile);
         else
             config.LoadFromXMLFile(configFile);
         GameServer.CreateInstance(config);
         Directory.SetCurrentDirectory(CD);
     }
     if (!GameServer.Instance.IsRunning)
     {
         Language.LanguageMgr.SetLangPath(Path.Combine(CD, "languages"));
         Console.WriteLine("Starting GameServer");
         if (!GameServer.Instance.Start())
         {
             Console.WriteLine("Error init GameServer");
         }
     }
     else
     {
         Console.WriteLine("GameServer already running, skip init of Gameserver...");
     }
 }
Beispiel #3
0
		public virtual void Init()
		{
			DirectoryInfo CodeBase = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath).Directory;
			Console.WriteLine("Code Base: " + CodeBase.FullName);
			DirectoryInfo FakeRoot = CodeBase.Parent;
			Console.WriteLine("Fake Root: " + FakeRoot.FullName);
			if(GameServer.Instance==null)
			{
				GameServerConfiguration config = new GameServerConfiguration();
				config.RootDirectory = FakeRoot.FullName;
				GameServer.CreateInstance(config);
			}
			if (!GameServer.Instance.IsRunning)
			{
				Console.WriteLine("Starting GameServer");
				if (!GameServer.Instance.Start())
				{
					Console.WriteLine("Error init GameServer");
				}
			}
			else
			{
				Console.WriteLine("GameServer already running, skip init of Gameserver...");
			}
		}
 /// <summary>
 /// Save the GameServer configuration
 /// </summary>
 /// <param name="gsc">The GameServer configuration which should be saved.</param>
 /// <returns></returns>
 public static void saveCurrentConfiguration(GameServerConfiguration gsc)
 {
     try
     {
         FileInfo configFileInfo = new FileInfo(getCurrentConfigFile());
         gsc.SaveToXMLFile(configFileInfo);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #5
0
		/// <summary>
		/// Gets the current configuration of the GameServer
		/// </summary>
		/// <returns></returns>
		public static GameServerConfiguration getCurrentConfiguration()
		{
			try
			{
				FileInfo configFileInfo = new FileInfo(getCurrentConfigFile());
				GameServerConfiguration config = new GameServerConfiguration();
				config.LoadFromXMLFile(configFileInfo);

				return config;
			}
			catch {
				throw;
			}
		}
Beispiel #6
0
		private static bool StartServer()
		{
			//TODO parse args for -config parameter!
			FileInfo dolserver = new FileInfo(Assembly.GetExecutingAssembly().Location);
			Directory.SetCurrentDirectory(dolserver.DirectoryName);
			FileInfo configFile = new FileInfo("./config/serverconfig.xml");
			GameServerConfiguration config = new GameServerConfiguration();
			if(configFile.Exists)
			{
				config.LoadFromXMLFile(configFile);
			}
			else
			{
				if(!configFile.Directory.Exists)
					configFile.Directory.Create();
				config.SaveToXMLFile(configFile);
			}

			GameServer.CreateInstance(config);

			return GameServer.Instance.Start();
		}
Beispiel #7
0
		/// <summary>
		/// Create Game Server Instance for Tests
		/// </summary>
		public static void CreateGameServerInstance()
		{
			Console.WriteLine("Create Game Server Instance");
			DirectoryInfo CodeBase = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath).Directory;
			Console.WriteLine("Code Base: " + CodeBase.FullName);
			DirectoryInfo FakeRoot = CodeBase.Parent;
			Console.WriteLine("Fake Root: " + FakeRoot.FullName);
			
			if(GameServer.Instance == null)
			{
				GameServerConfiguration config = new GameServerConfiguration();
				config.RootDirectory = FakeRoot.FullName;
				config.DBType = ConnectionType.DATABASE_SQLITE;
				config.DBConnectionString = string.Format("Data Source={0};Version=3;Pooling=False;Cache Size=1073741824;Journal Mode=Off;Synchronous=Off;Foreign Keys=True;Default Timeout=60",
			                                     Path.Combine(config.RootDirectory, "dol-tests-only.sqlite3.db"));
				config.Port = 0; // Auto Choosing Listen Port
				config.UDPPort = 0; // Auto Choosing Listen Port
				config.IP = System.Net.IPAddress.Parse("127.0.0.1");
				config.UDPIP = System.Net.IPAddress.Parse("127.0.0.1");
				config.RegionIP = System.Net.IPAddress.Parse("127.0.0.1");
				GameServer.CreateInstance(config);
				Console.WriteLine("Game Server Instance Created !");
			}
		}
Beispiel #8
0
		/// <summary>
		/// Creates the gameserver instance
		/// </summary>
		/// <param name="config"></param>
		public static void CreateInstance(GameServerConfiguration config)
		{
			//Only one intance
			if (Instance != null)
				return;

			//Try to find the log.config file, if it doesn't exist
			//we create it
			var logConfig = new FileInfo(config.LogConfigFile);
			if (!logConfig.Exists)
			{
				ResourceUtil.ExtractResource(logConfig.Name, logConfig.FullName);
			}

			//Configure and watch the config file
			XmlConfigurator.ConfigureAndWatch(logConfig);

			//Create the instance
			m_instance = new GameServer(config);
		}
Beispiel #9
0
		/// <summary>
		/// Constructor with a given configuration
		/// </summary>
		/// <param name="config">A valid game server configuration</param>
		protected GameServer(GameServerConfiguration config)
			: base(config)
		{
			m_gmLog = LogManager.GetLogger(Configuration.GMActionsLoggerName);
			m_cheatLog = LogManager.GetLogger(Configuration.CheatLoggerName);
		    m_inventoryLog = LogManager.GetLogger(Configuration.InventoryLoggerName);

			if (log.IsDebugEnabled)
			{
				log.Debug("Current directory is: " + Directory.GetCurrentDirectory());
				log.Debug("Gameserver root directory is: " + Configuration.RootDirectory);
				log.Debug("Changing directory to root directory");
			}
			Directory.SetCurrentDirectory(Configuration.RootDirectory);

			try
			{
				LoadInvalidNames();

				m_udpBuf = new byte[MAX_UDPBUF];
				m_udpReceiveCallback = new AsyncCallback(RecvFromCallback);
				m_udpSendCallback = new AsyncCallback(SendToCallback);

				if (!InitDB() || m_database == null)
				{
					if (log.IsErrorEnabled)
						log.Error("Could not initialize DB, please check path/connection string");
					throw new ApplicationException("DB initialization error");
				}

				if (log.IsInfoEnabled)
					log.Info("Game Server Initialization finished!");
			}
			catch (Exception e)
			{
				if (log.IsFatalEnabled)
					log.Fatal("GameServer initialization failed!", e);
				throw new ApplicationException("Fatal Error: Could not initialize Game Server", e);
			}
		}
Beispiel #10
0
		public void OnAction(Hashtable parameters)
		{
			Console.WriteLine("Starting GameServer ... please wait a moment!");
			FileInfo configFile;
			FileInfo currentAssembly = null;
			if (parameters["-config"] != null)
			{
				Console.WriteLine("Using config file: " + parameters["-config"]);
				configFile = new FileInfo((String)parameters["-config"]);
			}
			else
			{
				currentAssembly = new FileInfo(Assembly.GetEntryAssembly().Location);
				configFile = new FileInfo(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml");
			}

			GameServerConfiguration config = new GameServerConfiguration();
			if (configFile.Exists)
			{
				config.LoadFromXMLFile(configFile);
			}
			else
			{
				if (!configFile.Directory.Exists)
					configFile.Directory.Create();
				config.SaveToXMLFile(configFile);
				if (File.Exists(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "DOLConfig.exe"))
				{
					Console.WriteLine("No config file found, launching DOLConfig.exe...");
					System.Diagnostics.Process.Start(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "DOLConfig.exe");
					return;
				}
			}

			GameServer.CreateInstance(config);
			StartServer();

			bool run = true;
			while (run)
			{
				Console.Write("> ");
				string line = Console.ReadLine();

				switch (line.ToLower())
				{
					case "exit":
						run = false;
						break;
					case "stacktrace":
						log.Debug(PacketProcessor.GetConnectionThreadpoolStacks());
						break;
					case "clear":
						Console.Clear();
						break;
					default:
						if (line.Length <= 0)
							break;
						if (line[0] == '/')
						{
							line = line.Remove(0, 1);
							line = line.Insert(0, "&");
						}
						GameClient client = new GameClient(null);
						client.Out = new ConsolePacketLib();
						try
						{
							bool res = ScriptMgr.HandleCommandNoPlvl(client, line);
							if (!res)
							{
								Console.WriteLine("Unknown command: " + line);
							}
						}
						catch (Exception e)
						{
							Console.WriteLine(e.ToString());
						}
						break;
				}
			}
			if (GameServer.Instance != null)
				GameServer.Instance.Stop();
		}
Beispiel #11
0
		/// <summary>
		/// Saves current config out of the form
		/// </summary>
		private void saveConfig()
		{
			toolstripStatusLabelValue = "Try to save configuration ...";
			if (currentConfig == null)
			{
				currentConfig = new GameServerConfiguration();
			}

			//Full Server Name
			if (this.full_server_name_textbox.Text.Length == 0)
			{
				addWrongValueErrorHandler(this.full_server_name_textbox, "The value of \"Full Server Name\" is not set.");
				return;
			}
			currentConfig.ServerName = this.full_server_name_textbox.Text;

			//Short Server Name
			if (this.short_server_name_textbox.Text.Length == 0)
			{
				addWrongValueErrorHandler(this.short_server_name_textbox, "The value of \"Short Server Name\" is not set.");
				return;
			}
			currentConfig.ServerNameShort = this.short_server_name_textbox.Text;

			switch (this.game_type_selectbox.SelectedItem.ToString().ToLower())
			{
				case "pvp":
					currentConfig.ServerType = DOL.eGameServerType.GST_PvP;
					break;
				case "pve":
					currentConfig.ServerType = DOL.eGameServerType.GST_PvE;
					break;
				case "roleplay":
					currentConfig.ServerType = DOL.eGameServerType.GST_Roleplay;
					break;
				case "casual":
					currentConfig.ServerType = DOL.eGameServerType.GST_Casual;
					break;
				case "test":
					currentConfig.ServerType = DOL.eGameServerType.GST_Test;
					break;
				case "normal":
				default:
					currentConfig.ServerType = DOL.eGameServerType.GST_Normal;
					break;
			}

			//Parse Auto Account creation
			currentConfig.AutoAccountCreation = this.auto_account_creation_checkbox.Checked;

			//Ip
			if (ip_textbox.Text.Length == 0)
			{
				addWrongValueErrorHandler(this.ip_textbox, "The value of \"IP\" is not set.");
				return;
			}
			try
			{
				currentConfig.IP = new System.Net.IPAddress(ipToByteArray(this.ip_textbox.Text));
			}
			catch (Exception)
			{
				addWrongValueErrorHandler(this.ip_textbox, "The value of \"IP\" is not allowed.");
				return;
			}

			//currentConfig.Ip = new System.Net.IPAddress();
			//Port
			if (this.port_textbox.Text.Length == 0 || Convert.ToUInt16(this.port_textbox.Text) == 0)
			{
				addWrongValueErrorHandler(this.port_textbox, "The value of \"TCP Port\" is not allowed.");
				return;
			}
			currentConfig.Port = Convert.ToUInt16(this.port_textbox.Text);

			//UDP port
			if (this.udp_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.udp_port_textbox.Text) == 0)
			{
				addWrongValueErrorHandler(this.udp_port_textbox, "The value of \"UDP Port\" is not allowed.");
				return;
			}
			currentConfig.UDPPort = Convert.ToUInt16(this.udp_port_textbox.Text);

			//Detect Region IPs
			currentConfig.DetectRegionIP = this.detect_region_ip_checkbox.Checked;

			//Region IP
			if (region_ip_textbox.Text.Length == 0)
			{
				addWrongValueErrorHandler(this.region_ip_textbox, "The value of \"Region IP\" is not set.");
				return;
			}
			try
			{
				currentConfig.RegionIP = new System.Net.IPAddress(ipToByteArray(this.region_ip_textbox.Text));
			}
			catch (Exception)
			{
				addWrongValueErrorHandler(this.region_ip_textbox, "The value of \"Region IP\" is not allowed.");
				return;
			}


			//Region port
			if (this.region_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.region_port_textbox.Text) == 0)
			{
				addWrongValueErrorHandler(this.region_port_textbox, "The value of \"Region Port\" is not allowed.");
				return;
			}
			currentConfig.RegionPort = Convert.ToUInt16(this.region_port_textbox.Text);

			//Database Settings
			currentConfig.AutoSave = this.database_autosave_checkbox.Checked;

			//Auto database save interval
			if (this.database_autosave_interval_textbox.Text.Length == 0 || Convert.ToInt32(this.database_autosave_interval_textbox.Text) == 0)
			{
				addWrongValueErrorHandler(this.database_autosave_interval_textbox, "The value of \"Autosave Interval\" is not allowed.");
				return;
			}
			currentConfig.SaveInterval = Convert.ToInt32(this.database_autosave_interval_textbox.Text);

			//Database settings
			switch (this.database_type_selectbox.SelectedItem.ToString().ToLower())
			{
				case "xml":
					currentConfig.DBType = ConnectionType.DATABASE_XML;
					if(xml_path_textbox.Text.Length == 0) {
						addWrongValueErrorHandler(this.xml_path_textbox, "The value of \"Directory\" in \"XML Database settings\" is not set.");
						return;
					}
					currentConfig.DBConnectionString = xml_path_textbox.Text;
					break;
				case "mysql":
					currentConfig.DBType = ConnectionType.DATABASE_MYSQL;

					//Mysql connection string builder
					MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();

					//Host
					if (this.mysql_host_textbox.Text.Length == 0)
					{
						addWrongValueErrorHandler(this.mysql_host_textbox, "The value of \"Server Address\" in \"MySQL Database settings\" is not set.");
						return;
					}
					sb.Server = this.mysql_host_textbox.Text;

					//Port
					if (this.mysql_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.mysql_port_textbox.Text) == 0)
					{
						addWrongValueErrorHandler(this.mysql_port_textbox, "The value of \"Port\" in \"MySQL Database settings\" is not allowed.");
						return;
					}
					sb.Port = Convert.ToUInt16(this.mysql_port_textbox.Text);

					//Database Name
					if (this.mysql_database_name_textbox.Text.Length == 0)
					{
						addWrongValueErrorHandler(this.mysql_database_name_textbox, "The value of \"Database Name\" in \"MySQL Database settings\" is not set.");
						return;
					}
					sb.Database = this.mysql_database_name_textbox.Text;

					//Username
					if (this.mysql_username_textbox.Text.Length == 0)
					{
						addWrongValueErrorHandler(this.mysql_username_textbox, "The value of \"Username\" in \"MySQL Database settings\" is not set.");
						return;
					}
					sb.UserID = this.mysql_username_textbox.Text;

					//Password
					sb.Password = this.mysql_password_textbox.Text;

					//Treat tiny as boolean
					sb.TreatTinyAsBoolean = false;

					//Set generated connection string
					currentConfig.DBConnectionString = sb.ConnectionString;

					//Just for fun: Test the connection
					mysql_test_button_Click(null, null);

					break;
				default:
					addWrongValueErrorHandler(this.database_type_selectbox, "There is no database connection selected.");
					return;
			}

			//Finally save all configuration
			DOLConfigParser.saveCurrentConfiguration(currentConfig);

			//And write extra properties
			if(this.extraOptions != null) {
				DOLConfigParser.saveExtraOptions(this.extraOptions);
			}

			toolstripStatusLabelValue = "Configuration saved.";
			toolstripTimer.Start();
		}
Beispiel #12
0
		/// <summary>
		/// Set all data to default button event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void set_default_values_button_Click(object sender, EventArgs e)
		{
			if (tabControl1.SelectedTab == sp_tab)
				ResetSP();
			else
			{
				currentConfig = new GameServerConfiguration();
				loadConfig();
			}
		}
 public void InitConfig()
 {
     if (dolConfig==null) {
         dolConfig = new GameServerConfiguration();
         dolConfig.LoadFromXMLFile(new FileInfo(QuestDesignerMain.WorkingDirectory + System.Configuration.ConfigurationManager.AppSettings["DOLServerConfigFile"]));
     }
 }