[资源名称]
最新T端的延迟踢玩家出游戏的GM命令
[资源类型]
资料共享
[资源详情]
不用说,这个是一个GM命令的系统。通过事件系统的控制,来限制多少时间后踢玩家下线。
- #include "ScriptMgr.h"#include "ObjectMgr.h"
- #include "Chat.h"
- #include "Language.h"
- #define KICKDELAY 5000 /*Time in milliseconds 1s = 1000 */ //这里定义多少时间踢玩家下线。例如5000就是5秒,你执行命令后,5秒后对应的玩家被踢下线
- class kickplayer : public BasicEvent
- {
- public:
- kickplayer(Player* player) : _player(player) { }
- bool Execute(uint64 /*time*/, uint32 /*diff*/)
- {
- if (_player && _player->GetSession())
- _player->GetSession()->KickPlayer();
- return true;
- }
- private:
- Player* _player;
- };
- class Newkickcommand : public CommandScript
- {
- public:
- Newkickcommand() : CommandScript("Newkickcommand") { }
- ChatCommand* GetCommands() const
- {
- static ChatCommand commandTable[] =
- {
- { "kickp", SEC_GAMEMASTER, true, &HandleKickPlayerWithDelayCommand, "", NULL},
- { NULL, 0, false, NULL, "", NULL }
- };
- return commandTable;
- }
- static bool HandleKickPlayerWithDelayCommand(ChatHandler* handler, char const* args)
- {
- Player* target = NULL;
- std::string playerName;
- std::stringstream announcer;
- if (!handler->extractPlayerTarget((char*)args, &target, NULL, &playerName))
- return false;
- if (handler->GetSession() && target == handler->GetSession()->GetPlayer())
- {
- handler->SendSysMessage(LANG_COMMAND_KICKSELF);
- handler->SetSentErrorMessage(true);
- return false;
- }
- // check online security
- if (handler->HasLowerSecurity(target, 0))
- return false;
- char const* kickReason = strtok(NULL, " ");
- std::string kickReasonStr = "No reason";
- if (kickReason != NULL)
- kickReasonStr = kickReason;
- if(handler->GetSession() != NULL)
- {
- Player * plr = handler->GetSession()->GetPlayer();
- switch(plr->GetSession()->GetSecurity())
- {
- case SEC_GAMEMASTER:
- {
- announcer <<"|cffFF0000"<<"GameMaster "<<plr->GetName()<<" has kicked "<<target->GetName()<<" for reason: "<<kickReasonStr<<"|r";
- sWorld->SendWorldText(LANG_COMMAND_KICKMESSAGE,announcer.str().c_str());
- announcer.rdbuf()->str()="";
- }
- break;
- case SEC_ADMINISTRATOR:
- {
- announcer <<"|cffFF0000"<<"Administrator "<<plr->GetName()<<" has kicked "<<target->GetName()<<" for reason: "<<kickReasonStr<<"|r";
- sWorld->SendWorldText(LANG_COMMAND_KICKMESSAGE,announcer.str().c_str());
- announcer.rdbuf()->str()="";
- }
- break;
- }
- }
- else
- {
- announcer <<"|cffFF0000"<<"Core"<<" has kicked "<<target->GetName()<<" for reason: "<<kickReasonStr<<"|r";
- sWorld->SendWorldText(LANG_COMMAND_KICKMESSAGE,announcer.str().c_str());
- announcer.rdbuf()->str()="";
- }
- ChatHandler(target->GetSession()).PSendSysMessage("You will be kicked in %u seconds for %s", KICKDELAY, kickReasonStr);
- target->m_Events.AddEvent(new kickplayer(target), target->m_Events.CalculateTime(KICKDELAY)); //这里,就把踢下线的任务安排成为一个事件,到时间就自动踢下线了
- return true;
- }
- };
- void AddSC_NewKickDelay()
- {
- new Newkickcommand();
- }
复制代码
|
|