Builder commnad to add fame on players (Emca's hi5 extender)

  • Автор темы Автор темы Charus
  • Дата начала Дата начала

Charus

Единомышленник
Участник
Сообщения
24
Розыгрыши
0
Репутация
12
Реакции
6
Баллы
135
BuilderCmd2Handler.h
Код:
static bool AddFame(class CUserSocket* socket, class User* user, class CCreature* target, const BYTE* packet, const std::wstring& buffer);

BuilderCmd2Handler.cpp
Код:
bool __cdecl BuilderCmd2Handler::Handler(CUserSocket *socket, const BYTE *packet)
{
    GUARDED;

    // Get current user
    User *user = socket->user;
    if (!user) {
        return false;
    }

    // Get command into wstring and check it's length
    std::wstring buffer(reinterpret_cast<const wchar_t*>(packet));
    if (buffer.size() > 900) {
        return false;
    }

    // Get target object
    CSPointer<CObject> targetObject = user->GetTarget();

    // Cast target object (if any) to target creature
    CCreature *target = (targetObject && targetObject->IsCreature()) ? targetObject->CastCreature() : 0;

    // Log builder command to system log
    if (target) {
        CLog::Add(CLog::Blue, L"[AUDIT] BuilderCmd %s -> %s: %s", user->GetName(), target->GetName(), buffer.c_str());
    } else {
        CLog::Add(CLog::Blue, L"[AUDIT] BuilderCmd %s -> null: %s", user->GetName(), buffer.c_str());
    }

    // Custom builder commands + my favourite aliases/abbreviations
    if (buffer == L"gmliston") {
        return reinterpret_cast<bool(*)(CUserSocket*, User*, const wchar_t*)>(0x4B7264)(socket, user, L"//gmreg");
    } else if (buffer == L"gmlistoff") {
        return reinterpret_cast<bool(*)(CUserSocket*, User*, const wchar_t*)>(0x4B74C0)(socket, user, L"//gmunreg");
    } else if (buffer == L"res") {
        return reinterpret_cast<bool(*)(CUserSocket*, User*, const wchar_t*)>(0x4C4604)(socket, user, L"//resurrect 100");
    } else if (buffer == L"res 0") {
        return reinterpret_cast<bool(*)(CUserSocket*, User*, const wchar_t*)>(0x4C4604)(socket, user, L"//resurrect 0");
    } else if (buffer == L"heal") {
        if (target) {
            return reinterpret_cast<bool(*)(CUserSocket*, User*, const wchar_t*)>(0x50235C)(socket, user, target->GetName());
        } else {
            return reinterpret_cast<bool(*)(CUserSocket*, User*, const wchar_t*)>(0x50235C)(socket, user, user->GetName());
        }
    } else if (buffer.substr(0, 4) == L"say ") {
        return Say(socket, user, target, packet, buffer);
    } else if (buffer.substr(0, 14) == L"drop_item_each") {
        return DropItemEach(socket, user, target, packet, buffer);
    } else if (buffer.substr(0, 5) == L"give ") {
        return Give(socket, user, target, packet, buffer);
    } else if (buffer.substr(0, 5) == L"take ") {
        return Take(socket, user, target, packet, buffer);
    } else if (buffer.substr(0, 5) == L"diag ") {
        return Diag(socket, user, target, packet, buffer);
    } else if (buffer.substr(0, 9) == L"add_fame ") {
        return AddFame(socket, user, target, packet, buffer);
    } else if (buffer == L"debug 0") {
        Server::SetDebug(false);
        return false;
    } else if (buffer == L"debug 1") {
        Server::SetDebug(true);
        return false;
    } else if (buffer == L"test") {
        // Various test stuff can be put here like this:
        //CDB::Instance()->RequestTest(100);
        return false;
    } else {
        // Call original handler
        return reinterpret_cast<bool(*)(CUserSocket*, const BYTE*)>(0x510464)(socket, packet);
    }
}

Код:
bool BuilderCmd2Handler::AddFame(CUserSocket* socket, User* user, CCreature* target, const BYTE* packet, const std::wstring& buffer)
{
    GUARDED;

    // Check if target is user
    if (!target || !target->IsUser()) {
        user->SendSystemMessage(L"SYS", L"Invalid target");
        return false;
    }

    // Get item type and count from buffer via stringstream
    std::wstringstream s;
    s << buffer;
    std::wstring cmd;
    int count = 0;
    s >> cmd >> count;

    // Check if count is sane
    if (count <= 0) {
        user->SendSystemMessage(L"SYS", L"Invalid count");
        return false;
    }

    CUserSocket *targetSocket = reinterpret_cast<User*>(target)->GetUserSocket();
    if (!targetSocket) {
        user->SendSystemMessage(L"SYS", L"Target has no socket");
        return false;
    }

    // add fame to user
    targetSocket->user->AddPoint(FAME, count, true);
    
    // Send acknowledgement message
    user->SendSystemMessageFmt(L"SYS", L"Add %dx fame to %s", count, target->GetName());
    return false;
}

Enum.h
Код:
enum PointType {
    FAME = 5
};
 

Назад
Сверху Снизу