forked from mangoszero/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGMTicketMgr.cpp
More file actions
220 lines (183 loc) · 7.19 KB
/
GMTicketMgr.cpp
File metadata and controls
220 lines (183 loc) · 7.19 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2019 MaNGOS project <https://getmangos.eu>
*
* 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
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "SQLStorages.h"
#include "GMTicketMgr.h"
#include "ObjectMgr.h"
#include "ObjectGuid.h"
#include "ProgressBar.h"
#include "Policies/Singleton.h"
#include "Player.h"
INSTANTIATE_SINGLETON_1(GMTicketMgr);
void GMTicket::SaveSurveyData(WorldPacket& recvData) const
{
uint32 x;
recvData >> x; // answer range? (6 = 0-5?)
DEBUG_LOG("SURVEY: X = %u", x);
uint8 result[10];
memset(result, 0, sizeof(result));
for (int i = 0; i < 10; ++i)
{
uint32 questionID;
recvData >> questionID; // GMSurveyQuestions.dbc
if (!questionID)
break;
uint8 value;
std::string unk_text;
recvData >> value; // answer
recvData >> unk_text; // always empty?
result[i] = value;
DEBUG_LOG("SURVEY: ID %u, value %u, text %s", questionID, value, unk_text.c_str());
}
std::string comment;
recvData >> comment; // addional comment
DEBUG_LOG("SURVEY: comment %s", comment.c_str());
// TODO: chart this data in some way in DB
}
void GMTicket::Init(ObjectGuid guid, const std::string& text, const std::string& responseText, time_t update, uint32 ticketId)
{
m_guid = guid;
m_ticketId = ticketId;
m_text = text;
m_responseText = responseText;
m_lastUpdate = update;
}
void GMTicket::SetText(const char* text)
{
m_text = text ? text : "";
m_lastUpdate = time(NULL);
std::string escapedString = m_text;
CharacterDatabase.escape_string(escapedString);
CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' "
"WHERE guid = '%u'",
escapedString.c_str(), m_guid.GetCounter());
}
void GMTicket::SetResponseText(const char* text)
{
m_responseText = text ? text : "";
m_lastUpdate = time(NULL);
std::string escapedString = m_responseText;
CharacterDatabase.escape_string(escapedString);
CharacterDatabase.PExecute("UPDATE character_ticket SET response_text = '%s' "
"WHERE guid = '%u'",
escapedString.c_str(), m_guid.GetCounter());
}
void GMTicket::CloseWithSurvey() const
{
_Close(GM_TICKET_STATUS_SURVEY);
}
void GMTicket::CloseByClient() const
{
_Close(GM_TICKET_STATUS_DO_NOTHING);
}
void GMTicket::Close() const
{
_Close(GM_TICKET_STATUS_CLOSE);
}
void GMTicket::_Close(GMTicketStatus statusCode) const
{
Player* pPlayer = sObjectMgr.GetPlayer(m_guid);
CharacterDatabase.PExecute("UPDATE character_ticket "
"SET resolved = 1 "
"WHERE guid = %u AND resolved = 0",
m_guid.GetCounter());
if (pPlayer && statusCode != GM_TICKET_STATUS_DO_NOTHING)
{ pPlayer->GetSession()->SendGMTicketStatusUpdate(statusCode); }
}
void GMTicketMgr::LoadGMTickets()
{
m_GMTicketMap.clear(); // For reload case
QueryResult* result = CharacterDatabase.Query(
// 0 1 2 3 4
"SELECT guid, ticket_text, response_text, UNIX_TIMESTAMP(ticket_lastchange), ticket_id "
"FROM character_ticket "
"WHERE resolved = 0 "
"ORDER BY ticket_id ASC");
if (!result)
{
BarGoLink bar(1);
bar.step();
sLog.outString(">> Loaded `character_ticket`, table is empty.");
sLog.outString();
return;
}
BarGoLink bar(result->GetRowCount());
do
{
bar.step();
Field* fields = result->Fetch();
uint32 guidlow = fields[0].GetUInt32();
if (!guidlow)
{ continue; }
ObjectGuid guid = ObjectGuid(HIGHGUID_PLAYER, guidlow);
GMTicket& ticket = m_GMTicketMap[guid];
ticket.Init(guid, fields[1].GetCppString(), fields[2].GetCppString(), time_t(fields[3].GetUInt64()), fields[4].GetUInt32());
m_GMTicketIdMap[ticket.GetId()] = &ticket;
}
while (result->NextRow());
delete result;
sLog.outString(">> Loaded " SIZEFMTD " GM tickets", GetTicketCount());
sLog.outString();
}
void GMTicketMgr::Create(ObjectGuid guid, const char* text)
{
std::string escapedText = text;
CharacterDatabase.escape_string(escapedText);
CharacterDatabase.BeginTransaction();
//This needs to be Direct (not placed in queue) as we need the id of it soon afterwards
CharacterDatabase.DirectPExecute("INSERT INTO character_ticket "
"(guid, ticket_text) "
"VALUES "
"(%u, '%s')",
guid.GetCounter(), escapedText.c_str());
//Get the id of the ticket, needed for logging whispers
QueryResult* result = CharacterDatabase.PQuery("SELECT ticket_id, guid, resolved "
"FROM character_ticket "
"WHERE guid = %u AND resolved = 0;",
guid.GetCounter());
CharacterDatabase.CommitTransaction();
if (!result)
return;
Field* fields = result->Fetch();
uint32 ticketId = fields[0].GetUInt32();
//This implicitly creates a new instance since we're using operator[]
GMTicket& ticket = m_GMTicketMap[guid];
if (ticket.GetPlayerGuid())
m_GMTicketIdMap.erase(ticketId);
//Lets reinitialize with new data
ticket.Init(guid, text, "", time(NULL), ticketId);
m_GMTicketIdMap[ticketId] = &ticket;
}
void GMTicketMgr::DeleteAll()
{
for (GMTicketMap::const_iterator itr = m_GMTicketMap.begin(); itr != m_GMTicketMap.end(); ++itr)
{
if (Player* owner = sObjectMgr.GetPlayer(itr->first))
{ owner->GetSession()->SendGMTicketGetTicket(0x0A); }
}
CharacterDatabase.Execute("DELETE FROM character_ticket");
m_GMTicketIdMap.clear();
m_GMTicketMap.clear();
}