Toggle Command Script

Hey, I’ve been trying to implement a system of .toggle commands that would prevent players from using certain commands (.modify, .summon, .learn etc.) on other players if said toggles were off. The command script itself can be viewed here.

In order for these commands to work, I put in checks within the commands I wanted to be unusable when the toggle was disabled. For example, if I wanted players to be unable to use .summon when .toggle summon was off, I’d put:

if (!target->GetCommandStatus(TOGGLE_SUMMON) && !_player->IsAdmin())
{
handler->PSendSysMessage(“%s has summon toggled off. You can’t summon him/her.”, (targetName).c_str());
return true;
}

What IsAdmin() does is basically the same as handler->HasLowerSecurity: it disables players of lower security from being able to use commands on those with higher security levels. If you look into the Command Script, you will see that there are three commands I’m trying to get functioning: .toggle summon, .toggle appear, and .toggle modify. Summon and appear work as intended, but I seem to be getting many problems when using .modify commands when .toggle modify is off. There are two types of checks for the .modify commands that I put in: one for player-based .modify commands and one for unit-based (creature or player) commands. For player-based commands (like .modify hp), I use:

if (!target->GetCommandStatus(TOGGLE_MODIFY) && !handler->GetSession()->GetPlayer()->IsAdmin() && handler->GetSession()->GetPlayer()->GetGUID() != target->GetGUID())
{
handler->PSendSysMessage(“%s has modify disabled. You can’t use commands on them.”, target->GetName());
return true;
}

For unit-based commands (like .morph), I use:

if (target->GetTypeId() == TYPEID_PLAYER)
{
if (!target->ToPlayer()->GetCommandStatus(TOGGLE_MODIFY) && !handler->GetSession()->GetPlayer()->IsAdmin() && handler->GetSession()->GetPlayer()->GetGUID() != target->GetGUID())
{
handler->PSendSysMessage(“%s has modify disabled. You can’t use commands on them.”, target->GetName());
return true;
}
}

When compiling a new core, I tend to receive 0 errors (when all checks are put in correctly, I don’t make any typos etc.) and have no issues with the start-up of the worldserver. The command appears in the .commands list and has been added to the appropriate RBAC permissions and command tables in the DB. The command works when either argument (on, off) is used, but the worldserver crashes whenever someone attempts to use a .modify command on someone else, while their “modify” is toggled off. I can’t exactly determine what’s causing the problem from the dump files the server creates upon crashing, so I was wondering if anyone had some help to offer as far as getting the command functional goes.

And you no post the dumps /emoticons/default_sad.png

It could be helpful to see the custom functions as well.

handler->PSendSysMessage(“%s has modify disabled. You can’t use commands on them.”, target->GetName());

This is bad. GetName returns a std::string and PSendSysMessage expects a cstring. Use target->GetName().c_str()

This might be causing the crash.

Hm, I’ll try that out and see if it stops the crashes. Here’s the dump from the dumpfile, and here are the changes I put into Player.cpp:

On lines 874-876

m_toggleAppear = true;
m_toggleSummon = true;
m_toggleModify = true;

On lines 25763-25778, I added the Player::CanUseCommandOnPlayer function

bool Player::CanUseCommandOnPlayer(Player* target)
{
if (GetSession()) //If we’re in-game (not the console)
{
// If they’re an admin and we aren’t, we can’t use the command on them.
if (target->IsAdmin() && !IsAdmin())
return false;

    // If we aren't using the command on ourselves and our target has modify off, we can't use the command.
    else if (GetGUID() != target->GetGUID() && !target->GetCommandStatus(TOGGLE_MODIFY) && !IsAdmin())
	    return false;
	return true; //Every other check passed, we can probably use commands on this player.
}
return true; // !GetSession(), we're the console, we can do whatever we want.

}

Here are some of the functions I put into Player.h I defined as the //Toggle Command Values on lines 2335-2343:

//Toggle Command Values
bool m_toggleAppear;
bool m_toggleSummon;
bool m_toggleModify;

     void ToggleCommand(int command);
     bool GetCommandStatus(int command);
     bool IsAdmin();
     bool CanUseCommandOnPlayer(Player* target);

Oh, and also this on lines 898-902 in Player.h:

enum CommandNames
{
TOGGLE_APPEAR = 8,
TOGGLE_SUMMON = 9,
TOGGLE_MODIFY = 10
};

That’s as far as the custom functions and links go, is there anything else I may have messed up on that can be causing the crash?

Could it possibly be that I haven’t added the toggle commands into RBAC.h? I think that might be an issue, but that doesn’t explain how summon and appear are working properly. I also fear that changing the std::strings into cstrings would still bring forth compile errors of “target->GetName” needing to be attached to a class, since I’ve had problems with that before.

So, after a few weeks of putting it off, I finally tried converting target->GetName() to target->GetName().c_str. It was to no avail, since the core was unable to compile. I’m not sure that was the issue when it came to the command crash, but it may have had something to do with the “enum CommandNames” I put into Player.h. I may just have to merge the command statuses into “enum PlayerCommandStates” where all of the cheat commands are…but then again, the .cheat command statuses (and most of the commands themselves) don’t really work (for me) either.