From 96610d36c6160ccce64f20207e13e4473d72bdc7 Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Sat, 24 Mar 2007 12:17:02 +0000 Subject: [PATCH] * use databases instead of hardcoded values for language,map,zone,race,class names --- bin/data/zone.scp | 4 +-- src/Client/SCPDatabase.cpp | 43 +++++++++++++++++++++++++++++++ src/Client/SCPDatabase.h | 13 ++++++++++ src/Client/World/WorldSession.cpp | 33 +++++++++++++++--------- src/Client/World/WorldSession.h | 1 + 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/bin/data/zone.scp b/bin/data/zone.scp index fe8af55..ff322a1 100644 --- a/bin/data/zone.scp +++ b/bin/data/zone.scp @@ -64,7 +64,7 @@ name=Emerald Forest name=Scarlet Monastery Instance [209] -name=Zul\'Farrak Instance +name=Zul'Farrak Instance [229] name=Blackrock Spire Instance @@ -73,7 +73,7 @@ name=Blackrock Spire Instance name=Blackrock Depths Instance [249] -name=Onyxia\'s Lair Instance +name=Onyxia's Lair Instance [269] name=Caverns of Time diff --git a/src/Client/SCPDatabase.cpp b/src/Client/SCPDatabase.cpp index aec86cc..2467de6 100644 --- a/src/Client/SCPDatabase.cpp +++ b/src/Client/SCPDatabase.cpp @@ -2,6 +2,8 @@ #include "common.h" #include "SCPDatabase.h" +// for helper functions +#include "NameTables.h" uint32 SCPDatabase::LoadFromFile(char *fn) { @@ -93,4 +95,45 @@ bool SCPDatabaseMgr::HasDB(std::string n) SCPDatabase& SCPDatabaseMgr::GetDB(std::string n) { return _map[n]; +} + +// -- helper functions -- // + +std::string SCPDatabaseMgr::GetZoneName(uint32 id) +{ + return GetDB("zone").GetField(id).GetString("name"); +} + +std::string SCPDatabaseMgr::GetRaceName(uint32 id) +{ + std::string r = GetDB("race").GetField(id).GetString("name"); + if(r.empty()) + r = raceName[id]; + return r; +} + +std::string SCPDatabaseMgr::GetMapName(uint32 id) +{ + return GetDB("map").GetField(id).GetString("name"); +} + +std::string SCPDatabaseMgr::GetClassName_(uint32 id) +{ + std::string r = GetDB("class").GetField(id).GetString("name"); + if(r.empty()) + r = className[id]; + return r; +} + +std::string SCPDatabaseMgr::GetGenderName(uint32 id) +{ + return GetDB("gender").GetField(id).GetString("name"); +} + +std::string SCPDatabaseMgr::GetLangName(uint32 id) +{ + std::string r = GetDB("language").GetField(id).GetString("name"); + if(r.empty()) + r = LookupName(id,langNames); + return r; } \ No newline at end of file diff --git a/src/Client/SCPDatabase.h b/src/Client/SCPDatabase.h index ccc6016..3df8675 100644 --- a/src/Client/SCPDatabase.h +++ b/src/Client/SCPDatabase.h @@ -48,8 +48,21 @@ public: bool HasDB(std::string); SCPDatabase& GetDB(std::string); + ////////////////////// + // helper functions // + ////////////////////// + std::string GetZoneName(uint32 id); + std::string GetRaceName(uint32 id); + std::string GetClassName_(uint32 id); + std::string GetGenderName(uint32 id); + std::string GetMapName(uint32 id); + std::string GetLangName(uint32 id); + private: SCPDatabaseMap _map; }; + + + #endif diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 7d04afc..de6c1d3 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -196,10 +196,10 @@ OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const void WorldSession::SetTarget(uint64 guid) { - _targetGUID=guid; - // TODO: update the UpdateFields once implemented + SendSetSelection(guid); } +// redundant for now void WorldSession::SetFollowTarget(uint64 guid) { _followGUID=guid; @@ -344,8 +344,13 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket) int playerNum = 0; for(unsigned int i=0;i coords: map=%u zone=%u x=%f y=%f z=%f", plr[i]._mapId,plr[i]._zoneId,plr[i]._x,plr[i]._y,plr[i]._z); for(unsigned int inv=0;inv<20;inv++) @@ -401,6 +406,10 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) bool isCmd=false; recvPacket >> type >> lang; + + std::string langname = GetDBMgr().GetLangName(lang); + const char* ln = langname.c_str(); + if (type == CHAT_MSG_CHANNEL) { @@ -432,35 +441,35 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) } else if (type==CHAT_MSG_WHISPER ) { - logcustom(0,WHITE,"WHISP: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"WHISP: %s [%s]: %s",plrname.c_str(),ln,msg.c_str()); } else if (type==CHAT_MSG_CHANNEL ) { - logcustom(0,WHITE,"CHANNEL: [%s]: %s [%s]: %s",channel.c_str(),plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"CHANNEL: [%s]: %s [%s]: %s",channel.c_str(),plrname.c_str(),ln,msg.c_str()); } else if (type==CHAT_MSG_SAY ) { - logcustom(0,WHITE,"CHAT: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"CHAT: %s [%s]: %s",plrname.c_str(),ln,msg.c_str()); } else if (type==CHAT_MSG_YELL ) { - logcustom(0,WHITE,"CHAT: %s yells [%s]: %s ",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"CHAT: %s yells [%s]: %s ",plrname.c_str(),ln,msg.c_str()); } else if (type==CHAT_MSG_WHISPER_INFORM ) { - logcustom(0,WHITE,"TO %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"TO %s [%s]: %s",plrname.c_str(),ln,msg.c_str()); } else if (type==CHAT_MSG_GUILD ) { - logcustom(0,WHITE,"GUILD: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"GUILD: %s [%s]: %s",plrname.c_str(),ln,msg.c_str()); } else if (type==CHAT_MSG_PARTY ) { - logcustom(0,WHITE,"PARTY: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"PARTY: %s [%s]: %s",plrname.c_str(),ln,msg.c_str()); } else { - logcustom(0,WHITE,"UNK CHAT TYPE (%u): %s [%s]: %s",type,plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + logcustom(0,WHITE,"UNK CHAT TYPE (%u): %s [%s]: %s",type,plrname.c_str(),ln,msg.c_str()); } if(target_guid!=GetGuid() && msg.length()>1 && msg.at(0)=='-' && GetInstance()->GetConf()->allowgamecmd) diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index ab5f687..8de886b 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -31,6 +31,7 @@ public: void Init(void); PseuInstance *GetInstance(void) { return _instance; } + SCPDatabaseMgr& GetDBMgr(void) { return GetInstance()->dbmgr; } OpcodeHandler *_GetOpcodeHandlerTable(void) const;