コード例 #1
0
    public byte[] GetRealmEntryJSON(RealmId id, uint build)
    {
        byte[] compressed = new byte[0];
        Realm  realm      = GetRealm(id);

        if (realm != null)
        {
            if (!realm.Flags.HasAnyFlag(RealmFlags.Offline) && realm.Build == build)
            {
                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 ClientVersion();
                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;

                compressed = Json.Deflate("JamJSONRealmEntry", realmEntry);
            }
        }

        return(compressed);
    }
コード例 #2
0
ファイル: QueryHandler.cs プロジェクト: zgbjmy2009/CypherCore
        void HandleQueryRealmName(QueryRealmName queryRealmName)
        {
            RealmQueryResponse realmQueryResponse = new RealmQueryResponse();

            realmQueryResponse.VirtualRealmAddress = queryRealmName.VirtualRealmAddress;

            RealmId realmHandle = new RealmId(queryRealmName.VirtualRealmAddress);

            if (Global.ObjectMgr.GetRealmName(realmHandle.Index, ref realmQueryResponse.NameInfo.RealmNameActual, ref realmQueryResponse.NameInfo.RealmNameNormalized))
            {
                realmQueryResponse.LookupState = (byte)ResponseCodes.Success;
                realmQueryResponse.NameInfo.IsInternalRealm = false;
                realmQueryResponse.NameInfo.IsLocal         = queryRealmName.VirtualRealmAddress == Global.WorldMgr.GetRealm().Id.GetAddress();
            }
            else
            {
                realmQueryResponse.LookupState = (byte)ResponseCodes.Failure;
            }
        }
コード例 #3
0
 public Realm GetRealm(RealmId id)
 {
     return(_realms.LookupByKey(id));
 }
コード例 #4
0
    void UpdateRealms(object source, ElapsedEventArgs e)
    {
        PreparedStatement            stmt           = DB.Login.GetPreparedStatement(LoginStatements.SEL_REALMLIST);
        SQLResult                    result         = DB.Login.Query(stmt);
        Dictionary <RealmId, string> existingRealms = new Dictionary <RealmId, string>();

        foreach (var p in _realms)
        {
            existingRealms[p.Key] = p.Value.Name;
        }

        _realms.Clear();

        // Circle through results and add them to the realm map
        if (!result.IsEmpty())
        {
            do
            {
                var  realm   = new Realm();
                uint realmId = result.Read <uint>(0);
                realm.Name            = result.Read <string>(1);
                realm.ExternalAddress = IPAddress.Parse(result.Read <string>(2));
                realm.LocalAddress    = IPAddress.Parse(result.Read <string>(3));
                realm.LocalSubnetMask = IPAddress.Parse(result.Read <string>(4));
                realm.Port            = result.Read <ushort>(5);
                RealmType realmType = (RealmType)result.Read <byte>(6);
                if (realmType == RealmType.FFAPVP)
                {
                    realmType = RealmType.PVP;
                }
                if (realmType >= RealmType.MaxType)
                {
                    realmType = RealmType.Normal;
                }

                realm.Type     = (byte)realmType;
                realm.Flags    = (RealmFlags)result.Read <byte>(7);
                realm.Timezone = result.Read <byte>(8);
                AccountTypes allowedSecurityLevel = (AccountTypes)result.Read <byte>(9);
                realm.AllowedSecurityLevel = (allowedSecurityLevel <= AccountTypes.Administrator ? allowedSecurityLevel : AccountTypes.Administrator);
                realm.PopulationLevel      = result.Read <float>(10);
                realm.Build = result.Read <uint>(11);
                byte region      = result.Read <byte>(12);
                byte battlegroup = result.Read <byte>(13);

                realm.Id = new RealmId(region, battlegroup, realmId);

                UpdateRealm(realm);

                var subRegion = new RealmId(region, battlegroup, 0).GetAddressString();
                if (!_subRegions.Contains(subRegion))
                {
                    _subRegions.Add(subRegion);
                }

                if (!existingRealms.ContainsKey(realm.Id))
                {
                    Log.outInfo(LogFilter.Realmlist, "Added realm \"{0}\" at {1}:{2}", realm.Name, realm.ExternalAddress.ToString(), realm.Port);
                }
                else
                {
                    Log.outDebug(LogFilter.Realmlist, "Updating realm \"{0}\" at {1}:{2}", realm.Name, realm.ExternalAddress.ToString(), realm.Port);
                }

                existingRealms.Remove(realm.Id);
            }while (result.NextRow());
        }

        foreach (var pair in existingRealms)
        {
            Log.outInfo(LogFilter.Realmlist, "Removed realm \"{0}\".", pair.Value);
        }
    }
コード例 #5
0
        BattlenetRpcErrorCode HandleVerifyWebCredentials(VerifyWebCredentialsRequest verifyWebCredentialsRequest)
        {
            if (verifyWebCredentialsRequest.WebCredentials.IsEmpty)
            {
                return(BattlenetRpcErrorCode.Denied);
            }

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

            stmt.AddValue(0, verifyWebCredentialsRequest.WebCredentials.ToStringUtf8());

            SQLResult result = DB.Login.Query(stmt);

            if (result.IsEmpty())
            {
                return(BattlenetRpcErrorCode.Denied);
            }

            accountInfo = new AccountInfo(result);

            if (accountInfo.LoginTicketExpiry < Time.UnixTime)
            {
                return(BattlenetRpcErrorCode.TimedOut);
            }

            stmt = DB.Login.GetPreparedStatement(LoginStatements.SelBnetCharacterCountsByAccountId);
            stmt.AddValue(0, accountInfo.Id);

            SQLResult characterCountsResult = DB.Login.Query(stmt);

            if (!characterCountsResult.IsEmpty())
            {
                do
                {
                    var realmId = new RealmId(characterCountsResult.Read <byte>(3), characterCountsResult.Read <byte>(4), characterCountsResult.Read <uint>(2));
                    accountInfo.GameAccounts[characterCountsResult.Read <uint>(0)].CharacterCounts[realmId.GetAddress()] = characterCountsResult.Read <byte>(1);
                } while (characterCountsResult.NextRow());
            }

            stmt = DB.Login.GetPreparedStatement(LoginStatements.SelBnetLastPlayerCharacters);
            stmt.AddValue(0, accountInfo.Id);

            SQLResult lastPlayerCharactersResult = DB.Login.Query(stmt);

            if (!lastPlayerCharactersResult.IsEmpty())
            {
                do
                {
                    var realmId = new RealmId(lastPlayerCharactersResult.Read <byte>(1), lastPlayerCharactersResult.Read <byte>(2), lastPlayerCharactersResult.Read <uint>(3));

                    LastPlayedCharacterInfo lastPlayedCharacter = new LastPlayedCharacterInfo();
                    lastPlayedCharacter.RealmId        = realmId;
                    lastPlayedCharacter.CharacterName  = lastPlayerCharactersResult.Read <string>(4);
                    lastPlayedCharacter.CharacterGUID  = lastPlayerCharactersResult.Read <ulong>(5);
                    lastPlayedCharacter.LastPlayedTime = lastPlayerCharactersResult.Read <uint>(6);

                    accountInfo.GameAccounts[lastPlayerCharactersResult.Read <uint>(0)].LastPlayedCharacters[realmId.GetSubRegionAddress()] = lastPlayedCharacter;
                } while (lastPlayerCharactersResult.NextRow());
            }

            string ip_address = GetRemoteIpEndPoint().ToString();

            // If the IP is 'locked', check that the player comes indeed from the correct IP address
            if (accountInfo.IsLockedToIP)
            {
                Log.outDebug(LogFilter.Session, $"Session.HandleVerifyWebCredentials: Account: {accountInfo.Login} is locked to IP: {accountInfo.LastIP} is logging in from IP: {ip_address}");

                if (accountInfo.LastIP != ip_address)
                {
                    return(BattlenetRpcErrorCode.RiskAccountLocked);
                }
            }
            else
            {
                Log.outDebug(LogFilter.Session, $"Session.HandleVerifyWebCredentials: Account: {accountInfo.Login} is not locked to ip");
                if (accountInfo.LockCountry.IsEmpty() || accountInfo.LockCountry == "00")
                {
                    Log.outDebug(LogFilter.Session, $"Session.HandleVerifyWebCredentials: Account: {accountInfo.Login} is not locked to country");
                }
                else if (!accountInfo.LockCountry.IsEmpty() && !ipCountry.IsEmpty())
                {
                    Log.outDebug(LogFilter.Session, $"Session.HandleVerifyWebCredentials: Account: {accountInfo.Login} is locked to Country: {accountInfo.LockCountry} player Country: {ipCountry}");

                    if (ipCountry != accountInfo.LockCountry)
                    {
                        return(BattlenetRpcErrorCode.RiskAccountLocked);
                    }
                }
            }

            // If the account is banned, reject the logon attempt
            if (accountInfo.IsBanned)
            {
                if (accountInfo.IsPermanenetlyBanned)
                {
                    Log.outDebug(LogFilter.Session, $"{GetClientInfo()} Session.HandleVerifyWebCredentials: Banned account {accountInfo.Login} tried to login!");
                    return(BattlenetRpcErrorCode.GameAccountBanned);
                }
                else
                {
                    Log.outDebug(LogFilter.Session, $"{GetClientInfo()} Session.HandleVerifyWebCredentials: Temporarily banned account {accountInfo.Login} tried to login!");
                    return(BattlenetRpcErrorCode.GameAccountSuspended);
                }
            }

            LogonResult logonResult = new LogonResult();

            logonResult.ErrorCode      = 0;
            logonResult.AccountId      = new EntityId();
            logonResult.AccountId.Low  = accountInfo.Id;
            logonResult.AccountId.High = 0x100000000000000;
            foreach (var pair in accountInfo.GameAccounts)
            {
                EntityId gameAccountId = new EntityId();
                gameAccountId.Low  = pair.Value.Id;
                gameAccountId.High = 0x200000200576F57;
                logonResult.GameAccountId.Add(gameAccountId);
            }

            if (!ipCountry.IsEmpty())
            {
                logonResult.GeoipCountry = ipCountry;
            }

            logonResult.SessionKey = ByteString.CopyFrom(new byte[64].GenerateRandomKey(64));

            authed = true;

            SendRequest((uint)OriginalHash.AuthenticationListener, 5, logonResult);
            return(BattlenetRpcErrorCode.Ok);
        }