forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameServer.cs
More file actions
109 lines (82 loc) · 3.18 KB
/
Copy pathGameServer.cs
File metadata and controls
109 lines (82 loc) · 3.18 KB
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
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using L2dotNET.Controllers;
using L2dotNET.Handlers;
using L2dotNET.Logging.Abstraction;
using L2dotNET.Managers;
using L2dotNET.Models.Items;
using L2dotNET.Network;
using L2dotNET.Network.loginauth;
using L2dotNET.Tables;
using L2dotNET.Utility;
using L2dotNET.World;
using Microsoft.Extensions.DependencyInjection;
using NLog;
namespace L2dotNET
{
public class GameServer
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private TcpListener _listener;
public static IServiceProvider ServiceProvider { get; private set; }
public GameServer(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
public async void Start()
{
Config.Config config = ServiceProvider.GetService<Config.Config>();
await config.Initialise();
await ServiceProvider.GetService<PreReqValidation>().Initialise();
CharTemplateTable.Initialize();
// TODO: refactor NetworkBlock
NetworkBlock.Instance.Initialize();
GameTime.Initialize();
await ServiceProvider.GetService<IdFactory>().Initialise();
L2World.Initialize();
MapRegionTable.Initialize();
ZoneTable.Initialize();
await ServiceProvider.GetService<ItemTable>().Initialise();
ItemHandler.Initialize();
NpcTable.Initialize();
Capsule.Initialize();
BlowFishKeygen.GenerateKeys();
await ServiceProvider.GetService<IAdminCommandHandler>().Initialise();
await ServiceProvider.GetService<AnnouncementManager>().Initialise();
StaticObjTable.Initialize();
await ServiceProvider.GetService<SpawnTable>().Initialise();
await ServiceProvider.GetService<HtmCache>().Initialise();
// TODO: review plugin system
//PluginManager.Instance.Initialize(this);
ServiceProvider.GetService<AuthThread>().Initialise();
_listener = new TcpListener(IPAddress.Any, config.ServerConfig.Port);
try
{
_listener.Start();
}
catch (SocketException ex)
{
Log.Halt($"Socket Error: '{ex.SocketErrorCode}'. Message: '{ex.Message}' (Error Code: '{ex.NativeErrorCode}')");
}
Log.Info($"Listening Gameservers on port {config.ServerConfig.Port}");
Task.Factory.StartNew(WaitForClients);
}
private async void WaitForClients()
{
while (true)
{
TcpClient client = await _listener.AcceptTcpClientAsync();
#pragma warning disable 4014
Task.Factory.StartNew(() => AcceptClient(client));
#pragma warning restore 4014
}
}
private void AcceptClient(TcpClient clientSocket)
{
Log.Debug($"Received connection request from: {clientSocket.Client.RemoteEndPoint}");
ServiceProvider.GetService<ClientManager>().AddClient(clientSocket);
}
}
}