All pastes #906057 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-16 08:16 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NLog;
using WCell.Core;
using WCell.Core.Initialization;
using WCell.Core.DBC;
using WCell.Core.Network;

using WCell.RealmServer.Entities;

namespace WCell.RealmServer.Help
{
  

    public static class TicketHandler
    {
        private static Logger log = LogManager.GetCurrentClassLogger();

        public static bool TicketSystemStatus = 1;

        public static Dictionary<uint, Ticket> dic = new Dictionary<uint, Ticket>();



        [PacketHandler(RealmServerOpCode.CMSG_GMTICKET_CREATE)]
        public static void HandleCreateTicketPacket(RealmClient client, RealmPacketIn packet)
        {
            if (client.ActiveCharacter == null)
            {
                return;
            }
            uint id = client.ActiveCharacter.EntityId.Low;
            uint type = packet.ReadUInt32();
            packet.ReadBytes(1);
            float position_X = packet.ReadFloat();
            float position_Y = packet.ReadFloat();
            float position_Z = packet.ReadFloat();
            string message = packet.ReadString();
            string timestamp = DateTime.Now.ToLongTimeString();

             dic[id] = new Ticket(id, type, position_X, position_Y, position_Z, message, timestamp);

            using (RealmPacketOut repPacket = new RealmPacketOut(RealmServerOpCode.SMSG_GMTICKET_CREATE))
            {
                repPacket.WriteUInt(2);
                client.Send(repPacket);
           
            }


        }

        [PacketHandler(RealmServerOpCode.CMSG_GMTICKET_GETTICKET)]
        public static void HandleGetTicketPacket(RealmClient client, RealmPacketIn packet)
        {
            using (RealmPacketOut repPacket = new RealmPacketOut(RealmServerOpCode.SMSG_GMTICKET_GETTICKET))
            {

                uint id = client.ActiveCharacter.EntityId.Low;
                Ticket ticket;

                    if (dic.TryGetValue(id, out ticket))
                    {
                        repPacket.WriteUInt(6);
                        repPacket.WriteCString(ticket.Message);
                        repPacket.WriteByte((byte)ticket.Type);
                        client.Send(repPacket);
                    }
                    else
                    {
                        return;
                        
                    }

            }
        }

        [PacketHandler(RealmServerOpCode.CMSG_GMTICKET_SYSTEMSTATUS)]
        public static void HandleSystemStatusPacket(RealmClient client, RealmPacketIn packet)
        {
            using (RealmPacketOut repPacket = new RealmPacketOut(RealmServerOpCode.SMSG_GMTICKET_SYSTEMSTATUS))
            {

                repPacket.WriteUInt((uint)SystemStatus);
                client.Send(repPacket);

            }
        }


        [PacketHandler(RealmServerOpCode.CMSG_GMTICKET_DELETETICKET)]
        public static void HandleDeleteTicketPacket(RealmClient client, RealmPacketIn packet)
        {
            uint id = client.ActiveCharacter.EntityId.Low;

            using (RealmPacketOut repPacket = new RealmPacketOut(RealmServerOpCode.SMSG_GMTICKET_DELETETICKET))
            {

                    dic.Remove(id);
                    repPacket.WriteUInt(9);
                    client.Send(repPacket);

            }
        }

        [PacketHandler(RealmServerOpCode.CMSG_GMTICKET_UPDATETEXT)]
        public static void HandleUpdateTicketPacket(RealmClient client, RealmPacketIn packet)
        {
            using (RealmPacketOut repPacket = new RealmPacketOut(RealmServerOpCode.SMSG_GMTICKET_UPDATETEXT))
            {
                uint id = client.ActiveCharacter.EntityId.Low;
                Ticket ticket;
                packet.ReadBytes(1);

                if (dic.TryGetValue(id, out ticket))
                {
                    
                    ticket.Message = packet.ReadString();
                    ticket.Timestamp = DateTime.Now.ToLongTimeString();
                    dic.Remove(id);
                    dic[id] = ticket;
                    repPacket.WriteUInt(2);
                    client.Send(repPacket);

                }
                else
                {
                    repPacket.WriteUInt(1);
                    client.Send(repPacket);
                }

            }
        }


    }
}