forked from LeagueSandbox/GameServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.cs
73 lines (64 loc) · 2.37 KB
/
Server.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
using GameServerCore.Packets.Handlers;
using GameServerCore.Packets.PacketDefinitions;
using LeagueSandbox.GameServer.Logging;
using log4net;
using PacketDefinitions420;
using System;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
namespace LeagueSandbox.GameServer
{
/// <summary>
/// Class which controls the starting of the game and network loops.
/// </summary>
internal class Server : IDisposable
{
private Dictionary<long, string> _blowfishKeys;
private string _serverVersion = "0.2.0";
private readonly ILog _logger;
private Game _game;
private Config _config;
private ushort _serverPort { get; }
/// <summary>
/// Initialize base variables for future usage.
/// </summary>
public Server(Game game, ushort port, string configJson)
{
_logger = LoggerProvider.GetLogger();
_game = game;
_serverPort = port;
_config = Config.LoadFromJson(game, configJson);
_blowfishKeys = new Dictionary<long, string>();
foreach (var player in _config.Players)
_blowfishKeys.Add(player.Value.PlayerID, player.Value.BlowfishKey);
}
/// <summary>
/// Called upon the Program successfully initializing GameServerLauncher.
/// </summary>
public void Start()
{
var build = $"League Sandbox Build {ServerContext.BuildDateString}";
var packetServer = new PacketServer();
Console.Title = build;
_logger.Debug(build);
_logger.Debug($"Yorick {_serverVersion}");
_logger.Info($"Game started on port: {_serverPort}");
packetServer.InitServer(_serverPort, _blowfishKeys, _game, _game.RequestHandler, _game.ResponseHandler);
_game.Initialize(_config, packetServer);
}
/// <summary>
/// Called after the Program has finished setting up the Server for players to join.
/// </summary>
public void StartNetworkLoop()
{
_game.GameLoop();
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. Unused.
/// </summary>
public void Dispose()
{
// PathNode.DestroyTable();
}
}
}