Skip to content

Minor adjustments and allow loading of CMaNGOS data format #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Debug/
.vs/
SniffScripter/*.sql
enc_temp_folder/
35 changes: 17 additions & 18 deletions SniffScripter/Database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
#include <fstream>
#include <sstream>

// Keep track of how many database connections the
// Keep track of how many database connections
size_t Database::m_stDatabaseCount = 0;

Database::Database() :
Database::Database() :
m_pMYSQL(nullptr),
m_bQueriesTransaction(false),
m_bCancelToken(false),
m_bInit(false)
{

}

Database::~Database()
Expand Down Expand Up @@ -73,7 +72,7 @@ bool Database::Initialize(const char* infoString)
printf("Database::Initialize - Could not initialize Mysql connection");
return false;
}

std::string strHost;
std::string strPortOrSocket;
std::string strUser;
Expand All @@ -94,11 +93,11 @@ bool Database::Initialize(const char* infoString)
}

mysql_options(pMyqlInit, MYSQL_SET_CHARSET_NAME, "utf8");

int32 port = 0;

// Named pipe use option (Windows)
if (strHost == ".")
if (strHost == ".")
{
uint32 opt = MYSQL_PROTOCOL_PIPE;
mysql_options(pMyqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt);
Expand Down Expand Up @@ -134,7 +133,7 @@ bool Database::Initialize(const char* infoString)
}
else
{
printf("Database::Initialize - Could not connect to MySQL database %s at %s\n", strDbName.c_str(),strHost.c_str());
printf("Database::Initialize - Could not connect to MySQL database %s at %s\n", strDbName.c_str(), strHost.c_str());
mysql_close(pMyqlInit);
return false;
}
Expand All @@ -143,7 +142,7 @@ bool Database::Initialize(const char* infoString)
void Database::WorkerThread()
{
// Cycle until m_bCancelToken variable is set to false.
// However, we will also wait until we've finished emptying m_queueQueries.
// However, we will also wait until we've finished emptying m_queueQueries.
// Anything in that queue expected itself to be finished.

while (true)
Expand Down Expand Up @@ -207,13 +206,13 @@ int32 Database::QueryInt32(const char* format, ...)
std::shared_ptr<QueryResult> Database::LockedPerformQuery(const std::string strQuery)
{
std::lock_guard<std::mutex> lock(m_mutexMysql);
return PerformQuery(strQuery);
return PerformQuery(strQuery);
}

std::shared_ptr<QueryResult> Database::PerformQuery(const std::string strQuery)
{
ASSERT(m_pMYSQL);

if (!RawMysqlQueryCall(strQuery))
return nullptr;

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

// We anticipate that
// We anticipate that
m_queueQueries.pushMany(result);

m_vTransactionQueries.clear();
Expand All @@ -271,19 +270,19 @@ bool Database::ExecuteQueryInstant(const char* format, ...)
{
if (!format || !m_pMYSQL)
return false;

std::string strQuery;
FORMAT_STRING_ARGS(format, strQuery, MAX_QUERY_LEN);

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

bool Database::QueueExecuteQuery(const char* format,...)
bool Database::QueueExecuteQuery(const char* format, ...)
{
if (!format || !m_pMYSQL)
return false;

std::string strQuery;
FORMAT_STRING_ARGS(format, strQuery, MAX_QUERY_LEN);

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

bool Database::RawMysqlQueryCall(const std::string strQuery, const bool bDeleteGatheredData)
{
{
ASSERT(m_pMYSQL);

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

char strResult[MAX_QUERY_LEN];
ASSERT(str.size() < MAX_QUERY_LEN);

mysql_real_escape_string(m_pMYSQL, strResult, str.c_str(), str.size());

// Copy result.
str = strResult;
}

void Database::CallbackResult(const uint64 id, std::shared_ptr<CallbackQueryObj::ResultQueryHolder> result)
{
std::lock_guard<std::mutex> lock(m_mutexCallbackQueries);

auto itr = m_uoCallbackQueries.find(id);

if (itr != m_uoCallbackQueries.end())
Expand Down
15 changes: 6 additions & 9 deletions SniffScripter/Database/DbField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#include "DbField.h"
#include "Database.h"

DbField::DbField() :
DbField::DbField() :
m_pData(nullptr)
{

}

DbField::DbField(DbField &f)
DbField::DbField(DbField& f)
{
const char* value = nullptr;
value = f.getString();
Expand All @@ -22,7 +21,7 @@ DbField::DbField(DbField &f)
m_pData = nullptr;
}

DbField::DbField(const char* value)
DbField::DbField(const char* value)
{
if (value && (m_pData = new char[strlen(value) + 1]))
strcpy(m_pData, value);
Expand All @@ -33,13 +32,13 @@ DbField::DbField(const char* value)
DbField::~DbField()
{
if (m_pData)
delete [] m_pData;
delete[] m_pData;
}

void DbField::SetValue(const char* value)
{
if (m_pData)
delete [] m_pData;
delete[] m_pData;

if (value)
{
Expand All @@ -50,6 +49,4 @@ void DbField::SetValue(const char* value)
{
m_pData = nullptr;
}
}


}
2 changes: 1 addition & 1 deletion SniffScripter/Database/QueryObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void QueryObj::RunQuery(Database& db)
void CallbackQueryObj::RunQuery(Database& db)
{
std::shared_ptr<ResultQueryHolder> result(new ResultQueryHolder(m_strMsgToSelf));

// Would be nonsensical for this to be empty.
ASSERT(!m_uoQueries.empty());

Expand Down
12 changes: 5 additions & 7 deletions SniffScripter/Database/QueryResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "Database.h"
#include "QueryResult.h"

QueryResult::QueryResult(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount) :
m_pResult(result),
m_uiFieldCount(fieldCount),
QueryResult::QueryResult(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount) :
m_pResult(result),
m_uiFieldCount(fieldCount),
m_uiRowCount(rowCount)
{
m_pCurrentRow = new DbField[m_uiFieldCount];
Expand Down Expand Up @@ -46,7 +46,7 @@ void QueryResult::EndQuery()
{
if (m_pCurrentRow)
{
delete [] m_pCurrentRow;
delete[] m_pCurrentRow;
m_pCurrentRow = 0;
}

Expand All @@ -55,6 +55,4 @@ void QueryResult::EndQuery()
mysql_free_result(m_pResult);
m_pResult = 0;
}
}


}
29 changes: 14 additions & 15 deletions SniffScripter/Defines/SniffedEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ struct KnownObject
bool operator==(KnownObject const& other) const
{
return m_guid == other.m_guid &&
m_entry == other.m_entry &&
m_type == other.m_type;
m_entry == other.m_entry &&
m_type == other.m_type;
}
bool operator!=(KnownObject const& other) const
{
return !(m_guid == other.m_guid &&
m_entry == other.m_entry &&
m_type == other.m_type);
m_entry == other.m_entry &&
m_type == other.m_type);
}
bool operator<(KnownObject const& other) const
{
Expand Down Expand Up @@ -216,10 +216,9 @@ struct SniffedEvent_CreatureDeath : SniffedEvent
}
};


struct SniffedEvent_CreatureText : SniffedEvent
{
SniffedEvent_CreatureText(uint32 guid, uint32 entry, std::string text, uint32 chatType, std::string comment) :
SniffedEvent_CreatureText(uint32 guid, uint32 entry, std::string text, uint32 chatType, std::string comment) :
m_guid(guid), m_entry(entry), m_chatType(chatType), m_text(text), m_comment(comment) {};
uint32 m_guid = 0;
uint32 m_entry = 0;
Expand All @@ -239,7 +238,7 @@ struct SniffedEvent_CreatureText : SniffedEvent
txt += "Chat Type: " + GetGetChatTypeName(ConvertChatTypeToVmangosFormat(m_chatType)) + "\n";
txt += "Comment: " + m_comment;
}

return txt;
}
SniffedEventType GetType() const final
Expand Down Expand Up @@ -347,7 +346,7 @@ struct SniffedEvent_CreatureMovement : SniffedEvent
float m_orientation = 0.0f;
std::string ToString(bool /*singleLine*/) const final
{
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";
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";
txt += "Start Position: " + std::to_string(m_startX) + " " + std::to_string(m_startY) + " " + std::to_string(m_startZ) + "\n";
txt += "End Position: " + std::to_string(m_endX) + " " + std::to_string(m_endY) + " " + std::to_string(m_endZ) + "\n";
txt += "Final Orientation: " + std::to_string(m_orientation);
Expand All @@ -364,9 +363,9 @@ struct SniffedEvent_CreatureMovement : SniffedEvent
}
};

struct SniffedEvent_VmangosWaypoints : SniffedEvent
struct SniffedEvent_mangosWaypoints : SniffedEvent
{
SniffedEvent_VmangosWaypoints(uint32 guid, uint32 point, float position_x, float position_y, float position_z, float orientation, uint32 waittime, float wander_distance, uint32 script_id, std::string comment) :
SniffedEvent_mangosWaypoints(uint32 guid, uint32 point, float position_x, float position_y, float position_z, float orientation, uint32 waittime, float wander_distance, uint32 script_id, std::string comment) :
m_guid(guid), m_point(point), m_position_x(position_x), m_position_y(position_y), m_position_z(position_z), m_orientation(orientation), m_waittime(waittime), m_wander_distance(wander_distance), m_script_id(script_id), m_comment(comment) {};
uint32 m_guid = 0;
uint32 m_point = 0;
Expand All @@ -380,7 +379,7 @@ struct SniffedEvent_VmangosWaypoints : SniffedEvent
std::string m_comment;
std::string ToString(bool /*singleLine*/) const final
{
std::string txt = "(" + std::to_string(m_guid) + ", " + std::to_string(m_point) + ", " + std::to_string(m_position_x) + ", " + std::to_string(m_position_y) + ", " + std::to_string(m_position_z) + ", " + std::to_string(m_orientation) + ", " + std::to_string(m_waittime) + ", " + std::to_string(m_wander_distance) + ", " + std::to_string(m_script_id) + ")";
std::string txt = "(" + std::to_string(m_guid) + ", " + std::to_string(m_point) + ", " + std::to_string(m_position_x) + ", " + std::to_string(m_position_y) + ", " + std::to_string(m_position_z) + ", " + std::to_string(m_orientation) + ", " + std::to_string(m_waittime) + (CURRENT_BUILD >= TBC_START_BUILD ? "" : ", " + std::to_string(m_wander_distance)) + ", " + std::to_string(m_script_id) + ")";
return txt;
}
SniffedEventType GetType() const final
Expand Down Expand Up @@ -442,7 +441,7 @@ struct SniffedEvent_CreatureUpdate_faction : SniffedEvent
uint32 m_value = 0;
std::string ToString(bool /*singleLine*/) const final
{
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) + ").";
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) + ").";
return txt;
}
SniffedEventType GetType() const final
Expand Down Expand Up @@ -707,7 +706,7 @@ struct SniffedEvent_PlaySound : SniffedEvent
if (m_sourceId != 0)
txt += " Source is " + FormatObjectName(m_sourceGuid, m_sourceId, m_sourceType) + ".";
}

return txt;
}
SniffedEventType GetType() const final
Expand Down Expand Up @@ -754,7 +753,7 @@ struct SniffedEvent_SpellCastStart : SniffedEvent
}
};

struct SniffedEvent_SpellCastGo: SniffedEvent
struct SniffedEvent_SpellCastGo : SniffedEvent
{
SniffedEvent_SpellCastGo(uint32 spellId, uint32 casterGuid, uint32 casterId, std::string casterType, uint32 targetGuid, uint32 targetId, std::string targetType, uint32 hitTargetsCount, uint32 hitTargetsListId) :
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) {};
Expand Down Expand Up @@ -788,7 +787,7 @@ struct SniffedEvent_SpellCastGo: SniffedEvent
}
}
}

return txt;
}
SniffedEventType GetType() const final
Expand Down
2 changes: 1 addition & 1 deletion SniffScripter/Defines/TimelineMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TimelineMaker
static void PromptTimelineSaveMethod(uint32 startTime);
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);
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);

static uint32 SaveWaypointsToFile();
static void CreateWaypoints(uint32 guid, bool useStartPosition);

Expand Down
4 changes: 4 additions & 0 deletions SniffScripter/Defines/WorldDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <string>
#include "Common.h"

#define CURRENT_PATCH 10
#define CURRENT_BUILD 8606 // 2.4.3 (5875 - 1.12.1)
#define TBC_START_BUILD 5610 // 2.0.0

struct BroadcastText
{
BroadcastText(std::string maleText, std::string femaleText) : m_maleText(maleText), m_femaleText(femaleText) {};
Expand Down
Loading