Refactoring of BNetServer
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Realm;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
@@ -94,7 +95,7 @@ public class Realm : IEquatable<Realm>
|
||||
return new { ExternalAddress, LocalAddress, LocalSubnetMask, Port, Name, Type, Flags, Timezone, AllowedSecurityLevel, PopulationLevel }.GetHashCode();
|
||||
}
|
||||
|
||||
public RealmHandle Id;
|
||||
public RealmId Id;
|
||||
public uint Build;
|
||||
public IPAddress ExternalAddress;
|
||||
public IPAddress LocalAddress;
|
||||
@@ -109,52 +110,3 @@ public class Realm : IEquatable<Realm>
|
||||
public float PopulationLevel;
|
||||
}
|
||||
|
||||
public struct RealmHandle : IEquatable<RealmHandle>
|
||||
{
|
||||
public RealmHandle(byte region, byte battlegroup, uint index)
|
||||
{
|
||||
Region = region;
|
||||
Site = battlegroup;
|
||||
Realm = index;
|
||||
}
|
||||
public RealmHandle(uint realmAddress)
|
||||
{
|
||||
Region = (byte)((realmAddress >> 24) & 0xFF);
|
||||
Site = (byte)((realmAddress >> 16) & 0xFF);
|
||||
Realm = realmAddress & 0xFFFF;
|
||||
}
|
||||
|
||||
public uint GetAddress()
|
||||
{
|
||||
return (uint)((Region << 24) | (Site << 16) | (ushort)Realm);
|
||||
}
|
||||
public string GetAddressString()
|
||||
{
|
||||
return $"{Region}-{Site}-{Realm}";
|
||||
}
|
||||
|
||||
public string GetSubRegionAddress()
|
||||
{
|
||||
return $"{Region}-{Site}-0";
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj != null && obj is RealmHandle && Equals((RealmHandle)obj);
|
||||
}
|
||||
|
||||
public bool Equals(RealmHandle other)
|
||||
{
|
||||
return other.Realm == Realm;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return new { Site, Region, Realm }.GetHashCode();
|
||||
}
|
||||
|
||||
public byte Region;
|
||||
public byte Site;
|
||||
public uint Realm; // primary key in `realmlist` table
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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 System;
|
||||
|
||||
namespace Framework.Realm
|
||||
{
|
||||
public struct RealmId : IEquatable<RealmId>
|
||||
{
|
||||
public uint Index { get; set; }
|
||||
public byte Region { get; set; }
|
||||
public byte Site { get; set; }
|
||||
|
||||
public RealmId(byte region, byte battlegroup, uint index)
|
||||
{
|
||||
Region = region;
|
||||
Site = battlegroup;
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public RealmId(uint realmAddress)
|
||||
{
|
||||
Region = (byte)((realmAddress >> 24) & 0xFF);
|
||||
Site = (byte)((realmAddress >> 16) & 0xFF);
|
||||
Index = realmAddress & 0xFFFF;
|
||||
}
|
||||
|
||||
public uint GetAddress()
|
||||
{
|
||||
return (uint)((Region << 24) | (Site << 16) | (ushort)Index);
|
||||
}
|
||||
|
||||
public string GetAddressString()
|
||||
{
|
||||
return $"{Region}-{Site}-{Index}";
|
||||
}
|
||||
|
||||
public string GetSubRegionAddress()
|
||||
{
|
||||
return $"{Region}-{Site}-0";
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj != null && obj is RealmId && Equals((RealmId)obj);
|
||||
}
|
||||
|
||||
public bool Equals(RealmId other)
|
||||
{
|
||||
return other.Index == Index;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return new { Site, Region, Index }.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.Rest;
|
||||
using Framework.Web;
|
||||
using Framework.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,6 +25,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Timers;
|
||||
using System.Collections.Concurrent;
|
||||
using Framework.Realm;
|
||||
|
||||
public class RealmManager : Singleton<RealmManager>
|
||||
{
|
||||
@@ -91,7 +92,7 @@ public class RealmManager : Singleton<RealmManager>
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_REALMLIST);
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
Dictionary<RealmHandle, string> existingRealms = new Dictionary<RealmHandle, string>();
|
||||
Dictionary<RealmId, string> existingRealms = new Dictionary<RealmId, string>();
|
||||
foreach (var p in _realms)
|
||||
existingRealms[p.Key] = p.Value.Name;
|
||||
|
||||
@@ -125,11 +126,11 @@ public class RealmManager : Singleton<RealmManager>
|
||||
byte region = result.Read<byte>(12);
|
||||
byte battlegroup = result.Read<byte>(13);
|
||||
|
||||
realm.Id = new RealmHandle(region, battlegroup, realmId);
|
||||
realm.Id = new RealmId(region, battlegroup, realmId);
|
||||
|
||||
UpdateRealm(realm);
|
||||
|
||||
var subRegion = new RealmHandle(region, battlegroup, 0).GetAddressString();
|
||||
var subRegion = new RealmId(region, battlegroup, 0).GetAddressString();
|
||||
if (!_subRegions.Contains(subRegion))
|
||||
_subRegions.Add(subRegion);
|
||||
|
||||
@@ -147,7 +148,7 @@ public class RealmManager : Singleton<RealmManager>
|
||||
Log.outInfo(LogFilter.Realmlist, "Removed realm \"{0}\".", pair.Value);
|
||||
}
|
||||
|
||||
public Realm GetRealm(RealmHandle id)
|
||||
public Realm GetRealm(RealmId id)
|
||||
{
|
||||
return _realms.LookupByKey(id);
|
||||
}
|
||||
@@ -177,7 +178,7 @@ public class RealmManager : Singleton<RealmManager>
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetRealmEntryJSON(RealmHandle id, uint build)
|
||||
public byte[] GetRealmEntryJSON(RealmId id, uint build)
|
||||
{
|
||||
byte[] compressed = new byte[0];
|
||||
Realm realm = GetRealm(id);
|
||||
@@ -209,7 +210,7 @@ public class RealmManager : Singleton<RealmManager>
|
||||
}
|
||||
realmEntry.Version = version;
|
||||
|
||||
realmEntry.CfgRealmsID = (int)realm.Id.Realm;
|
||||
realmEntry.CfgRealmsID = (int)realm.Id.Index;
|
||||
realmEntry.Flags = (int)realm.Flags;
|
||||
realmEntry.Name = realm.Name;
|
||||
realmEntry.CfgConfigsID = (int)realm.GetConfigId();
|
||||
@@ -256,7 +257,7 @@ public class RealmManager : Singleton<RealmManager>
|
||||
realmListUpdate.Update.Version.Build = (int)realm.Value.Build;
|
||||
}
|
||||
|
||||
realmListUpdate.Update.CfgRealmsID = (int)realm.Value.Id.Realm;
|
||||
realmListUpdate.Update.CfgRealmsID = (int)realm.Value.Id.Index;
|
||||
realmListUpdate.Update.Flags = (int)flag;
|
||||
realmListUpdate.Update.Name = realm.Value.Name;
|
||||
realmListUpdate.Update.CfgConfigsID = (int)realm.Value.GetConfigId();
|
||||
@@ -270,9 +271,9 @@ public class RealmManager : Singleton<RealmManager>
|
||||
return Json.Deflate("JSONRealmListUpdates", realmList);
|
||||
}
|
||||
|
||||
public BattlenetRpcErrorCode JoinRealm(uint realmAddress, uint build, IPAddress clientAddress, Array<byte> clientSecret, LocaleConstant locale, string os, string accountName, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
|
||||
public BattlenetRpcErrorCode JoinRealm(uint realmAddress, uint build, IPAddress clientAddress, byte[] clientSecret, Locale locale, string os, string accountName, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
|
||||
{
|
||||
Realm realm = GetRealm(new RealmHandle(realmAddress));
|
||||
Realm realm = GetRealm(new RealmId(realmAddress));
|
||||
if (realm != null)
|
||||
{
|
||||
if (realm.Flags.HasAnyFlag(RealmFlags.Offline) || realm.Build != build)
|
||||
@@ -328,7 +329,7 @@ public class RealmManager : Singleton<RealmManager>
|
||||
List<string> GetSubRegions() { return _subRegions; }
|
||||
|
||||
List<RealmBuildInfo> _builds = new List<RealmBuildInfo>();
|
||||
ConcurrentDictionary<RealmHandle, Realm> _realms = new ConcurrentDictionary<RealmHandle, Realm>();
|
||||
ConcurrentDictionary<RealmId, Realm> _realms = new ConcurrentDictionary<RealmId, Realm>();
|
||||
List<string> _subRegions = new List<string>();
|
||||
Timer _updateTimer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user