2010-11-09 10:15:35 -05:00
/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
2010-11-09 10:15:35 -05:00
*
* 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 2 of the License, or (at your
* option) 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 <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: gm_commandscript
%Complete: 100
Comment: All gm related commands
Category: commandscripts
EndScriptData */
2010-11-13 22:29:46 +01:00
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Chat.h"
2011-09-08 15:11:55 +02:00
#include "AccountMgr.h"
2012-01-28 16:03:36 -05:00
#include "World.h"
2010-11-09 10:15:35 -05:00
class gm_commandscript : public CommandScript
{
2010-11-19 14:04:21 +01:00
public :
gm_commandscript () : CommandScript ( "gm_commandscript" ) { }
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
ChatCommand * GetCommands () const
{
static ChatCommand gmCommandTable [] =
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
{ "chat" , SEC_MODERATOR , false , & HandleGMChatCommand , "" , NULL },
{ "fly" , SEC_ADMINISTRATOR , false , & HandleGMFlyCommand , "" , NULL },
{ "ingame" , SEC_PLAYER , true , & HandleGMListIngameCommand , "" , NULL },
{ "list" , SEC_ADMINISTRATOR , true , & HandleGMListFullCommand , "" , NULL },
{ "visible" , SEC_MODERATOR , false , & HandleGMVisibleCommand , "" , NULL },
{ "" , SEC_MODERATOR , false , & HandleGMCommand , "" , NULL },
{ NULL , 0 , false , NULL , "" , NULL }
};
static ChatCommand commandTable [] =
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
{ "gm" , SEC_MODERATOR , false , NULL , "" , gmCommandTable },
{ NULL , 0 , false , NULL , "" , NULL }
};
return commandTable ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Enables or disables hiding of the staff badge
2011-10-10 10:33:13 -03:00
static bool HandleGMChatCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
{
2011-09-08 15:11:55 +02:00
WorldSession * session = handler -> GetSession ();
if ( ! AccountMgr :: IsPlayerAccount ( session -> GetSecurity ()) && session -> GetPlayer () -> isGMChat ())
session -> SendNotification ( LANG_GM_CHAT_ON );
2010-11-19 14:04:21 +01:00
else
2011-09-08 15:11:55 +02:00
session -> SendNotification ( LANG_GM_CHAT_OFF );
2010-11-19 14:04:21 +01:00
return true ;
2010-11-09 10:15:35 -05:00
}
2011-10-10 10:33:13 -03:00
std :: string param = ( char * ) args ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( param == "on" )
2010-11-19 14:04:21 +01:00
{
handler -> GetSession () -> GetPlayer () -> SetGMChat ( true );
handler -> GetSession () -> SendNotification ( LANG_GM_CHAT_ON );
2010-11-09 10:15:35 -05:00
return true ;
}
2011-10-10 10:33:13 -03:00
if ( param == "off" )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> GetSession () -> GetPlayer () -> SetGMChat ( false );
handler -> GetSession () -> SendNotification ( LANG_GM_CHAT_OFF );
2010-11-09 10:15:35 -05:00
return true ;
}
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_USE_BOL );
handler -> SetSentErrorMessage ( true );
return false ;
}
2011-10-10 10:33:13 -03:00
static bool HandleGMFlyCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2011-06-30 14:24:56 +02:00
Player * target = handler -> getSelectedPlayer ();
2010-11-19 14:04:21 +01:00
if ( ! target )
target = handler -> GetSession () -> GetPlayer ();
2011-11-20 18:28:18 +01:00
WorldPacket data ;
2010-11-19 14:04:21 +01:00
if ( strncmp ( args , "on" , 3 ) == 0 )
2012-01-21 22:25:01 +01:00
target -> SendSetFlyPacket ( true );
2010-11-19 14:04:21 +01:00
else if ( strncmp ( args , "off" , 4 ) == 0 )
2012-01-21 22:25:01 +01:00
target -> SendSetFlyPacket ( false );
2010-11-19 14:04:21 +01:00
else
{
handler -> SendSysMessage ( LANG_USE_BOL );
return false ;
}
handler -> PSendSysMessage ( LANG_COMMAND_FLYMODE_STATUS , handler -> GetNameLink ( target ). c_str (), args );
return true ;
}
2011-10-10 10:33:13 -03:00
static bool HandleGMListIngameCommand ( ChatHandler * handler , char const * /*args*/ )
2010-11-19 14:04:21 +01:00
{
bool first = true ;
bool footer = false ;
2011-10-31 17:25:12 -04:00
TRINITY_READ_GUARD ( HashMapHolder < Player >:: LockType , * HashMapHolder < Player >:: GetLock ());
2011-10-21 17:29:09 -04:00
HashMapHolder < Player >:: MapType const & m = sObjectAccessor -> GetPlayers ();
2010-11-19 14:04:21 +01:00
for ( HashMapHolder < Player >:: MapType :: const_iterator itr = m . begin (); itr != m . end (); ++ itr )
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
AccountTypes itrSec = itr -> second -> GetSession () -> GetSecurity ();
if (( itr -> second -> isGameMaster () || ( ! AccountMgr :: IsPlayerAccount ( itrSec ) && itrSec <= AccountTypes ( sWorld -> getIntConfig ( CONFIG_GM_LEVEL_IN_GM_LIST )))) &&
2010-11-19 14:04:21 +01:00
( ! handler -> GetSession () || itr -> second -> IsVisibleGloballyFor ( handler -> GetSession () -> GetPlayer ())))
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
if ( first )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
first = false ;
footer = true ;
handler -> SendSysMessage ( LANG_GMS_ON_SRV );
handler -> SendSysMessage ( "========================" );
2010-11-09 10:15:35 -05:00
}
2011-10-10 10:33:13 -03:00
char const * name = itr -> second -> GetName ();
uint8 security = itrSec ;
2010-11-19 14:04:21 +01:00
uint8 max = (( 16 - strlen ( name )) / 2 );
uint8 max2 = max ;
2011-10-10 10:33:13 -03:00
if (( max + max2 + strlen ( name )) == 16 )
max2 = max - 1 ;
2010-11-19 14:04:21 +01:00
if ( handler -> GetSession ())
handler -> PSendSysMessage ( "| %s GMLevel %u" , name , security );
else
handler -> PSendSysMessage ( "|%*s%s%*s| %u |" , max , " " , name , max2 , " " , security );
2010-11-09 10:15:35 -05:00
}
}
2010-11-19 14:04:21 +01:00
if ( footer )
handler -> SendSysMessage ( "========================" );
if ( first )
handler -> SendSysMessage ( LANG_GMS_NOT_LOGGED );
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
/// Display the list of GMs
2011-10-10 10:33:13 -03:00
static bool HandleGMListFullCommand ( ChatHandler * handler , char const * /*args*/ )
2010-11-19 14:04:21 +01:00
{
///- Get the accounts with GM Level >0
2012-01-28 16:03:36 -05:00
QueryResult result = LoginDatabase . PQuery ( "SELECT a.username, aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel >= %u AND (aa.realmid = -1 OR aa.realmid = %u)" , SEC_MODERATOR , realmID );
2010-11-19 14:04:21 +01:00
if ( result )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_GMLIST );
handler -> SendSysMessage ( "========================" );
///- Cycle through them. Display username and GM level
do
2010-11-09 10:15:35 -05:00
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2011-10-10 10:33:13 -03:00
char const * name = fields [ 0 ]. GetCString ();
2010-11-19 14:04:21 +01:00
uint8 security = fields [ 1 ]. GetUInt8 ();
2011-10-10 10:33:13 -03:00
uint8 max = ( 16 - strlen ( name )) / 2 ;
2010-11-19 14:04:21 +01:00
uint8 max2 = max ;
2011-10-10 10:33:13 -03:00
if (( max + max2 + strlen ( name )) == 16 )
max2 = max - 1 ;
2010-11-19 14:04:21 +01:00
if ( handler -> GetSession ())
handler -> PSendSysMessage ( "| %s GMLevel %u" , name , security );
else
handler -> PSendSysMessage ( "|%*s%s%*s| %u |" , max , " " , name , max2 , " " , security );
2011-10-10 10:33:13 -03:00
} while ( result -> NextRow ());
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( "========================" );
}
else
handler -> PSendSysMessage ( LANG_GMLIST_EMPTY );
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//Enable\Disable Invisible mode
2011-10-10 10:33:13 -03:00
static bool HandleGMVisibleCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_YOU_ARE , handler -> GetSession () -> GetPlayer () -> isGMVisible () ? handler -> GetTrinityString ( LANG_VISIBLE ) : handler -> GetTrinityString ( LANG_INVISIBLE ));
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
std :: string param = ( char * ) args ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( param == "on" )
2010-11-19 14:04:21 +01:00
{
handler -> GetSession () -> GetPlayer () -> SetGMVisible ( true );
handler -> GetSession () -> SendNotification ( LANG_INVISIBLE_VISIBLE );
return true ;
2010-11-09 10:15:35 -05:00
}
2011-10-10 10:33:13 -03:00
if ( param == "off" )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> GetSession () -> SendNotification ( LANG_INVISIBLE_INVISIBLE );
handler -> GetSession () -> GetPlayer () -> SetGMVisible ( false );
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_USE_BOL );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//Enable\Disable GM Mode
2011-10-10 10:33:13 -03:00
static bool HandleGMCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
{
if ( handler -> GetSession () -> GetPlayer () -> isGameMaster ())
2010-11-09 10:15:35 -05:00
handler -> GetSession () -> SendNotification ( LANG_GM_ON );
2010-11-19 14:04:21 +01:00
else
2010-11-09 10:15:35 -05:00
handler -> GetSession () -> SendNotification ( LANG_GM_OFF );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
std :: string param = ( char * ) args ;
2010-11-19 14:04:21 +01:00
2011-10-10 10:33:13 -03:00
if ( param == "on" )
2010-11-19 14:04:21 +01:00
{
handler -> GetSession () -> GetPlayer () -> SetGameMaster ( true );
handler -> GetSession () -> SendNotification ( LANG_GM_ON );
handler -> GetSession () -> GetPlayer () -> UpdateTriggerVisibility ();
#ifdef _DEBUG_VMAPS
2011-09-15 14:08:17 +02:00
VMAP :: IVMapManager * vMapManager = VMAP :: VMapFactory :: createOrGetVMapManager ();
2010-11-19 14:04:21 +01:00
vMapManager -> processCommand ( "stoplog" );
#endif
return true ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
2011-10-10 10:33:13 -03:00
if ( param == "off" )
2010-11-19 14:04:21 +01:00
{
handler -> GetSession () -> GetPlayer () -> SetGameMaster ( false );
handler -> GetSession () -> SendNotification ( LANG_GM_OFF );
handler -> GetSession () -> GetPlayer () -> UpdateTriggerVisibility ();
#ifdef _DEBUG_VMAPS
2011-09-15 14:08:17 +02:00
VMAP :: IVMapManager * vMapManager = VMAP :: VMapFactory :: createOrGetVMapManager ();
2010-11-19 14:04:21 +01:00
vMapManager -> processCommand ( "startlog" );
#endif
return true ;
}
handler -> SendSysMessage ( LANG_USE_BOL );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
};
void AddSC_gm_commandscript ()
{
new gm_commandscript ();
}