forked from Dawn-of-Light/DOLSharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameServerConfiguration.cs
594 lines (521 loc) · 16.1 KB
/
GameServerConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
/*
* DAWN OF LIGHT - The first free open source DAoC server emulator
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Linq;
using DOL.Config;
using DOL.Database.Connection;
namespace DOL.GS
{
/// <summary>
/// This is the game server configuration
/// </summary>
public class GameServerConfiguration : BaseServerConfiguration
{
#region Server
/// <summary>
/// holds the server root directory
/// </summary>
protected string m_rootDirectory;
/// <summary>
/// Holds the log configuration file path
/// </summary>
protected string m_logConfigFile;
/// <summary>
/// Name of the scripts compilation target
/// </summary>
protected string m_scriptCompilationTarget;
/// <summary>
/// The assemblies to include when compiling the scripts
/// </summary>
protected string m_scriptAssemblies;
/// <summary>
/// Enable/Disable Startup Script Compilation
/// </summary>
protected bool m_enableCompilation;
/// <summary>
/// True if the server shall automatically create accounts
/// </summary>
protected bool m_autoAccountCreation;
/// <summary>
/// The game server type
/// </summary>
protected eGameServerType m_serverType;
/// <summary>
/// The game server name
/// </summary>
protected string m_ServerName;
/// <summary>
/// The short server name, shown in /loc command
/// </summary>
protected string m_ServerNameShort;
/// <summary>
/// The count of server cpu
/// </summary>
protected int m_cpuCount;
/// <summary>
/// The max client count.
/// </summary>
protected int m_maxClientCount;
/// <summary>
/// The endpoint to send UDP packets from.
/// </summary>
protected IPEndPoint m_udpOutEndpoint;
#endregion
#region Logging
/// <summary>
/// The logger name where to log the gm+ commandos
/// </summary>
protected string m_gmActionsLoggerName;
/// <summary>
/// The logger name where to log cheat attempts
/// </summary>
protected string m_cheatLoggerName;
/// <summary>
/// The file name of the invalid names file
/// </summary>
protected string m_invalidNamesFile = "";
#endregion
#region Database
/// <summary>
/// The path to the XML database folder
/// </summary>
protected string m_dbConnectionString;
/// <summary>
/// Type database type
/// </summary>
protected ConnectionType m_dbType;
/// <summary>
/// True if the server shall autosave the db
/// </summary>
protected bool m_autoSave;
/// <summary>
/// The auto save interval in minutes
/// </summary>
protected int m_saveInterval;
#endregion
#region Load/Save
/// <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_enableCompilation = root["Server"]["EnableCompilation"].GetBoolean(true);
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>
/// Saves the values into a specific config element
/// </summary>
/// <param name="root">the root config element</param>
protected override void SaveToConfig(ConfigElement root)
{
base.SaveToConfig(root);
root["Server"]["ServerName"].Set(m_ServerName);
root["Server"]["ServerNameShort"].Set(m_ServerNameShort);
// Removed to not confuse users
// root["Server"]["RootDirectory"].Set(m_rootDirectory);
root["Server"]["LogConfigFile"].Set(m_logConfigFile);
root["Server"]["ScriptCompilationTarget"].Set(m_scriptCompilationTarget);
root["Server"]["ScriptAssemblies"].Set(m_scriptAssemblies);
root["Server"]["EnableCompilation"].Set(m_enableCompilation);
root["Server"]["AutoAccountCreation"].Set(m_autoAccountCreation);
string serverType = "Normal";
switch (m_serverType)
{
case eGameServerType.GST_Normal:
serverType = "Normal";
break;
case eGameServerType.GST_Casual:
serverType = "Casual";
break;
case eGameServerType.GST_Roleplay:
serverType = "Roleplay";
break;
case eGameServerType.GST_PvE:
serverType = "PvE";
break;
case eGameServerType.GST_PvP:
serverType = "PvP";
break;
case eGameServerType.GST_Test:
serverType = "Test";
break;
default:
serverType = "Normal";
break;
}
root["Server"]["GameType"].Set(serverType);
root["Server"]["CheatLoggerName"].Set(m_cheatLoggerName);
root["Server"]["GMActionLoggerName"].Set(m_gmActionsLoggerName);
root["Server"]["InvalidNamesFile"].Set(m_invalidNamesFile);
string db = "XML";
switch (m_dbType)
{
case ConnectionType.DATABASE_XML:
db = "XML";
break;
case ConnectionType.DATABASE_MYSQL:
db = "MYSQL";
break;
case ConnectionType.DATABASE_SQLITE:
db = "SQLITE";
break;
case ConnectionType.DATABASE_MSSQL:
db = "MSSQL";
break;
case ConnectionType.DATABASE_ODBC:
db = "ODBC";
break;
case ConnectionType.DATABASE_OLEDB:
db = "OLEDB";
break;
default:
m_dbType = ConnectionType.DATABASE_XML;
break;
}
root["Server"]["DBType"].Set(db);
root["Server"]["DBConnectionString"].Set(m_dbConnectionString);
root["Server"]["DBAutosave"].Set(m_autoSave);
root["Server"]["DBAutosaveInterval"].Set(m_saveInterval);
root["Server"]["CpuUse"].Set(m_cpuUse);
// Store UDP out endpoint
if (m_udpOutEndpoint != null)
{
root["Server"]["UDPOutIP"].Set(m_udpOutEndpoint.Address.ToString());
root["Server"]["UDPOutPort"].Set(m_udpOutEndpoint.Port.ToString());
}
}
#endregion
#region Constructors
/// <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 = " ";
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;
}
#endregion
/// <summary>
/// Gets or sets the root directory of the server
/// </summary>
public string RootDirectory
{
get { return m_rootDirectory; }
set { m_rootDirectory = value; }
}
/// <summary>
/// Gets or sets the log configuration file of this server
/// </summary>
public string LogConfigFile
{
get
{
if(Path.IsPathRooted(m_logConfigFile))
return m_logConfigFile;
else
return Path.Combine(m_rootDirectory, m_logConfigFile);
}
set { m_logConfigFile = value; }
}
/// <summary>
/// Gets or sets the script compilation target
/// </summary>
public string ScriptCompilationTarget
{
get { return m_scriptCompilationTarget; }
set { m_scriptCompilationTarget = value; }
}
/// <summary>
/// Gets or sets the script assemblies to be included in the script compilation
/// </summary>
[Obsolete("ScriptAssemblies is going to be removed.")]
public string[] ScriptAssemblies
{
get
{
return new string[] { "System.dll", "System.Xml.dll" }
.Union(new DirectoryInfo(Path.Combine(RootDirectory, "lib"))
.EnumerateFiles("*.dll", SearchOption.TopDirectoryOnly)
.Select(f => f.Name).Where(f => !f.Equals(new FileInfo(ScriptCompilationTarget).Name, StringComparison.OrdinalIgnoreCase)))
.Union(AdditionalScriptAssemblies)
.ToArray();
}
}
public string[] AdditionalScriptAssemblies => string.IsNullOrEmpty(m_scriptAssemblies.Trim()) ? Array.Empty<string>() : m_scriptAssemblies.Split(',');
/// <summary>
/// Get or Set the Compilation Flag
/// </summary>
public bool EnableCompilation
{
get { return m_enableCompilation; }
set { m_enableCompilation = value; }
}
/// <summary>
/// Gets or sets the auto account creation flag
/// </summary>
public bool AutoAccountCreation
{
get { return m_autoAccountCreation; }
set { m_autoAccountCreation = value; }
}
/// <summary>
/// Gets or sets the server type
/// </summary>
public eGameServerType ServerType
{
get { return m_serverType; }
set { m_serverType = value; }
}
/// <summary>
/// Gets or sets the server name
/// </summary>
public string ServerName
{
get { return m_ServerName; }
set { m_ServerName = value; }
}
/// <summary>
/// Gets or sets the short server name
/// </summary>
public string ServerNameShort
{
get { return m_ServerNameShort; }
set { m_ServerNameShort = value; }
}
/// <summary>
/// Gets or sets the GM action logger name
/// </summary>
public string GMActionsLoggerName
{
get { return m_gmActionsLoggerName; }
set { m_gmActionsLoggerName = value; }
}
/// <summary>
/// Gets or sets the cheat logger name
/// </summary>
public string CheatLoggerName
{
get { return m_cheatLoggerName; }
set { m_cheatLoggerName = value; }
}
/// <summary>
/// Gets or sets the trade logger name
/// </summary>
public string InventoryLoggerName { get; set; }
/// <summary>
/// Gets or sets the invalid name filename
/// </summary>
public string InvalidNamesFile
{
get
{
if(Path.IsPathRooted(m_invalidNamesFile))
return m_invalidNamesFile;
else
return Path.Combine(m_rootDirectory, m_invalidNamesFile);
}
set { m_invalidNamesFile = value; }
}
/// <summary>
/// Gets or sets the xml database path
/// </summary>
public string DBConnectionString
{
get { return m_dbConnectionString; }
set { m_dbConnectionString = value; }
}
/// <summary>
/// Gets or sets the DB type
/// </summary>
public ConnectionType DBType
{
get { return m_dbType; }
set { m_dbType = value; }
}
/// <summary>
/// Gets or sets the autosave flag
/// </summary>
public bool AutoSave
{
get { return m_autoSave; }
set { m_autoSave = value; }
}
/// <summary>
/// Gets or sets the autosave interval
/// </summary>
public int SaveInterval
{
get { return m_saveInterval; }
set { m_saveInterval = value; }
}
/// <summary>
/// Gets or sets the server cpu count
/// </summary>
public int CpuCount
{
get { return m_cpuCount; }
set { m_cpuCount = value; }
}
/// <summary>
/// Gets or sets the max cout of clients allowed
/// </summary>
public int MaxClientCount
{
get { return m_maxClientCount; }
set { m_maxClientCount = value; }
}
/// <summary>
/// Gets or sets UDP address and port to send UDP packets from.
/// If <code>null</code> then <see cref="Socket"/> decides where to bind.
/// </summary>
public IPEndPoint UDPOutEndpoint
{
get { return m_udpOutEndpoint; }
set { m_udpOutEndpoint = value; }
}
private int m_cpuUse;
public int CPUUse
{
get { return m_cpuUse; }
set { m_cpuUse = value; }
}
}
}