Implement new commands for add/remove/lookup titles.

Autor Vladimir.

--HG--
branch : trunk
This commit is contained in:
win32
2010-01-21 11:19:34 +02:00
parent ce620223eb
commit 19ac6f6a3c
11 changed files with 368 additions and 44 deletions
+13 -1
View File
@@ -58,6 +58,7 @@
// |color|Htalent:talent_id,rank|h[name]|h|r - client, talent icon shift-click
// |color|Htaxinode:id|h[name]|h|r
// |color|Htele:id|h[name]|h|r
// |color|Htitle:id|h[name]|h|r
// |color|Htrade:spell_id,cur_value,max_value,unk3int,unk3str|h[name]|h|r - client, spellbook profession icon shift-click
bool ChatHandler::load_command_table = true;
@@ -126,6 +127,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "level", SEC_ADMINISTRATOR, true, &ChatHandler::HandleCharacterLevelCommand, "", NULL },
{ "rename", SEC_GAMEMASTER, true, &ChatHandler::HandleCharacterRenameCommand, "", NULL },
{ "reputation", SEC_GAMEMASTER, true, &ChatHandler::HandleCharacterReputationCommand, "", NULL },
{ "titles", SEC_GAMEMASTER, true, &ChatHandler::HandleCharacterTitlesCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
@@ -317,6 +319,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "spell", SEC_ADMINISTRATOR, true, &ChatHandler::HandleLookupSpellCommand, "", NULL },
{ "taxinode", SEC_ADMINISTRATOR, true, &ChatHandler::HandleLookupTaxiNodeCommand, "", NULL },
{ "tele", SEC_MODERATOR, true, &ChatHandler::HandleLookupTeleCommand, "", NULL },
{ "title", SEC_GAMEMASTER, true, &ChatHandler::HandleLookupTitleCommand, "", NULL },
{ "map", SEC_ADMINISTRATOR, true, &ChatHandler::HandleLookupMapCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
@@ -339,7 +342,6 @@ ChatCommand * ChatHandler::getCommandTable()
{ "faction", SEC_MODERATOR, false, &ChatHandler::HandleModifyFactionCommand, "", NULL },
{ "spell", SEC_MODERATOR, false, &ChatHandler::HandleModifySpellCommand, "", NULL },
{ "tp", SEC_MODERATOR, false, &ChatHandler::HandleModifyTalentCommand, "", NULL },
{ "titles", SEC_MODERATOR, false, &ChatHandler::HandleModifyKnownTitlesCommand, "", NULL },
{ "mount", SEC_MODERATOR, false, &ChatHandler::HandleModifyMountCommand, "", NULL },
{ "honor", SEC_MODERATOR, false, &ChatHandler::HandleModifyHonorCommand, "", NULL },
{ "rep", SEC_GAMEMASTER, false, &ChatHandler::HandleModifyRepCommand, "", NULL },
@@ -598,6 +600,15 @@ ChatCommand * ChatHandler::getCommandTable()
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand titlesCommandTable[] =
{
{ "add", SEC_GAMEMASTER, false, &ChatHandler::HandleTitlesAddCommand, "", NULL },
{ "current", SEC_GAMEMASTER, false, &ChatHandler::HandleTitlesCurrentCommand, "", NULL },
{ "remove", SEC_GAMEMASTER, false, &ChatHandler::HandleTitlesRemoveCommand, "", NULL },
{ "setmask", SEC_GAMEMASTER, false, &ChatHandler::HandleTitlesSetMaskCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand unbanCommandTable[] =
{
{ "account", SEC_ADMINISTRATOR, true, &ChatHandler::HandleUnBanAccountCommand, "", NULL },
@@ -647,6 +658,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "gobject", SEC_GAMEMASTER, false, NULL, "", gobjectCommandTable },
{ "honor", SEC_GAMEMASTER, false, NULL, "", honorCommandTable },
{ "wp", SEC_GAMEMASTER, false, NULL, "", wpCommandTable },
{ "titles", SEC_GAMEMASTER, false, NULL, "", titlesCommandTable },
{ "quest", SEC_ADMINISTRATOR, false, NULL, "", questCommandTable },
{ "reload", SEC_ADMINISTRATOR, true, NULL, "", reloadCommandTable },
{ "list", SEC_ADMINISTRATOR, true, NULL, "", listCommandTable },
+7 -1
View File
@@ -137,6 +137,7 @@ class TRINITY_DLL_SPEC ChatHandler
bool HandleCharacterLevelCommand(const char* args);
bool HandleCharacterRenameCommand(const char * args);
bool HandleCharacterReputationCommand(const char* args);
bool HandleCharacterTitlesCommand(const char* args);
bool HandleDebugAnimCommand(const char* args);
bool HandleDebugArenaCommand(const char * args);
@@ -264,8 +265,8 @@ class TRINITY_DLL_SPEC ChatHandler
bool HandleLookupTaxiNodeCommand(const char * args);
bool HandleLookupTeleCommand(const char * args);
bool HandleLookupMapCommand(const char* args);
bool HandleLookupTitleCommand(const char * args);
bool HandleModifyKnownTitlesCommand(const char* args);
bool HandleModifyHPCommand(const char* args);
bool HandleModifyManaCommand(const char* args);
bool HandleModifyRageCommand(const char* args);
@@ -459,6 +460,11 @@ class TRINITY_DLL_SPEC ChatHandler
bool HandleTeleGroupCommand(const char* args);
bool HandleTeleNameCommand(const char* args);
bool HandleTitlesAddCommand(const char* args);
bool HandleTitlesCurrentCommand(const char* args);
bool HandleTitlesRemoveCommand(const char* args);
bool HandleTitlesSetMaskCommand(const char* args);
bool HandleUnBanAccountCommand(const char* args);
bool HandleUnBanCharacterCommand(const char* args);
bool HandleUnBanIPCommand(const char* args);
+1 -1
View File
@@ -625,7 +625,7 @@ struct CharTitlesEntry
{
uint32 ID; // 0, title ids, for example in Quest::GetCharTitleId()
//uint32 unk1; // 1 flags?
//char* name[16]; // 2-17, unused
char* name[16]; // 2-17
// 18 string flag, unused
//char* name2[16]; // 19-34, unused
// 35 string flag, unused
+1 -1
View File
@@ -32,7 +32,7 @@ const char BankBagSlotPricesEntryfmt[]="ni";
const char BarberShopStyleEntryfmt[]="nixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiii";
const char BattlemasterListEntryfmt[]="niiiiiiiiiiiixxxssssssssssssssssxxx";
const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiiiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char CharTitlesEntryfmt[]="nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi";
const char CharTitlesEntryfmt[]="nxssssssssssssssssxxxxxxxxxxxxxxxxxxi";
const char ChatChannelsEntryfmt[]="iixssssssssssssssssxxxxxxxxxxxxxxxxxx";
// ChatChannelsEntryfmt, index not used (more compact store)
const char ChrClassesEntryfmt[]="nxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxixii";
+9 -1
View File
@@ -330,7 +330,15 @@ enum TrinityStrings
LANG_CUSTOMIZE_PLAYER_GUID = 346,
LANG_COMMAND_GOTAXINODENOTFOUND = 347,
LANG_GAMEOBJECT_HAVE_INVALID_DATA = 348,
// Room for more level 2 349-399 not used
LANG_TITLE_LIST_CHAT = 349,
LANG_TITLE_LIST_CONSOLE = 350,
LANG_COMMAND_NOTITLEFOUND = 351,
LANG_INVALID_TITLE_ID = 352,
LANG_TITLE_ADD_RES = 353,
LANG_TITLE_REMOVE_RES = 354,
LANG_TITLE_CURRENT_RES = 355,
LANG_CURRENT_TITLE_RESET = 356,
// Room for more level 2 357-399 not used
// level 3 chat
LANG_SCRIPTS_RELOADED = 400,
-36
View File
@@ -1074,42 +1074,6 @@ bool ChatHandler::HandleRecallCommand(const char* args)
return true;
}
//Edit Player KnownTitles
bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
{
if(!*args)
return false;
uint64 titles = 0;
sscanf((char*)args, UI64FMTD, &titles);
Player *chr = getSelectedPlayer();
if (!chr)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (HasLowerSecurity(chr, 0))
return false;
uint64 titles2 = titles;
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
titles2 &= ~(uint64(1) << tEntry->bit_index);
titles &= ~titles2; // remove not existed titles
chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
SendSysMessage(LANG_DONE);
return true;
}
//Edit Player HP
bool ChatHandler::HandleModifyHPCommand(const char* args)
{
+302
View File
@@ -20,6 +20,7 @@
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "DBCStores.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Item.h"
@@ -4242,3 +4243,304 @@ bool ChatHandler::HandleNpcSetLinkCommand(const char* args)
PSendSysMessage("LinkGUID '%u' added to creature with DBTableGUID: '%u'", linkguid, pCreature->GetDBTableGUIDLow());
return true;
}
bool ChatHandler::HandleLookupTitleCommand(const char* args)
{
if(!*args)
return false;
// can be NULL in console call
Player* target = getSelectedPlayer();
// title name have single string arg for player name
char const* targetName = target ? target->GetName() : "NAME";
std::string namepart = args;
std::wstring wnamepart;
if(!Utf8toWStr(namepart,wnamepart))
return false;
// converting string that we try to find to lower case
wstrToLower( wnamepart );
uint32 counter = 0; // Counter for figure out that we found smth.
// Search in CharTitles.dbc
for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
{
CharTitlesEntry const *titleInfo = sCharTitlesStore.LookupEntry(id);
if(titleInfo)
{
int loc = GetSessionDbcLocale();
std::string name = titleInfo->name[loc];
if(name.empty())
continue;
if (!Utf8FitTo(name, wnamepart))
{
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if(loc==GetSessionDbcLocale())
continue;
name = titleInfo->name[loc];
if(name.empty())
continue;
if (Utf8FitTo(name, wnamepart))
break;
}
}
if(loc < MAX_LOCALE)
{
char const* knownStr = target && target->HasTitle(titleInfo) ? GetTrinityString(LANG_KNOWN) : "";
char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE)==titleInfo->bit_index
? GetTrinityString(LANG_ACTIVE)
: "";
char titleNameStr[80];
snprintf(titleNameStr,80,name.c_str(),targetName);
// send title in "id (idx:idx) - [namedlink locale]" format
if (m_session)
PSendSysMessage(LANG_TITLE_LIST_CHAT,id,titleInfo->bit_index,id,titleNameStr,localeNames[loc],knownStr,activeStr);
else
PSendSysMessage(LANG_TITLE_LIST_CONSOLE,id,titleInfo->bit_index,titleNameStr,localeNames[loc],knownStr,activeStr);
++counter;
}
}
}
if (counter == 0) // if counter == 0 then we found nth
SendSysMessage(LANG_COMMAND_NOTITLEFOUND);
return true;
}
bool ChatHandler::HandleTitlesAddCommand(const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = extractKeyFromLink((char*)args,"Htitle");
if(!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
PSendSysMessage(LANG_INVALID_TITLE_ID, id);
SetSentErrorMessage(true);
return false;
}
Player * target = getSelectedPlayer();
if(!target)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if(!titleInfo)
{
PSendSysMessage(LANG_INVALID_TITLE_ID, id);
SetSentErrorMessage(true);
return false;
}
std::string tNameLink = GetNameLink(target);
char const* targetName = target->GetName();
char titleNameStr[80];
snprintf(titleNameStr,80,titleInfo->name[GetSessionDbcLocale()],targetName);
target->SetTitle(titleInfo);
PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
return true;
}
bool ChatHandler::HandleTitlesRemoveCommand(const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = extractKeyFromLink((char*)args,"Htitle");
if(!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
PSendSysMessage(LANG_INVALID_TITLE_ID, id);
SetSentErrorMessage(true);
return false;
}
Player * target = getSelectedPlayer();
if(!target)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if(!titleInfo)
{
PSendSysMessage(LANG_INVALID_TITLE_ID, id);
SetSentErrorMessage(true);
return false;
}
target->SetTitle(titleInfo,true);
std::string tNameLink = GetNameLink(target);
char const* targetName = target->GetName();
char titleNameStr[80];
snprintf(titleNameStr,80,titleInfo->name[GetSessionDbcLocale()],targetName);
PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,0);
PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
}
return true;
}
//Edit Player KnownTitles
bool ChatHandler::HandleTitlesSetMaskCommand(const char* args)
{
if(!*args)
return false;
uint64 titles = 0;
sscanf((char*)args, UI64FMTD, &titles);
Player *target = getSelectedPlayer();
if (!target)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (HasLowerSecurity(target, 0))
return false;
uint64 titles2 = titles;
for(uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
titles2 &= ~(uint64(1) << tEntry->bit_index);
titles &= ~titles2; // remove not existed titles
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
SendSysMessage(LANG_DONE);
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,0);
PSendSysMessage(LANG_CURRENT_TITLE_RESET,GetNameLink(target).c_str());
}
return true;
}
bool ChatHandler::HandleCharacterTitlesCommand(const char* args)
{
Player* target;
if(!extractPlayerTarget((char*)args,&target))
return false;
LocaleConstant loc = GetSessionDbcLocale();
char const* targetName = target->GetName();
char const* knownStr = GetTrinityString(LANG_KNOWN);
// Search in CharTitles.dbc
for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
{
CharTitlesEntry const *titleInfo = sCharTitlesStore.LookupEntry(id);
if (titleInfo && target->HasTitle(titleInfo))
{
std::string name = titleInfo->name[loc];
if(name.empty())
continue;
char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE)==titleInfo->bit_index
? GetTrinityString(LANG_ACTIVE)
: "";
char titleNameStr[80];
snprintf(titleNameStr,80,name.c_str(),targetName);
// send title in "id (idx:idx) - [namedlink locale]" format
if (m_session)
PSendSysMessage(LANG_TITLE_LIST_CHAT,id,titleInfo->bit_index,id,titleNameStr,localeNames[loc],knownStr,activeStr);
else
PSendSysMessage(LANG_TITLE_LIST_CONSOLE,id,titleInfo->bit_index,name.c_str(),localeNames[loc],knownStr,activeStr);
}
}
return true;
}
bool ChatHandler::HandleTitlesCurrentCommand(const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = extractKeyFromLink((char*)args,"Htitle");
if(!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
PSendSysMessage(LANG_INVALID_TITLE_ID, id);
SetSentErrorMessage(true);
return false;
}
Player * target = getSelectedPlayer();
if(!target)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if(!titleInfo)
{
PSendSysMessage(LANG_INVALID_TITLE_ID, id);
SetSentErrorMessage(true);
return false;
}
std::string tNameLink = GetNameLink(target);
target->SetTitle(titleInfo); // to be sure that title now known
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,titleInfo->bit_index);
PSendSysMessage(LANG_TITLE_CURRENT_RES, id, titleInfo->name[GetSessionDbcLocale()], tNameLink.c_str());
return true;
}
+2 -2
View File
@@ -1612,7 +1612,7 @@ bool ChatHandler::HandleSetSkillCommand(const char *args)
if (!target->GetSkillValue(skill))
{
PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[0]);
PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[GetSessionDbcLocale()]);
SetSentErrorMessage(true);
return false;
}
@@ -1623,7 +1623,7 @@ bool ChatHandler::HandleSetSkillCommand(const char *args)
return false;
target->SetSkill(skill, level, max);
PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], tNameLink.c_str(), level, max);
PSendSysMessage(LANG_SET_SKILL, skill, sl->name[GetSessionDbcLocale()], tNameLink.c_str(), level, max);
return true;
}