[10331] More basic chat command parsing functions and its uses.

* Commands .debug update and .modify bit removed as redundent
* Command .debug getvalue now can output values in float/int/hex/bitstring formats
* Command .debug setvalue now ca accept values in int/float/hex/bitstring formats
* Command .debug mod32value renamed to modvaue and can add int/float or apply hex mask
  (in 3 modes: |= &= &=~ ) to value in update field
* Command .debug moditemvalue added similar .debug modvalue for item case.
* Command .npc set movetype now propertly update spawned in world creature state.
* Command .modify spell renamed to .debug spellmods and restored to working state.
* Commands .account password and .account set password now allow use quoted strings
  for passwords and then now possible set from chat/console passwords with white spaces.
* Many commands converted to new functions without modify functionality
  except better error detection in some cases at wrong command syntax use.

* Also fixed warnings in reload commands after prev. chat commit. Thanks to SkirnirMaNGOS for reporting.
This commit is contained in:
VladimirMangos 2010-08-08 05:58:59 +04:00
parent fefd648d3e
commit 59e672f1bc
17 changed files with 906 additions and 814 deletions

View file

@ -161,33 +161,26 @@ bool ChatHandler::HandleGMCommand(char* args)
return true;
}
std::string argstr = args;
bool value;
if (!ExtractOnOff(&args, value))
{
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
}
if (argstr == "on")
if (value)
{
m_session->GetPlayer()->SetGameMaster(true);
m_session->SendNotification(LANG_GM_ON);
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("stoplog");
#endif
return true;
}
if (argstr == "off")
else
{
m_session->GetPlayer()->SetGameMaster(false);
m_session->SendNotification(LANG_GM_OFF);
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("startlog");
#endif
return true;
}
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
return true;
}
// Enables or disables hiding of the staff badge
@ -202,25 +195,26 @@ bool ChatHandler::HandleGMChatCommand(char* args)
return true;
}
std::string argstr = args;
bool value;
if (!ExtractOnOff(&args, value))
{
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
}
if (argstr == "on")
if (value)
{
m_session->GetPlayer()->SetGMChat(true);
m_session->SendNotification(LANG_GM_CHAT_ON);
return true;
}
if (argstr == "off")
else
{
m_session->GetPlayer()->SetGMChat(false);
m_session->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
return true;
}
//Enable\Dissable Invisible mode
@ -232,25 +226,26 @@ bool ChatHandler::HandleGMVisibleCommand(char* args)
return true;
}
std::string argstr = args;
bool value;
if (!ExtractOnOff(&args, value))
{
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
}
if (argstr == "on")
if (value)
{
m_session->GetPlayer()->SetGMVisible(true);
m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
return true;
}
if (argstr == "off")
else
{
m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
m_session->GetPlayer()->SetGMVisible(false);
return true;
}
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
return true;
}
@ -313,7 +308,7 @@ bool ChatHandler::HandleGPSCommand(char* args)
uint32 have_map = GridMap::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
uint32 have_vmap = GridMap::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
if(have_vmap)
if (have_vmap)
{
if(map->IsOutdoors(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ()))
PSendSysMessage("You are OUTdoor");
@ -901,60 +896,6 @@ bool ChatHandler::HandleModifyFactionCommand(char* args)
return true;
}
//Edit Player Spell
bool ChatHandler::HandleModifySpellCommand(char* args)
{
if(!*args) return false;
char* pspellflatid = strtok(args, " ");
if (!pspellflatid)
return false;
char* pop = strtok(NULL, " ");
if (!pop)
return false;
char* pval = strtok(NULL, " ");
if (!pval)
return false;
uint16 mark;
char* pmark = strtok(NULL, " ");
uint8 spellflatid = atoi(pspellflatid);
uint8 op = atoi(pop);
uint16 val = atoi(pval);
if(!pmark)
mark = 65535;
else
mark = atoi(pmark);
Player *chr = getSelectedPlayer();
if (chr == NULL)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (HasLowerSecurity(chr, 0))
return false;
PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
data << uint8(spellflatid);
data << uint8(op);
data << uint16(val);
data << uint16(mark);
chr->GetSession()->SendPacket(&data);
return true;
}
//Edit Player TP
bool ChatHandler::HandleModifyTalentCommand (char* args)
{
@ -1006,47 +947,37 @@ bool ChatHandler::HandleModifyTalentCommand (char* args)
//Enable On\OFF all taxi paths
bool ChatHandler::HandleTaxiCheatCommand(char* args)
{
if (!*args)
bool value;
if (!ExtractOnOff(&args, value))
{
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
}
std::string argstr = args;
Player *chr = getSelectedPlayer();
if (!chr)
{
chr=m_session->GetPlayer();
}
// check online security
else if (HasLowerSecurity(chr, 0))
return false;
if (argstr == "on")
if (value)
{
chr->SetTaxiCheater(true);
PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
return true;
}
if (argstr == "off")
else
{
chr->SetTaxiCheater(false);
PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
return true;
}
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
return true;
}
//Edit Player Aspeed
@ -1628,61 +1559,6 @@ bool ChatHandler::HandleModifyMoneyCommand(char* args)
return true;
}
//Edit Unit field
bool ChatHandler::HandleModifyBitCommand(char* args)
{
if( !*args )
return false;
Unit *unit = getSelectedUnit();
if (!unit)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
// check online security
if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
return false;
char* pField = strtok(args, " ");
if (!pField)
return false;
char* pBit = strtok(NULL, " ");
if (!pBit)
return false;
uint16 field = atoi(pField);
uint32 bit = atoi(pBit);
if (field < OBJECT_END || field >= unit->GetValuesCount())
{
SendSysMessage(LANG_BAD_VALUE);
SetSentErrorMessage(true);
return false;
}
if (bit < 1 || bit > 32)
{
SendSysMessage(LANG_BAD_VALUE);
SetSentErrorMessage(true);
return false;
}
if ( unit->HasFlag( field, (1<<(bit-1)) ) )
{
unit->RemoveFlag( field, (1<<(bit-1)) );
PSendSysMessage(LANG_REMOVE_BIT, bit, field);
}
else
{
unit->SetFlag( field, (1<<(bit-1)) );
PSendSysMessage(LANG_SET_BIT, bit, field);
}
return true;
}
bool ChatHandler::HandleModifyHonorCommand (char* args)
{
if (!*args)
@ -1805,11 +1681,7 @@ bool ChatHandler::HandleLookupTeleCommand(char * args)
return false;
}
char const* str = strtok(args, " ");
if(!str)
return false;
std::string namepart = str;
std::string namepart = args;
std::wstring wnamepart;
if(!Utf8toWStr(namepart,wnamepart))
@ -1851,26 +1723,28 @@ bool ChatHandler::HandleWhispersCommand(char* args)
return true;
}
std::string argstr = args;
bool value;
if (!ExtractOnOff(&args, value))
{
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
}
// whisper on
if (argstr == "on")
if (value)
{
m_session->GetPlayer()->SetAcceptWhispers(true);
SendSysMessage(LANG_COMMAND_WHISPERON);
return true;
}
// whisper off
if (argstr == "off")
else
{
m_session->GetPlayer()->SetAcceptWhispers(false);
SendSysMessage(LANG_COMMAND_WHISPEROFF);
return true;
}
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
return true;
}
//Save all players in the world
@ -1921,7 +1795,7 @@ bool ChatHandler::HandleSendMailCommand(char* args)
// teleport player to given game_tele.entry
bool ChatHandler::HandleTeleNameCommand(char* args)
{
char* nameStr = ExtractOptArg(&args);
char* nameStr = ExtractOptNotLastArg(&args);
Player* target;
uint64 target_guid;
@ -2267,24 +2141,19 @@ bool ChatHandler::HandleGoCommand(char* args)
//teleport at coordinates
bool ChatHandler::HandleGoXYCommand(char* args)
{
if (!*args)
return false;
Player* _player = m_session->GetPlayer();
char* px = strtok(args, " ");
char* py = strtok(NULL, " ");
char* pmapid = strtok(NULL, " ");
if (!px || !py)
float x;
if (!ExtractFloat(&args, x))
return false;
float y;
if (!ExtractFloat(&args, y))
return false;
float x = (float)atof(px);
float y = (float)atof(py);
uint32 mapid;
if (pmapid)
mapid = (uint32)atoi(pmapid);
else mapid = _player->GetMapId();
if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
return false;
return HandleGoHelper(_player, mapid, x, y);
}
@ -2292,27 +2161,23 @@ bool ChatHandler::HandleGoXYCommand(char* args)
//teleport at coordinates, including Z
bool ChatHandler::HandleGoXYZCommand(char* args)
{
if (!*args)
return false;
Player* _player = m_session->GetPlayer();
char* px = strtok(args, " ");
char* py = strtok(NULL, " ");
char* pz = strtok(NULL, " ");
char* pmapid = strtok(NULL, " ");
if (!px || !py || !pz)
float x;
if (!ExtractFloat(&args, x))
return false;
float y;
if (!ExtractFloat(&args, y))
return false;
float z;
if (!ExtractFloat(&args, z))
return false;
float x = (float)atof(px);
float y = (float)atof(py);
float z = (float)atof(pz);
uint32 mapid;
if (pmapid)
mapid = (uint32)atoi(pmapid);
else
mapid = _player->GetMapId();
if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
return false;
return HandleGoHelper(_player, mapid, x, y, &z);
}
@ -2379,21 +2244,19 @@ bool ChatHandler::HandleGoZoneXYCommand(char* args)
//teleport to grid
bool ChatHandler::HandleGoGridCommand(char* args)
{
if (!*args)
return false;
Player* _player = m_session->GetPlayer();
char* px = strtok(args, " ");
char* py = strtok(NULL, " ");
char* pmapid = strtok(NULL, " ");
if (!px || !py)
float grid_x;
if (!ExtractFloat(&args, grid_x))
return false;
float grid_x = (float)atof(px);
float grid_y = (float)atof(py);
uint32 mapid = pmapid ? (uint32)atoi(pmapid) : _player->GetMapId();
float grid_y;
if (!ExtractFloat(&args, grid_y))
return false;
uint32 mapid;
if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
return false;
// center of grid
float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;