예제 #1
0
//kick player
bool ChatHandler::HandleKickPlayerCommand(const char *args)
{
    Player* target = NULL;
    std::string playerName;
    std::string announce;
    if (!extractPlayerTarget((char*)args, &target, NULL, &playerName))
        return false;

    if (m_session && target == m_session->GetPlayer())
    {
        SendSysMessage(LANG_COMMAND_KICKSELF);
        SetSentErrorMessage(true);
        return false;
    }

    // check online security
    if (HasLowerSecurity(target, 0))
        return false;

    if (sWorld->getBoolConfig(CONFIG_SHOW_KICK_IN_WORLD))
        sWorld->SendWorldText(LANG_COMMAND_KICKMESSAGE, playerName.c_str());
    else
        PSendSysMessage(LANG_COMMAND_KICKMESSAGE, playerName.c_str());

    announce = "The character '";
    announce += target->GetName();
    announce += "' was kicked by the character '";
    announce += m_session->GetPlayerName();
    announce += "'.";
    HandleAnnounceCommand(announce.c_str());

    target->GetSession()->KickPlayer();
    return true;
}
예제 #2
0
//mute player for some times
bool ChatHandler::HandleMuteCommand(const char* args)
{
    std::string announce;

    char* nameStr;
    char* delayStr;
    extractOptFirstArg((char*)args, &nameStr, &delayStr);
    if (!delayStr)
        return false;

    char *mutereason = strtok(NULL, "\r");
    std::string mutereasonstr = "No reason";
    if (mutereason != NULL)
         mutereasonstr = mutereason;

    if(!mutereason)
    {
        PSendSysMessage("You must enter a reason of mute");
        SetSentErrorMessage(true);
        return false;
    }

    Player* target;
    uint64 target_guid;
    std::string target_name;
    if (!extractPlayerTarget(nameStr, &target, &target_guid, &target_name))
        return false;

    uint32 accountId = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(target_guid);

    // find only player from same account if any
    if (!target)
        if (WorldSession* session = sWorld->FindSession(accountId))
            target = session->GetPlayer();

    uint32 notspeaktime = (uint32) atoi(delayStr);

    // must have strong lesser security level
    if (HasLowerSecurity (target, target_guid, true))
        return false;

    PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);

    if (target)
    {
        // Target is online, mute will be in effect right away.
        int64 muteTime = time(NULL) + notspeaktime * MINUTE;
        target->GetSession()->m_muteTime = muteTime;

        stmt->setInt64(0, muteTime);

        ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notspeaktime, mutereasonstr.c_str());
    }
    else
    {
        // Target is offline, mute will be in effect starting from the next login.
        int32 muteTime = -int32(notspeaktime * MINUTE);

        stmt->setInt64(0, muteTime);
    }

    stmt->setUInt32(1, accountId);

    LoginDatabase.Execute(stmt);

    std::string nameLink = playerLink(target_name);

    PSendSysMessage(target ? LANG_YOU_DISABLE_CHAT : LANG_COMMAND_DISABLE_CHAT_DELAYED, nameLink.c_str(), notspeaktime, mutereasonstr.c_str());

    announce = "The character '";
    announce += nameStr;
    announce += "' was muted for ";
    announce += delayStr;
    announce += " minutes by the character '";
    announce += m_session->GetPlayerName();
    announce += "'. The reason is: ";
    announce += mutereason;
    HandleAnnounceCommand(announce.c_str());

    return true;
}
예제 #3
0
// Jail by WarHead edited by spgm
bool ChatHandler::HandleJailCommand(const char *args)
{
    std::string cname, announce, ban_reason, ban_by;
    time_t localtime;
    localtime = time(NULL);

    char *charname = strtok((char*)args, " ");
    if (charname == NULL)
    {
        SendSysMessage(LANG_JAIL_NONAME);
        return true;
    } else cname = charname;

    char *timetojail = strtok(NULL, " ");
    if (timetojail == NULL)
    {
        SendSysMessage(LANG_JAIL_NOTIME);
        return true;
    }

    uint32 jailtime = (uint32) atoi((char*)timetojail);
    if (jailtime < 1 || jailtime > sObjectMgr->m_jailconf_max_duration)
    {
        PSendSysMessage(LANG_JAIL_VALUE, sObjectMgr->m_jailconf_max_duration);
        return true;
    }

    char *reason = strtok(NULL, "\0");
    std::string jailreason;
    if (reason == NULL || strlen((const char*)reason) < sObjectMgr->m_jailconf_min_reason)
    {
        PSendSysMessage(LANG_JAIL_NOREASON, sObjectMgr->m_jailconf_min_reason);
        return true;
    } else jailreason = reason;

    uint64 GUID = sObjectMgr->GetPlayerGUIDByName(cname.c_str());
    if (GUID == 0)
    {
        SendSysMessage(LANG_JAIL_WRONG_NAME);
        return true;
    }

    Player *chr = sObjectMgr->GetPlayer(GUID);
    if (!chr)
    {
		uint32 jail_guid = GUID_LOPART(GUID);
		std::string jail_char = cname;
		bool jail_isjailed = true;
		uint32 jail_release = localtime + (jailtime * 60 * 60);
		uint32 jail_amnestietime = localtime +(60* 60 * 24 * sObjectMgr->m_jailconf_amnestie);
		std::string jail_reason = jailreason;
		uint32 jail_times = 0;

		SQLTransaction trans = CharacterDatabase.BeginTransaction();
		QueryResult result = CharacterDatabase.PQuery("SELECT * FROM `jail` WHERE `guid`='%u' LIMIT 1", jail_guid);
		CharacterDatabase.CommitTransaction(trans);

        if (!result)
        {
            jail_times = 1;
        }
        else
        {
            Field *fields = result->Fetch();
            jail_times = fields[5].GetUInt32()+1;
        }

        uint32 jail_gmacc = m_session->GetAccountId();
        std::string jail_gmchar = m_session->GetPlayerName();

        SQLTransaction trans2 = CharacterDatabase.BeginTransaction();
		if (!result) CharacterDatabase.PExecute("INSERT INTO `jail` VALUES ('%u','%s','%u','%u','%s','%u','%u','%s',CURRENT_TIMESTAMP,'%u')", jail_guid, jail_char.c_str(), jail_release, jail_amnestietime, jail_reason.c_str(), jail_times, jail_gmacc, jail_gmchar.c_str(), jailtime);
        else CharacterDatabase.PExecute("UPDATE `jail` SET `release`='%u', `amnestietime`='%u',`reason`='%s',`times`='%u',`gmacc`='%u',`gmchar`='%s',`duration`='%u' WHERE `guid`='%u' LIMIT 1", jail_release, jail_amnestietime, jail_reason.c_str(), jail_times, jail_gmacc, jail_gmchar.c_str(), jailtime, jail_guid);
        CharacterDatabase.CommitTransaction(trans2);

        PSendSysMessage(LANG_JAIL_WAS_JAILED, cname.c_str(), jailtime);

        announce = GetTrinityString(LANG_JAIL_ANNOUNCE1);
        announce += cname;
        announce += GetTrinityString(LANG_JAIL_ANNOUNCE2);
        announce += timetojail;
        announce += GetTrinityString(LANG_JAIL_ANNOUNCE3);
        announce += m_session->GetPlayerName();
        announce += GetTrinityString(LANG_JAIL_ANNOUNCE4);
        announce += jail_reason;

        HandleAnnounceCommand(announce.c_str());

        if ((sObjectMgr->m_jailconf_max_jails == jail_times) && !sObjectMgr->m_jailconf_ban)
        {
            SQLTransaction trans = CharacterDatabase.BeginTransaction();
            QueryResult result = CharacterDatabase.PQuery("SELECT * FROM `characters` WHERE `guid`='%u' LIMIT 1", GUID_LOPART(GUID));
            CharacterDatabase.CommitTransaction(trans);

            if (!result)
            {
                PSendSysMessage(LANG_NO_PLAYER, cname.c_str());
                return true;
            }

            Field *fields = result->Fetch();

            Player::DeleteFromDB(GUID, fields[1].GetUInt32());
        }
        else if ((sObjectMgr->m_jailconf_max_jails == jail_times) && sObjectMgr->m_jailconf_ban)
        {
            SQLTransaction trans = CharacterDatabase.BeginTransaction();
            QueryResult result = CharacterDatabase.PQuery("SELECT * FROM `characters` WHERE `guid`='%u' LIMIT 1", GUID_LOPART(GUID));
            CharacterDatabase.CommitTransaction(trans);

            if (!result)
            {
                PSendSysMessage(LANG_NO_PLAYER, cname.c_str());
                return true;
            }
            Field *fields = result->Fetch();
            uint32 acc_id = fields[1].GetUInt32();

            SQLTransaction trans2 = LoginDatabase.BeginTransaction();
            result = LoginDatabase.PQuery("SELECT * FROM `account` WHERE `id`='%u' LIMIT 1", acc_id);
            LoginDatabase.CommitTransaction(trans2);

            if (!result)
            {
                PSendSysMessage(LANG_NO_PLAYER, cname.c_str());
                return true;
            }
            ban_reason = GetTrinityString(LANG_JAIL_BAN_REASON);
            ban_by = GetTrinityString(LANG_JAIL_BAN_BY);

            SQLTransaction trans3 = LoginDatabase.BeginTransaction();
            LoginDatabase.PExecute("INSERT IGNORE INTO `account_banned` (`id`,`bandate`,`bannedby`,`banreason`) VALUES ('%u',UNIX_TIMESTAMP,'%s','%s')", acc_id, ban_by.c_str(), ban_reason.c_str());
            LoginDatabase.CommitTransaction(trans3);

        }
        return true;
    }

    SQLTransaction trans = CharacterDatabase.BeginTransaction();
    QueryResult result = CharacterDatabase.PQuery("SELECT * FROM `characters` WHERE `guid`='%u' LIMIT 1", chr->GetGUIDLow());
    CharacterDatabase.CommitTransaction(trans);

    if (!result)
    {
        PSendSysMessage(LANG_NO_PLAYER, cname.c_str());
        return true;
    }

    Field *fields = result->Fetch();

    if (chr->GetName() == m_session->GetPlayerName())
    {
        SendSysMessage(LANG_JAIL_NO_JAIL);
        return true;
    }

		chr->SaveToDB();

		chr->m_jail_guid = fields[0].GetUInt32();
		chr->m_jail_char = fields[3].GetString();
		chr->m_jail_isjailed = true;
		chr->m_jail_release = localtime + (jailtime * 60 * 60);
		chr->m_jail_amnestietime = localtime +(60* 60 * 24 * sObjectMgr->m_jailconf_amnestie);
		chr->m_jail_reason = jailreason;
		chr->m_jail_times = chr->m_jail_times+1;
		chr->m_jail_gmacc = m_session->GetAccountId();
		chr->m_jail_gmchar = m_session->GetPlayerName();
		chr->m_jail_duration = jailtime;

		chr->_SaveJail();

		PSendSysMessage(LANG_JAIL_WAS_JAILED, fields[3].GetString().c_str(), jailtime);
		ChatHandler(chr).PSendSysMessage(LANG_JAIL_YOURE_JAILED, m_session->GetPlayerName(), jailtime);
		ChatHandler(chr).PSendSysMessage(LANG_JAIL_REASON, m_session->GetPlayerName(), jailreason.c_str());

		announce = GetTrinityString(LANG_JAIL_ANNOUNCE1);
		announce += fields[3].GetString();
		announce += GetTrinityString(LANG_JAIL_ANNOUNCE2);
		announce += timetojail;
		announce += GetTrinityString(LANG_JAIL_ANNOUNCE3);
		announce += m_session->GetPlayerName();
		announce += GetTrinityString(LANG_JAIL_ANNOUNCE4);
		announce += chr->m_jail_reason;

		HandleAnnounceCommand(announce.c_str());

    if (sObjectMgr->m_jailconf_max_jails == chr->m_jail_times)
    {
        chr->GetSession()->KickPlayer();
        chr->DeleteFromDB(fields[0].GetUInt64(), fields[1].GetUInt32());
    }
    else if ((sObjectMgr->m_jailconf_max_jails == chr->m_jail_times) && sObjectMgr->m_jailconf_ban)
    {
        uint32 acc_id = chr->GetSession()->GetAccountId();
        ban_reason = GetTrinityString(LANG_JAIL_BAN_REASON);
        ban_by = GetTrinityString(LANG_JAIL_BAN_BY);

		SQLTransaction trans = LoginDatabase.BeginTransaction();
        LoginDatabase.PExecute("INSERT IGNORE INTO `account_banned` (`id`,`bandate`,`bannedby`,`banreason`) VALUES ('%u',UNIX_TIMESTAMP,'%s','%s')", acc_id, ban_by.c_str(), ban_reason.c_str());
        LoginDatabase.CommitTransaction(trans);

        chr->GetSession()->LogoutPlayer(false);
    }
    else chr->GetSession()->LogoutPlayer(false);
    return true;
}
예제 #4
0
파일: Level2.cpp 프로젝트: ice74/blizzwow
//mute player for some times
bool ChatHandler::HandleMuteCommand(const char* args)
{
    std::string announce;

    char* nameStr;
    char* delayStr;
    extractOptFirstArg((char*)args,&nameStr,&delayStr);
    if (!delayStr)
        return false;

    char *mutereason = strtok(NULL, "\r");
    std::string mutereasonstr = "Нет причины";
    if (mutereason != NULL)
        mutereasonstr = mutereason;

    if(!mutereason)
    {
        PSendSysMessage("Вы должны ввести причину блокировки чата");
        SetSentErrorMessage(true);
        return false;
    }

    Player* target;
    uint64 target_guid;
    std::string target_name;
    if (!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
        return false;

    uint32 account_id = target ? target->GetSession()->GetAccountId() : sObjectMgr.GetPlayerAccountIdByGUID(target_guid);

    // find only player from same account if any
    if (!target)
        if (WorldSession* session = sWorld.FindSession(account_id))
            target = session->GetPlayer();

    uint32 notspeaktime = (uint32) atoi(delayStr);

    // must have strong lesser security level
    if (HasLowerSecurity (target,target_guid,true))
        return false;

    time_t mutetime = time(NULL) + notspeaktime*60;

    if (target)
        target->GetSession()->m_muteTime = mutetime;

    LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'",uint64(mutetime), account_id);

    if (target)
        ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notspeaktime, mutereasonstr.c_str());

    std::string nameLink = playerLink(target_name);

    PSendSysMessage(LANG_YOU_DISABLE_CHAT, nameLink.c_str(), notspeaktime, mutereasonstr.c_str());

    announce = "У игрока '";
    announce += nameStr;
    announce += "' был отключён чат на ";
    announce += delayStr;
    announce += " минут персонажем '";
    announce += m_session->GetPlayerName();
    announce += "'. Причина: ";
    announce += mutereason;
    HandleAnnounceCommand(announce.c_str());

    return true;
}