aboutsummaryrefslogtreecommitdiff
path: root/src/game/TicketHandler.cpp
blob: e766cb2763e7ad33868fac0d7192ebe2dc0351f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
 *
 * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "Language.h"
#include "WorldPacket.h"
#include "Common.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "World.h"

void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data )
{
    if(GM_Ticket *ticket = objmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID()))
    {
        WorldPacket data( SMSG_GMTICKET_CREATE, 4 );
        data << uint32(1); // 1 - You already have GM ticket
        SendPacket( &data );
        return;
    }

    uint32 map;
    float x, y, z;
    std::string ticketText, ticketText2;

    SendQueryTimeResponse();

    WorldPacket data(SMSG_GMTICKET_CREATE, 4);
    recv_data >> map;
    recv_data >> x;
    recv_data >> y;
    recv_data >> z;
    recv_data >> ticketText;
    recv_data >> ticketText2;

    GM_Ticket *ticket = new GM_Ticket;
    ticket->name = GetPlayer()->GetName();
    ticket->guid = objmgr.GenerateGMTicketId();
    ticket->playerGuid = GetPlayer()->GetGUID();
    ticket->message = ticketText;
    ticket->createtime = time(NULL);
    ticket->map = map;
    ticket->pos_x = x;
    ticket->pos_y = y;
    ticket->pos_z = z;
    ticket->timestamp = time(NULL);
    ticket->closed = 0;
    ticket->assignedToGM = 0;
    ticket->comment = "";

    objmgr.AddOrUpdateGMTicket(*ticket, true);

    data << uint32(2);
    SendPacket(&data);

    sWorld.SendGMText(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName(), ticket->guid);

}

void WorldSession::HandleGMTicketUpdateOpcode( WorldPacket & recv_data)
{
    WorldPacket data(SMSG_GMTICKET_UPDATETEXT, 4);

    std::string message;
    recv_data >> message;

    GM_Ticket *ticket = objmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());
    if(!ticket)
    {
        data << uint32(1);
        SendPacket(&data);
        return;
    }

    ticket->message = message;
    ticket->timestamp = time(NULL);

    objmgr.AddOrUpdateGMTicket(*ticket);

    data << uint32(2);
    SendPacket(&data);

    sWorld.SendGMText(LANG_COMMAND_TICKETUPDATED, GetPlayer()->GetName(), ticket->guid);

}

void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket & /*recv_data*/)
{
    GM_Ticket* ticket = objmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());

    if(ticket)
    {
        WorldPacket data(SMSG_GMTICKET_DELETETICKET, 4);
        data << uint32(9);
        SendPacket(&data);

        sWorld.SendGMText(LANG_COMMAND_TICKETPLAYERABANDON, GetPlayer()->GetName(), ticket->guid );
        objmgr.RemoveGMTicket(ticket, GetPlayer()->GetGUID(), false);
        SendGMTicketGetTicket(0x0A, 0);
    }
}

void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket & /*recv_data*/)
{
    SendQueryTimeResponse();

    GM_Ticket *ticket = objmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());
    if(ticket)
        SendGMTicketGetTicket(0x06, ticket->message.c_str());
    else
        SendGMTicketGetTicket(0x0A, 0);

}

void WorldSession::HandleGMTicketSystemStatusOpcode( WorldPacket & /*recv_data*/)
{
    WorldPacket data(SMSG_GMTICKET_SYSTEMSTATUS, 4);
    data << uint32(1);
    SendPacket(&data);
}

void WorldSession::SendGMTicketGetTicket(uint32 status, char const* text)
{
    int len = text ? strlen(text) : 0;
    WorldPacket data( SMSG_GMTICKET_GETTICKET, (4+len+1+4+2+4+4) );
    data << uint32(status); // standard 0x0A, 0x06 if text present
    if(status == 6)
    {
        data << text; // ticket text
        data << uint8(0x7); // ticket category
        data << float(0); // tickets in queue?
        data << float(0); // if > "tickets in queue" then "We are currently experiencing a high volume of petitions."
        data << float(0); // 0 - "Your ticket will be serviced soon", 1 - "Wait time currently unavailable"
        data << uint8(0); // if == 2 and next field == 1 then "Your ticket has been escalated"
        data << uint8(0); // const
    }
    SendPacket( &data );
}