2010-11-09 10:15:35 -05:00
/*
2012-12-31 23:15:50 +01:00
* Copyright (C) 2008-2013 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: account_commandscript
%Complete: 100
Comment: All account related commands
Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
2010-11-13 22:29:46 +01:00
#include "Chat.h"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2012-11-17 05:18:37 +01:00
#include "Player.h"
2012-11-20 12:30:30 +01:00
#include "ScriptMgr.h"
2010-11-09 10:15:35 -05:00
class account_commandscript : public CommandScript
{
2010-11-19 14:04:21 +01:00
public :
account_commandscript () : CommandScript ( "account_commandscript" ) { }
2010-11-09 10:15:35 -05:00
2013-07-06 20:21:45 +01:00
ChatCommand * GetCommands () const OVERRIDE
2010-11-19 14:04:21 +01:00
{
2013-07-25 01:49:04 +02:00
static ChatCommand accountSetSecTable [] =
{
2013-09-27 12:46:01 +02:00
{ "regmail" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET_SEC_REGMAIL , true , & HandleAccountSetRegEmailCommand , "" , NULL },
{ "email" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET_SEC_EMAIL , true , & HandleAccountSetEmailCommand , "" , NULL },
2013-07-25 01:49:04 +02:00
{ NULL , 0 , false , NULL , "" , NULL }
};
2010-11-19 14:04:21 +01:00
static ChatCommand accountSetCommandTable [] =
2010-11-09 10:15:35 -05:00
{
2013-09-27 12:46:01 +02:00
{ "addon" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET_ADDON , true , & HandleAccountSetAddonCommand , "" , NULL },
{ "sec" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET_SEC , true , NULL , "" , accountSetSecTable },
{ "gmlevel" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET_GMLEVEL , true , & HandleAccountSetGmLevelCommand , "" , NULL },
{ "password" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET_PASSWORD , true , & HandleAccountSetPasswordCommand , "" , NULL },
2013-07-25 01:49:04 +02:00
{ NULL , 0 , false , NULL , "" , NULL }
2010-11-19 14:04:21 +01:00
};
2013-04-15 14:56:00 +03:00
static ChatCommand accountLockCommandTable [] =
{
2013-09-27 12:46:01 +02:00
{ "country" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_LOCK_COUNTRY , true , & HandleAccountLockCountryCommand , "" , NULL },
{ "ip" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_LOCK_IP , true , & HandleAccountLockIpCommand , "" , NULL },
2013-07-25 01:49:04 +02:00
{ NULL , 0 , false , NULL , "" , NULL }
2013-04-15 14:56:00 +03:00
};
2010-11-19 14:04:21 +01:00
static ChatCommand accountCommandTable [] =
2010-11-09 10:15:35 -05:00
{
2013-09-27 12:46:01 +02:00
{ "addon" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_ADDON , false , & HandleAccountAddonCommand , "" , NULL },
{ "create" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_CREATE , true , & HandleAccountCreateCommand , "" , NULL },
{ "delete" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_DELETE , true , & HandleAccountDeleteCommand , "" , NULL },
{ "email" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_EMAIL , false , & HandleAccountEmailCommand , "" , NULL },
{ "onlinelist" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_ONLINE_LIST , true , & HandleAccountOnlineListCommand , "" , NULL },
{ "lock" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_LOCK , false , NULL , "" , accountLockCommandTable },
{ "set" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_SET , true , NULL , "" , accountSetCommandTable },
{ "password" , rbac :: RBAC_PERM_COMMAND_ACCOUNT_PASSWORD , false , & HandleAccountPasswordCommand , "" , NULL },
{ "" , rbac :: RBAC_PERM_COMMAND_ACCOUNT , false , & HandleAccountCommand , "" , NULL },
2013-07-25 01:49:04 +02:00
{ NULL , 0 , false , NULL , "" , NULL }
2010-11-19 14:04:21 +01:00
};
static ChatCommand commandTable [] =
{
2013-09-27 12:46:01 +02:00
{ "account" , rbac :: RBAC_PERM_COMMAND_ACCOUNT , true , NULL , "" , accountCommandTable },
2013-07-25 01:49:04 +02:00
{ NULL , 0 , false , NULL , "" , NULL }
2010-11-19 14:04:21 +01:00
};
return commandTable ;
}
2011-10-10 10:33:13 -03:00
static bool HandleAccountAddonCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
char * exp = strtok (( char * ) args , " " );
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
uint32 accountId = handler -> GetSession () -> GetAccountId ();
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
int expansion = atoi ( exp ); //get int anyway (0 if error)
2010-12-23 23:25:44 +01:00
if ( expansion < 0 || uint8 ( expansion ) > sWorld -> getIntConfig ( CONFIG_EXPANSION ))
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_IMPROPER_VALUE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2011-12-31 20:14:38 +01:00
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_UPD_EXPANSION );
2011-12-25 18:12:58 +01:00
stmt -> setUInt8 ( 0 , uint8 ( expansion ));
stmt -> setUInt32 ( 1 , accountId );
LoginDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_ACCOUNT_ADDON , expansion );
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
/// Create an account
2011-10-10 10:33:13 -03:00
static bool HandleAccountCreateCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2013-09-02 16:18:55 +01:00
std :: string email ;
2013-07-25 01:49:04 +02:00
2010-11-19 14:04:21 +01:00
///- %Parse the command line arguments
2011-10-10 10:33:13 -03:00
char * accountName = strtok (( char * ) args , " " );
char * password = strtok ( NULL , " " );
2013-09-02 16:18:55 +01:00
char * possibleEmail = strtok ( NULL , " ' " );
if ( possibleEmail )
email = possibleEmail ;
2013-07-25 01:49:04 +02:00
2011-10-10 10:33:13 -03:00
if ( ! accountName || ! password )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2013-09-02 16:18:55 +01:00
AccountOpResult result = sAccountMgr -> CreateAccount ( std :: string ( accountName ), std :: string ( password ), email );
2011-09-29 12:43:05 +02:00
switch ( result )
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
case AOR_OK :
handler -> PSendSysMessage ( LANG_ACCOUNT_CREATED , accountName );
2012-01-06 17:49:15 +01:00
if ( handler -> GetSession ())
2012-08-03 14:20:18 +02:00
{
2013-07-25 01:49:04 +02:00
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %d (IP: %s) Character:[%s] (GUID: %u) created Account %s (Email: '%s')" ,
2012-10-24 13:29:34 +02:00
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
2013-07-25 01:49:04 +02:00
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow (),
2013-09-02 16:18:55 +01:00
accountName , email . c_str ());
2012-08-03 14:20:18 +02:00
}
2011-10-10 10:33:13 -03:00
break ;
case AOR_NAME_TOO_LONG :
handler -> SendSysMessage ( LANG_ACCOUNT_TOO_LONG );
handler -> SetSentErrorMessage ( true );
return false ;
2013-07-25 01:49:04 +02:00
case AOR_NAME_ALREADY_EXIST :
2011-10-10 10:33:13 -03:00
handler -> SendSysMessage ( LANG_ACCOUNT_ALREADY_EXIST );
handler -> SetSentErrorMessage ( true );
return false ;
case AOR_DB_INTERNAL_ERROR :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_CREATED_SQL_ERROR , accountName );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_CREATED , accountName );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
/// Delete a user account and all associated characters in this realm
2013-03-08 21:41:30 +01:00
/// @todo This function has to be enhanced to respect the login/realm split (delete char, delete account chars in realm then delete account)
2011-10-10 10:33:13 -03:00
static bool HandleAccountDeleteCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
///- Get the account name from the command line
2011-10-10 10:33:13 -03:00
char * account = strtok (( char * ) args , " " );
if ( ! account )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
std :: string accountName = account ;
if ( ! AccountMgr :: normalizeString ( accountName ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
uint32 accountId = AccountMgr :: GetId ( accountName );
if ( ! accountId )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
/// Commands not recommended call from chat, but support anyway
/// can delete only for account with less security
/// This is also reject self apply in fact
2011-10-10 10:33:13 -03:00
if ( handler -> HasLowerSecurityAccount ( NULL , accountId , true ))
2010-11-19 14:04:21 +01:00
return false ;
2011-10-10 10:33:13 -03:00
AccountOpResult result = AccountMgr :: DeleteAccount ( accountId );
2011-09-29 12:43:05 +02:00
switch ( result )
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
case AOR_OK :
handler -> PSendSysMessage ( LANG_ACCOUNT_DELETED , accountName . c_str ());
break ;
case AOR_NAME_NOT_EXIST :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
case AOR_DB_INTERNAL_ERROR :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_DELETED_SQL_ERROR , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_DELETED , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
/// Display info on users currently in the realm
2011-10-10 10:33:13 -03:00
static bool HandleAccountOnlineListCommand ( ChatHandler * handler , char const * /*args*/ )
2010-11-19 14:04:21 +01:00
{
///- Get the list of accounts ID logged to the realm
2012-03-24 01:25:08 +01:00
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_CHARACTER_ONLINE );
PreparedQueryResult result = CharacterDatabase . Query ( stmt );
if ( ! result )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_ACCOUNT_LIST_EMPTY );
2010-11-09 10:15:35 -05:00
return true ;
}
2010-11-19 14:04:21 +01:00
///- Display the list of account/characters online
handler -> SendSysMessage ( LANG_ACCOUNT_LIST_BAR_HEADER );
handler -> SendSysMessage ( LANG_ACCOUNT_LIST_HEADER );
handler -> SendSysMessage ( LANG_ACCOUNT_LIST_BAR );
///- Cycle through accounts
do
2010-11-09 10:15:35 -05:00
{
2012-03-24 01:25:08 +01:00
Field * fieldsDB = result -> Fetch ();
2010-11-19 14:04:21 +01:00
std :: string name = fieldsDB [ 0 ]. GetString ();
uint32 account = fieldsDB [ 1 ]. GetUInt32 ();
///- Get the username, last IP and GM level of each account
// No SQL injection. account is uint32.
2012-03-24 01:25:08 +01:00
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_ACCOUNT_INFO );
stmt -> setUInt32 ( 0 , account );
PreparedQueryResult resultLogin = LoginDatabase . Query ( stmt );
2011-10-10 10:33:13 -03:00
2010-11-19 14:04:21 +01:00
if ( resultLogin )
2010-11-09 10:15:35 -05:00
{
2011-09-15 14:08:17 +02:00
Field * fieldsLogin = resultLogin -> Fetch ();
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_ACCOUNT_LIST_LINE ,
2011-09-13 14:15:35 +02:00
fieldsLogin [ 0 ]. GetCString (), name . c_str (), fieldsLogin [ 1 ]. GetCString (),
2012-03-24 23:05:00 +00:00
fieldsDB [ 2 ]. GetUInt16 (), fieldsDB [ 3 ]. GetUInt16 (), fieldsLogin [ 3 ]. GetUInt8 (),
fieldsLogin [ 2 ]. GetUInt8 ());
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
else
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_ACCOUNT_LIST_ERROR , name . c_str ());
2012-08-03 14:20:18 +02:00
}
while ( result -> NextRow ());
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_ACCOUNT_LIST_BAR );
return true ;
}
2010-11-09 10:15:35 -05:00
2013-04-15 14:56:00 +03:00
static bool HandleAccountLockCountryCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
{
handler -> SendSysMessage ( LANG_USE_BOL );
handler -> SetSentErrorMessage ( true );
return false ;
}
std :: string param = ( char * ) args ;
if ( ! param . empty ())
{
if ( param == "on" )
{
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_LOGON_COUNTRY );
uint32 ip = inet_addr ( handler -> GetSession () -> GetRemoteAddress (). c_str ());
EndianConvertReverse ( ip );
stmt -> setUInt32 ( 0 , ip );
PreparedQueryResult result = LoginDatabase . Query ( stmt );
if ( result )
{
Field * fields = result -> Fetch ();
std :: string country = fields [ 0 ]. GetString ();
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_UPD_ACCOUNT_LOCK_CONTRY );
stmt -> setString ( 0 , country );
stmt -> setUInt32 ( 1 , handler -> GetSession () -> GetAccountId ());
LoginDatabase . Execute ( stmt );
handler -> PSendSysMessage ( LANG_COMMAND_ACCLOCKLOCKED );
}
else
{
handler -> PSendSysMessage ( "[IP2NATION] Table empty" );
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_AUTHSERVER , "[IP2NATION] Table empty" );
2013-04-15 14:56:00 +03:00
}
}
else if ( param == "off" )
{
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_UPD_ACCOUNT_LOCK_CONTRY );
stmt -> setString ( 0 , "00" );
stmt -> setUInt32 ( 1 , handler -> GetSession () -> GetAccountId ());
LoginDatabase . Execute ( stmt );
handler -> PSendSysMessage ( LANG_COMMAND_ACCLOCKUNLOCKED );
}
return true ;
}
handler -> SendSysMessage ( LANG_USE_BOL );
handler -> SetSentErrorMessage ( true );
return false ;
}
static bool HandleAccountLockIpCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
{
2010-11-09 10:15:35 -05:00
handler -> SendSysMessage ( LANG_USE_BOL );
handler -> SetSentErrorMessage ( true );
return false ;
}
2011-10-10 10:33:13 -03:00
std :: string param = ( char * ) args ;
2010-11-09 10:15:35 -05:00
2011-12-25 18:12:58 +01:00
if ( ! param . empty ())
2010-11-19 14:04:21 +01:00
{
2011-12-31 20:14:38 +01:00
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_UPD_ACCOUNT_LOCK );
2011-12-25 18:12:58 +01:00
if ( param == "on" )
{
stmt -> setBool ( 0 , true ); // locked
handler -> PSendSysMessage ( LANG_COMMAND_ACCLOCKLOCKED );
}
else if ( param == "off" )
{
stmt -> setBool ( 0 , false ); // unlocked
handler -> PSendSysMessage ( LANG_COMMAND_ACCLOCKUNLOCKED );
}
stmt -> setUInt32 ( 1 , handler -> GetSession () -> GetAccountId ());
LoginDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
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
2013-07-25 01:49:04 +02:00
static bool HandleAccountEmailCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
2013-09-11 20:54:04 +02:00
char * oldEmail = strtok (( char * ) args , " " );
2013-07-25 01:49:04 +02:00
char * password = strtok ( NULL , " " );
2013-09-11 20:54:04 +02:00
char * email = strtok ( NULL , " " );
2013-07-25 01:49:04 +02:00
char * emailConfirmation = strtok ( NULL , " " );
if ( ! oldEmail || ! password || ! email || ! emailConfirmation )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( ! AccountMgr :: CheckEmail ( handler -> GetSession () -> GetAccountId (), std :: string ( oldEmail )))
{
handler -> SendSysMessage ( LANG_COMMAND_WRONGEMAIL );
handler -> SetSentErrorMessage ( true );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change email, but the provided email [%s] is not equal to registration email [%s]." ,
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow (),
email , oldEmail );
return false ;
}
if ( ! AccountMgr :: CheckPassword ( handler -> GetSession () -> GetAccountId (), std :: string ( password )))
{
handler -> SendSysMessage ( LANG_COMMAND_WRONGOLDPASSWORD );
handler -> SetSentErrorMessage ( true );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change email, but the provided password is wrong." ,
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow ());
return false ;
}
if ( strcmp ( email , oldEmail ) == 0 )
{
handler -> SendSysMessage ( LANG_OLD_EMAIL_IS_NEW_EMAIL );
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( strcmp ( email , emailConfirmation ) != 0 )
{
handler -> SendSysMessage ( LANG_NEW_EMAILS_NOT_MATCH );
handler -> SetSentErrorMessage ( true );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change email, but the provided password is wrong." ,
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow ());
return false ;
}
AccountOpResult result = AccountMgr :: ChangeEmail ( handler -> GetSession () -> GetAccountId (), std :: string ( email ));
switch ( result )
{
case AOR_OK :
handler -> SendSysMessage ( LANG_COMMAND_EMAIL );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Changed Email from [%s] to [%s]." ,
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow (),
oldEmail , email );
break ;
case AOR_EMAIL_TOO_LONG :
handler -> SendSysMessage ( LANG_EMAIL_TOO_LONG );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> SendSysMessage ( LANG_COMMAND_NOTCHANGEEMAIL );
handler -> SetSentErrorMessage ( true );
return false ;
}
return true ;
}
2011-10-10 10:33:13 -03:00
static bool HandleAccountPasswordCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
2013-09-12 16:39:41 +02:00
// If no args are given at all, we can return false right away.
2010-11-19 14:04:21 +01:00
if ( !* args )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2013-09-12 16:39:41 +02:00
// First, we check config. What security type (sec type) is it ? Depending on it, the command branches out
2013-07-25 01:49:04 +02:00
uint32 pwConfig = sWorld -> getIntConfig ( CONFIG_ACC_PASSCHANGESEC ); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
2013-09-12 16:39:41 +02:00
// Command is supposed to be: .account password [$oldpassword] [$newpassword] [$newpasswordconfirmation] [$emailconfirmation]
2013-10-03 17:07:25 +02:00
char * oldPassword = strtok (( char * ) args , " " ); // This extracts [$oldpassword]
char * newPassword = strtok ( NULL , " " ); // This extracts [$newpassword]
char * passwordConfirmation = strtok ( NULL , " " ); // This extracts [$newpasswordconfirmation]
char const * emailConfirmation = strtok ( NULL , " " ); // This defines the emailConfirmation variable, which is optional depending on sec type.
if ( ! emailConfirmation ) // This extracts [$emailconfirmation]. If it doesn't exist, however...
emailConfirmation = "" ; // ... it's simply "" for emailConfirmation.
2010-11-09 10:15:35 -05:00
2013-09-12 16:39:41 +02:00
//Is any of those variables missing for any reason ? We return false.
2011-10-10 10:33:13 -03:00
if ( ! oldPassword || ! newPassword || ! passwordConfirmation )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2013-09-12 16:39:41 +02:00
// We compare the old, saved password to the entered old password - no chance for the unauthorized.
2011-10-10 10:33:13 -03:00
if ( ! AccountMgr :: CheckPassword ( handler -> GetSession () -> GetAccountId (), std :: string ( oldPassword )))
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_COMMAND_WRONGOLDPASSWORD );
handler -> SetSentErrorMessage ( true );
2013-07-25 01:49:04 +02:00
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change password, but the provided old password is wrong." ,
2012-12-18 01:57:04 +01:00
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow ());
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
}
2013-09-12 16:39:41 +02:00
// This compares the old, current email to the entered email - however, only...
2013-09-27 12:46:01 +02:00
if (( pwConfig == PW_EMAIL || ( pwConfig == PW_RBAC && handler -> HasPermission ( rbac :: RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE ))) // ...if either PW_EMAIL or PW_RBAC with the Permission is active...
2013-09-12 16:39:41 +02:00
&& ! AccountMgr :: CheckEmail ( handler -> GetSession () -> GetAccountId (), std :: string ( emailConfirmation ))) // ... and returns false if the comparison fails.
2013-07-25 01:49:04 +02:00
{
handler -> SendSysMessage ( LANG_COMMAND_WRONGEMAIL );
handler -> SetSentErrorMessage ( true );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change password, but the entered email [%s] is wrong." ,
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow (),
emailConfirmation );
2013-09-11 20:54:04 +02:00
return false ;
2013-07-25 01:49:04 +02:00
}
2013-09-12 16:39:41 +02:00
// Making sure that newly entered password is correctly entered.
2011-10-10 10:33:13 -03:00
if ( strcmp ( newPassword , passwordConfirmation ) != 0 )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_NEW_PASSWORDS_NOT_MATCH );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2013-09-12 16:39:41 +02:00
// Changes password and prints result.
2011-10-10 10:33:13 -03:00
AccountOpResult result = AccountMgr :: ChangePassword ( handler -> GetSession () -> GetAccountId (), std :: string ( newPassword ));
2011-09-29 12:43:05 +02:00
switch ( result )
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
case AOR_OK :
handler -> SendSysMessage ( LANG_COMMAND_PASSWORD );
2013-05-13 15:07:36 +02:00
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "Account: %u (IP: %s) Character:[%s] (GUID: %u) Changed Password." ,
2012-12-18 01:57:04 +01:00
handler -> GetSession () -> GetAccountId (), handler -> GetSession () -> GetRemoteAddress (). c_str (),
handler -> GetSession () -> GetPlayer () -> GetName (). c_str (), handler -> GetSession () -> GetPlayer () -> GetGUIDLow ());
2011-10-10 10:33:13 -03:00
break ;
case AOR_PASS_TOO_LONG :
handler -> SendSysMessage ( LANG_PASSWORD_TOO_LONG );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> SendSysMessage ( LANG_COMMAND_NOTCHANGEPASSWORD );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
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
static bool HandleAccountCommand ( ChatHandler * handler , char const * /*args*/ )
2010-11-19 14:04:21 +01:00
{
2013-07-25 01:49:04 +02:00
// GM Level
2011-10-10 10:33:13 -03:00
AccountTypes gmLevel = handler -> GetSession () -> GetSecurity ();
handler -> PSendSysMessage ( LANG_ACCOUNT_LEVEL , uint32 ( gmLevel ));
2013-07-25 01:49:04 +02:00
// Security level required
2013-09-27 12:46:01 +02:00
bool hasRBAC = ( handler -> HasPermission ( rbac :: RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE ) ? true : false );
2013-07-25 01:49:04 +02:00
uint32 pwConfig = sWorld -> getIntConfig ( CONFIG_ACC_PASSCHANGESEC ); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
handler -> PSendSysMessage ( LANG_ACCOUNT_SEC_TYPE , ( pwConfig == PW_NONE ? "Lowest level: No Email input required." :
pwConfig == PW_EMAIL ? "Highest level: Email input required." :
pwConfig == PW_RBAC ? "Special level: Your account may require email input depending on settings. That is the case if another lien is printed." :
"Unknown security level: Notify technician for details." ));
// RBAC required display - is not displayed for console
if ( pwConfig == PW_RBAC && handler -> GetSession () && hasRBAC )
handler -> PSendSysMessage ( LANG_RBAC_EMAIL_REQUIRED );
// Email display if sufficient rights
2013-09-27 12:46:01 +02:00
if ( handler -> HasPermission ( rbac :: RBAC_PERM_MAY_CHECK_OWN_EMAIL ))
2013-07-25 01:49:04 +02:00
{
std :: string emailoutput ;
uint32 accountId = handler -> GetSession () -> GetAccountId ();
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_GET_EMAIL_BY_ID );
stmt -> setUInt32 ( 0 , accountId );
PreparedQueryResult result = LoginDatabase . Query ( stmt );
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
if ( result )
{
emailoutput = ( * result )[ 0 ]. GetString ();
handler -> PSendSysMessage ( LANG_COMMAND_EMAIL_OUTPUT , emailoutput . c_str ());
}
}
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
/// Set/Unset the expansion level for an account
2011-10-10 10:33:13 -03:00
static bool HandleAccountSetAddonCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
///- Get the command line arguments
2011-10-10 10:33:13 -03:00
char * account = strtok (( char * ) args , " " );
char * exp = strtok ( NULL , " " );
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( ! account )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
std :: string accountName ;
uint32 accountId ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( ! exp )
2010-11-19 14:04:21 +01:00
{
Player * player = handler -> getSelectedPlayer ();
if ( ! player )
2010-11-09 10:15:35 -05:00
return false ;
2011-10-10 10:33:13 -03:00
accountId = player -> GetSession () -> GetAccountId ();
AccountMgr :: GetName ( accountId , accountName );
exp = account ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
else
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
///- Convert Account name to Upper Format
2011-10-10 10:33:13 -03:00
accountName = account ;
if ( ! AccountMgr :: normalizeString ( accountName ))
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
2010-11-09 10:15:35 -05:00
return false ;
}
2011-10-10 10:33:13 -03:00
accountId = AccountMgr :: GetId ( accountName );
if ( ! accountId )
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
2010-11-09 10:15:35 -05:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Let set addon state only for lesser (strong) security level
// or to self account
2012-03-16 19:40:57 +08:00
if ( handler -> GetSession () && handler -> GetSession () -> GetAccountId () != accountId &&
2011-10-10 10:33:13 -03:00
handler -> HasLowerSecurityAccount ( NULL , accountId , true ))
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
int expansion = atoi ( exp ); //get int anyway (0 if error)
2010-12-23 23:25:44 +01:00
if ( expansion < 0 || uint8 ( expansion ) > sWorld -> getIntConfig ( CONFIG_EXPANSION ))
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-12-31 20:14:38 +01:00
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_UPD_EXPANSION );
2011-12-31 00:32:05 +01:00
stmt -> setUInt8 ( 0 , expansion );
stmt -> setUInt32 ( 1 , accountId );
LoginDatabase . Execute ( stmt );
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_SETADDON , accountName . c_str (), accountId , expansion );
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
static bool HandleAccountSetGmLevelCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
2013-07-25 01:49:04 +02:00
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
2010-11-19 14:04:21 +01:00
return false ;
2013-07-25 01:49:04 +02:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
std :: string targetAccountName ;
uint32 targetAccountId = 0 ;
uint32 targetSecurity = 0 ;
uint32 gm = 0 ;
char * arg1 = strtok (( char * ) args , " " );
char * arg2 = strtok ( NULL , " " );
char * arg3 = strtok ( NULL , " " );
bool isAccountNameGiven = true ;
2010-11-09 10:15:35 -05:00
2013-05-17 21:11:18 -05:00
if ( ! arg3 )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
if ( ! handler -> getSelectedPlayer ())
2010-11-09 10:15:35 -05:00
return false ;
2010-11-19 14:04:21 +01:00
isAccountNameGiven = false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Check for second parameter
if ( ! isAccountNameGiven && ! arg2 )
return false ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Check for account
if ( isAccountNameGiven )
{
targetAccountName = arg1 ;
if ( ! AccountMgr :: normalizeString ( targetAccountName ))
2010-11-09 10:15:35 -05:00
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , targetAccountName . c_str ());
2010-11-09 10:15:35 -05:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-19 14:04:21 +01:00
}
// Check for invalid specified GM level.
gm = ( isAccountNameGiven ) ? atoi ( arg2 ) : atoi ( arg1 );
if ( gm > SEC_CONSOLE )
{
handler -> SendSysMessage ( LANG_BAD_VALUE );
handler -> SetSentErrorMessage ( true );
return false ;
}
// handler->getSession() == NULL only for console
2011-09-08 10:49:58 +02:00
targetAccountId = ( isAccountNameGiven ) ? AccountMgr :: GetId ( targetAccountName ) : handler -> getSelectedPlayer () -> GetSession () -> GetAccountId ();
2010-11-19 14:04:21 +01:00
int32 gmRealmID = ( isAccountNameGiven ) ? atoi ( arg3 ) : atoi ( arg2 );
2011-10-10 10:33:13 -03:00
uint32 playerSecurity ;
2010-11-19 14:04:21 +01:00
if ( handler -> GetSession ())
2011-10-10 10:33:13 -03:00
playerSecurity = AccountMgr :: GetSecurity ( handler -> GetSession () -> GetAccountId (), gmRealmID );
2010-11-19 14:04:21 +01:00
else
2011-10-10 10:33:13 -03:00
playerSecurity = SEC_CONSOLE ;
2010-11-19 14:04:21 +01:00
// can set security level only for target with less security and to less security that we have
2013-07-25 01:49:04 +02:00
// This also restricts setting handler's own security.
2011-09-08 10:49:58 +02:00
targetSecurity = AccountMgr :: GetSecurity ( targetAccountId , gmRealmID );
2011-10-10 10:33:13 -03:00
if ( targetSecurity >= playerSecurity || gm >= playerSecurity )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_YOURS_SECURITY_IS_LOW );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
2011-10-10 10:33:13 -03:00
if ( gmRealmID == - 1 && ! AccountMgr :: IsConsoleAccount ( playerSecurity ))
2010-11-19 14:04:21 +01:00
{
2012-03-24 01:25:08 +01:00
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST );
stmt -> setUInt32 ( 0 , targetAccountId );
stmt -> setUInt8 ( 1 , uint8 ( gm ));
PreparedQueryResult result = LoginDatabase . Query ( stmt );
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_YOURS_SECURITY_IS_LOW );
2010-11-09 10:15:35 -05:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Check if provided realmID has a negative value other than -1
if ( gmRealmID < - 1 )
{
handler -> SendSysMessage ( LANG_INVALID_REALMID );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2013-09-27 12:46:01 +02:00
rbac :: RBACData * rbac = isAccountNameGiven ? NULL : handler -> getSelectedPlayer () -> GetSession () -> GetRBACData ();
2013-02-04 08:21:25 +01:00
sAccountMgr -> UpdateAccountAccess ( rbac , targetAccountId , uint8 ( gm ), gmRealmID );
2011-10-10 10:33:13 -03:00
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_YOU_CHANGE_SECURITY , targetAccountName . c_str (), gm );
return true ;
}
/// Set password for account
2011-10-10 10:33:13 -03:00
static bool HandleAccountSetPasswordCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
2013-07-25 01:49:04 +02:00
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
2010-11-19 14:04:21 +01:00
return false ;
2013-07-25 01:49:04 +02:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
///- Get the command line arguments
2011-10-10 10:33:13 -03:00
char * account = strtok (( char * ) args , " " );
2012-08-03 14:20:18 +02:00
char * password = strtok ( NULL , " " );
char * passwordConfirmation = strtok ( NULL , " " );
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( ! account || ! password || ! passwordConfirmation )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
std :: string accountName = account ;
if ( ! AccountMgr :: normalizeString ( accountName ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2011-10-10 10:33:13 -03:00
uint32 targetAccountId = AccountMgr :: GetId ( accountName );
2010-11-19 14:04:21 +01:00
if ( ! targetAccountId )
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
/// can set password only for target with less security
2013-07-25 01:49:04 +02:00
/// This also restricts setting handler's own password
2011-10-10 10:33:13 -03:00
if ( handler -> HasLowerSecurityAccount ( NULL , targetAccountId , true ))
2010-11-19 14:04:21 +01:00
return false ;
2011-10-10 10:33:13 -03:00
if ( strcmp ( password , passwordConfirmation ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> SendSysMessage ( LANG_NEW_PASSWORDS_NOT_MATCH );
handler -> SetSentErrorMessage ( true );
2010-11-19 14:04:21 +01:00
return false ;
}
2011-10-10 10:33:13 -03:00
AccountOpResult result = AccountMgr :: ChangePassword ( targetAccountId , password );
2010-11-19 14:04:21 +01:00
switch ( result )
{
2011-10-10 10:33:13 -03:00
case AOR_OK :
handler -> SendSysMessage ( LANG_COMMAND_PASSWORD );
break ;
case AOR_NAME_NOT_EXIST :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
case AOR_PASS_TOO_LONG :
handler -> SendSysMessage ( LANG_PASSWORD_TOO_LONG );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> SendSysMessage ( LANG_COMMAND_NOTCHANGEPASSWORD );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
return true ;
}
2013-07-25 01:49:04 +02:00
/// Set normal email for account
static bool HandleAccountSetEmailCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
///- Get the command line arguments
char * account = strtok (( char * ) args , " " );
char * email = strtok ( NULL , " " );
char * emailConfirmation = strtok ( NULL , " " );
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
if ( ! account || ! email || ! emailConfirmation )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
std :: string accountName = account ;
if ( ! AccountMgr :: normalizeString ( accountName ))
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
uint32 targetAccountId = AccountMgr :: GetId ( accountName );
if ( ! targetAccountId )
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
/// can set email only for target with less security
/// This also restricts setting handler's own email.
if ( handler -> HasLowerSecurityAccount ( NULL , targetAccountId , true ))
return false ;
2013-09-02 16:18:55 +01:00
2013-07-25 01:49:04 +02:00
if ( strcmp ( email , emailConfirmation ) != 0 )
{
handler -> SendSysMessage ( LANG_NEW_EMAILS_NOT_MATCH );
handler -> SetSentErrorMessage ( true );
return false ;
}
AccountOpResult result = AccountMgr :: ChangeEmail ( targetAccountId , email );
switch ( result )
{
case AOR_OK :
handler -> SendSysMessage ( LANG_COMMAND_EMAIL );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "ChangeEmail: Account %s [Id: %u] had it's email changed to %s." ,
accountName . c_str (), targetAccountId , email );
break ;
case AOR_NAME_NOT_EXIST :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
case AOR_EMAIL_TOO_LONG :
handler -> SendSysMessage ( LANG_EMAIL_TOO_LONG );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> SendSysMessage ( LANG_COMMAND_NOTCHANGEEMAIL );
handler -> SetSentErrorMessage ( true );
return false ;
}
return true ;
}
/// Change registration email for account
static bool HandleAccountSetRegEmailCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
//- We do not want anything short of console to use this by default.
//- So we force that.
if ( handler -> GetSession ())
return false ;
///- Get the command line arguments
char * account = strtok (( char * ) args , " " );
char * email = strtok ( NULL , " " );
char * emailConfirmation = strtok ( NULL , " " );
if ( ! account || ! email || ! emailConfirmation )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
std :: string accountName = account ;
if ( ! AccountMgr :: normalizeString ( accountName ))
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
uint32 targetAccountId = AccountMgr :: GetId ( accountName );
if ( ! targetAccountId )
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
/// can set email only for target with less security
/// This also restricts setting handler's own email.
if ( handler -> HasLowerSecurityAccount ( NULL , targetAccountId , true ))
return false ;
if ( strcmp ( email , emailConfirmation ) != 0 )
{
handler -> SendSysMessage ( LANG_NEW_EMAILS_NOT_MATCH );
handler -> SetSentErrorMessage ( true );
return false ;
}
AccountOpResult result = AccountMgr :: ChangeRegEmail ( targetAccountId , email );
switch ( result )
{
case AOR_OK :
handler -> SendSysMessage ( LANG_COMMAND_EMAIL );
TC_LOG_INFO ( LOG_FILTER_CHARACTER , "ChangeRegEmail: Account %s [Id: %u] had it's Registration Email changed to %s." ,
accountName . c_str (), targetAccountId , email );
break ;
case AOR_NAME_NOT_EXIST :
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
case AOR_EMAIL_TOO_LONG :
handler -> SendSysMessage ( LANG_EMAIL_TOO_LONG );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> SendSysMessage ( LANG_COMMAND_NOTCHANGEEMAIL );
handler -> SetSentErrorMessage ( true );
return false ;
}
return true ;
}
2010-11-09 10:15:35 -05:00
};
void AddSC_account_commandscript ()
{
new account_commandscript ();
}