diff --git a/Source/BNetServer/Networking/Services/GameUtilities.cs b/Source/BNetServer/Networking/Services/GameUtilities.cs index ee72a8f59..8260599ab 100644 --- a/Source/BNetServer/Networking/Services/GameUtilities.cs +++ b/Source/BNetServer/Networking/Services/GameUtilities.cs @@ -23,13 +23,25 @@ namespace BNetServer.Networking Bgs.Protocol.Attribute command = null; Dictionary Params = new(); + string removeSuffix(string str) + { + var pos = str.LastIndexOf('_'); + if (pos != -1) + return str.Substring(0, pos); + + return str; + } for (int i = 0; i < request.Attribute.Count; ++i) { Bgs.Protocol.Attribute attr = request.Attribute[i]; - Params[attr.Name] = attr.Value; if (attr.Name.Contains("Command_")) + { command = attr; + Params[removeSuffix(attr.Name)] = attr.Value; + } + else + Params[attr.Name] = attr.Value; } if (command == null) @@ -38,12 +50,12 @@ namespace BNetServer.Networking return BattlenetRpcErrorCode.RpcMalformedRequest; } - return command.Name switch + return removeSuffix(command.Name) switch { - "Command_RealmListTicketRequest_v1_b9" => GetRealmListTicket(Params, response), - "Command_LastCharPlayedRequest_v1_b9" => GetLastCharPlayed(Params, response), - "Command_RealmListRequest_v1_b9" => GetRealmList(Params, response), - "Command_RealmJoinRequest_v1_b9" => JoinRealm(Params, response), + "Command_RealmListTicketRequest_v1" => GetRealmListTicket(Params, response), + "Command_LastCharPlayedRequest_v1" => GetLastCharPlayed(Params, response), + "Command_RealmListRequest_v1" => GetRealmList(Params, response), + "Command_RealmJoinRequest_v1" => JoinRealm(Params, response), _ => BattlenetRpcErrorCode.RpcNotImplemented }; } @@ -54,7 +66,7 @@ namespace BNetServer.Networking if (!authed) return BattlenetRpcErrorCode.Denied; - if (request.AttributeKey == "Command_RealmListRequest_v1_b9") + if (request.AttributeKey == "Command_RealmListRequest_v1") { Global.RealmMgr.WriteSubRegions(response); return BattlenetRpcErrorCode.Ok; @@ -115,7 +127,7 @@ namespace BNetServer.Networking BattlenetRpcErrorCode GetLastCharPlayed(Dictionary Params, ClientResponse response) { - Variant subRegion = Params.LookupByKey("Command_LastCharPlayedRequest_v1_b9"); + Variant subRegion = Params.LookupByKey("Command_LastCharPlayedRequest_v1"); if (subRegion != null) { var lastPlayerChar = gameAccountInfo.LastPlayedCharacters.LookupByKey(subRegion.StringValue); @@ -162,7 +174,7 @@ namespace BNetServer.Networking return BattlenetRpcErrorCode.UserServerBadWowAccount; string subRegionId = ""; - Variant subRegion = Params.LookupByKey("Command_RealmListRequest_v1_b9"); + Variant subRegion = Params.LookupByKey("Command_RealmListRequest_v1"); if (subRegion != null) subRegionId = subRegion.StringValue; diff --git a/Source/Game/Services/GameUtilitiesService.cs b/Source/Game/Services/GameUtilitiesService.cs index 6673716d6..ba057ca39 100644 --- a/Source/Game/Services/GameUtilitiesService.cs +++ b/Source/Game/Services/GameUtilitiesService.cs @@ -32,13 +32,25 @@ namespace Game { Bgs.Protocol.Attribute command = null; Dictionary Params = new(); + string removeSuffix(string str) + { + var pos = str.IndexOf('_'); + if (pos != -1) + return str.Substring(0, pos); + + return str; + } for (int i = 0; i < request.Attribute.Count; ++i) { Bgs.Protocol.Attribute attr = request.Attribute[i]; - Params[attr.Name] = attr.Value; if (attr.Name.Contains("Command_")) + { command = attr; + Params[removeSuffix(attr.Name)] = attr.Value; + } + else + Params[attr.Name] = attr.Value; } if (command == null) @@ -47,18 +59,18 @@ namespace Game return BattlenetRpcErrorCode.RpcMalformedRequest; } - if (command.Name == "Command_RealmListRequest_v1_b9") - return HandleRealmListRequest(Params, response); - else if (command.Name == "Command_RealmJoinRequest_v1_b9") - return HandleRealmJoinRequest(Params, response); - - return BattlenetRpcErrorCode.RpcNotImplemented; + return removeSuffix(command.Name) switch + { + "Command_RealmListRequest_v1" => HandleRealmListRequest(Params, response), + "Command_RealmJoinRequest_v1" => HandleRealmJoinRequest(Params, response), + _ => BattlenetRpcErrorCode.RpcNotImplemented + }; } [Service(OriginalHash.GameUtilitiesService, 10)] BattlenetRpcErrorCode HandleGetAllValuesForAttribute(GetAllValuesForAttributeRequest request, GetAllValuesForAttributeResponse response) { - if (request.AttributeKey == "Command_RealmListRequest_v1_b9") + if (request.AttributeKey == "Command_RealmListRequest_v1") { Global.RealmMgr.WriteSubRegions(response); return BattlenetRpcErrorCode.Ok; @@ -70,7 +82,7 @@ namespace Game BattlenetRpcErrorCode HandleRealmListRequest(Dictionary Params, ClientResponse response) { string subRegionId = ""; - var subRegion = Params.LookupByKey("Command_RealmListRequest_v1_b9"); + var subRegion = Params.LookupByKey("Command_RealmListRequest_v1"); if (subRegion != null) subRegionId = subRegion.StringValue;