aboutsummaryrefslogtreecommitdiff
path: root/src/game/TicketHandler.cpp
blob: ff920cab04bbf7ae9624707e8cfea8be5fe685d0 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright (C) 2005-2009 MaNGOS
 *
 * Copyright (C) 2008-2009 Trinity
 *
 * 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 "ObjectAccessor.h"
#include "WorldPacket.h"
#include "Common.h"
#include "Log.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "Chat.h"
#include "TicketMgr.h"
#include "World.h"
#include "Chat.h"


void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data )
{
    // always do a packet check
    CHECK_PACKET_SIZE(recv_data, 4*4+1+2*4);

    uint32 map;
    float x, y, z;
    std::string ticketText = "";
    std::string ticketText2 = "";
    GM_Ticket *ticket = new GM_Ticket;

    WorldPacket data(SMSG_GMTICKET_CREATE, 4);

    // recv Data
    //TODO: Add map coordinates to tickets.
    recv_data >> map;
    recv_data >> x;
    recv_data >> y;
    recv_data >> z;
    recv_data >> ticketText;

    // get additional data, rarely used
    recv_data >> ticketText2;

    // assign values
    ticket->name = GetPlayer()->GetName();
    ticket->guid = ticketmgr.GenerateTicketID();
    ticket->playerGuid = GetPlayer()->GetGUID();
    ticket->message = ticketText;
    ticket->timestamp = time(NULL);
    ticket->closed = 0;
    ticket->assignedToGM = 0;
    ticket->comment = "";

    // remove ticket by player, shouldn't happen
    ticketmgr.RemoveGMTicketByPlayer(GetPlayer()->GetGUID(), GetPlayer()->GetGUID());

    // add ticket
    ticketmgr.AddGMTicket(ticket, false);

    // Response - no errors
    data << uint32(2);

    // Send ticket creation
    SendPacket(&data);

    sWorld.SendGMText(LANG_COMMAND_TICKETNEW, ticket->name.c_str(), ticket->guid);

}

void WorldSession::HandleGMTicketUpdateOpcode( WorldPacket & recv_data)
{
    // always do a packet check
    CHECK_PACKET_SIZE(recv_data,1);

    std::string message = "";
    time_t t = time(NULL);

    WorldPacket data(SMSG_GMTICKET_UPDATETEXT, 4);

    // recv Data
    recv_data >> message;

    // Update Ticket
    GM_Ticket *ticket = ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());

    // Check if player has a GM Ticket yet
    if(!ticket)
    {
        // Response - error couldnt find existing Ticket
        data << uint32(1);

        // Send packet
        SendPacket(&data);
        return;
    }

    ticket->message = message;
    ticket->timestamp = (uint32)t;

    ticketmgr.UpdateGMTicket(ticket);

    // Response - no errors
    data << uint32(2);

    // Send packet
    SendPacket(&data);

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

}

void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket & /*recv_data*/)
{
    // NO recv_data, NO packet check size

    GM_Ticket* ticket = ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());

    // CHeck for Ticket
    if(ticket)
    {
        // Remove Tickets from Player

        // Response - no errors
        WorldPacket data(SMSG_GMTICKET_DELETETICKET, 4);
        data << uint32(9);
        // Send Packet
        SendPacket(&data);

        sWorld.SendGMText(LANG_COMMAND_TICKETPLAYERABANDON, GetPlayer()->GetName(), ticket->guid );
        ticketmgr.RemoveGMTicketByPlayer(GetPlayer()->GetGUID(), GetPlayer()->GetGUID());
    }
}

void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket & /*recv_data*/)
{
    // NO recv_data NO packet size check

    WorldPacket data(SMSG_GMTICKET_GETTICKET, 400);

    // get Current Ticket
    GM_Ticket *ticket = ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());

    // check for existing ticket
    if(!ticket)
    {
        data << uint32(10);
        // send packet
        SendPacket(&data);
        return;
    }

    // Send current Ticket
    data << uint32(6); // unk ?
    data << ticket->message.c_str();

    SendPacket(&data);

}

void WorldSession::HandleGMTicketSystemStatusOpcode( WorldPacket & /*recv_data*/)
{
    // NO recv_data NO packet size check

    WorldPacket data(SMSG_GMTICKET_SYSTEMSTATUS, 4);

    // Response - System is working Fine

    // No need for checks, ticket system is active
    // in case of disactivity, this should be set to (0)

    data << uint32(1);


    // Send Packet
    SendPacket(&data);
}