All pastes #507783 Raw Edit

ALOWHA!!!!!!

public text v1 · immutable
·published 2007-05-24 19:01 UTC
rendered paste body
/*************************************************************************
 *                              RealmStruct.cs
 *                            ------------------
 *   begin                : Jan 24, 2007
 *   copyright            : (C) The WCell Team
 *   email                : info@wcell.org
 *************************************************************************/

/*************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *************************************************************************/

using System;
using System.IO;
using WCell.Core;
using WCell.Network;

namespace WCell.AuthServer
{
    /// <summary>
    /// Defines a realm server entry in the realm list.
    /// </summary>
    public class RealmStruct
    {
        private RealmType m_type;
        private RealmColor m_color;
        private RealmStatus m_status;
        private string m_name;
        private string m_address;
        private float m_population;
        private byte m_chars;
        private RealmTimeZone m_timeZone;
        private DateTime m_lastUpdated;

        /// <summary>
        /// Realm icon as shown in Realm List (aka PVP, PVE, etc) 
        /// </summary>
        public RealmType Type
        {
            get { return m_type; }
            set { m_type = value; }
        }

        /// <summary>
        /// Realm status as shown in Realm List (Good, Locked)
        /// </summary>
        public RealmStatus Status
        {
            get { return m_status; }
            set { m_status = value; }
        }

        /// <summary>
        /// Realm color as shown in Realm List (Green, Red, Offline)
        /// </summary>
        public RealmColor Color
        {
            get { return m_color; }
            set { m_color = value; }
        }

        /// <summary>
        /// Realm name. 
        /// </summary>
        public string Name
        {
            get { return m_name; }
            set { m_name = value; }
        }

        /// <summary>
        /// Realm address: "IP:PORT". 
        /// </summary>
        public string Address
        {
            get { return m_address; }
            set { m_address = value; }
        }

        /// <summary>
        /// Realm population. (1.6+ for high value and 1.6- for lower) 
        /// </summary>
        public float Population
        {
            get { return m_population; }
            set { m_population = value; }
        }

        /// <summary>
        /// Characters the client has on this realm. 
        /// </summary>
        public byte Chars
        {
            get { return m_chars; }
            set { m_chars = value; }
        }

        /// <summary>
        /// Realm timezone.
        /// </summary>
        public RealmTimeZone TimeZone
        {
            get { return m_timeZone; }
            set { m_timeZone = value; }
        }

        /// <summary>
        /// Last update of this realm entry.
        /// </summary>
        public DateTime LastUpdated
        {
            get
            {
                return m_lastUpdated;
            }
        }

        /// <summary>
        /// Refreshes the 'Last Updated' field of this realm server entry
        /// </summary>
        public void Touch()
        {
            m_lastUpdated = DateTime.Now;
        }

        #region Packet handler

        /// <summary>
        /// Handles an incoming realm list request.
        /// </summary>
        /// <param name="client">the Session the incoming packet belongs to</param>
        /// <param name="packet">the full packet</param>
        [PacketHandler(AuthServerOpCode.REALM_LIST)]
        public static void RealmListRequest(AuthClient client, PacketIn packet)
        {
            SendRealmList(client);
        }

        /// <summary>
        /// Sends the realm list to the client.
        /// </summary>
        /// <param name="client">the Session the incoming packet belongs to</param>
        public static void SendRealmList(AuthClient client)
        {
            using (AuthPacketOut packet = new AuthPacketOut(AuthServerOpCode.REALM_LIST))
            {
                packet.WriteShort(0);
                packet.WriteInt(0); //Unknown Value (0x0000)

                packet.WriteShort((short) client.Server.RealmCount); //Number of realms sent by the server.  

                foreach(RealmStruct realm in client.Server.Realms.Values)
                {
                    realm.BindRealm(packet);
                }

                packet.WriteShort(0);

                //Write size
                packet.Seek(1, SeekOrigin.Begin);
                packet.WriteShort((short) (packet.PacketSize - 3));

                client.Send(packet);
            }
        }

        /// <summary>
        /// Writes the realm information to the specified packet
        /// </summary>
        /// <param name="packet">The packet to write the realm info to</param>
        public void BindRealm(AuthPacketOut packet)
        {
            packet.WriteByte((byte) Type);
            packet.WriteByte((byte) Status);
            packet.WriteByte((byte) Color);
            packet.WriteString(Name);
            packet.WriteString(Address);
            packet.Write(Population);
            packet.WriteByte(Chars);
            packet.WriteByte((byte) TimeZone);
            packet.WriteByte(0x00); // realm separator
        }

        #endregion
    }
}