Updated Bnet Server.
Port From (https://github.com/TrinityCore/TrinityCore)
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Game.Networking
|
||||
_receiveBuffer = new byte[1024];
|
||||
}
|
||||
|
||||
public void Accept()
|
||||
public void Start()
|
||||
{
|
||||
// wait 1 second for active connections to send negotiation request
|
||||
for (int counter = 0; counter < 10 && _socket.Available == 0; counter++)
|
||||
@@ -46,7 +46,7 @@ namespace Game.Networking
|
||||
}
|
||||
|
||||
Send("Authentication Required\r\n");
|
||||
Send("Email: ");
|
||||
Send("Username: ");
|
||||
string userName = ReadString();
|
||||
if (userName.IsEmpty())
|
||||
{
|
||||
@@ -64,7 +64,7 @@ namespace Game.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CheckAccessLevelAndPassword(userName, password))
|
||||
if (!CheckAccessLevel(userName) || Global.AccountMgr.CheckPassword(userName, password))
|
||||
{
|
||||
Send("Authentication failed\r\n");
|
||||
CloseSocket();
|
||||
@@ -129,56 +129,29 @@ namespace Game.Networking
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckAccessLevelAndPassword(string email, string password)
|
||||
bool CheckAccessLevel(string user)
|
||||
{
|
||||
//"SELECT a.id, a.username FROM account a LEFT JOIN battlenet_accounts ba ON a.battlenet_account = ba.id WHERE ba.email = ?"
|
||||
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_GAME_ACCOUNT_LIST);
|
||||
stmt.AddValue(0, email);
|
||||
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS);
|
||||
stmt.AddValue(0, user);
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {email} does not exist in database");
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {user} does not exist in database");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint accountId = result.Read<uint>(0);
|
||||
string username = result.Read<string>(1);
|
||||
|
||||
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_BY_ID);
|
||||
stmt.AddValue(0, accountId);
|
||||
result = DB.Login.Query(stmt);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {email} has no privilege to login");
|
||||
return false;
|
||||
}
|
||||
|
||||
//"SELECT SecurityLevel, RealmID FROM account_access WHERE AccountID = ? and (RealmID = ? OR RealmID = -1) ORDER BY SecurityLevel desc");
|
||||
if (result.Read<byte>(0) < ConfigMgr.GetDefaultValue("Ra.MinLevel", (byte)AccountTypes.Administrator))
|
||||
{
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {email} has no privilege to login");
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {user} has no privilege to login");
|
||||
return false;
|
||||
}
|
||||
else if (result.Read<int>(1) != -1)
|
||||
{
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {email} has to be assigned on all realms (with RealmID = '-1')");
|
||||
Log.outInfo(LogFilter.CommandsRA, $"User {user} has to be assigned on all realms (with RealmID = '-1')");
|
||||
return false;
|
||||
}
|
||||
|
||||
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_CHECK_PASSWORD);
|
||||
stmt.AddValue(0, accountId);
|
||||
result = DB.Login.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
var salt = result.Read<byte[]>(0);
|
||||
var verifier = result.Read<byte[]>(1);
|
||||
|
||||
if (SRP6.CheckLogin(username, password, salt, verifier))
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.outInfo(LogFilter.CommandsRA, $"Wrong password for user: {email}");
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessCommand(string command)
|
||||
|
||||
@@ -69,11 +69,11 @@ namespace Game.Networking
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Accept()
|
||||
public override void Start()
|
||||
{
|
||||
string ip_address = GetRemoteIpAddress().ToString();
|
||||
|
||||
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SelIpInfo);
|
||||
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_IP_INFO);
|
||||
stmt.AddValue(0, ip_address);
|
||||
stmt.AddValue(1, BitConverter.ToUInt32(GetRemoteIpAddress().Address.GetAddressBytes(), 0));
|
||||
|
||||
@@ -489,7 +489,7 @@ namespace Game.Networking
|
||||
var address = GetRemoteIpAddress();
|
||||
|
||||
Sha256 digestKeyHash = new();
|
||||
digestKeyHash.Process(account.game.SessionKey, account.game.SessionKey.Length);
|
||||
digestKeyHash.Process(account.game.KeyData, account.game.KeyData.Length);
|
||||
if (account.game.OS == "Wn64")
|
||||
digestKeyHash.Finish(buildInfo.Win64AuthSeed);
|
||||
else if (account.game.OS == "Mc64")
|
||||
@@ -515,7 +515,7 @@ namespace Game.Networking
|
||||
}
|
||||
|
||||
Sha256 keyData = new();
|
||||
keyData.Finish(account.game.SessionKey);
|
||||
keyData.Finish(account.game.KeyData);
|
||||
|
||||
HmacSha256 sessionKeyHmac = new(keyData.Digest);
|
||||
sessionKeyHmac.Process(_serverChallenge, 16);
|
||||
@@ -652,7 +652,7 @@ namespace Game.Networking
|
||||
Global.ScriptMgr.OnAccountLogin(account.game.Id);
|
||||
|
||||
_worldSession = new WorldSession(account.game.Id, authSession.RealmJoinTicket, account.battleNet.Id, this, account.game.Security, (Expansion)account.game.Expansion,
|
||||
mutetime, account.game.OS, account.battleNet.Locale, account.game.Recruiter, account.game.IsRectuiter);
|
||||
mutetime, account.game.OS, account.game.TimezoneOffset, account.battleNet.Locale, account.game.Recruiter, account.game.IsRectuiter);
|
||||
|
||||
// Initialize Warden system only if it is enabled by config
|
||||
//if (wardenActive)
|
||||
@@ -839,15 +839,15 @@ namespace Game.Networking
|
||||
{
|
||||
public AccountInfo(SQLFields fields)
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11
|
||||
// SELECT a.id, a.sessionkey, ba.last_ip, ba.locked, ba.lock_country, a.expansion, a.mutetime, ba.locale, a.recruiter, a.os, ba.id, aa.gmLevel,
|
||||
// 12 13 14
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
// SELECT a.id, a.session_key, ba.last_ip, ba.locked, ba.lock_country, a.expansion, a.mutetime, ba.locale, a.recruiter, a.os, a.timezone_offset, ba.id, aa.SecurityLevel,
|
||||
// 13 14 15
|
||||
// bab.unbandate > UNIX_TIMESTAMP() OR bab.unbandate = bab.bandate, ab.unbandate > UNIX_TIMESTAMP() OR ab.unbandate = ab.bandate, r.id
|
||||
// FROM account a LEFT JOIN battlenet_accounts ba ON a.battlenet_account = ba.id LEFT JOIN account_access aa ON a.id = aa.id AND aa.RealmID IN (-1, ?)
|
||||
// FROM account a LEFT JOIN battlenet_accounts ba ON a.battlenet_account = ba.id LEFT JOIN account_access aa ON a.id = aa.AccountID AND aa.RealmID IN (-1, ?)
|
||||
// LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id LEFT JOIN account_banned ab ON a.id = ab.id LEFT JOIN account r ON a.id = r.recruiter
|
||||
// WHERE a.username = ? ORDER BY aa.RealmID DESC LIMIT 1
|
||||
// WHERE a.username = ? AND LENGTH(a.session_key) = 40 ORDER BY aa.RealmID DESC LIMIT 1
|
||||
game.Id = fields.Read<uint>(0);
|
||||
game.SessionKey = fields.Read<byte[]>(1);
|
||||
game.KeyData = fields.Read<byte[]>(1);
|
||||
battleNet.LastIP = fields.Read<string>(2);
|
||||
battleNet.IsLockedToIP = fields.Read<bool>(3);
|
||||
battleNet.LockCountry = fields.Read<string>(4);
|
||||
@@ -856,11 +856,12 @@ namespace Game.Networking
|
||||
battleNet.Locale = (Locale)fields.Read<byte>(7);
|
||||
game.Recruiter = fields.Read<uint>(8);
|
||||
game.OS = fields.Read<string>(9);
|
||||
battleNet.Id = fields.Read<uint>(10);
|
||||
game.Security = (AccountTypes)fields.Read<byte>(11);
|
||||
battleNet.IsBanned = fields.Read<uint>(12) != 0;
|
||||
game.IsBanned = fields.Read<uint>(13) != 0;
|
||||
game.IsRectuiter = fields.Read<uint>(14) != 0;
|
||||
game.TimezoneOffset = TimeSpan.FromMinutes(fields.Read<short>(10));
|
||||
battleNet.Id = fields.Read<uint>(11);
|
||||
game.Security = (AccountTypes)fields.Read<byte>(12);
|
||||
battleNet.IsBanned = fields.Read<uint>(13) != 0;
|
||||
game.IsBanned = fields.Read<uint>(14) != 0;
|
||||
game.IsRectuiter = fields.Read<uint>(15) != 0;
|
||||
|
||||
if (battleNet.Locale >= Locale.Total)
|
||||
battleNet.Locale = Locale.enUS;
|
||||
@@ -884,11 +885,12 @@ namespace Game.Networking
|
||||
public struct Game
|
||||
{
|
||||
public uint Id;
|
||||
public byte[] SessionKey;
|
||||
public byte[] KeyData;
|
||||
public byte Expansion;
|
||||
public long MuteTime;
|
||||
public string OS;
|
||||
public uint Recruiter;
|
||||
public string OS;
|
||||
public TimeSpan TimezoneOffset;
|
||||
public bool IsRectuiter;
|
||||
public AccountTypes Security;
|
||||
public bool IsBanned;
|
||||
|
||||
@@ -10,7 +10,9 @@ namespace Game.Networking
|
||||
{
|
||||
public class WorldSocketManager : SocketManager<WorldSocket>
|
||||
{
|
||||
public override bool StartNetwork(string bindIp, int port, int threadCount)
|
||||
public static WorldSocketManager Instance { get; } = new WorldSocketManager();
|
||||
|
||||
public override bool StartNetwork(string bindIp, int port, int threadCount = 1)
|
||||
{
|
||||
_tcpNoDelay = ConfigMgr.GetDefaultValue("Network.TcpNodelay", true);
|
||||
|
||||
@@ -29,6 +31,7 @@ namespace Game.Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
Acceptor.AsyncAcceptSocket(OnSocketAccept);
|
||||
_instanceAcceptor.AsyncAcceptSocket(OnSocketOpen);
|
||||
|
||||
return true;
|
||||
@@ -62,6 +65,11 @@ namespace Game.Networking
|
||||
base.OnSocketOpen(sock);
|
||||
}
|
||||
|
||||
static void OnSocketAccept(Socket sock)
|
||||
{
|
||||
Global.WorldSocketMgr.OnSocketOpen(sock);
|
||||
}
|
||||
|
||||
AsyncAcceptor _instanceAcceptor;
|
||||
int _socketSendBufferSize;
|
||||
bool _tcpNoDelay;
|
||||
|
||||
Reference in New Issue
Block a user