Beispiel #1
0
        /// <summary>
        /// Worlds data server > client packet.
        /// </summary>
        /// <param name="lastWorld">Last world user was played in.</param>
        /// <param name="summary">Worlds summary.</param>
        /// <returns>Worlds summary <see cref="Packet"/></returns>
        internal static Packet ToPacket( byte lastWorld, WorldSummary[] summary )
        {
            Packet p = new OPPacket(Opcode);

            p.WriteByte
                (
                    ( byte )summary.Length,
                    lastWorld
                );

            int bits;

            foreach ( WorldSummary ws in summary )
            {
                bits = 0x00;

                if ( ws.IsTestServer )
                    bits |= 0x04;
                if ( ws.ShowClock )
                    bits |= 0x02;

                p.WriteByte(ws.ID);
                p.WriteByte(127);  // temp hack
                p.WriteByte(0);
                p.WriteByte(0);
                p.WriteByte(1);
                //p.WriteBytesArray(ws.Address);
                p.WriteInt(ws.Port);

                p.WriteByte
                    (
                        ws.AgeLimit,
                        ( ws.IsPvP ? ( byte )0x01 : ( byte )0x00 )
                    );

                p.WriteShort
                    (
                        ws.UsersOnline,
                        ws.UsersMax
                    );

                p.WriteByte(ws.IsOnline ? ( byte )0x01 : ( byte )0x00);
                p.WriteInt(bits);

                p.WriteInt(ws.ShowBrackets ? ( byte )0x01 : ( byte )0x00);
            }

            return p;
        }
 /// <summary>
 /// Gets <see cref="WorldSummary"/> array.
 /// </summary>
 /// <returns><see cref="WorldSummary"/> array.</returns>
 internal static WorldSummary[] Get()
 {
     WorldSummary[] current = new WorldSummary[m_WorldsSummary.Count];
     m_WorldsSummary.Values.CopyTo(current, 0);
     return current;
 }
        /// <summary>
        /// Gets worlds list from database.
        /// </summary>
        /// <returns>Worlds list pre-cached data.</returns>
        public override WorldSummary[] Worlds_Cache()
        {
            MsSqlDataCommand msdc = new MsSqlDataCommand
                (
                    "[Worlds_Cache]",
                    CommandType.StoredProcedure
                );

            SetConnection(ref msdc, m_ActiveConnections.Next());
            DataTable worlds = new DataTable();

            WorldSummary[] array = new WorldSummary[0] { };

            if ( msdc.Execute(ref worlds) && worlds.Rows.Count > 0 )
            {
                array = new WorldSummary[worlds.Rows.Count];

                for ( int i = 0; i < array.Length; i++ )
                {
                    DataRow row = worlds.Rows[i];

                    array[i] = new WorldSummary()
                    {
                        ID = ( byte )row["id"],
                        Address = System.Net.IPAddress.Parse(( string )row["outer_ip"]).GetAddressBytes(),
                        Port = ( int )row["port"],
                        AccessLevel = ( byte )row["access_level"],
                        UsersMax = ( short )row["max_users"],
                        AgeLimit = ( byte )row["age_limit"],
                        IsPvP = ( bool )row["is_pvp"],
                        IsTestServer = ( bool )row["is_test"],
                        ShowClock = ( bool )row["show_clock"],
                        ShowBrackets = ( bool )row["show_brackets"]
                    };
                }
            }

            ReleaseCommand(msdc);

            return array;
        }