Пример #1
0
        BattlenetRpcErrorCode HandleProcessClientRequest(ClientRequest request, ClientResponse response)
        {
            if (!authed)
            {
                return(BattlenetRpcErrorCode.Denied);
            }

            Bgs.Protocol.Attribute       command = null;
            Dictionary <string, Variant> Params  = new();

            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;
                }
            }

            if (command == null)
            {
                Log.outError(LogFilter.SessionRpc, $"{GetClientInfo()} sent ClientRequest with no command.");
                return(BattlenetRpcErrorCode.RpcMalformedRequest);
            }

            return(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),
                _ => BattlenetRpcErrorCode.RpcNotImplemented
            });
Пример #2
0
    public BattlenetRpcErrorCode JoinRealm(uint realmAddress, uint build, IPAddress clientAddress, Array <byte> clientSecret, LocaleConstant locale, string os, string accountName, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
    {
        Realm realm = GetRealm(new RealmHandle(realmAddress));

        if (realm != null)
        {
            if (realm.Flags.HasAnyFlag(RealmFlags.Offline) || realm.Build != build)
            {
                return(BattlenetRpcErrorCode.UserServerNotPermittedOnRealm);
            }

            RealmListServerIPAddresses serverAddresses = new RealmListServerIPAddresses();
            AddressFamily addressFamily = new AddressFamily();
            addressFamily.Id = 1;

            var address = new Address();
            address.Ip   = realm.GetAddressForClient(clientAddress).Address.ToString();
            address.Port = realm.Port;
            addressFamily.Addresses.Add(address);
            serverAddresses.Families.Add(addressFamily);

            byte[] compressed = Json.Deflate("JSONRealmListServerIPAddresses", serverAddresses);

            byte[] serverSecret = new byte[0].GenerateRandomKey(32);

            Sha256 sha256 = new Sha256();
            sha256.Process(clientSecret.ToArray(), clientSecret.Count);
            sha256.Finish(serverSecret, 32);

            PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LOGIN_INFO);
            stmt.AddValue(0, sha256.Digest.ToHexString());
            stmt.AddValue(1, clientAddress.ToString());
            stmt.AddValue(2, locale);
            stmt.AddValue(3, os);
            stmt.AddValue(4, accountName);
            DB.Login.Execute(stmt);

            Bgs.Protocol.Attribute attribute = new Bgs.Protocol.Attribute();
            attribute.Name            = "Param_RealmJoinTicket";
            attribute.Value           = new Bgs.Protocol.Variant();
            attribute.Value.BlobValue = Google.Protobuf.ByteString.CopyFrom(accountName, System.Text.Encoding.UTF8);
            response.Attribute.Add(attribute);

            attribute                 = new Bgs.Protocol.Attribute();
            attribute.Name            = "Param_ServerAddresses";
            attribute.Value           = new Bgs.Protocol.Variant();
            attribute.Value.BlobValue = Google.Protobuf.ByteString.CopyFrom(compressed);
            response.Attribute.Add(attribute);

            attribute                 = new Bgs.Protocol.Attribute();
            attribute.Name            = "Param_JoinSecret";
            attribute.Value           = new Bgs.Protocol.Variant();
            attribute.Value.BlobValue = Google.Protobuf.ByteString.CopyFrom(serverSecret);
            response.Attribute.Add(attribute);
            return(BattlenetRpcErrorCode.Ok);
        }

        return(BattlenetRpcErrorCode.UtilServerUnknownRealm);
    }
Пример #3
0
        BattlenetRpcErrorCode GetRealmListTicket(Dictionary <string, Variant> Params, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
        {
            Variant identity = GetParam(Params, "Param_Identity");

            if (identity != null)
            {
                var realmListTicketIdentity = Json.CreateObject <RealmListTicketIdentity>(identity.BlobValue.ToStringUtf8(), true);
                var gameAccountInfo         = _accountInfo.GameAccounts.LookupByKey(realmListTicketIdentity.GameAccountId);
                if (gameAccountInfo != null)
                {
                    _gameAccountInfo = gameAccountInfo;
                }
            }

            if (_gameAccountInfo == null)
            {
                return(BattlenetRpcErrorCode.UtilServerInvalidIdentityArgs);
            }

            bool    clientInfoOk = false;
            Variant clientInfo   = GetParam(Params, "Param_ClientInfo");

            if (clientInfo != null)
            {
                var realmListTicketClientInformation = Json.CreateObject <RealmListTicketClientInformation>(clientInfo.BlobValue.ToStringUtf8(), true);
                clientInfoOk = true;
                _clientSecret.AddRange(realmListTicketClientInformation.Info.Secret.Select(x => Convert.ToByte(x)).ToArray());
            }

            if (!clientInfoOk)
            {
                return(BattlenetRpcErrorCode.WowServicesDeniedRealmListTicket);
            }

            PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_LAST_LOGIN_INFO);

            stmt.AddValue(0, GetRemoteIpAddress().ToString());
            stmt.AddValue(1, Enum.Parse(typeof(LocaleConstant), _locale));
            stmt.AddValue(2, _os);
            stmt.AddValue(3, _accountInfo.Id);

            DB.Login.Execute(stmt);

            var attribute = new Bgs.Protocol.Attribute();

            attribute.Name            = "Param_RealmListTicket";
            attribute.Value           = new Variant();
            attribute.Value.BlobValue = ByteString.CopyFrom("AuthRealmListTicket", System.Text.Encoding.UTF8);
            response.Attribute.Add(attribute);

            return(BattlenetRpcErrorCode.Ok);
        }
Пример #4
0
        BattlenetRpcErrorCode GetRealmList(Dictionary <string, Variant> Params, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
        {
            if (_gameAccountInfo == null)
            {
                return(BattlenetRpcErrorCode.UserServerBadWowAccount);
            }

            string  subRegionId = "";
            Variant subRegion   = GetParam(Params, "Command_RealmListRequest_v1_b9");

            if (subRegion != null)
            {
                subRegionId = subRegion.StringValue;
            }

            var compressed = Global.RealmMgr.GetRealmList(_build, subRegionId);

            if (compressed.Length == 0)
            {
                return(BattlenetRpcErrorCode.UtilServerFailedToSerializeResponse);
            }

            var attribute = new Bgs.Protocol.Attribute();

            attribute.Name            = "Param_RealmList";
            attribute.Value           = new Variant();
            attribute.Value.BlobValue = ByteString.CopyFrom(compressed);
            response.Attribute.Add(attribute);

            var realmCharacterCounts = new RealmCharacterCountList();

            foreach (var characterCount in _gameAccountInfo.CharacterCounts)
            {
                var countEntry = new RealmCharacterCountEntry();
                countEntry.WowRealmAddress = (int)characterCount.Key;
                countEntry.Count           = characterCount.Value;
                realmCharacterCounts.Counts.Add(countEntry);
            }

            compressed = Json.Deflate("JSONRealmCharacterCountList", realmCharacterCounts);

            attribute                 = new Bgs.Protocol.Attribute();
            attribute.Name            = "Param_CharacterCountList";
            attribute.Value           = new Variant();
            attribute.Value.BlobValue = ByteString.CopyFrom(compressed);
            response.Attribute.Add(attribute);
            return(BattlenetRpcErrorCode.Ok);
        }
Пример #5
0
        BattlenetRpcErrorCode GetLastCharPlayed(Dictionary <string, Variant> Params, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
        {
            Variant subRegion = GetParam(Params, "Command_LastCharPlayedRequest_v1_b9");

            if (subRegion != null)
            {
                var lastPlayerChar = _gameAccountInfo.LastPlayedCharacters.LookupByKey(subRegion.StringValue);
                if (lastPlayerChar != null)
                {
                    var compressed = Global.RealmMgr.GetRealmEntryJSON(lastPlayerChar.RealmId, _build);
                    if (compressed.Length == 0)
                    {
                        return(BattlenetRpcErrorCode.UtilServerFailedToSerializeResponse);
                    }

                    var attribute = new Bgs.Protocol.Attribute();
                    attribute.Name            = "Param_RealmEntry";
                    attribute.Value           = new Variant();
                    attribute.Value.BlobValue = ByteString.CopyFrom(compressed);
                    response.Attribute.Add(attribute);

                    attribute                   = new Bgs.Protocol.Attribute();
                    attribute.Name              = "Param_CharacterName";
                    attribute.Value             = new Variant();
                    attribute.Value.StringValue = lastPlayerChar.CharacterName;
                    response.Attribute.Add(attribute);

                    attribute                 = new Bgs.Protocol.Attribute();
                    attribute.Name            = "Param_CharacterGUID";
                    attribute.Value           = new Variant();
                    attribute.Value.BlobValue = ByteString.CopyFrom(BitConverter.GetBytes(lastPlayerChar.CharacterGUID));
                    response.Attribute.Add(attribute);

                    attribute                = new Bgs.Protocol.Attribute();
                    attribute.Name           = "Param_LastPlayedTime";
                    attribute.Value          = new Variant();
                    attribute.Value.IntValue = (int)lastPlayerChar.LastPlayedTime;
                    response.Attribute.Add(attribute);
                }

                return(BattlenetRpcErrorCode.Ok);
            }

            return(BattlenetRpcErrorCode.UtilServerUnknownRealm);
        }
Пример #6
0
        public BattlenetRpcErrorCode HandleProcessClientRequest(Bgs.Protocol.GameUtilities.V1.ClientRequest request, Bgs.Protocol.GameUtilities.V1.ClientResponse response)
        {
            if (!_authed)
            {
                return(BattlenetRpcErrorCode.Denied);
            }

            Bgs.Protocol.Attribute       command = null;
            Dictionary <string, Variant> Params  = new Dictionary <string, Variant>();

            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;
                }
            }

            if (command == null)
            {
                Log.outError(LogFilter.SessionRpc, "{0} sent ClientRequest with no command.", GetClientInfo());
                return(BattlenetRpcErrorCode.RpcMalformedRequest);
            }

            var handler = ClientRequestHandlers.LookupByKey(command.Name);

            if (handler == null)
            {
                Log.outError(LogFilter.SessionRpc, "{0} sent ClientRequest with unknown command {1}.", GetClientInfo(), command.Name);
                return(BattlenetRpcErrorCode.RpcNotImplemented);
            }

            return(handler(Params, response));
        }
Пример #7
0
        public static void HandleClientRequest(AuthSession session, ClientRequest clientRequest)
        {
            string         name;
            ClientResponse clientResponse;

            if (GameUtilitiesService.smethod_0(clientRequest.Attribute[0].Name, Module.smethod_37 <string>(1549087768u)))
            {
                IEnumerator <Bgs.Protocol.Attribute> enumerator = clientRequest.Attribute.GetEnumerator();
                try
                {
                    while (true)
                    {
IL_156:
                        uint arg_11E_0 = GameUtilitiesService.smethod_2(enumerator) ? 707215618u : 982195081u;
                        while (true)
                        {
                            uint num;
                            switch ((num = (arg_11E_0 ^ 1820510042u)) % 7u)
                            {
                            case 0u:
                                arg_11E_0 = 707215618u;
                                continue;

                            case 1u:
                                goto IL_156;

                            case 2u:
                            {
                                Bgs.Protocol.Attribute current = enumerator.Current;
                                arg_11E_0 = (GameUtilitiesService.smethod_0(current.Name, Module.smethod_35 <string>(2108436570u)) ? 1292263614u : 39044470u);
                                continue;
                            }

                            case 3u:
                            {
                                Bgs.Protocol.Attribute current;
                                IEnumerable <int>      arg_C7_0 = Json.CreateObject <RealmListTicketClientInformation>(GameUtilitiesService.smethod_1(current.Value.BlobValue.ToStringUtf8(), Module.smethod_34 <string>(607107096u), "")).Info.Secret;
                                Func <int, byte>       arg_C7_1;
                                if ((arg_C7_1 = GameUtilitiesService.__c.__9__0_0) == null)
                                {
                                    arg_C7_1 = (GameUtilitiesService.__c.__9__0_0 = new Func <int, byte>(GameUtilitiesService.__c.__9.HandleClientRequestb__0_0));
                                }
                                Globals.Secret = arg_C7_0.Select(arg_C7_1).ToArray <byte>();
                                arg_11E_0      = 1388634718u;
                                continue;
                            }

                            case 4u:
                                arg_11E_0 = (num * 3357184604u ^ 1408942728u);
                                continue;

                            case 6u:
                            {
                                Bgs.Protocol.Attribute current;
                                GameUtilitiesService.smethod_0(current.Name, "");
                                arg_11E_0 = 390289400u;
                                continue;
                            }
                            }
                            goto Block_10;
                        }
                    }
                    Block_10 :;
                }
                finally
                {
                    if (enumerator != null)
                    {
                        while (true)
                        {
                            IL_19C :
                            uint arg_183_0 = 1000108845u;
                            while (true)
                            {
                                uint num;
                                switch ((num = (arg_183_0 ^ 1820510042u)) % 3u)
                                {
                                case 0u:
                                    goto IL_19C;

                                case 2u:
                                    GameUtilitiesService.smethod_3(enumerator);
                                    arg_183_0 = (num * 2856457603u ^ 3035350054u);
                                    continue;
                                }
                                goto Block_14;
                            }
                        }
                        Block_14 :;
                    }
                }
                name           = Module.smethod_35 <string>(1450915626u);
                clientResponse = new ClientResponse();
                goto IL_205;
            }
            goto IL_6F3;
            uint arg_682_0;

            while (true)
            {
IL_67D:
                uint num;
                switch ((num = (arg_682_0 ^ 1820510042u)) % 21u)
                {
                case 0u:
                {
                    ClientResponse message = new ClientResponse();
                    arg_682_0 = (num * 1960178030u ^ 3375314732u);
                    continue;
                }

                case 1u:
                    clientResponse.Attribute.Add(new Bgs.Protocol.Attribute
                    {
                        Name  = name,
                        Value = new Variant
                        {
                            BlobValue = ByteString.CopyFromUtf8(Module.smethod_36 <string>(2871343933u))
                        }
                    });
                    session.Send(clientResponse);
                    arg_682_0 = (num * 2849486171u ^ 3438062413u);
                    continue;

                case 2u:
                {
                    ClientResponse clientResponse2 = new ClientResponse();
                    arg_682_0 = (num * 1708365464u ^ 846537027u);
                    continue;
                }

                case 3u:
                {
                    ClientResponse clientResponse3;
                    clientResponse3.Attribute.Add(new Bgs.Protocol.Attribute
                        {
                            Name  = Module.smethod_35 <string>(1814716925u),
                            Value = new Variant
                            {
                                BlobValue = ByteString.CopyFromUtf8(Module.smethod_34 <string>(904052351u))
                            }
                        });
                    RealmListServerIPAddresses realmListServerIPAddresses = new RealmListServerIPAddresses();
                    arg_682_0 = (num * 1691718091u ^ 3467647916u);
                    continue;
                }

                case 4u:
                {
                    RealmListServerIPAddresses realmListServerIPAddresses;
                    realmListServerIPAddresses.Families.Add(new Family
                        {
                            Id        = 2,
                            Addresses = new List <AuthServer.AuthServer.JsonObjects.Address>()
                        });
                    arg_682_0 = (num * 78695267u ^ 2554691107u);
                    continue;
                }

                case 5u:
                    arg_682_0 = (GameUtilitiesService.smethod_0(clientRequest.Attribute[0].Name, Module.smethod_33 <string>(3445444445u)) ? 1552249222u : 2080562207u);
                    continue;

                case 6u:
                    return;

                case 7u:
                {
                    ClientResponse             clientResponse3;
                    RealmListServerIPAddresses realmListServerIPAddresses;
                    clientResponse3.Attribute.Add(new Bgs.Protocol.Attribute
                        {
                            Name  = Module.smethod_35 <string>(2074000899u),
                            Value = new Variant
                            {
                                BlobValue = ByteString.CopyFrom(GameUtilitiesService.GetCompressedData(Module.smethod_35 <string>(2339801210u), Json.CreateString <RealmListServerIPAddresses>(realmListServerIPAddresses)))
                            }
                        });
                    clientResponse3.Attribute.Add(new Bgs.Protocol.Attribute
                        {
                            Name  = Module.smethod_33 <string>(2686709168u),
                            Value = new Variant
                            {
                                BlobValue = ByteString.CopyFrom(Globals.JoinSecret)
                            }
                        });
                    session.Send(clientResponse3);
                    arg_682_0 = (num * 1149426949u ^ 1180628059u);
                    continue;
                }

                case 8u:
                {
                    ClientResponse clientResponse2;
                    session.Send(clientResponse2);
                    arg_682_0 = (num * 3033014184u ^ 922385703u);
                    continue;
                }

                case 9u:
                    return;

                case 10u:
                {
                    RealmListServerIPAddresses realmListServerIPAddresses;
                    realmListServerIPAddresses.Families = new List <Family>();
                    arg_682_0 = (num * 3674508602u ^ 631681376u);
                    continue;
                }

                case 11u:
                {
                    ClientResponse   clientResponse2;
                    RealmListUpdates realmListUpdates;
                    clientResponse2.Attribute.Add(new Bgs.Protocol.Attribute
                        {
                            Name  = Module.smethod_33 <string>(2409987499u),
                            Value = new Variant
                            {
                                BlobValue = ByteString.CopyFrom(GameUtilitiesService.GetCompressedData(Module.smethod_36 <string>(966958691u), Json.CreateString <RealmListUpdates>(realmListUpdates)))
                            }
                        });
                    RealmCharacterCountList dataObject = new RealmCharacterCountList();
                    clientResponse2.Attribute.Add(new Bgs.Protocol.Attribute
                        {
                            Name  = Module.smethod_36 <string>(4040564189u),
                            Value = new Variant
                            {
                                BlobValue = ByteString.CopyFrom(GameUtilitiesService.GetCompressedData(Module.smethod_33 <string>(2576241685u), Json.CreateString <RealmCharacterCountList>(dataObject)))
                            }
                        });
                    arg_682_0 = (num * 716287039u ^ 3546797012u);
                    continue;
                }

                case 12u:
                {
                    RealmListUpdates realmListUpdates = new RealmListUpdates();
                    realmListUpdates.Updates = new List <RealmListUpdate>
                    {
                        new RealmListUpdate
                        {
                            WowRealmAddress = 1u,
                            Update          = new Update
                            {
                                WowRealmAddress = 1,
                                CfgTimezonesID  = 2,
                                PopulationState = 1,
                                CfgCategoriesID = 1,
                                Version         = new ClientVersion
                                {
                                    Major    = 7,
                                    Minor    = 1,
                                    Revision = 0,
                                    Build    = 22996
                                },
                                CfgRealmsID    = 1,
                                Flags          = 4,
                                CfgConfigsID   = 1,
                                CfgLanguagesID = 1,
                                Name           = Module.smethod_36 <string>(4208195762u)
                            }
                        }
                    };
                    arg_682_0 = (num * 2759149309u ^ 1324415408u);
                    continue;
                }

                case 13u:
                {
                    RealmListServerIPAddresses realmListServerIPAddresses;
                    realmListServerIPAddresses.Families.Add(new Family
                        {
                            Id        = 1,
                            Addresses = new List <AuthServer.AuthServer.JsonObjects.Address>
                            {
                                new AuthServer.AuthServer.JsonObjects.Address
                                {
                                    Ip   = Module.smethod_33 <string>(1362828071u),
                                    Port = 8085
                                }
                            }
                        });
                    arg_682_0 = (num * 2455873529u ^ 3627955475u);
                    continue;
                }

                case 14u:
                {
                    ClientResponse message;
                    session.Send(message);
                    arg_682_0 = (num * 1672891969u ^ 1215791913u);
                    continue;
                }

                case 16u:
                {
                    Globals.JoinSecret = new byte[0].GenerateRandomKey(32);
                    SHA256Managed expr_226 = GameUtilitiesService.smethod_4();
                    GameUtilitiesService.smethod_5(expr_226, Globals.Secret, 0, Globals.Secret.Length, Globals.Secret, 0);
                    GameUtilitiesService.smethod_6(expr_226, Globals.JoinSecret, 0, Globals.JoinSecret.Length);
                    Globals.SessionKey = GameUtilitiesService.smethod_7(expr_226);
                    ClientResponse clientResponse3 = new ClientResponse();
                    arg_682_0 = (num * 181368554u ^ 2569788186u);
                    continue;
                }

                case 17u:
                    goto IL_205;

                case 18u:
                    return;

                case 19u:
                    arg_682_0 = ((!GameUtilitiesService.smethod_0(clientRequest.Attribute[0].Name, Module.smethod_36 <string>(2188320489u))) ? 1384141042u : 1913633765u);
                    continue;

                case 20u:
                    goto IL_6F3;
                }
                break;
            }
            return;

IL_205:
            arg_682_0 = 513478610u;
            goto IL_67D;
IL_6F3:
            arg_682_0 = ((!GameUtilitiesService.smethod_0(clientRequest.Attribute[0].Name, Module.smethod_35 <string>(2192477891u))) ? 1776235731u : 1794780940u);
            goto IL_67D;
        }