How i can change account command

Hello! I wish I could change the command .account Set gmlevel 2 -1 for by GM for a specified time.

Example: .account set gmlevel 2 -1 30d

Where 30d would be 30 days and thus gradually, primarily as the ban command works, is there any possibility of this being done?

Why do I have interest in being able to stipulate GM’s for a test period.

You can create a new command or change the existing one at https://github.com/TrinityCore/TrinityCore/blob/3.3.5/src/server/scripts/Commands/cs_account.cpp#L637

— Canned message start —
This thread is not related to the official Trinity codebase and was moved to the Custom Code section.
Please read the stickies next time.
— Canned message end —

someone help me with this change in command?

create new row with timestamp 30d alter and check if its in the past

I created two columns in account_access table as shown below building on the account_banned table, but not know what it change in c ++ all try went wrong

http://i.imgur.com/QIbHQdU.png

    static bool HandleAccountSetGmLevelCommand(ChatHandler* handler, char const* args)
    {
        if (!*args)
        {
            handler->SendSysMessage(LANG_CMD_SYNTAX);
            handler->SetSentErrorMessage(true);
            return false;
        }

        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;

        if (!arg3)
        {
            if (!handler->getSelectedPlayer())
                return false;
            isAccountNameGiven = false;
        }

        // Check for second parameter
        if (!isAccountNameGiven && !arg2)
            return false;

        // Check for account
        if (isAccountNameGiven)
        {
            targetAccountName = arg1;
            if (!Utf8ToUpperOnlyLatin(targetAccountName))
            {
                handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName.c_str());
                handler->SetSentErrorMessage(true);
                return false;
            }
        }

        // 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
        targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
        int32 gmRealmID = (isAccountNameGiven) ? atoi(arg3) : atoi(arg2);
        uint32 playerSecurity;
        if (handler->GetSession())
            playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
        else
            playerSecurity = SEC_CONSOLE;

        // can set security level only for target with less security and to less security that we have
        // This also restricts setting handler's own security.
        targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
        if (targetSecurity >= playerSecurity || gm >= playerSecurity)
        {
            handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
            handler->SetSentErrorMessage(true);
            return false;
        }

        // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
        if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
        {
            PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST);

            stmt->setUInt32(0, targetAccountId);
            stmt->setUInt8(1, uint8(gm));

            PreparedQueryResult result = LoginDatabase.Query(stmt);

            if (result)
            {
                handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
                handler->SetSentErrorMessage(true);
                return false;
            }
        }

        // Check if provided realmID has a negative value other than -1
        if (gmRealmID < -1)
        {
            handler->SendSysMessage(LANG_INVALID_REALMID);
            handler->SetSentErrorMessage(true);
            return false;
        }

        rbac::RBACData* rbac = isAccountNameGiven ? NULL : handler->getSelectedPlayer()->GetSession()->GetRBACData();
        sAccountMgr->UpdateAccountAccess(rbac, targetAccountId, uint8(gm), gmRealmID);

        handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
        return true;
    }

Someone can help me?

For the gmIn column, when you create her just set :

datetype = timestamp and default value = CURRENT_TIMESTAMP, with nothing in length.

When the new row will be created, that will get the date and the hour.

For gmOut, look down.

And after, you’ll need to check if gmOut isn’t in the past, on login for example.

If it’s past , set gmlevel to 0.

So, i’ve done some research for gmOut, maybe that would work :

In accountMgr.h :

modify the UpdateAccountAccess prototype to get a new argument and create a new prototype for the timestamp :

void UpdateAccountAccess(rbac::RBACData* rbac, uint32 accountId, uint8 securityLevel, int32 realmId, std::string gmOut);

std::string GetGmOut(char* arg4);

In accountMgr.cpp :

Modify the function UpdateAccountAccess and create the function GetGmOut :

void AccountMgr::UpdateAccountAccess(rbac::RBACData* rbac, uint32 accountId, uint8 securityLevel, int32 realmId, std::string gmOut)
{
if (rbac && securityLevel == rbac->GetSecurityLevel())
rbac->SetSecurityLevel(securityLevel);

// Delete old security level from DB
if (realmId == -1)
{
    PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
    stmt->setUInt32(0, accountId);
    LoginDatabase.Execute(stmt);
}
else
{
    PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
    stmt->setUInt32(0, accountId);
    stmt->setUInt32(1, realmId);
    LoginDatabase.Execute(stmt);
}

// Add new security level
if (securityLevel)
{
    PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
    stmt->setUInt32(0, accountId);
    stmt->setUInt8(1, securityLevel);
    stmt->setInt32(2, realmId);
stmt->setString(4, gmOut);
    LoginDatabase.Execute(stmt);
}

}

std::string AccountMgr::GetGmOut(char* arg4)
{
//Transforming the days in second
*arg4 = *arg4 * 86400;

time_t t = time(NULL);

//Adding second to the actual timestamp
t += *arg4;
struct tm *tm = localtime(&t);
char date[32];
//Getting the correct form
strftime(date, sizeof(date), “%Y-%m-%d %H:%M:%S”, tm);

//Transforming the char* date into a string
std::string gmOut = std::string(date);

return(gmOut);

}

And in cs_account.cpp :

add a new argument for the command, and create the gmOut variable :

char* arg1 = strtok((char*)args, " ");
char* arg2 = strtok(NULL, " ");
char* arg3 = strtok(NULL, " ");
char* arg4 = strtok(NULL, " ");
bool isAccountNameGiven = true;
std::string gmOut;

Call the function getGmOut and modify the command :

sAccountMgr->GetGmOut(arg4);

rbac::RBACData* rbac = isAccountNameGiven ? NULL : handler->getSelectedPlayer()->GetSession()->GetRBACData();
sAccountMgr->UpdateAccountAccess(rbac, targetAccountId, uint8(gm), gmRealmID, gmOut);
handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm, gmOut);
return true;

Ps : I don’t have experience in c++, so maybe that it’s false.

There isn’t any errors on building, but i dont have try to run wordlserver or test the command.

Nice i will test and report thx.

Any feedback ?