/*************************************************************************
* 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
{
///
/// Defines a realm server entry in the realm list.
///
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;
///
/// Realm icon as shown in Realm List (aka PVP, PVE, etc)
///
public RealmType Type
{
get { return m_type; }
set { m_type = value; }
}
///
/// Realm status as shown in Realm List (Good, Locked)
///
public RealmStatus Status
{
get { return m_status; }
set { m_status = value; }
}
///
/// Realm color as shown in Realm List (Green, Red, Offline)
///
public RealmColor Color
{
get { return m_color; }
set { m_color = value; }
}
///
/// Realm name.
///
public string Name
{
get { return m_name; }
set { m_name = value; }
}
///
/// Realm address: "IP:PORT".
///
public string Address
{
get { return m_address; }
set { m_address = value; }
}
///
/// Realm population. (1.6+ for high value and 1.6- for lower)
///
public float Population
{
get { return m_population; }
set { m_population = value; }
}
///
/// Characters the client has on this realm.
///
public byte Chars
{
get { return m_chars; }
set { m_chars = value; }
}
///
/// Realm timezone.
///
public RealmTimeZone TimeZone
{
get { return m_timeZone; }
set { m_timeZone = value; }
}
///
/// Last update of this realm entry.
///
public DateTime LastUpdated
{
get
{
return m_lastUpdated;
}
}
///
/// Refreshes the 'Last Updated' field of this realm server entry
///
public void Touch()
{
m_lastUpdated = DateTime.Now;
}
#region Packet handler
///
/// Handles an incoming realm list request.
///
/// the Session the incoming packet belongs to
/// the full packet
[PacketHandler(AuthServerOpCode.REALM_LIST)]
public static void RealmListRequest(AuthClient client, PacketIn packet)
{
SendRealmList(client);
}
///
/// Sends the realm list to the client.
///
/// the Session the incoming packet belongs to
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);
}
}
///
/// Writes the realm information to the specified packet
///
/// The packet to write the realm info to
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
}
}