예제 #1
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);
    }