2010-10-07 15:35:36 +02:00
/*
2015-01-01 00:27:46 +01:00
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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, see <http://www.gnu.org/licenses/>.
2008-12-31 15:07:29 +01:00
*/
2009-10-17 15:51:44 -07:00
2012-10-17 00:53:55 +02:00
#include "zlib.h"
2008-12-31 15:07:29 +01:00
#include "Common.h"
2012-11-20 14:54:33 +01:00
#include "Language.h"
2009-06-15 23:58:29 +02:00
#include "ObjectMgr.h"
2012-11-20 14:54:33 +01:00
#include "Opcodes.h"
2008-12-31 15:07:29 +01:00
#include "Player.h"
2015-02-08 01:07:00 +01:00
#include "SupportMgr.h"
2015-02-02 00:03:51 +01:00
#include "TicketPackets.h"
2012-11-20 14:54:33 +01:00
#include "Util.h"
2008-12-31 15:07:29 +01:00
#include "World.h"
2012-11-20 14:54:33 +01:00
#include "WorldPacket.h"
2010-08-29 20:28:14 -07:00
#include "WorldSession.h"
2009-10-17 15:51:44 -07:00
2015-02-08 01:07:00 +01:00
void WorldSession :: HandleGMTicketCreateOpcode ( WorldPackets :: Ticket :: GMTicketCreate & packet )
2008-12-31 15:07:29 +01:00
{
2010-11-14 00:29:34 +01:00
// Don't accept tickets if the ticket queue is disabled. (Ticket UI is greyed out but not fully dependable)
2015-02-08 01:07:00 +01:00
if ( sSupportMgr -> GetSupportSystemStatus () == GMTICKET_QUEUE_STATUS_DISABLED )
2010-11-14 00:29:34 +01:00
return ;
2010-12-23 23:25:44 +01:00
if ( GetPlayer () -> getLevel () < sWorld -> getIntConfig ( CONFIG_TICKET_LEVEL_REQ ))
2010-03-09 12:58:48 +01:00
{
2010-12-23 23:25:44 +01:00
SendNotification ( GetTrinityString ( LANG_TICKET_REQ ), sWorld -> getIntConfig ( CONFIG_TICKET_LEVEL_REQ ));
2010-03-09 12:58:48 +01:00
return ;
}
2012-03-28 03:59:03 +02:00
GMTicketResponse response = GMTICKET_RESPONSE_CREATE_ERROR ;
2015-02-08 01:07:00 +01:00
GmTicket * ticket = sSupportMgr -> GetGmTicketByPlayerGuid ( GetPlayer () -> GetGUID ());
2013-05-11 11:19:57 +02:00
if ( ticket && ticket -> IsCompleted ())
2015-02-08 01:07:00 +01:00
sSupportMgr -> CloseTicket < GmTicket > ( ticket -> GetId (), GetPlayer () -> GetGUID ());
2013-05-11 11:19:57 +02:00
2011-04-19 14:04:18 +06:00
// Player must not have ticket
2013-05-11 11:19:57 +02:00
if ( ! ticket || ticket -> IsClosed ())
2009-06-19 00:25:12 +02:00
{
2012-10-17 00:53:55 +02:00
std :: string chatLog ;
2015-02-08 01:07:00 +01:00
if ( packet . DataLength > 0 && packet . ChatHistoryData . DecompressedSize < 0xFFFF )
2012-10-17 00:53:55 +02:00
{
ByteBuffer dest ;
2015-02-08 01:07:00 +01:00
dest . resize ( size_t ( packet . ChatHistoryData . DecompressedSize ));
2012-10-17 00:53:55 +02:00
2015-02-08 01:07:00 +01:00
uLongf realSize = packet . ChatHistoryData . DecompressedSize ;
if ( uncompress ( dest . contents (), & realSize , packet . ChatHistoryData . Data . contents (), packet . ChatHistoryData . Data . size ()) == Z_OK )
2012-10-17 00:53:55 +02:00
dest >> chatLog ;
else
{
2015-02-01 20:52:05 +01:00
TC_LOG_ERROR ( "network" , "CMSG_GM_TICKET_CREATE possibly corrupt. Uncompression failed." );
2012-10-17 00:53:55 +02:00
return ;
}
}
2014-01-18 21:12:56 +01:00
ticket = new GmTicket ( GetPlayer ());
2015-02-08 01:07:00 +01:00
ticket -> SetPosition ( packet . Map , packet . Pos );
ticket -> SetDescription ( packet . Description );
ticket -> SetGmAction ( packet . NeedResponse , packet . NeedMoreHelp );
2014-01-18 21:12:56 +01:00
2015-02-08 01:07:00 +01:00
//TODO: more reasearch needed
//if (!chatLog.empty())
//ticket->SetChatLog(times, chatLog);
2014-01-18 21:12:56 +01:00
2015-02-08 01:07:00 +01:00
sSupportMgr -> AddTicket ( ticket );
sSupportMgr -> UpdateLastChange ();
2009-10-17 15:51:44 -07:00
2012-10-24 13:29:34 +02:00
sWorld -> SendGMText ( LANG_COMMAND_TICKETNEW , GetPlayer () -> GetName (). c_str (), ticket -> GetId ());
2009-10-17 15:51:44 -07:00
2012-03-28 03:59:03 +02:00
response = GMTICKET_RESPONSE_CREATE_SUCCESS ;
2011-04-19 14:04:18 +06:00
}
2015-02-08 01:07:00 +01:00
sSupportMgr -> SendGmTicketUpdate ( this , response );
2008-12-31 15:07:29 +01:00
}
2009-10-17 15:51:44 -07:00
2015-02-08 01:07:00 +01:00
void WorldSession :: HandleGMTicketUpdateTextOpcode ( WorldPackets :: Ticket :: GMTicketUpdateText & packet )
2008-12-31 15:07:29 +01:00
{
2012-03-28 03:59:03 +02:00
GMTicketResponse response = GMTICKET_RESPONSE_UPDATE_ERROR ;
2015-02-08 01:07:00 +01:00
if ( GmTicket * ticket = sSupportMgr -> GetGmTicketByPlayerGuid ( GetPlayer () -> GetGUID ()))
2009-02-09 08:16:34 -05:00
{
2011-04-19 14:04:18 +06:00
SQLTransaction trans = SQLTransaction ( NULL );
2015-02-08 01:07:00 +01:00
ticket -> SetDescription ( packet . Description );
2011-04-19 14:04:18 +06:00
ticket -> SaveToDB ( trans );
2009-10-17 15:51:44 -07:00
2012-10-24 13:29:34 +02:00
sWorld -> SendGMText ( LANG_COMMAND_TICKETUPDATED , GetPlayer () -> GetName (). c_str (), ticket -> GetId ());
2009-10-17 15:51:44 -07:00
2012-03-28 03:59:03 +02:00
response = GMTICKET_RESPONSE_UPDATE_SUCCESS ;
2011-04-19 14:04:18 +06:00
}
2015-02-08 01:07:00 +01:00
sSupportMgr -> SendGmTicketUpdate ( this , response );
2008-12-31 15:07:29 +01:00
}
2009-10-17 15:51:44 -07:00
2015-02-08 01:07:00 +01:00
void WorldSession :: HandleGMTicketDeleteOpcode ( WorldPackets :: Ticket :: GMTicketDelete & /*packet*/ )
2008-12-31 15:07:29 +01:00
{
2015-02-08 01:07:00 +01:00
if ( GmTicket * ticket = sSupportMgr -> GetGmTicketByPlayerGuid ( GetPlayer () -> GetGUID ()))
2009-02-09 08:16:34 -05:00
{
2015-02-08 01:07:00 +01:00
sSupportMgr -> SendGmTicketUpdate ( this , GMTICKET_RESPONSE_TICKET_DELETED );
2009-10-17 15:51:44 -07:00
2012-10-24 13:29:34 +02:00
sWorld -> SendGMText ( LANG_COMMAND_TICKETPLAYERABANDON , GetPlayer () -> GetName (). c_str (), ticket -> GetId ());
2011-04-19 14:04:18 +06:00
2015-02-08 01:07:00 +01:00
sSupportMgr -> CloseTicket < GmTicket > ( ticket -> GetId (), GetPlayer () -> GetGUID ());
sSupportMgr -> SendGmTicket ( this , NULL );
2009-02-09 08:16:34 -05:00
}
2008-12-31 15:07:29 +01:00
}
2009-10-17 15:51:44 -07:00
2015-02-03 18:11:38 +01:00
void WorldSession :: HandleGMTicketGetCaseStatusOpcode ( WorldPackets :: Ticket :: GMTicketGetCaseStatus & /*packet*/ )
2008-12-31 15:07:29 +01:00
{
2015-02-08 01:07:00 +01:00
// TODO: Implement GmCase and handle this packet properly
WorldPackets :: Ticket :: GMTicketCaseStatus status ;
status . OldestTicketTime = time ( nullptr );
SendPacket ( status . Write ());
2015-02-03 18:11:38 +01:00
}
void WorldSession :: HandleGMTicketGetTicketOpcode ( WorldPackets :: Ticket :: GMTicketGetTicket & /*packet*/ )
{
2010-01-29 22:24:18 +01:00
SendQueryTimeResponse ();
2009-10-17 15:51:44 -07:00
2015-02-08 01:07:00 +01:00
if ( GmTicket * ticket = sSupportMgr -> GetGmTicketByPlayerGuid ( GetPlayer () -> GetGUID ()))
2010-08-29 20:28:14 -07:00
{
2011-04-19 14:04:18 +06:00
if ( ticket -> IsCompleted ())
ticket -> SendResponse ( this );
2010-08-29 20:28:14 -07:00
else
2015-02-08 01:07:00 +01:00
sSupportMgr -> SendGmTicket ( this , ticket );
2010-08-29 20:28:14 -07:00
}
2009-06-19 00:25:12 +02:00
else
2015-02-08 01:07:00 +01:00
sSupportMgr -> SendGmTicket ( this , NULL );
2008-12-31 15:07:29 +01:00
}
2009-10-17 15:51:44 -07:00
2015-02-02 00:03:51 +01:00
void WorldSession :: HandleGMTicketSystemStatusOpcode ( WorldPackets :: Ticket :: GMTicketGetSystemStatus & /*packet*/ )
2008-12-31 15:07:29 +01:00
{
2010-11-14 00:29:34 +01:00
// Note: This only disables the ticket UI at client side and is not fully reliable
2015-02-03 18:11:38 +01:00
// Note: This disables the whole customer support UI after trying to send a ticket in disabled state (MessageBox: "GM Help Tickets are currently unavaiable."). UI remains disabled until the character relogs.
2015-02-02 00:03:51 +01:00
WorldPackets :: Ticket :: GMTicketSystemStatus response ;
2015-02-08 01:07:00 +01:00
response . Status = sSupportMgr -> GetSupportSystemStatus () ? GMTICKET_QUEUE_STATUS_ENABLED : GMTICKET_QUEUE_STATUS_DISABLED ;
2015-02-02 00:03:51 +01:00
SendPacket ( response . Write ());
2009-01-10 12:45:01 +01:00
}
2009-10-17 15:51:44 -07:00
2015-02-08 01:07:00 +01:00
void WorldSession :: HandleGMSurveySubmit ( WorldPackets :: Ticket :: GMSurveySubmit & /*packet*/ )
2010-08-29 20:28:14 -07:00
{
2015-02-08 01:07:00 +01:00
/*uint32 nextSurveyID = sSupportMgr->GetNextSurveyID();
2010-08-29 20:28:14 -07:00
2014-06-04 19:45:02 +02:00
std::unordered_set<uint32> surveyIds;
2014-06-03 23:24:00 +02:00
SQLTransaction trans = CharacterDatabase.BeginTransaction();
2015-02-08 01:07:00 +01:00
for (auto const& q : packet.SurveyQuestion)
2010-08-29 20:28:14 -07:00
{
2015-02-08 01:07:00 +01:00
if (!q.QuestionID)
2010-08-29 20:28:14 -07:00
break;
2014-06-04 19:45:02 +02:00
// make sure the same sub survey is not added to DB twice
2015-02-08 01:07:00 +01:00
if (!surveyIds.insert(q.QuestionID).second)
2014-06-04 19:45:02 +02:00
continue;
2012-01-01 01:09:38 +01:00
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GM_SUBSURVEY);
2011-04-19 14:04:18 +06:00
stmt->setUInt32(0, nextSurveyID);
2015-02-08 01:07:00 +01:00
stmt->setUInt32(1, q.QuestionID); // ref to i'th GMSurveySurveys.dbc field (all fields in that dbc point to fields in GMSurveyQuestions.dbc)
stmt->setUInt32(2, q.Answer); // probably some sort of ref to GMSurveyAnswers.dbc
stmt->setString(3, q.AnswerComment); // comment ("Usage: GMSurveyAnswerSubmit(question, rank, comment)")
2014-06-03 23:24:00 +02:00
trans->Append(stmt);
2010-08-29 20:28:14 -07:00
}
2012-01-01 01:09:38 +01:00
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GM_SURVEY);
2014-10-24 19:56:17 +02:00
stmt->setUInt64(0, GetPlayer()->GetGUID().GetCounter());
2011-04-19 14:04:18 +06:00
stmt->setUInt32(1, nextSurveyID);
2015-02-08 01:07:00 +01:00
stmt->setUInt32(2, packet.SurveyID); // GMSurveyCurrentSurvey.dbc, column 1 (all 9) ref to GMSurveySurveys.dbc
stmt->setString(3, packet.Comment);
2014-06-03 23:24:00 +02:00
trans->Append(stmt);
2015-02-08 01:07:00 +01:00
CharacterDatabase.CommitTransaction(trans);*/
2010-08-29 20:28:14 -07:00
}
2015-02-08 01:07:00 +01:00
void WorldSession :: HandleGMResponseResolve ( WorldPackets :: Ticket :: GMTicketResponseResolve & /*packet*/ )
2010-08-29 20:28:14 -07:00
{
2015-02-08 01:07:00 +01:00
if ( GmTicket * ticket = sSupportMgr -> GetGmTicketByPlayerGuid ( GetPlayer () -> GetGUID ()))
2010-08-29 20:28:14 -07:00
{
2015-02-08 01:07:00 +01:00
bool showSurvey = false ;
2011-04-19 14:04:18 +06:00
if ( float ( rand_chance ()) < sWorld -> getFloatConfig ( CONFIG_CHANCE_OF_GM_SURVEY ))
2015-02-08 01:07:00 +01:00
showSurvey = true ;
2010-08-29 20:28:14 -07:00
2015-02-08 01:07:00 +01:00
WorldPackets :: Ticket :: GMTicketResolveResponse response ;
response . ShowSurvey = showSurvey ;
SendPacket ( response . Write ());
2010-08-29 20:28:14 -07:00
2015-02-08 01:07:00 +01:00
sSupportMgr -> SendGmTicketUpdate ( this , GMTICKET_RESPONSE_TICKET_DELETED );
2011-04-19 14:04:18 +06:00
2015-02-08 01:07:00 +01:00
sSupportMgr -> CloseTicket < GmTicket > ( ticket -> GetId (), GetPlayer () -> GetGUID ());
sSupportMgr -> SendGmTicket ( this , NULL );
2010-08-29 20:28:14 -07:00
}
}
2015-02-08 01:07:00 +01:00
void WorldSession :: HandleSupportTicketSubmitBug ( WorldPackets :: Ticket :: SupportTicketSubmitBug & packet )
{
BugTicket * ticket = new BugTicket ( GetPlayer ());
ticket -> SetPosition ( packet . Header . MapID , packet . Header . Position );
ticket -> SetFacing ( packet . Header . Facing );
ticket -> SetNote ( packet . Note );
sSupportMgr -> AddTicket ( ticket );
}
void WorldSession :: HandleSupportTicketSubmitSuggestion ( WorldPackets :: Ticket :: SupportTicketSubmitSuggestion & packet )
{
SuggestionTicket * ticket = new SuggestionTicket ( GetPlayer ());
ticket -> SetPosition ( packet . Header . MapID , packet . Header . Position );
ticket -> SetFacing ( packet . Header . Facing );
ticket -> SetNote ( packet . Note );
sSupportMgr -> AddTicket ( ticket );
}
void WorldSession :: HandleSupportTicketSubmitComplaint ( WorldPackets :: Ticket :: SupportTicketSubmitComplaint & packet )
{
ComplaintTicket * comp = new ComplaintTicket ( GetPlayer ());
comp -> SetPosition ( packet . Header . MapID , packet . Header . Position );
comp -> SetFacing ( packet . Header . Facing );
comp -> SetChatLog ( packet . ChatLog );
comp -> SetTargetCharacterGuid ( packet . TargetCharacterGUID );
comp -> SetComplaintType ( GMSupportComplaintType ( packet . ComplaintType ));
comp -> SetNote ( packet . Note );
sSupportMgr -> AddTicket ( comp );
}