/*
* Ascent MMORPG Server
* Copyright (C) 2005-2007 Ascent Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
///////////////////////////////////////////////
// Admin Movement Commands
//
#include "StdAfx.h"
bool ChatHandler::HandleResetReputationCommand(const char *args, WorldSession *m_session)
{
Player *plr = getSelectedChar(m_session);
if(!plr)
{
SystemMessage(m_session, "Select a player or yourself first.");
return true;
}
plr->_InitialReputation();
SystemMessage(m_session, "Done. Relog for changes to take effect.");
return true;
}
bool ChatHandler::HandleInvincibleCommand(const char *args, WorldSession *m_session)
{
Player *chr = getSelectedChar(m_session);
char msg[100];
if(chr)
{
chr->bInvincible = !chr->bInvincible;
snprintf(msg, 100, "Invincibility is now %s", chr->bInvincible ? "ON. You may have to leave and re-enter this zone for changes to take effect." : "OFF. Exit and re-enter this zone for this change to take effect.");
} else {
snprintf(msg, 100, "Select a player or yourself first.");
}
SystemMessage(m_session, msg);
return true;
}
bool ChatHandler::HandleInvisibleCommand(const char *args, WorldSession *m_session)
{
char msg[256];
Player* pChar =m_session->GetPlayer();
snprintf(msg, 256, "Invisibility and Invincibility are now ");
if(pChar->m_isGmInvisible)
{
pChar->m_isGmInvisible = false;
pChar->bInvincible = false;
sSocialMgr.LoggedOut(pChar);
snprintf(msg, 256, "%s OFF.", msg);
} else {
pChar->m_isGmInvisible = true;
pChar->bInvincible = true;
sSocialMgr.LoggedIn(pChar);
snprintf(msg, 256, "%s ON.", msg);
}
snprintf(msg, 256, "%s You may have to leave and re-enter this zone for changes to take effect.", msg);
GreenSystemMessage(m_session, (const char*)msg);
return true;
}
bool ChatHandler::HandleGUIDCommand(const char* args, WorldSession *m_session)
{
uint64 guid;
guid = m_session->GetPlayer()->GetSelection();
if (guid == 0)
{
SystemMessage(m_session, "No selection.");
return true;
}
char buf[256];
snprintf((char*)buf,256,"Object guid is: lowpart %u highpart %X", (unsigned int)GUID_LOPART(guid), (unsigned int)GUID_HIPART(guid));
SystemMessage(m_session, buf);
return true;
}
bool ChatHandler::CreateGuildCommand(const char* args, WorldSession *m_session)
{
if(!*args)
return false;
Player * ptarget = m_session->GetPlayer()->GetMapMgr()->GetPlayer(m_session->GetPlayer()->GetSelection());
if(ptarget == 0)
{
ptarget = m_session->GetPlayer();
}
if(strlen((char*)args)>75)
{
// send message to user
char buf[256];
snprintf((char*)buf,256,"The name was too long by %i", strlen((char*)args)-75);
SystemMessage(m_session, buf);
return true;
}
for (uint32 i = 0; i < strlen(args); i++) {
if(!isalpha(args[i]) && args[i]!=' ') {
SystemMessage(m_session, "Error, name can only contain chars A-Z and a-z.");
return true;
}
}
if(objmgr.GetGuildByGuildName(args))
{
WorldPacket data(SMSG_GUILD_COMMAND_RESULT, 100);
data << uint32(0);
data << args;
data << uint32(C_R_GUILD_NAME_EXISTS);
m_session->SendPacket(&data);
return true;
}
Guild *pGuild = new Guild;
uint32 guildId = pGuild->GetFreeGuildIdFromDb();
if(guildId == 0)
{
printf("Error Getting Free Guild ID");
delete pGuild;
return false;
}
//Guild Setup
pGuild->SetGuildId( guildId );
pGuild->SetGuildName( args );
pGuild->CreateRank("Guild Master", GR_RIGHT_ALL);
pGuild->CreateRank("Officer", GR_RIGHT_ALL);
pGuild->CreateRank("Veteran", GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK);
pGuild->CreateRank("Member", GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK);
pGuild->CreateRank("Initiate", GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK);
pGuild->SetGuildEmblemStyle( 0xFFFF );
pGuild->SetGuildEmblemColor( 0xFFFF );
pGuild->SetGuildBorderStyle( 0xFFFF );
pGuild->SetGuildBorderColor( 0xFFFF );
pGuild->SetGuildBackgroundColor( 0xFFFF );
objmgr.AddGuild(pGuild);
//Guild Leader Setup
ptarget->SetGuildId( pGuild->GetGuildId() );
ptarget->SetUInt32Value(PLAYER_GUILDID, pGuild->GetGuildId() );
ptarget->SetGuildRank(GUILDRANK_GUILD_MASTER);
ptarget->SetUInt32Value(PLAYER_GUILDRANK,GUILDRANK_GUILD_MASTER);
pGuild->SetGuildLeaderGuid( ptarget->GetGUID() );
pGuild->AddNewGuildMember( ptarget );
pGuild->SaveToDb();
pGuild->SaveRanksToDb();
return true;
}
/*
#define isalpha(c) {isupper(c) || islower(c))
#define isupper(c) (c >= 'A' && c <= 'Z')
#define islower(c) (c >= 'a' && c <= 'z')
*/
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session)
{
uint64 guid = m_session->GetPlayer()->GetSelection();
if (guid == 0)
{
SystemMessage(m_session, "No selection.");
return true;
}
Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid);
if(!unit)
{
SystemMessage(m_session, "You should select a creature.");
return true;
}
sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f",
unit->GetSQL_id(), unit->GetCreatureName()->Name, unit->GetPositionX(), unit->GetPositionY(),
unit->GetPositionZ());
if(unit->m_spawn == 0)
return false;
BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid);
if(unit->IsInWorld())
{
if(unit->m_spawn)
{
uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize));
uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize));
unit->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(cellx, celly)->CreatureSpawns.erase(unit->m_spawn);
}
unit->RemoveFromWorld(false);
}
unit->DeleteFromDB();
delete unit;
return true;
}
bool ChatHandler::HandleDeMorphCommand(const char* args, WorldSession *m_session)
{
sLog.outError("Demorphed %s",m_session->GetPlayer()->GetName());
m_session->GetPlayer()->DeMorph();
return true;
}
bool ChatHandler::HandleItemCommand(const char* args, WorldSession *m_session)
{
char* pitem = strtok((char*)args, " ");
if (!pitem)
return false;
uint64 guid = m_session->GetPlayer()->GetSelection();
if (guid == 0)
{
SystemMessage(m_session, "No selection.");
return true;
}
Creature * pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid);
if(!pCreature)
{
SystemMessage(m_session, "You should select a creature.");
return true;
}
uint32 item = atoi(pitem);
int amount = -1;
char* pamount = strtok(NULL, " ");
if (pamount)
amount = atoi(pamount);
ItemPrototype* tmpItem = ItemPrototypeStorage.LookupEntry(item);
std::stringstream sstext;
if(tmpItem)
{
std::stringstream ss;
ss << "INSERT INTO vendors VALUES ('" << pCreature->GetUInt32Value(OBJECT_FIELD_ENTRY) << "', '" << item << "', '" << amount << "')" << '\0';
WorldDatabase.Execute( ss.str().c_str() );
pCreature->AddVendorItem(item, amount);
sstext << "Item '" << item << "' '" << tmpItem->Name1 << "' Added to list" << '\0';
}
else
{
sstext << "Item '" << item << "' Not Found in Database." << '\0';
}
SystemMessage(m_session, sstext.str().c_str());
return true;
}
bool ChatHandler::HandleItemRemoveCommand(const char* args, WorldSession *m_session)
{
char* iguid = strtok((char*)args, " ");
if (!iguid)
return false;
uint64 guid = m_session->GetPlayer()->GetSelection();
if (guid == 0)
{
SystemMessage(m_session, "No selection.");
return true;
}
Creature * pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid);
if(!pCreature)
{
SystemMessage(m_session, "You should select a creature.");
return true;
}
uint32 itemguid = atoi(iguid);
int slot = pCreature->GetSlotByItemId(itemguid);
std::stringstream sstext;
if(slot != -1)
{
uint32 guidlow = GUID_LOPART(guid);
std::stringstream ss;
ss << "DELETE FROM vendors WHERE vendorGuid = " << guidlow << " AND itemGuid = " << itemguid << '\0';
WorldDatabase.Execute( ss.str().c_str() );
pCreature->RemoveVendorItem(itemguid);
ItemPrototype* tmpItem = ItemPrototypeStorage.LookupEntry(itemguid);
if(tmpItem)
{
sstext << "Item '" << itemguid << "' '" << tmpItem->Name1 << "' Deleted from list" << '\0';
}
else
{
sstext << "Item '" << itemguid << "' Deleted from list" << '\0';
}
}
else
{
sstext << "Item '" << itemguid << "' Not Found in List." << '\0';
}
SystemMessage(m_session, sstext.str().c_str());
return true;
}
bool ChatHandler::HandleRunCommand(const char* args, WorldSession *m_session)
{
if(!*args)
return false;
int option = atoi((char*)args);
if(option != 0 && option != 1)
{
SystemMessage(m_session, "Incorrect value, use 0 or 1");
return true;
}
uint64 guid = m_session->GetPlayer()->GetSelection();
if (guid == 0)
{
SystemMessage(m_session, "No selection.");
return true;
}
Creature * pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid);
if(!pCreature)
{
SystemMessage(m_session, "You should select a creature.");
return true;
}
char sql[512];
snprintf(sql, 512, "UPDATE creatures SET running = '%i' WHERE id = '%u'", (int)option, (unsigned int)GUID_LOPART(guid));
WorldDatabase.Execute( sql );
pCreature->GetAIInterface()->setMoveRunFlag(option > 0);
SystemMessage(m_session, "Value saved.");
return true;
}
bool ChatHandler::HandleNPCFlagCommand(const char* args, WorldSession *m_session)
{
if (!*args)
return false;
uint32 npcFlags = (uint32) atoi((char*)args);
uint64 guid = m_session->GetPlayer()->GetSelection();
if (guid == 0)
{
SystemMessage(m_session, "No selection.");
return true;
}
Creature * pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid);
if(!pCreature)
{
SystemMessage(m_session, "You should select a creature.");
return true;
}
pCreature->SetUInt32Value(UNIT_NPC_FLAGS , npcFlags);
pCreature->SaveToDB();
SystemMessage(m_session, "Value saved, you may need to rejoin or clean your client cache.");
return true;
}
bool ChatHandler::HandleSaveAllCommand(const char *args, WorldSession *m_session)
{
PlayerStorageMap::const_iterator itr;
uint32 stime = now();
uint32 count = 0;
objmgr._playerslock.AcquireReadLock();
for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++)
{
if(itr->second->GetSession())
{
itr->second->SaveToDB(false);
count++;
}
}
objmgr._playerslock.ReleaseReadLock();
char msg[100];
snprintf(msg, 100, "Saved all %d online players in %d msec.", (int)count, int((uint32)now() - stime));
sWorld.SendWorldText(msg);
sWorld.SendWorldWideScreenText(msg);
//sWorld.SendIRCMessage(msg);
return true;
}
bool ChatHandler::HandleKillCommand(const char *args, WorldSession *m_session)
{
Unit * target = m_session->GetPlayer()->GetMapMgr()->GetUnit(m_session->GetPlayer()->GetSelection());
if(target == 0)
{
RedSystemMessage(m_session, "A valid selection is required.");
return true;
}
sGMLog.writefromsession(m_session, "used kill command on "I64FMT, target->GetGUID());
// If we're killing a player, send a message indicating a gm killed them.
if(target->IsPlayer())
{
Player * plr = static_cast(target);
plr->SetUInt32Value(UNIT_FIELD_HEALTH, 0);
plr->KillPlayer();
BlueSystemMessageToPlr(plr, "%s killed you with a GM command.", m_session->GetPlayer()->GetName());
}
else
{
/*
// Cast insta-kill.
SpellEntry * se = sSpellStore.LookupEntry(5);
if(se == 0) return false;
SpellCastTargets targets(target->GetGUID());
Spell * sp = new Spell(m_session->GetPlayer(), se, true, 0);
sp->prepare(&targets);
*/
SpellEntry * se = sSpellStore.LookupEntry(20479);
if(se == 0) return false;
SpellCastTargets targets(target->GetGUID());
Spell * sp = new Spell(target, se, true, 0);
sp->prepare(&targets);
}
return true;
}
bool ChatHandler::HandleCastSpellCommand(const char* args, WorldSession *m_session)
{
Unit *caster = m_session->GetPlayer();
Unit *target = getSelectedChar(m_session, false);
if(!target)
target = getSelectedCreature(m_session, false);
if(!target)
{
RedSystemMessage(m_session, "Must select a char or creature.");
return false;
}
uint32 spellid = atol(args);
SpellEntry *spellentry = sSpellStore.LookupEntry(spellid);
if(!spellentry)
{
RedSystemMessage(m_session, "Invalid spell id!");
return false;
}
Spell *sp = new Spell(caster, spellentry, false, NULL);
if(!sp)
{
RedSystemMessage(m_session, "Spell failed creation!");
delete sp;
return false;
}
BlueSystemMessage(m_session, "Casting spell %d on target.", spellid);
SpellCastTargets targets;
targets.m_unitTarget = target->GetGUID();
sp->prepare(&targets);
return true;
}
bool ChatHandler::HandleCastSpellNECommand(const char* args, WorldSession *m_session)
{
Unit *caster = m_session->GetPlayer();
Unit *target = getSelectedChar(m_session, false);
if(!target)
target = getSelectedCreature(m_session, false);
if(!target)
{
RedSystemMessage(m_session, "Must select a char or creature.");
return false;
}
uint32 spellId = atol(args);
SpellEntry *spellentry = sSpellStore.LookupEntry(spellId);
if(!spellentry)
{
RedSystemMessage(m_session, "Invalid spell id!");
return false;
}
BlueSystemMessage(m_session, "Casting spell %d on target.", spellId);
WorldPacket data;
data.Initialize( SMSG_SPELL_START );
data << caster->GetNewGUID();
data << caster->GetNewGUID();
data << spellId;
data << uint16(0);
data << uint32(0);
data << uint16(2);
data << target->GetGUID();
// WPAssert(data.size() == 36);
m_session->SendPacket( &data );
data.Initialize( SMSG_SPELL_GO );
data << caster->GetNewGUID();
data << caster->GetNewGUID();
data << spellId;
data << uint8(0) << uint8(1) << uint8(1);
data << target->GetGUID();
data << uint8(0);
data << uint16(2);
data << target->GetGUID();
// WPAssert(data.size() == 42);
m_session->SendPacket( &data );
return true;
}
bool ChatHandler::HandleMonsterSayCommand(const char* args, WorldSession *m_session)
{
Unit *crt = getSelectedCreature(m_session, false);
if(!crt)
crt = getSelectedChar(m_session, false);
if(!crt)
{
RedSystemMessage(m_session, "Please select a creature or player before using this command.");
return true;
}
if(crt->GetTypeId() == TYPEID_PLAYER)
{
WorldPacket * data = this->FillMessageData(CHAT_MSG_SAY, LANG_UNIVERSAL, args, crt->GetGUID(), 0);
crt->SendMessageToSet(data, true);
delete data;
}
else
{
crt->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, args);
}
return true;
}
bool ChatHandler::HandleMonsterYellCommand(const char* args, WorldSession *m_session)
{
Unit *crt = getSelectedCreature(m_session, false);
if(!crt)
crt = getSelectedChar(m_session, false);
if(!crt)
{
RedSystemMessage(m_session, "Please select a creature or player before using this command.");
return true;
}
if(crt->GetTypeId() == TYPEID_PLAYER)
{
WorldPacket * data = this->FillMessageData(CHAT_MSG_YELL, LANG_UNIVERSAL, args, crt->GetGUID(), 0);
crt->SendMessageToSet(data, true);
delete data;
}
else
{
crt->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, args);
}
return true;
}
bool ChatHandler::HandleGOSelect(const char *args, WorldSession *m_session)
{
GameObject *GObj = NULL;
std::set