* use databases instead of hardcoded values for language,map,zone,race,class names

This commit is contained in:
False.Genesis 2007-03-24 12:17:02 +00:00
parent 1ea085ae7b
commit 96610d36c6
5 changed files with 80 additions and 14 deletions

View File

@ -64,7 +64,7 @@ name=Emerald Forest
name=Scarlet Monastery Instance name=Scarlet Monastery Instance
[209] [209]
name=Zul\'Farrak Instance name=Zul'Farrak Instance
[229] [229]
name=Blackrock Spire Instance name=Blackrock Spire Instance
@ -73,7 +73,7 @@ name=Blackrock Spire Instance
name=Blackrock Depths Instance name=Blackrock Depths Instance
[249] [249]
name=Onyxia\'s Lair Instance name=Onyxia's Lair Instance
[269] [269]
name=Caverns of Time name=Caverns of Time

View File

@ -2,6 +2,8 @@
#include "common.h" #include "common.h"
#include "SCPDatabase.h" #include "SCPDatabase.h"
// for helper functions
#include "NameTables.h"
uint32 SCPDatabase::LoadFromFile(char *fn) uint32 SCPDatabase::LoadFromFile(char *fn)
{ {
@ -94,3 +96,44 @@ SCPDatabase& SCPDatabaseMgr::GetDB(std::string n)
{ {
return _map[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;
}

View File

@ -48,8 +48,21 @@ public:
bool HasDB(std::string); bool HasDB(std::string);
SCPDatabase& GetDB(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: private:
SCPDatabaseMap _map; SCPDatabaseMap _map;
}; };
#endif #endif

View File

@ -196,10 +196,10 @@ OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const
void WorldSession::SetTarget(uint64 guid) void WorldSession::SetTarget(uint64 guid)
{ {
_targetGUID=guid; SendSetSelection(guid);
// TODO: update the UpdateFields once implemented
} }
// redundant for now
void WorldSession::SetFollowTarget(uint64 guid) void WorldSession::SetFollowTarget(uint64 guid)
{ {
_followGUID=guid; _followGUID=guid;
@ -344,8 +344,13 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
int playerNum = 0; int playerNum = 0;
for(unsigned int i=0;i<num;i++){ for(unsigned int i=0;i<num;i++){
logcustom(0,LGREEN,"## %s (%u) [%s/%s]", logcustom(0,LGREEN,"## %s (%u) [%s/%s] Map: %s; Zone: %s",
plr[i]._name.c_str(),plr[i]._level,raceName[plr[i]._race],className[plr[i]._class]); plr[i]._name.c_str(),
plr[i]._level,
GetDBMgr().GetRaceName(plr[i]._race).c_str(),
GetDBMgr().GetClassName_(plr[i]._class).c_str(),
GetDBMgr().GetMapName(plr[i]._mapId).c_str(),
GetDBMgr().GetZoneName(plr[i]._zoneId).c_str());
logdetail("-> coords: map=%u zone=%u x=%f y=%f z=%f", logdetail("-> 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); plr[i]._mapId,plr[i]._zoneId,plr[i]._x,plr[i]._y,plr[i]._z);
for(unsigned int inv=0;inv<20;inv++) for(unsigned int inv=0;inv<20;inv++)
@ -402,6 +407,10 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
recvPacket >> type >> lang; recvPacket >> type >> lang;
std::string langname = GetDBMgr().GetLangName(lang);
const char* ln = langname.c_str();
if (type == CHAT_MSG_CHANNEL) if (type == CHAT_MSG_CHANNEL)
{ {
recvPacket >> channel; // extract channel name recvPacket >> channel; // extract channel name
@ -432,35 +441,35 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
} }
else if (type==CHAT_MSG_WHISPER ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 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) if(target_guid!=GetGuid() && msg.length()>1 && msg.at(0)=='-' && GetInstance()->GetConf()->allowgamecmd)

View File

@ -31,6 +31,7 @@ public:
void Init(void); void Init(void);
PseuInstance *GetInstance(void) { return _instance; } PseuInstance *GetInstance(void) { return _instance; }
SCPDatabaseMgr& GetDBMgr(void) { return GetInstance()->dbmgr; }
OpcodeHandler *_GetOpcodeHandlerTable(void) const; OpcodeHandler *_GetOpcodeHandlerTable(void) const;