Skip to content

Commit a6fa3c0

Browse files
committed
Minor adjustments and allow loading of CMaNGOS data format
1 parent 00695fc commit a6fa3c0

11 files changed

+179
-159
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Debug/
2+
.vs/
3+
SniffScripter/*.sql

SniffScripter/Database/Database.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
#include <fstream>
1010
#include <sstream>
1111

12-
// Keep track of how many database connections the
12+
// Keep track of how many database connections
1313
size_t Database::m_stDatabaseCount = 0;
1414

15-
Database::Database() :
15+
Database::Database() :
1616
m_pMYSQL(nullptr),
1717
m_bQueriesTransaction(false),
1818
m_bCancelToken(false),
1919
m_bInit(false)
2020
{
21-
2221
}
2322

2423
Database::~Database()
@@ -73,7 +72,7 @@ bool Database::Initialize(const char* infoString)
7372
printf("Database::Initialize - Could not initialize Mysql connection");
7473
return false;
7574
}
76-
75+
7776
std::string strHost;
7877
std::string strPortOrSocket;
7978
std::string strUser;
@@ -94,11 +93,11 @@ bool Database::Initialize(const char* infoString)
9493
}
9594

9695
mysql_options(pMyqlInit, MYSQL_SET_CHARSET_NAME, "utf8");
97-
96+
9897
int32 port = 0;
9998

10099
// Named pipe use option (Windows)
101-
if (strHost == ".")
100+
if (strHost == ".")
102101
{
103102
uint32 opt = MYSQL_PROTOCOL_PIPE;
104103
mysql_options(pMyqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt);
@@ -134,7 +133,7 @@ bool Database::Initialize(const char* infoString)
134133
}
135134
else
136135
{
137-
printf("Database::Initialize - Could not connect to MySQL database %s at %s\n", strDbName.c_str(),strHost.c_str());
136+
printf("Database::Initialize - Could not connect to MySQL database %s at %s\n", strDbName.c_str(), strHost.c_str());
138137
mysql_close(pMyqlInit);
139138
return false;
140139
}
@@ -143,7 +142,7 @@ bool Database::Initialize(const char* infoString)
143142
void Database::WorkerThread()
144143
{
145144
// Cycle until m_bCancelToken variable is set to false.
146-
// However, we will also wait until we've finished emptying m_queueQueries.
145+
// However, we will also wait until we've finished emptying m_queueQueries.
147146
// Anything in that queue expected itself to be finished.
148147

149148
while (true)
@@ -207,13 +206,13 @@ int32 Database::QueryInt32(const char* format, ...)
207206
std::shared_ptr<QueryResult> Database::LockedPerformQuery(const std::string strQuery)
208207
{
209208
std::lock_guard<std::mutex> lock(m_mutexMysql);
210-
return PerformQuery(strQuery);
209+
return PerformQuery(strQuery);
211210
}
212211

213212
std::shared_ptr<QueryResult> Database::PerformQuery(const std::string strQuery)
214213
{
215214
ASSERT(m_pMYSQL);
216-
215+
217216
if (!RawMysqlQueryCall(strQuery))
218217
return nullptr;
219218

@@ -254,7 +253,7 @@ void Database::CommitManyQueries()
254253
for (size_t i = 0; i < m_vTransactionQueries.size(); ++i)
255254
result.push_back(std::make_shared<QueryObj>(m_vTransactionQueries[i]));
256255

257-
// We anticipate that
256+
// We anticipate that
258257
m_queueQueries.pushMany(result);
259258

260259
m_vTransactionQueries.clear();
@@ -271,19 +270,19 @@ bool Database::ExecuteQueryInstant(const char* format, ...)
271270
{
272271
if (!format || !m_pMYSQL)
273272
return false;
274-
273+
275274
std::string strQuery;
276275
FORMAT_STRING_ARGS(format, strQuery, MAX_QUERY_LEN);
277276

278277
std::lock_guard<std::mutex> lock(m_mutexMysql);
279278
return RawMysqlQueryCall(strQuery, true);
280279
}
281280

282-
bool Database::QueueExecuteQuery(const char* format,...)
281+
bool Database::QueueExecuteQuery(const char* format, ...)
283282
{
284283
if (!format || !m_pMYSQL)
285284
return false;
286-
285+
287286
std::string strQuery;
288287
FORMAT_STRING_ARGS(format, strQuery, MAX_QUERY_LEN);
289288

@@ -301,7 +300,7 @@ bool Database::QueueExecuteQuery(const char* format,...)
301300
}
302301

303302
bool Database::RawMysqlQueryCall(const std::string strQuery, const bool bDeleteGatheredData)
304-
{
303+
{
305304
ASSERT(m_pMYSQL);
306305

307306
if (mysql_query(m_pMYSQL, strQuery.c_str()))
@@ -332,17 +331,17 @@ void Database::EscapeString(std::string& str)
332331

333332
char strResult[MAX_QUERY_LEN];
334333
ASSERT(str.size() < MAX_QUERY_LEN);
335-
334+
336335
mysql_real_escape_string(m_pMYSQL, strResult, str.c_str(), str.size());
337-
336+
338337
// Copy result.
339338
str = strResult;
340339
}
341340

342341
void Database::CallbackResult(const uint64 id, std::shared_ptr<CallbackQueryObj::ResultQueryHolder> result)
343342
{
344343
std::lock_guard<std::mutex> lock(m_mutexCallbackQueries);
345-
344+
346345
auto itr = m_uoCallbackQueries.find(id);
347346

348347
if (itr != m_uoCallbackQueries.end())

SniffScripter/Database/DbField.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
#include "DbField.h"
66
#include "Database.h"
77

8-
DbField::DbField() :
8+
DbField::DbField() :
99
m_pData(nullptr)
1010
{
11-
1211
}
1312

14-
DbField::DbField(DbField &f)
13+
DbField::DbField(DbField& f)
1514
{
1615
const char* value = nullptr;
1716
value = f.getString();
@@ -22,7 +21,7 @@ DbField::DbField(DbField &f)
2221
m_pData = nullptr;
2322
}
2423

25-
DbField::DbField(const char* value)
24+
DbField::DbField(const char* value)
2625
{
2726
if (value && (m_pData = new char[strlen(value) + 1]))
2827
strcpy(m_pData, value);
@@ -33,13 +32,13 @@ DbField::DbField(const char* value)
3332
DbField::~DbField()
3433
{
3534
if (m_pData)
36-
delete [] m_pData;
35+
delete[] m_pData;
3736
}
3837

3938
void DbField::SetValue(const char* value)
4039
{
4140
if (m_pData)
42-
delete [] m_pData;
41+
delete[] m_pData;
4342

4443
if (value)
4544
{
@@ -50,6 +49,4 @@ void DbField::SetValue(const char* value)
5049
{
5150
m_pData = nullptr;
5251
}
53-
}
54-
55-
52+
}

SniffScripter/Database/QueryObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void QueryObj::RunQuery(Database& db)
2121
void CallbackQueryObj::RunQuery(Database& db)
2222
{
2323
std::shared_ptr<ResultQueryHolder> result(new ResultQueryHolder(m_strMsgToSelf));
24-
24+
2525
// Would be nonsensical for this to be empty.
2626
ASSERT(!m_uoQueries.empty());
2727

SniffScripter/Database/QueryResult.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "Database.h"
66
#include "QueryResult.h"
77

8-
QueryResult::QueryResult(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount) :
9-
m_pResult(result),
10-
m_uiFieldCount(fieldCount),
8+
QueryResult::QueryResult(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount) :
9+
m_pResult(result),
10+
m_uiFieldCount(fieldCount),
1111
m_uiRowCount(rowCount)
1212
{
1313
m_pCurrentRow = new DbField[m_uiFieldCount];
@@ -46,7 +46,7 @@ void QueryResult::EndQuery()
4646
{
4747
if (m_pCurrentRow)
4848
{
49-
delete [] m_pCurrentRow;
49+
delete[] m_pCurrentRow;
5050
m_pCurrentRow = 0;
5151
}
5252

@@ -55,6 +55,4 @@ void QueryResult::EndQuery()
5555
mysql_free_result(m_pResult);
5656
m_pResult = 0;
5757
}
58-
}
59-
60-
58+
}

SniffScripter/Defines/SniffedEvents.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ struct KnownObject
1919
bool operator==(KnownObject const& other) const
2020
{
2121
return m_guid == other.m_guid &&
22-
m_entry == other.m_entry &&
23-
m_type == other.m_type;
22+
m_entry == other.m_entry &&
23+
m_type == other.m_type;
2424
}
2525
bool operator!=(KnownObject const& other) const
2626
{
2727
return !(m_guid == other.m_guid &&
28-
m_entry == other.m_entry &&
29-
m_type == other.m_type);
28+
m_entry == other.m_entry &&
29+
m_type == other.m_type);
3030
}
3131
bool operator<(KnownObject const& other) const
3232
{
@@ -216,10 +216,9 @@ struct SniffedEvent_CreatureDeath : SniffedEvent
216216
}
217217
};
218218

219-
220219
struct SniffedEvent_CreatureText : SniffedEvent
221220
{
222-
SniffedEvent_CreatureText(uint32 guid, uint32 entry, std::string text, uint32 chatType, std::string comment) :
221+
SniffedEvent_CreatureText(uint32 guid, uint32 entry, std::string text, uint32 chatType, std::string comment) :
223222
m_guid(guid), m_entry(entry), m_chatType(chatType), m_text(text), m_comment(comment) {};
224223
uint32 m_guid = 0;
225224
uint32 m_entry = 0;
@@ -239,7 +238,7 @@ struct SniffedEvent_CreatureText : SniffedEvent
239238
txt += "Chat Type: " + GetGetChatTypeName(ConvertChatTypeToVmangosFormat(m_chatType)) + "\n";
240239
txt += "Comment: " + m_comment;
241240
}
242-
241+
243242
return txt;
244243
}
245244
SniffedEventType GetType() const final
@@ -347,7 +346,7 @@ struct SniffedEvent_CreatureMovement : SniffedEvent
347346
float m_orientation = 0.0f;
348347
std::string ToString(bool /*singleLine*/) const final
349348
{
350-
std::string txt = "Creature " + WorldDatabase::GetCreatureName(m_entry) + " (Guid: " + std::to_string(m_guid) + " Entry: " + std::to_string(m_entry) + ") moves to point " + std::to_string(m_point) + " in " + std::to_string(m_moveTime) +" ms.\n";
349+
std::string txt = "Creature " + WorldDatabase::GetCreatureName(m_entry) + " (Guid: " + std::to_string(m_guid) + " Entry: " + std::to_string(m_entry) + ") moves to point " + std::to_string(m_point) + " in " + std::to_string(m_moveTime) + " ms.\n";
351350
txt += "Start Position: " + std::to_string(m_startX) + " " + std::to_string(m_startY) + " " + std::to_string(m_startZ) + "\n";
352351
txt += "End Position: " + std::to_string(m_endX) + " " + std::to_string(m_endY) + " " + std::to_string(m_endZ) + "\n";
353352
txt += "Final Orientation: " + std::to_string(m_orientation);
@@ -442,7 +441,7 @@ struct SniffedEvent_CreatureUpdate_faction : SniffedEvent
442441
uint32 m_value = 0;
443442
std::string ToString(bool /*singleLine*/) const final
444443
{
445-
std::string txt = "Creature " + WorldDatabase::GetCreatureName(m_entry) + " (Guid: " + std::to_string(m_guid) + " Entry: " + std::to_string(m_entry) + ") updates faction to " + std::to_string(m_value) + + " (" + WorldDatabase::GetFactionName(m_value) + ").";
444+
std::string txt = "Creature " + WorldDatabase::GetCreatureName(m_entry) + " (Guid: " + std::to_string(m_guid) + " Entry: " + std::to_string(m_entry) + ") updates faction to " + std::to_string(m_value) + +" (" + WorldDatabase::GetFactionName(m_value) + ").";
446445
return txt;
447446
}
448447
SniffedEventType GetType() const final
@@ -707,7 +706,7 @@ struct SniffedEvent_PlaySound : SniffedEvent
707706
if (m_sourceId != 0)
708707
txt += " Source is " + FormatObjectName(m_sourceGuid, m_sourceId, m_sourceType) + ".";
709708
}
710-
709+
711710
return txt;
712711
}
713712
SniffedEventType GetType() const final
@@ -754,7 +753,7 @@ struct SniffedEvent_SpellCastStart : SniffedEvent
754753
}
755754
};
756755

757-
struct SniffedEvent_SpellCastGo: SniffedEvent
756+
struct SniffedEvent_SpellCastGo : SniffedEvent
758757
{
759758
SniffedEvent_SpellCastGo(uint32 spellId, uint32 casterGuid, uint32 casterId, std::string casterType, uint32 targetGuid, uint32 targetId, std::string targetType, uint32 hitTargetsCount, uint32 hitTargetsListId) :
760759
m_spellId(spellId), m_casterGuid(casterGuid), m_casterId(casterId), m_casterType(casterType), m_targetGuid(targetGuid), m_targetId(targetId), m_targetType(targetType), m_hitTargetsCount(hitTargetsCount), m_hitTargetsListId(hitTargetsListId) {};
@@ -788,7 +787,7 @@ struct SniffedEvent_SpellCastGo: SniffedEvent
788787
}
789788
}
790789
}
791-
790+
792791
return txt;
793792
}
794793
SniffedEventType GetType() const final

SniffScripter/Defines/TimelineMaker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TimelineMaker
1616
static void PromptTimelineSaveMethod(uint32 startTime);
1717
static void CreateTimelineForGuids(uint32 uiStartTime, std::vector<uint32>& vCreatureGuids, std::vector<uint32> vGameObjectGuids, bool showReclaimCorpse, bool showReleaseSpirit, bool showQuests, bool showCreatureInteract, bool showGameObjectUse, bool showItemUse, bool showDeaths, bool showAttacks, bool showTexts, bool showEmotes, bool showMoves, bool showUpdates, bool showCasts, bool showSounds);
1818
static void CreateTimelineForAll(uint32 uiStartTime, uint32 uiEndTime, bool showReclaimCorpse, bool showReleaseSpirit, bool showQuests, bool showUseItem, bool showCreatures, bool showCreatureInteract, bool showCreatureDeaths, bool showCreatureAttacks, bool showCreatureTexts, bool showCreatureEmotes, bool showCreatureMoves, bool showCreatureCasts, bool showCreatureUpdates, bool showGameObjects, bool showGameObjectUse, bool showGameObjectCasts, bool showGameObjectUpdates, bool showSounds);
19-
19+
2020
static uint32 SaveWaypointsToFile();
2121
static void CreateWaypoints(uint32 guid, bool useStartPosition);
2222

0 commit comments

Comments
 (0)