2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "WorldPacket.h"
23 #include "GMTicketMgr.h"
24 #include "ObjectAccessor.h"
28 void WorldSession::SendGMTicketGetTicket(uint32 status
, char const* text
)
30 int len
= text
? strlen(text
) : 0;
31 WorldPacket
data( SMSG_GMTICKET_GETTICKET
, (4+len
+1+4+2+4+4) );
32 data
<< uint32(status
); // standard 0x0A, 0x06 if text present
35 data
<< text
; // ticket text
36 data
<< uint8(0x7); // ticket category
37 data
<< float(0); // time from ticket creation?
38 data
<< float(0); // const
39 data
<< float(0); // const
40 data
<< uint8(0); // const
41 data
<< uint8(0); // const
46 void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket
& /*recv_data*/ )
48 WorldPacket
data( SMSG_QUERY_TIME_RESPONSE
, 4+4 );
49 data
<< (uint32
)time(NULL
);
53 GMTicket
* ticket
= ticketmgr
.GetGMTicket(GetPlayer()->GetGUIDLow());
55 SendGMTicketGetTicket(0x06,ticket
->GetText());
57 SendGMTicketGetTicket(0x0A,0);
60 void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket
& recv_data
)
62 CHECK_PACKET_SIZE(recv_data
,1);
64 std::string ticketText
;
65 recv_data
>> ticketText
;
67 CharacterDatabase
.escape_string(ticketText
);
69 if(GMTicket
* ticket
= ticketmgr
.GetGMTicket(GetPlayer()->GetGUIDLow()))
70 ticket
->SetText(ticketText
.c_str());
72 sLog
.outError("Ticket update: Player %s (GUID: %u) doesn't have active ticket", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
75 void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket
& /*recv_data*/ )
77 ticketmgr
.Delete(GetPlayer()->GetGUIDLow());
79 WorldPacket
data( SMSG_GMTICKET_DELETETICKET
, 4 );
83 SendGMTicketGetTicket(0x0A, 0);
86 void WorldSession::HandleGMTicketCreateOpcode( WorldPacket
& recv_data
)
88 CHECK_PACKET_SIZE(recv_data
, 4*4+1+2*4);
92 std::string ticketText
= "";
95 recv_data
>> map
>> x
>> y
>> z
; // last check 2.4.3
96 recv_data
>> ticketText
;
99 CHECK_PACKET_SIZE(recv_data
,4*4+(ticketText
.size()+1)+2*4);
101 recv_data
>> unk1
>> unk2
;
102 // note: the packet might contain more data, but the exact structure of that is unknown
104 sLog
.outDebug("TicketCreate: map %u, x %f, y %f, z %f, text %s, unk1 %u, unk2 %u", map
, x
, y
, z
, ticketText
.c_str(), unk1
, unk2
);
106 CharacterDatabase
.escape_string(ticketText
);
108 if(ticketmgr
.GetGMTicket(GetPlayer()->GetGUIDLow()))
110 WorldPacket
data( SMSG_GMTICKET_CREATE
, 4 );
116 ticketmgr
.Create(_player
->GetGUIDLow(), ticketText
.c_str());
118 WorldPacket
data( SMSG_QUERY_TIME_RESPONSE
, 4+4 );
119 data
<< (uint32
)time(NULL
);
123 data
.Initialize( SMSG_GMTICKET_CREATE
, 4 );
126 DEBUG_LOG("update the ticket\n");
128 //TODO: Guard player map
129 HashMapHolder
<Player
>::MapType
&m
= ObjectAccessor::Instance().GetPlayers();
130 for(HashMapHolder
<Player
>::MapType::iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
)
132 if(itr
->second
->GetSession()->GetSecurity() >= SEC_GAMEMASTER
&& itr
->second
->isAcceptTickets())
133 ChatHandler(itr
->second
).PSendSysMessage(LANG_COMMAND_TICKETNEW
,GetPlayer()->GetName());
137 void WorldSession::HandleGMTicketSystemStatusOpcode( WorldPacket
& /*recv_data*/ )
139 WorldPacket
data( SMSG_GMTICKET_SYSTEMSTATUS
,4 );
140 data
<< uint32(1); // we can also disable ticket system by sending 0 value
145 void WorldSession::HandleGMSurveySubmit( WorldPacket
& recv_data
)
147 // GM survey is shown after SMSG_GM_TICKET_STATUS_UPDATE with status = 3
148 CHECK_PACKET_SIZE(recv_data
,4+4);
150 recv_data
>> x
; // answer range? (6 = 0-5?)
151 sLog
.outDebug("SURVEY: X = %u", x
);
154 memset(result
, 0, sizeof(result
));
155 for( int i
= 0; i
< 10; ++i
)
157 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos()+4);
159 recv_data
>> questionID
; // GMSurveyQuestions.dbc
163 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos()+1+1);
165 std::string unk_text
;
166 recv_data
>> value
; // answer
167 recv_data
>> unk_text
; // always empty?
170 sLog
.outDebug("SURVEY: ID %u, value %u, text %s", questionID
, value
, unk_text
.c_str());
173 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos()+1);
175 recv_data
>> comment
; // addional comment
176 sLog
.outDebug("SURVEY: comment %s", comment
.c_str());
178 // TODO: chart this data in some way