[207] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2008 Trinity |
---|
| 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "Common.h" |
---|
| 22 | #include "Language.h" |
---|
| 23 | #include "WorldPacket.h" |
---|
| 24 | #include "Log.h" |
---|
| 25 | #include "GMTicketMgr.h" |
---|
| 26 | #include "ObjectAccessor.h" |
---|
| 27 | #include "Player.h" |
---|
| 28 | #include "Chat.h" |
---|
| 29 | |
---|
| 30 | void WorldSession::SendGMTicketGetTicket(uint32 status, char const* text) |
---|
| 31 | { |
---|
| 32 | int len = text ? strlen(text) : 0; |
---|
| 33 | WorldPacket data( SMSG_GMTICKET_GETTICKET, (4+len+1+4+2+4+4) ); |
---|
| 34 | data << uint32(status); // standard 0x0A, 0x06 if text present |
---|
| 35 | if(status == 6) |
---|
| 36 | { |
---|
| 37 | data << text; // ticket text |
---|
| 38 | data << uint8(0x7); // ticket category |
---|
| 39 | data << float(0); // time from ticket creation? |
---|
| 40 | data << float(0); // const |
---|
| 41 | data << float(0); // const |
---|
| 42 | data << uint8(0); // const |
---|
| 43 | data << uint8(0); // const |
---|
| 44 | } |
---|
| 45 | SendPacket( &data ); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 49 | { |
---|
| 50 | WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 ); |
---|
| 51 | data << (uint32)time(NULL); |
---|
| 52 | data << (uint32)0; |
---|
| 53 | SendPacket( &data ); |
---|
| 54 | |
---|
| 55 | GMTicket* ticket = ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow()); |
---|
| 56 | if(ticket) |
---|
| 57 | SendGMTicketGetTicket(0x06,ticket->GetText()); |
---|
| 58 | else |
---|
| 59 | SendGMTicketGetTicket(0x0A,0); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket & recv_data ) |
---|
| 63 | { |
---|
| 64 | CHECK_PACKET_SIZE(recv_data,1); |
---|
| 65 | |
---|
| 66 | std::string ticketText; |
---|
| 67 | recv_data >> ticketText; |
---|
| 68 | |
---|
| 69 | CharacterDatabase.escape_string(ticketText); |
---|
| 70 | |
---|
| 71 | if(GMTicket* ticket = ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) |
---|
| 72 | ticket->SetText(ticketText.c_str()); |
---|
| 73 | else |
---|
| 74 | sLog.outError("Ticket update: Player %s (GUID: %u) doesn't have active ticket", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 78 | { |
---|
| 79 | ticketmgr.Delete(GetPlayer()->GetGUIDLow()); |
---|
| 80 | |
---|
| 81 | WorldPacket data( SMSG_GMTICKET_DELETETICKET, 4 ); |
---|
| 82 | data << uint32(9); |
---|
| 83 | SendPacket( &data ); |
---|
| 84 | |
---|
| 85 | SendGMTicketGetTicket(0x0A, 0); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data ) |
---|
| 89 | { |
---|
| 90 | CHECK_PACKET_SIZE(recv_data, 4*4+1+2*4); |
---|
| 91 | |
---|
| 92 | uint32 map; |
---|
| 93 | float x, y, z; |
---|
| 94 | std::string ticketText = ""; |
---|
| 95 | uint32 unk1, unk2; |
---|
| 96 | |
---|
| 97 | recv_data >> map >> x >> y >> z; // last check 2.4.3 |
---|
| 98 | recv_data >> ticketText; |
---|
| 99 | |
---|
| 100 | // recheck |
---|
| 101 | CHECK_PACKET_SIZE(recv_data,4*4+(ticketText.size()+1)+2*4); |
---|
| 102 | |
---|
| 103 | recv_data >> unk1 >> unk2; |
---|
| 104 | // note: the packet might contain more data, but the exact structure of that is unknown |
---|
| 105 | |
---|
| 106 | 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); |
---|
| 107 | |
---|
| 108 | CharacterDatabase.escape_string(ticketText); |
---|
| 109 | |
---|
| 110 | if(GMTicket* ticket = ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) |
---|
| 111 | { |
---|
| 112 | WorldPacket data( SMSG_GMTICKET_CREATE, 4 ); |
---|
| 113 | data << uint32(1); |
---|
| 114 | SendPacket( &data ); |
---|
| 115 | return; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | ticketmgr.Create(_player->GetGUIDLow(), ticketText.c_str()); |
---|
| 119 | |
---|
| 120 | WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 ); |
---|
| 121 | data << (uint32)time(NULL); |
---|
| 122 | data << (uint32)0; |
---|
| 123 | SendPacket( &data ); |
---|
| 124 | |
---|
| 125 | data.Initialize( SMSG_GMTICKET_CREATE, 4 ); |
---|
| 126 | data << uint32(2); |
---|
| 127 | SendPacket( &data ); |
---|
| 128 | DEBUG_LOG("update the ticket\n"); |
---|
| 129 | |
---|
| 130 | //TODO: Guard player map |
---|
| 131 | HashMapHolder::MapType &m = ObjectAccessor::Instance().GetPlayers(); |
---|
| 132 | for(HashMapHolder::MapType::iterator itr = m.begin(); itr != m.end(); ++itr) |
---|
| 133 | { |
---|
| 134 | if(itr->second->GetSession()->GetSecurity() >= SEC_GAMEMASTER && itr->second->isAcceptTickets()) |
---|
| 135 | ChatHandler(itr->second).PSendSysMessage(LANG_COMMAND_TICKETNEW,GetPlayer()->GetName()); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | void WorldSession::HandleGMTicketSystemStatusOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 140 | { |
---|
| 141 | WorldPacket data( SMSG_GMTICKET_SYSTEMSTATUS,4 ); |
---|
| 142 | data << uint32(1); // we can also disable ticket system by sending 0 value |
---|
| 143 | |
---|
| 144 | SendPacket( &data ); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void WorldSession::HandleGMSurveySubmit( WorldPacket & recv_data) |
---|
| 148 | { |
---|
| 149 | // GM survey is shown after SMSG_GM_TICKET_STATUS_UPDATE with status = 3 |
---|
| 150 | CHECK_PACKET_SIZE(recv_data,4+4); |
---|
| 151 | uint32 x; |
---|
| 152 | recv_data >> x; // answer range? (6 = 0-5?) |
---|
| 153 | sLog.outDebug("SURVEY: X = %u", x); |
---|
| 154 | |
---|
| 155 | uint8 result[10]; |
---|
| 156 | memset(result, 0, sizeof(result)); |
---|
| 157 | for( int i = 0; i < 10; ++i) |
---|
| 158 | { |
---|
| 159 | CHECK_PACKET_SIZE(recv_data,recv_data.rpos()+4); |
---|
| 160 | uint32 questionID; |
---|
| 161 | recv_data >> questionID; // GMSurveyQuestions.dbc |
---|
| 162 | if (!questionID) |
---|
| 163 | break; |
---|
| 164 | |
---|
| 165 | CHECK_PACKET_SIZE(recv_data,recv_data.rpos()+1+1); |
---|
| 166 | uint8 value; |
---|
| 167 | std::string unk_text; |
---|
| 168 | recv_data >> value; // answer |
---|
| 169 | recv_data >> unk_text; // always empty? |
---|
| 170 | |
---|
| 171 | result[i] = value; |
---|
| 172 | sLog.outDebug("SURVEY: ID %u, value %u, text %s", questionID, value, unk_text.c_str()); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | CHECK_PACKET_SIZE(recv_data,recv_data.rpos()+1); |
---|
| 176 | std::string comment; |
---|
| 177 | recv_data >> comment; // addional comment |
---|
| 178 | sLog.outDebug("SURVEY: comment %s", comment.c_str()); |
---|
| 179 | |
---|
| 180 | // TODO: chart this data in some way |
---|
| 181 | } |
---|