Refactoring of BNetServer

This commit is contained in:
hondacrx
2020-07-12 00:06:43 -04:00
parent 4164384b72
commit 581d077acd
318 changed files with 2046 additions and 4694 deletions
+22 -39
View File
@@ -1,28 +1,20 @@
/*
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using BNetServer.Networking;
using Framework.Configuration;
using Framework.Database;
using Framework.Networking;
using Framework.Web.API;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Timers;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace BNetServer
{
@@ -34,18 +26,10 @@ namespace BNetServer
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Console.CancelKeyPress += (o, e) =>
{
Global.RealmMgr.Close();
Log.outInfo(LogFilter.Server, "Halting process...");
Environment.Exit(-1);
};
if (!ConfigMgr.Load(Process.GetCurrentProcess().ProcessName + ".conf"))
if (!ConfigMgr.Load("BNetServer.conf"))
ExitNow();
// Initialize the database connection
// Initialize the database
if (!StartDB())
ExitNow();
@@ -55,7 +39,7 @@ namespace BNetServer
int restPort = ConfigMgr.GetDefaultValue("LoginREST.Port", 8081);
if (restPort < 0 || restPort > 0xFFFF)
{
Log.outError(LogFilter.Network, "Specified login service port ({0}) out of allowed range (1-65535), defaulting to 8081", restPort);
Log.outError(LogFilter.Network, "Specified login service port ({restPort}) out of allowed range (1-65535), defaulting to 8081");
restPort = 8081;
}
@@ -67,14 +51,14 @@ namespace BNetServer
// Get the list of realms for the server
Global.RealmMgr.Initialize(ConfigMgr.GetDefaultValue("RealmsStateUpdateDelay", 10));
Global.SessionMgr.Initialize();
Global.LoginServiceMgr.Initialize();
var sessionSocketServer = new SocketManager<Session>();
// Start the listening port (acceptor) for auth connections
int bnPort = ConfigMgr.GetDefaultValue("BattlenetPort", 1119);
if (bnPort < 0 || bnPort > 0xFFFF)
{
Log.outError(LogFilter.Server, "Specified battle.net port ({0}) out of allowed range (1-65535)", bnPort);
Log.outError(LogFilter.Server, $"Specified battle.net port ({bnPort}) out of allowed range (1-65535)");
ExitNow();
}
@@ -84,11 +68,9 @@ namespace BNetServer
ExitNow();
}
Log.outInfo(LogFilter.Server, $"Bnetserver started successfully, listening on {bindIp}:{bnPort}");
uint _banExpiryCheckInterval = ConfigMgr.GetDefaultValue("BanExpiryCheckInterval", 60u);
_banExpiryCheckTimer = new Timer(_banExpiryCheckInterval);
_banExpiryCheckTimer.Elapsed += _banExpiryCheckTimer_Elapsed;
_banExpiryCheckTimer.Elapsed += BanExpiryCheckTimer_Elapsed;
_banExpiryCheckTimer.Start();
}
@@ -106,17 +88,18 @@ namespace BNetServer
static void ExitNow()
{
Log.outInfo(LogFilter.Server, "Halting process...");
Console.WriteLine("Halting process...");
System.Threading.Thread.Sleep(10000);
Environment.Exit(-1);
}
static void _banExpiryCheckTimer_Elapsed(object sender, ElapsedEventArgs e)
static void BanExpiryCheckTimer_Elapsed(object sender, ElapsedEventArgs e)
{
DB.Login.Execute(DB.Login.GetPreparedStatement(LoginStatements.DEL_EXPIRED_IP_BANS));
DB.Login.Execute(DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPIRED_ACCOUNT_BANS));
DB.Login.Execute(DB.Login.GetPreparedStatement(LoginStatements.DEL_BNET_EXPIRED_ACCOUNT_BANNED));
DB.Login.Execute(DB.Login.GetPreparedStatement(LoginStatements.DelExpiredIpBans));
DB.Login.Execute(DB.Login.GetPreparedStatement(LoginStatements.UpdExpiredAccountBans));
DB.Login.Execute(DB.Login.GetPreparedStatement(LoginStatements.DelBnetExpiredAccountBanned));
}
static Timer _banExpiryCheckTimer;
}
}
}