/// <summary> /// Constructs a server configuration with default values /// </summary> public GameServerConfiguration() : base() { m_ServerName = "Dawn Of Light"; m_ServerNameShort = "DOLSERVER"; if (Assembly.GetEntryAssembly() != null) { m_rootDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName; } else { m_rootDirectory = new FileInfo(Assembly.GetAssembly(typeof(GameServer)).Location).DirectoryName; } m_logConfigFile = Path.Combine(Path.Combine(".", "config"), "logconfig.xml"); m_scriptCompilationTarget = Path.Combine(Path.Combine(".", "lib"), "GameServerScripts.dll"); m_scriptAssemblies = "System.dll,System.Xml.dll"; m_enableCompilation = true; m_autoAccountCreation = true; m_serverType = eGameServerType.GST_Normal; m_cheatLoggerName = "cheats"; m_gmActionsLoggerName = "gmactions"; InventoryLoggerName = "inventories"; m_invalidNamesFile = Path.Combine(Path.Combine(".", "config"), "invalidnames.txt"); m_dbType = ConnectionType.DATABASE_SQLITE; m_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(m_rootDirectory, "dol.sqlite3.db")); m_autoSave = true; m_saveInterval = 10; m_maxClientCount = 500; // Get count of CPUs m_cpuCount = Environment.ProcessorCount; if (m_cpuCount < 1) { try { m_cpuCount = int.Parse(Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")); } catch { m_cpuCount = -1; } } if (m_cpuCount < 1) { m_cpuCount = 1; } m_cpuUse = m_cpuCount; }
/// <summary> /// Constructs a server configuration with default values /// </summary> public GameServerConfiguration() : base() { m_ServerName = "Dawn Of Light"; m_ServerNameShort = "DOLSERVER"; if (Assembly.GetEntryAssembly() != null) { m_rootDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName; } else { m_rootDirectory = Path.Combine(new FileInfo(Assembly.GetAssembly(typeof(GameServer)).Location).DirectoryName, ".."); // GameServer is in ./lib/ } m_logConfigFile = Path.Combine(Path.Combine(".", "config"), "logconfig.xml"); m_scriptCompilationTarget = Path.Combine(Path.Combine(".", "lib"), "GameServerScripts.dll"); m_scriptAssemblies = "System.Text.RegularExpressions.dll,Microsoft.CSharp.dll"; // Regex + dynamic m_enableCompilation = true; m_autoAccountCreation = true; m_serverType = eGameServerType.GST_Normal; m_cheatLoggerName = "cheats"; m_gmActionsLoggerName = "gmactions"; InventoryLoggerName = "inventories"; m_invalidNamesFile = Path.Combine(Path.Combine(".", "config"), "invalidnames.txt"); m_dbType = ConnectionType.DATABASE_SQLITE; m_dbConnectionString = $"Data Source={Path.Combine(m_rootDirectory, "dol.sqlite3.db")}"; m_autoSave = true; m_saveInterval = 10; m_maxClientCount = 500; // Get count of CPUs m_cpuCount = Environment.ProcessorCount; if (m_cpuCount < 1) { try { m_cpuCount = int.Parse(Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")); } catch { m_cpuCount = -1; } } if (m_cpuCount < 1) { m_cpuCount = 1; } m_cpuUse = m_cpuCount; }
/// <summary> /// Create server rules handler for specified server type /// </summary> /// <param name="serverType">server type used to look for rules handler</param> /// <returns>server rules handler or normal server type handler if errors</returns> public static IServerRules CreateServerRules(eGameServerType serverType) { Type rules = null; // first search in scripts foreach (Assembly script in Scripts) { foreach (Type type in script.GetTypes()) { if (type.IsClass == false) continue; if (type.GetInterface("DOL.GS.ServerRules.IServerRules") == null) continue; // look for attribute try { object[] objs = type.GetCustomAttributes(typeof(ServerRulesAttribute), false); if (objs.Length == 0) continue; foreach (ServerRulesAttribute attrib in objs) { if (attrib.ServerType == serverType) { rules = type; break; } } } catch (Exception e) { if (log.IsErrorEnabled) log.Error("CreateServerRules", e); } if (rules != null) break; } } if (rules == null) { // second search in gameserver foreach (Type type in Assembly.GetAssembly(typeof(GameServer)).GetTypes()) { if (type.IsClass == false) continue; if (type.GetInterface("DOL.GS.ServerRules.IServerRules") == null) continue; // look for attribute try { object[] objs = type.GetCustomAttributes(typeof(ServerRulesAttribute), false); if (objs.Length == 0) continue; foreach (ServerRulesAttribute attrib in objs) { if (attrib.ServerType == serverType) { rules = type; break; } } } catch (Exception e) { if (log.IsErrorEnabled) log.Error("CreateServerRules", e); } if (rules != null) break; } } if (rules != null) { try { IServerRules rls = (IServerRules)Activator.CreateInstance(rules, null); if (log.IsInfoEnabled) log.Info("Found server rules for " + serverType + " server type (" + rls.RulesDescription() + ")."); return rls; } catch (Exception e) { if (log.IsErrorEnabled) log.Error("CreateServerRules", e); } } if (log.IsWarnEnabled) log.Warn("Rules for " + serverType + " server type not found, using \"normal\" server type rules."); return new NormalServerRules(); }
public ServerRulesAttribute(eGameServerType serverType) { ServerType = serverType; }
/// <summary> /// Constructs a server configuration with default values /// </summary> public GameServerConfiguration() : base() { m_ServerName = "Dawn Of Light"; m_ServerNameShort = "DOLSERVER"; if(Assembly.GetEntryAssembly()!=null) m_rootDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName; else m_rootDirectory = new FileInfo(Assembly.GetAssembly(typeof(GameServer)).Location).DirectoryName; m_logConfigFile = "." + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "logconfig.xml"; m_scriptCompilationTarget = "."+Path.DirectorySeparatorChar+"lib"+Path.DirectorySeparatorChar+"GameServerScripts.dll"; m_scriptAssemblies = "System.dll,System.Xml.dll"; m_autoAccountCreation = true; m_serverType = eGameServerType.GST_Normal; m_cheatLoggerName = "cheats"; m_gmActionsLoggerName = "gmactions"; InventoryLoggerName = "inventories"; m_invalidNamesFile = "." + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "invalidnames.txt"; m_dbType = ConnectionType.DATABASE_SQLITE; m_dbConnectionString = "Data Source="+m_rootDirectory+Path.DirectorySeparatorChar+"dol.sqlite3.db"+";Version=3;Pooling=False;Cache Size=1073741824;Journal Mode=Off;Synchronous=Off;Foreign Keys=True;Default Timeout=60"; m_autoSave = true; m_saveInterval = 10; m_maxClientCount = 500; // Get count of CPUs m_cpuCount = Environment.ProcessorCount; if (m_cpuCount < 1) { try { m_cpuCount = int.Parse(Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")); } catch { m_cpuCount = -1; } } if (m_cpuCount < 1) { m_cpuCount = 1; } m_cpuUse = m_cpuCount; }
/// <summary> /// Loads the config values from a specific config element /// </summary> /// <param name="root">the root config element</param> protected override void LoadFromConfig(ConfigElement root) { base.LoadFromConfig(root); // Removed to not confuse users // m_rootDirectory = root["Server"]["RootDirectory"].GetString(m_rootDirectory); m_logConfigFile = root["Server"]["LogConfigFile"].GetString(m_logConfigFile); m_scriptCompilationTarget = root["Server"]["ScriptCompilationTarget"].GetString(m_scriptCompilationTarget); m_scriptAssemblies = root["Server"]["ScriptAssemblies"].GetString(m_scriptAssemblies); m_autoAccountCreation = root["Server"]["AutoAccountCreation"].GetBoolean(m_autoAccountCreation); string serverType = root["Server"]["GameType"].GetString("Normal"); switch (serverType.ToLower()) { case "normal": m_serverType = eGameServerType.GST_Normal; break; case "casual": m_serverType = eGameServerType.GST_Casual; break; case "roleplay": m_serverType = eGameServerType.GST_Roleplay; break; case "pve": m_serverType = eGameServerType.GST_PvE; break; case "pvp": m_serverType = eGameServerType.GST_PvP; break; case "test": m_serverType = eGameServerType.GST_Test; break; default: m_serverType = eGameServerType.GST_Normal; break; } m_ServerName = root["Server"]["ServerName"].GetString(m_ServerName); m_ServerNameShort = root["Server"]["ServerNameShort"].GetString(m_ServerNameShort); m_cheatLoggerName = root["Server"]["CheatLoggerName"].GetString(m_cheatLoggerName); m_gmActionsLoggerName = root["Server"]["GMActionLoggerName"].GetString(m_gmActionsLoggerName); m_invalidNamesFile = root["Server"]["InvalidNamesFile"].GetString(m_invalidNamesFile); string db = root["Server"]["DBType"].GetString("XML"); switch (db.ToLower()) { case "xml": m_dbType = ConnectionType.DATABASE_XML; break; case "mysql": m_dbType = ConnectionType.DATABASE_MYSQL; break; case "sqlite": m_dbType = ConnectionType.DATABASE_SQLITE; break; case "mssql": m_dbType = ConnectionType.DATABASE_MSSQL; break; case "odbc": m_dbType = ConnectionType.DATABASE_ODBC; break; case "oledb": m_dbType = ConnectionType.DATABASE_OLEDB; break; default: m_dbType = ConnectionType.DATABASE_XML; break; } m_dbConnectionString = root["Server"]["DBConnectionString"].GetString(m_dbConnectionString); m_autoSave = root["Server"]["DBAutosave"].GetBoolean(m_autoSave); m_saveInterval = root["Server"]["DBAutosaveInterval"].GetInt(m_saveInterval); m_maxClientCount = root["Server"]["MaxClientCount"].GetInt(m_maxClientCount); m_cpuCount = root["Server"]["CpuCount"].GetInt(m_cpuCount); if (m_cpuCount < 1) m_cpuCount = 1; m_cpuUse = root["Server"]["CpuUse"].GetInt(m_cpuUse); if (m_cpuUse < 1) m_cpuUse = 1; // Parse UDP out endpoint IPAddress address = null; int port = -1; string addressStr = root["Server"]["UDPOutIP"].GetString(string.Empty); string portStr = root["Server"]["UDPOutPort"].GetString(string.Empty); if (IPAddress.TryParse(addressStr, out address) && int.TryParse(portStr, out port) && IPEndPoint.MaxPort >= port && IPEndPoint.MinPort <= port) { m_udpOutEndpoint = new IPEndPoint(address, port); } }
/// <summary> /// Loads the config values from a specific config element /// </summary> /// <param name="root">the root config element</param> protected override void LoadFromConfig(ConfigElement root) { base.LoadFromConfig(root); // Removed to not confuse users // m_rootDirectory = root["Server"]["RootDirectory"].GetString(m_rootDirectory); m_logConfigFile = root["Server"]["LogConfigFile"].GetString(m_logConfigFile); m_scriptCompilationTarget = root["Server"]["ScriptCompilationTarget"].GetString(m_scriptCompilationTarget); m_scriptAssemblies = root["Server"]["ScriptAssemblies"].GetString(m_scriptAssemblies); m_autoAccountCreation = root["Server"]["AutoAccountCreation"].GetBoolean(m_autoAccountCreation); string serverType = root["Server"]["GameType"].GetString("Normal"); switch (serverType.ToLower()) { case "normal": m_serverType = eGameServerType.GST_Normal; break; case "casual": m_serverType = eGameServerType.GST_Casual; break; case "roleplay": m_serverType = eGameServerType.GST_Roleplay; break; case "pve": m_serverType = eGameServerType.GST_PvE; break; case "pvp": m_serverType = eGameServerType.GST_PvP; break; case "test": m_serverType = eGameServerType.GST_Test; break; default: m_serverType = eGameServerType.GST_Normal; break; } m_ServerName = root["Server"]["ServerName"].GetString(m_ServerName); m_ServerNameShort = root["Server"]["ServerNameShort"].GetString(m_ServerNameShort); m_cheatLoggerName = root["Server"]["CheatLoggerName"].GetString(m_cheatLoggerName); m_gmActionsLoggerName = root["Server"]["GMActionLoggerName"].GetString(m_gmActionsLoggerName); m_invalidNamesFile = root["Server"]["InvalidNamesFile"].GetString(m_invalidNamesFile); string db = root["Server"]["DBType"].GetString("XML"); switch (db.ToLower()) { case "xml": m_dbType = ConnectionType.DATABASE_XML; break; case "mysql": m_dbType = ConnectionType.DATABASE_MYSQL; break; case "sqlite": m_dbType = ConnectionType.DATABASE_SQLITE; break; case "mssql": m_dbType = ConnectionType.DATABASE_MSSQL; break; case "odbc": m_dbType = ConnectionType.DATABASE_ODBC; break; case "oledb": m_dbType = ConnectionType.DATABASE_OLEDB; break; default: m_dbType = ConnectionType.DATABASE_XML; break; } m_dbConnectionString = root["Server"]["DBConnectionString"].GetString(m_dbConnectionString); m_autoSave = root["Server"]["DBAutosave"].GetBoolean(m_autoSave); m_saveInterval = root["Server"]["DBAutosaveInterval"].GetInt(m_saveInterval); m_maxClientCount = root["Server"]["MaxClientCount"].GetInt(m_maxClientCount); m_cpuCount = root["Server"]["CpuCount"].GetInt(m_cpuCount); if (m_cpuCount < 1) { m_cpuCount = 1; } m_cpuUse = root["Server"]["CpuUse"].GetInt(m_cpuUse); if (m_cpuUse < 1) { m_cpuUse = 1; } // Parse UDP out endpoint IPAddress address = null; int port = -1; string addressStr = root["Server"]["UDPOutIP"].GetString(string.Empty); string portStr = root["Server"]["UDPOutPort"].GetString(string.Empty); if (IPAddress.TryParse(addressStr, out address) && int.TryParse(portStr, out port) && IPEndPoint.MaxPort >= port && IPEndPoint.MinPort <= port) { m_udpOutEndpoint = new IPEndPoint(address, port); } }
/// <summary> /// Create server rules handler for specified server type /// </summary> /// <param name="serverType">server type used to look for rules handler</param> /// <returns>server rules handler or normal server type handler if errors</returns> public static IServerRules CreateServerRules(eGameServerType serverType) { Type rules = null; // first search in scripts foreach (Assembly script in Scripts) { foreach (Type type in script.GetTypes()) { if (type.IsClass == false) { continue; } if (type.GetInterface("DOL.GS.ServerRules.IServerRules") == null) { continue; } // look for attribute try { object[] objs = type.GetCustomAttributes(typeof(ServerRulesAttribute), false); if (objs.Length == 0) { continue; } foreach (ServerRulesAttribute attrib in objs) { if (attrib.ServerType == serverType) { rules = type; break; } } } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("CreateServerRules", e); } } if (rules != null) { break; } } } if (rules == null) { // second search in gameserver foreach (Type type in Assembly.GetAssembly(typeof(GameServer)).GetTypes()) { if (type.IsClass == false) { continue; } if (type.GetInterface("DOL.GS.ServerRules.IServerRules") == null) { continue; } // look for attribute try { object[] objs = type.GetCustomAttributes(typeof(ServerRulesAttribute), false); if (objs.Length == 0) { continue; } foreach (ServerRulesAttribute attrib in objs) { if (attrib.ServerType == serverType) { rules = type; break; } } } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("CreateServerRules", e); } } if (rules != null) { break; } } } if (rules != null) { try { IServerRules rls = (IServerRules)Activator.CreateInstance(rules, null); if (log.IsInfoEnabled) { log.Info("Found server rules for " + serverType + " server type (" + rls.RulesDescription() + ")."); } return(rls); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("CreateServerRules", e); } } } if (log.IsWarnEnabled) { log.Warn("Rules for " + serverType + " server type not found, using \"normal\" server type rules."); } return(new NormalServerRules()); }
/// <summary> /// Constructs a server configuration with default values /// </summary> public GameServerConfiguration() : base() { m_ServerName = "Dawn Of Light"; m_ServerNameShort = "DOLSERVER"; if (Assembly.GetEntryAssembly() != null) m_rootDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName; else m_rootDirectory = new FileInfo(Assembly.GetAssembly(typeof(GameServer)).Location).DirectoryName; m_logConfigFile = "." + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "logconfig.xml"; m_regionConfigFile = "." + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "regions.xml"; m_zoneConfigFile = "." + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "zones.xml"; m_scriptCompilationTarget = "." + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + "GameServerScripts.dll"; m_scriptAssemblies = "DOLBase.dll,GameServer.dll,DOLDatabase.dll,System.dll,log4net.dll,System.Xml.dll"; m_autoAccountCreation = true; m_serverType = eGameServerType.GST_Normal; m_cheatLoggerName = "cheats"; m_gmActionsLoggerName = "gmactions"; InventoryLoggerName = "inventories"; m_invalidNamesFile = "." + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "invalidnames.txt"; m_dbType = ConnectionType.DATABASE_XML; m_dbConnectionString = m_rootDirectory + Path.DirectorySeparatorChar + "xml_db"; m_autoSave = true; m_saveInterval = 10; m_maxClientCount = 500; // Get count of CPUs m_cpuCount = Environment.ProcessorCount; if (m_cpuCount < 1) { try { m_cpuCount = int.Parse(Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")); } catch { m_cpuCount = -1; } } if (m_cpuCount < 1) m_cpuCount = 1; m_cpuUse = 1; }
public ServerRulesAttribute(eGameServerType serverType) { m_serverType = serverType; }