Beispiel #1
0
        private void BuildRealmListPacket(AuthSession session, ByteBuffer packet)
        {
            int shardCount = session.Server.AuthDB.ExecuteQuery("select count(0) from shard where enabled = true", result =>
            {
                if (result.Read())
                {
                    return(result.GetInt32(0));
                }
                else
                {
                    log.Error("got no results when querying for count on shard table");
                    return(0);
                }
            });

            if (shardCount > byte.MaxValue)
            {
                log.WarnFormat("shard count {0} is being truncated to maximum client allowed value of {1}", shardCount, byte.MaxValue);
                shardCount = byte.MaxValue;
            }

            packet.Append(0);
            packet.Append((byte)shardCount);

            session.Server.AuthDB.ExecuteQuery("select name, address, port, recommended, type, last_ping from shard where enabled = true limit ?", byte.MaxValue, result =>
            {
                while (result.Read())
                {
                    string name       = result.GetString(0);
                    string address    = result.GetString(1) + ':' + result.GetInt32(2);
                    DateTime lastPing = result.GetDateTime(5);

                    ShardType type      = (ShardType)result.GetByte(4);
                    ShardFlags flags    = ShardFlags.None;
                    byte characterCount = 0;
                    float population    = 0.0f;
                    byte category       = 0;

                    TimeSpan timeSinceLastPing = DateTime.Now - lastPing;
                    if (timeSinceLastPing > new TimeSpan(0, 0, 0, 0, session.Server.AppConfig.ShardOfflineTimeoutMilliseconds))
                    {
                        flags |= ShardFlags.Offline;
                    }

                    if (result.GetBoolean(3))
                    {
                        flags |= ShardFlags.Recommended;
                    }

                    packet.Append((int)type);
                    packet.Append((byte)flags);
                    packet.Append(name);
                    packet.Append(address);
                    packet.Append(population);
                    packet.Append(characterCount);
                    packet.Append(category);
                    packet.Append((byte)0);
                }
                return(true);
            });

            packet.Append((short)2);
        }
Beispiel #2
0
        public async Task <ShardEntity> Create(string address, int port, ShardType type, ShardFlags flags)
        {
            if (IsExists)
            {
                throw new ShardExistsException($"shard {this.GetPrimaryKeyString()} already exists; cannot create shard");
            }

            State.Name       = this.GetPrimaryKeyString();
            State.Address    = address ?? throw new ArgumentNullException(nameof(address));
            State.Port       = port;
            State.ShardType  = type;
            State.ShardFlags = flags;
            State.Enabled    = true;

            await WriteStateAsync();

            // orleans will safe-copy this automatically
            return(State);
        }