Core/Realms: Realmlist refactors

* Removed global realm variable from World and use RealmList everywhere
* Match auth build key with client version
* Restored allowedSecurityLevel checks for realmlist packet building
* Restored updating population field
Port From (https://github.com/TrinityCore/TrinityCore/commit/c4b710446d62c95eb8124175203fa5f394912594)
This commit is contained in:
Hondacrx
2024-09-26 12:53:15 -04:00
parent 8341244e4d
commit d70529bc19
36 changed files with 393 additions and 298 deletions
@@ -7,6 +7,20 @@ namespace Framework.Constants
{
[Flags]
public enum RealmFlags
{
None = 0x00,
VersionMismatch = 0x01,
Hidden = 0x02,
Tournament = 0x04,
VersionBelow = 0x08,
VersionAbove = 0x10,
MobileVersionMismatch = 0x20,
MobileVersionBelow = 0x40,
MobileVersionAbove = 0x80
}
[Flags]
public enum LegacyRealmFlags
{
None = 0x00,
VersionMismatch = 0x01,
@@ -19,6 +33,18 @@ namespace Framework.Constants
Full = 0x80
}
public enum RealmPopulationState
{
Offline = 0,
Low = 1,
Medium = 2,
High = 3,
New = 4,
Recommended = 5,
Full = 6,
Locked = 7
}
public enum RealmType
{
Normal = 0,
@@ -11,6 +11,7 @@ namespace Framework.Database
const string BnetGameAccountInfo = "a.id, a.username, ab.unbandate, ab.unbandate = ab.bandate, aa.SecurityLevel";
PrepareStatement(LoginStatements.SEL_REALMLIST, "SELECT id, name, address, localAddress, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild, Region, Battlegroup FROM realmlist WHERE flag <> 3 ORDER BY name");
PrepareStatement(LoginStatements.UPD_REALM_POPULATION, "UPDATE realmlist SET population = ? WHERE id = ?");
PrepareStatement(LoginStatements.DEL_EXPIRED_IP_BANS, "DELETE FROM ip_banned WHERE unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()");
PrepareStatement(LoginStatements.UPD_EXPIRED_ACCOUNT_BANS, "UPDATE account_banned SET active = 0 WHERE active = 1 AND unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()");
PrepareStatement(LoginStatements.SEL_IP_INFO, "SELECT unbandate > UNIX_TIMESTAMP() OR unbandate = bandate AS banned, NULL as country FROM ip_banned WHERE ip = ?");
@@ -26,7 +27,7 @@ namespace Framework.Database
PrepareStatement(LoginStatements.UPD_LOGON, "UPDATE account SET salt = ?, verifier = ? WHERE id = ?");
PrepareStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME, "SELECT id FROM account WHERE username = ?");
PrepareStatement(LoginStatements.SEL_ACCOUNT_LIST_BY_NAME, "SELECT id, username FROM account WHERE username = ?");
PrepareStatement(LoginStatements.SEL_ACCOUNT_INFO_BY_NAME, "SELECT a.id, a.session_key_bnet, 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, " +
PrepareStatement(LoginStatements.SEL_ACCOUNT_INFO_BY_NAME, "SELECT a.id, a.session_key_bnet, ba.last_ip, ba.locked, ba.lock_country, a.expansion, a.mutetime, a.client_build, a.locale, a.recruiter, a.os, a.timezone_offset, ba.id, aa.SecurityLevel, " +
"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 account r ON a.id = r.recruiter 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 AND ab.active = 1 " +
@@ -74,7 +75,6 @@ namespace Framework.Database
PrepareStatement(LoginStatements.SEL_ACCOUNT_WHOIS, "SELECT username, email, last_ip FROM account WHERE id = ?");
PrepareStatement(LoginStatements.SEL_LAST_ATTEMPT_IP, "SELECT last_attempt_ip FROM account WHERE id = ?");
PrepareStatement(LoginStatements.SEL_LAST_IP, "SELECT last_ip FROM account WHERE id = ?");
PrepareStatement(LoginStatements.SEL_REALMLIST_SECURITY_LEVEL, "SELECT allowedSecurityLevel from realmlist WHERE id = ?");
PrepareStatement(LoginStatements.DEL_ACCOUNT, "DELETE FROM account WHERE id = ?");
PrepareStatement(LoginStatements.SEL_AUTOBROADCAST, "SELECT id, weight, text FROM autobroadcast WHERE realmid = ? OR realmid = -1");
PrepareStatement(LoginStatements.GET_EMAIL_BY_ID, "SELECT email FROM account WHERE id = ?");
@@ -112,7 +112,7 @@ namespace Framework.Database
" FROM battlenet_accounts ba LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id LEFT JOIN account a ON ba.id = a.battlenet_account" +
" LEFT JOIN account_banned ab ON a.id = ab.id AND ab.active = 1 LEFT JOIN account_access aa ON a.id = aa.AccountID AND aa.RealmID = -1 WHERE ba.LoginTicket = ? ORDER BY a.id");
PrepareStatement(LoginStatements.UPD_BNET_LAST_LOGIN_INFO, "UPDATE battlenet_accounts SET last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ? WHERE id = ?");
PrepareStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LOGIN_INFO, "UPDATE account SET session_key_bnet = ?, last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ?, timezone_offset = ? WHERE username = ?");
PrepareStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LOGIN_INFO, "UPDATE account SET session_key_bnet = ?, last_ip = ?, last_login = NOW(), client_build = ?, locale = ?, failed_logins = 0, os = ?, timezone_offset = ? WHERE username = ?");
PrepareStatement(LoginStatements.SEL_BNET_CHARACTER_COUNTS_BY_ACCOUNT_ID, "SELECT rc.acctid, rc.numchars, r.id, r.Region, r.Battlegroup FROM realmcharacters rc INNER JOIN realmlist r ON rc.realmid = r.id WHERE rc.acctid = ?");
PrepareStatement(LoginStatements.SEL_BNET_CHARACTER_COUNTS_BY_BNET_ID, "SELECT rc.acctid, rc.numchars, r.id, r.Region, r.Battlegroup FROM realmcharacters rc INNER JOIN realmlist r ON rc.realmid = r.id LEFT JOIN account a ON rc.acctid = a.id WHERE a.battlenet_account = ?");
PrepareStatement(LoginStatements.SEL_BNET_LAST_PLAYER_CHARACTERS, "SELECT lpc.accountId, lpc.region, lpc.battlegroup, lpc.realmId, lpc.characterName, lpc.characterGUID, lpc.lastPlayedTime FROM account_last_played_character lpc LEFT JOIN account a ON lpc.accountId = a.id WHERE a.battlenet_account = ?");
@@ -145,7 +145,7 @@ namespace Framework.Database
PrepareStatement(LoginStatements.REP_ACCOUNT_TOYS, "REPLACE INTO battlenet_account_toys (accountId, itemId, isFavourite, hasFanfare) VALUES (?, ?, ?, ?)");
// Battle Pets
PrepareStatement(LoginStatements.SEL_BATTLE_PETS, "SELECT bp.guid, bp.species, bp.breed, bp.displayId, bp.level, bp.exp, bp.health, bp.quality, bp.flags, bp.name, bp.nameTimestamp, bp.owner, dn.genitive, dn.dative, dn.accusative, dn.instrumental, dn.prepositional FROM battle_pets bp LEFT JOIN battle_pet_declinedname dn ON bp.guid = dn.guid WHERE bp.battlenetAccountId = ? AND (bp.ownerRealmId IS NULL OR bp.ownerRealmId = ?)");
PrepareStatement(LoginStatements.SEL_BATTLE_PETS, "SELECT bp.guid, bp.species, bp.breed, bp.displayId, bp.level, bp.exp, bp.health, bp.quality, bp.flags, bp.name, bp.nameTimestamp, bp.owner, bp.ownerRealmId, dn.genitive, dn.dative, dn.accusative, dn.instrumental, dn.prepositional FROM battle_pets bp LEFT JOIN battle_pet_declinedname dn ON bp.guid = dn.guid WHERE bp.battlenetAccountId = ? AND (bp.ownerRealmId IS NULL OR bp.ownerRealmId = ?)");
PrepareStatement(LoginStatements.INS_BATTLE_PETS, "INSERT INTO battle_pets (guid, battlenetAccountId, species, breed, displayId, level, exp, health, quality, flags, name, nameTimestamp, owner, ownerRealmId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PrepareStatement(LoginStatements.DEL_BATTLE_PETS, "DELETE FROM battle_pets WHERE battlenetAccountId = ? AND guid = ?");
PrepareStatement(LoginStatements.DEL_BATTLE_PETS_BY_OWNER, "DELETE FROM battle_pets WHERE owner = ? AND ownerRealmId = ?");
@@ -180,6 +180,7 @@ namespace Framework.Database
public enum LoginStatements
{
SEL_REALMLIST,
UPD_REALM_POPULATION,
DEL_EXPIRED_IP_BANS,
UPD_EXPIRED_ACCOUNT_BANS,
SEL_IP_INFO,
@@ -237,7 +238,6 @@ namespace Framework.Database
SEL_ACCOUNT_ACCESS_SECLEVEL_TEST,
SEL_ACCOUNT_ACCESS,
SEL_ACCOUNT_WHOIS,
SEL_REALMLIST_SECURITY_LEVEL,
DEL_ACCOUNT,
SEL_AUTOBROADCAST,
SEL_LAST_ATTEMPT_IP,
+1 -1
View File
@@ -66,6 +66,6 @@ public class Realm : IEquatable<Realm>
public RealmFlags Flags;
public byte Timezone;
public AccountTypes AllowedSecurityLevel;
public float PopulationLevel;
public RealmPopulationState PopulationLevel;
}
+150 -107
View File
@@ -83,6 +83,7 @@ public class RealmManager : Singleton<RealmManager>
{
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_REALMLIST);
SQLResult result = DB.Login.Query(stmt);
Dictionary<RealmId, string> existingRealms = new();
foreach (var p in _realms)
existingRealms[p.Key] = p.Value.Name;
@@ -94,11 +95,26 @@ public class RealmManager : Singleton<RealmManager>
{
do
{
var realm = new Realm();
uint realmId = result.Read<uint>(0);
realm.Name = result.Read<string>(1);
realm.Addresses.Add(IPAddress.Parse(result.Read<string>(2)));
realm.Addresses.Add(IPAddress.Parse(result.Read<string>(3)));
string name = result.Read<string>(1);
string externalAddressString = result.Read<string>(2);
string localAddressString = result.Read<string>(3);
if (!IPAddress.TryParse(externalAddressString, out IPAddress externalAddress))
{
Log.outError(LogFilter.Realmlist, $"Could not resolve address {externalAddressString} for realm \"{name}\" id {realmId}");
continue;
}
if (!IPAddress.TryParse(localAddressString, out IPAddress localAddress))
{
Log.outError(LogFilter.Realmlist, $"Could not resolve localAddress {localAddressString} for realm \"{name}\" id {realmId}");
continue;
}
var realm = new Realm();
realm.Addresses.Add(externalAddress);
realm.Addresses.Add(localAddress);
realm.Port = result.Read<ushort>(4);
RealmType realmType = (RealmType)result.Read<byte>(5);
if (realmType == RealmType.FFAPVP)
@@ -107,11 +123,11 @@ public class RealmManager : Singleton<RealmManager>
realmType = RealmType.Normal;
realm.Type = (byte)realmType;
realm.Flags = (RealmFlags)result.Read<byte>(6);
realm.Flags = ConvertLegacyRealmFlags((LegacyRealmFlags)result.Read<byte>(6));
realm.Timezone = result.Read<byte>(7);
AccountTypes allowedSecurityLevel = (AccountTypes)result.Read<byte>(8);
realm.AllowedSecurityLevel = (allowedSecurityLevel <= AccountTypes.Administrator ? allowedSecurityLevel : AccountTypes.Administrator);
realm.PopulationLevel = result.Read<float>(9);
realm.PopulationLevel = ConvertLegacyPopulationState((LegacyRealmFlags)result.Read<byte>(6), result.Read<float>(9));
realm.Build = result.Read<uint>(10);
byte region = result.Read<byte>(11);
byte battlegroup = result.Read<byte>(12);
@@ -125,9 +141,9 @@ public class RealmManager : Singleton<RealmManager>
_subRegions.Add(subRegion);
if (!existingRealms.ContainsKey(realm.Id))
Log.outInfo(LogFilter.Realmlist, "Added realm \"{0}\" at {1}:{2}", realm.Name, realm.Addresses[0].ToString(), realm.Port);
Log.outInfo(LogFilter.Realmlist, $"Added realm \"{realm.Name}\" at {externalAddressString}:{realm.Port}");
else
Log.outDebug(LogFilter.Realmlist, "Updating realm \"{0}\" at {1}:{2}", realm.Name, realm.Addresses[0].ToString(), realm.Port);
Log.outDebug(LogFilter.Realmlist, $"Updating realm \"{realm.Name}\" at {externalAddressString}:{realm.Port}");
existingRealms.Remove(realm.Id);
}
@@ -136,6 +152,15 @@ public class RealmManager : Singleton<RealmManager>
foreach (var pair in existingRealms)
Log.outInfo(LogFilter.Realmlist, "Removed realm \"{0}\".", pair.Value);
_removedRealms = existingRealms;
if (_currentRealmId.HasValue)
{
var realm = _realms.LookupByKey(_currentRealmId.Value);
if (realm != null)
_currentRealmId = realm.Id; // fill other fields of realm id
}
}
public Realm GetRealm(RealmId id)
@@ -143,18 +168,31 @@ public class RealmManager : Singleton<RealmManager>
return _realms.LookupByKey(id);
}
public bool GetRealmNames(RealmId id, out string name, out string normalizedName)
public RealmId GetCurrentRealmId()
{
name = null;
normalizedName = null;
return _currentRealmId.HasValue ? _currentRealmId.Value : new();
}
Realm realm = GetRealm(id);
if (realm == null)
return false;
public void SetCurrentRealmId(RealmId id)
{
_currentRealmId = id;
}
name = realm.Name;
normalizedName = realm.NormalizedName;
return true;
public Realm GetCurrentRealm()
{
if (_currentRealmId.HasValue)
return GetRealm(_currentRealmId.Value);
return null;
}
public void WriteSubRegions(Bgs.Protocol.GameUtilities.V1.GetAllValuesForAttributeResponse response)
{
foreach (string subRegion in GetSubRegions())
{
var variant = new Bgs.Protocol.Variant();
variant.StringValue = subRegion;
response.AttributeValue.Add(variant);
}
}
public RealmBuildInfo GetBuildInfo(uint build)
@@ -172,121 +210,100 @@ public class RealmManager : Singleton<RealmManager>
return buildInfo != null ? (buildInfo.MajorVersion * 10000 + buildInfo.MinorVersion * 100 + buildInfo.BugfixVersion) : 0;
}
public void WriteSubRegions(Bgs.Protocol.GameUtilities.V1.GetAllValuesForAttributeResponse response)
void FillRealmEntry(Realm realm, uint clientBuild, AccountTypes accountSecurityLevel, RealmEntry realmEntry)
{
foreach (string subRegion in GetSubRegions())
realmEntry.WowRealmAddress = (int)realm.Id.GetAddress();
realmEntry.CfgTimezonesID = 1;
if (accountSecurityLevel >= realm.AllowedSecurityLevel || realm.PopulationLevel == RealmPopulationState.Offline)
realmEntry.PopulationState = (int)realm.PopulationLevel;
else
realmEntry.PopulationState = (int)RealmPopulationState.Locked;
realmEntry.CfgCategoriesID = realm.Timezone;
ClientVersion version = new();
RealmBuildInfo buildInfo = GetBuildInfo(realm.Build);
if (buildInfo != null)
{
var variant = new Bgs.Protocol.Variant();
variant.StringValue = subRegion;
response.AttributeValue.Add(variant);
version.Major = (int)buildInfo.MajorVersion;
version.Minor = (int)buildInfo.MinorVersion;
version.Revision = (int)buildInfo.BugfixVersion;
version.Build = (int)buildInfo.Build;
}
else
{
version.Major = 6;
version.Minor = 2;
version.Revision = 4;
version.Build = (int)realm.Build;
}
RealmFlags flag = realm.Flags;
if (realm.Build != clientBuild)
flag |= RealmFlags.VersionMismatch;
realmEntry.Version = version;
realmEntry.CfgRealmsID = (int)realm.Id.Index;
realmEntry.Flags = (int)flag;
realmEntry.Name = realm.Name;
realmEntry.CfgConfigsID = (int)realm.GetConfigId();
realmEntry.CfgLanguagesID = 1;
}
public byte[] GetRealmEntryJSON(RealmId id, uint build)
public byte[] GetRealmEntryJSON(RealmId id, uint build, AccountTypes accountSecurityLevel)
{
byte[] compressed = new byte[0];
byte[] compressed = [];
Realm realm = GetRealm(id);
if (realm != null)
{
if (!realm.Flags.HasAnyFlag(RealmFlags.Offline) && realm.Build == build)
if (realm.PopulationLevel != RealmPopulationState.Offline && realm.Build == build && accountSecurityLevel >= realm.AllowedSecurityLevel)
{
var realmEntry = new RealmEntry();
realmEntry.WowRealmAddress = (int)realm.Id.GetAddress();
realmEntry.CfgTimezonesID = 1;
realmEntry.PopulationState = Math.Max((int)realm.PopulationLevel, 1);
realmEntry.CfgCategoriesID = realm.Timezone;
ClientVersion version = new();
RealmBuildInfo buildInfo = GetBuildInfo(realm.Build);
if (buildInfo != null)
{
version.Major = (int)buildInfo.MajorVersion;
version.Minor = (int)buildInfo.MinorVersion;
version.Revision = (int)buildInfo.BugfixVersion;
version.Build = (int)buildInfo.Build;
}
else
{
version.Major = 6;
version.Minor = 2;
version.Revision = 4;
version.Build = (int)realm.Build;
}
realmEntry.Version = version;
realmEntry.CfgRealmsID = (int)realm.Id.Index;
realmEntry.Flags = (int)realm.Flags;
realmEntry.Name = realm.Name;
realmEntry.CfgConfigsID = (int)realm.GetConfigId();
realmEntry.CfgLanguagesID = 1;
RealmEntry realmEntry = new();
FillRealmEntry(realm, build, accountSecurityLevel, realmEntry);
var jsonData = Encoding.UTF8.GetBytes("JamJSONRealmEntry:" + JsonSerializer.Serialize(realmEntry) + "\0");
var compressedData = ZLib.Compress(jsonData);
compressed = BitConverter.GetBytes(jsonData.Length).Combine(compressedData);
compressed = BitConverter.GetBytes(jsonData.Length).Combine(ZLib.Compress(jsonData));
}
}
return compressed;
}
public byte[] GetRealmList(uint build, string subRegion)
public byte[] GetRealmList(uint build, AccountTypes accountSecurityLevel, string subRegion)
{
var realmList = new RealmListUpdates();
foreach (var realm in _realms)
foreach (var (_, realm) in _realms)
{
if (realm.Value.Id.GetSubRegionAddress() != subRegion)
if (realm.Id.GetSubRegionAddress() != subRegion)
continue;
RealmFlags flag = realm.Value.Flags;
if (realm.Value.Build != build)
flag |= RealmFlags.VersionMismatch;
RealmListUpdatePart state = new();
FillRealmEntry(realm, build, accountSecurityLevel, state.Update);
state.Deleting = false;
realmList.Updates.Add(state);
}
RealmListUpdate realmListUpdate = new();
realmListUpdate.Update.WowRealmAddress = (int)realm.Value.Id.GetAddress();
realmListUpdate.Update.CfgTimezonesID = 1;
realmListUpdate.Update.PopulationState = (realm.Value.Flags.HasAnyFlag(RealmFlags.Offline) ? 0 : Math.Max((int)realm.Value.PopulationLevel, 1));
realmListUpdate.Update.CfgCategoriesID = realm.Value.Timezone;
foreach (var (id, _) in _removedRealms)
{
if (id.GetSubRegionAddress() != subRegion)
continue;
RealmBuildInfo buildInfo = GetBuildInfo(realm.Value.Build);
if (buildInfo != null)
{
realmListUpdate.Update.Version.Major = (int)buildInfo.MajorVersion;
realmListUpdate.Update.Version.Minor = (int)buildInfo.MinorVersion;
realmListUpdate.Update.Version.Revision = (int)buildInfo.BugfixVersion;
realmListUpdate.Update.Version.Build = (int)buildInfo.Build;
}
else
{
realmListUpdate.Update.Version.Major = 7;
realmListUpdate.Update.Version.Minor = 1;
realmListUpdate.Update.Version.Revision = 0;
realmListUpdate.Update.Version.Build = (int)realm.Value.Build;
}
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();
realmListUpdate.Update.CfgLanguagesID = 1;
realmListUpdate.Deleting = false;
realmList.Updates.Add(realmListUpdate);
RealmListUpdatePart state = new();
state.WoWRealmAddress = (int)id.GetAddress();
state.Deleting = true;
realmList.Updates.Add(state);
}
var jsonData = Encoding.UTF8.GetBytes("JSONRealmListUpdates:" + JsonSerializer.Serialize(realmList) + "\0");
var compressedData = ZLib.Compress(jsonData);
return BitConverter.GetBytes(jsonData.Length).Combine(compressedData);
return BitConverter.GetBytes(jsonData.Length).Combine(ZLib.Compress(jsonData));
}
public BattlenetRpcErrorCode JoinRealm(uint realmAddress, uint build, IPAddress clientAddress, byte[] clientSecret, Locale locale, string os, TimeSpan timezoneOffset, string accountName, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
public BattlenetRpcErrorCode JoinRealm(uint realmAddress, uint build, IPAddress clientAddress, byte[] clientSecret, Locale locale, string os, TimeSpan timezoneOffset, string accountName, AccountTypes accountSecurityLevel, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
{
Realm realm = GetRealm(new RealmId(realmAddress));
if (realm != null)
{
if (realm.Flags.HasAnyFlag(RealmFlags.Offline) || realm.Build != build)
if (realm.PopulationLevel == RealmPopulationState.Offline || realm.Build != build || accountSecurityLevel < realm.AllowedSecurityLevel)
return BattlenetRpcErrorCode.UserServerNotPermittedOnRealm;
RealmListServerIPAddresses serverAddresses = new();
@@ -300,9 +317,7 @@ public class RealmManager : Singleton<RealmManager>
serverAddresses.Families.Add(addressFamily);
var jsonData = Encoding.UTF8.GetBytes("JSONRealmListServerIPAddresses:" + JsonSerializer.Serialize(serverAddresses) + "\0");
var compressedData = ZLib.Compress(jsonData);
byte[] compressed = BitConverter.GetBytes(jsonData.Length).Combine(compressedData);
byte[] compressed = BitConverter.GetBytes(jsonData.Length).Combine(ZLib.Compress(jsonData));
byte[] serverSecret = new byte[0].GenerateRandomKey(32);
byte[] keyData = clientSecret.Combine(serverSecret);
@@ -310,16 +325,17 @@ public class RealmManager : Singleton<RealmManager>
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LOGIN_INFO);
stmt.AddValue(0, keyData);
stmt.AddValue(1, clientAddress.ToString());
stmt.AddValue(2, (byte)locale);
stmt.AddValue(3, os);
stmt.AddValue(4, (short)timezoneOffset.TotalMinutes);
stmt.AddValue(5, accountName);
stmt.AddValue(2, build);
stmt.AddValue(3, (byte)locale);
stmt.AddValue(4, os);
stmt.AddValue(5, (short)timezoneOffset.TotalMinutes);
stmt.AddValue(6, accountName);
DB.Login.DirectExecute(stmt);
Bgs.Protocol.Attribute attribute = new();
attribute.Name = "Param_RealmJoinTicket";
attribute.Value = new Bgs.Protocol.Variant();
attribute.Value.BlobValue = Google.Protobuf.ByteString.CopyFrom(accountName, System.Text.Encoding.UTF8);
attribute.Value.BlobValue = Google.Protobuf.ByteString.CopyFrom(accountName, Encoding.UTF8);
response.Attribute.Add(attribute);
attribute = new Bgs.Protocol.Attribute();
@@ -339,13 +355,40 @@ public class RealmManager : Singleton<RealmManager>
return BattlenetRpcErrorCode.UtilServerUnknownRealm;
}
RealmFlags ConvertLegacyRealmFlags(LegacyRealmFlags legacyRealmFlags)
{
RealmFlags realmFlags = RealmFlags.None;
if (legacyRealmFlags.HasAnyFlag(LegacyRealmFlags.VersionMismatch))
realmFlags |= RealmFlags.VersionMismatch;
return realmFlags;
}
RealmPopulationState ConvertLegacyPopulationState(LegacyRealmFlags legacyRealmFlags, float population)
{
if (legacyRealmFlags .HasAnyFlag(LegacyRealmFlags.Offline))
return RealmPopulationState.Offline;
if (legacyRealmFlags.HasAnyFlag(LegacyRealmFlags.Recommended))
return RealmPopulationState.Recommended;
if (legacyRealmFlags.HasAnyFlag(LegacyRealmFlags.New))
return RealmPopulationState.New;
if (legacyRealmFlags.HasAnyFlag(LegacyRealmFlags.Full) || population > 0.95f)
return RealmPopulationState.Full;
if (population > 0.66f)
return RealmPopulationState.High;
if (population > 0.33f)
return RealmPopulationState.Medium;
return RealmPopulationState.Low;
}
public ICollection<Realm> GetRealms() { return _realms.Values; }
List<string> GetSubRegions() { return _subRegions; }
List<RealmBuildInfo> _builds = new();
ConcurrentDictionary<RealmId, Realm> _realms = new();
Dictionary<RealmId, string> _removedRealms = new();
List<string> _subRegions = new();
Timer _updateTimer;
RealmId? _currentRealmId;
}
public class RealmBuildInfo
@@ -0,0 +1,17 @@
// 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.Text.Json.Serialization;
using Framework.Web.Rest.Realmlist;
namespace Framework.Web.Rest.Realmlist
{
internal class RealmListRAFInfo
{
[JsonPropertyName("wowRealmAddress")]
public int WowRealmAddress { get; set; }
[JsonPropertyName("faction")]
public int Faction { get; set; }
}
}
@@ -5,8 +5,11 @@ using System.Text.Json.Serialization;
namespace Framework.Web
{
public class RealmListUpdate
public class RealmListUpdatePart
{
[JsonPropertyName("wowRealmAddress")]
public int WoWRealmAddress { get; set; }
[JsonPropertyName("update")]
public RealmEntry Update { get; set; } = new RealmEntry();
@@ -9,6 +9,6 @@ namespace Framework.Web
public class RealmListUpdates
{
[JsonPropertyName("updates")]
public IList<RealmListUpdate> Updates { get; set; } = new List<RealmListUpdate>();
public IList<RealmListUpdatePart> Updates { get; set; } = new List<RealmListUpdatePart>();
}
}