Example #1
0
BString ObjectController::handleCancelShutdownGalaxy(BString message) const
{
    int8 replyData[128];

    if (!AdminManager::Instance()->shutdownPending())
    {
        sprintf(replyData,"No shutdown in progress");
    }
    else
    {
        sprintf(replyData,"OK");

        // We have no idea of how much white space are inserted in string...
        BString ansiData;
        int32 index = indexOfFirstField(message);
        if (index < 0)
        {
            // We may not have any "next field", it's optional here.
            index = 0;
            ansiData = "";
        }
        else
        {
            // Now we can get the broadcaste from the message.
            // Remove first field from message.
            ansiData.setLength(message.getLength());
            message.substring(ansiData, static_cast<uint16>(index), message.getLength());
        }

        // Send request to all zones, via chatserver.
        this->cancelScheduledShutdown(ansiData);
    }
    return replyData;
}
Example #2
0
BString ObjectController::handleBroadcastGalaxy(BString message) const
{
    int8* replyStr = "OK";

    int8 rawData[128];
    // We have no idea of how much white space are inserted in string...
    int32 index = indexOfFirstField(message);
    if (index >= 0)
    {
        // Now we can get the broadcast from the message.

        // Remove white space from start of message.
        BString ansiData;
        ansiData.setLength(message.getLength());
        message.substring(ansiData, static_cast<uint16>(index), message.getLength());

        // Any valid message?
        int32 elementCount = sscanf(ansiData.getAnsi(), "%80s", rawData);
        if (elementCount > 0)
        {
            this->broadcastGalaxyMessage(ansiData, -1);
        }
        else
        {
            replyStr = "No broadcast supplied";
        }
    }
    else
    {
        replyStr = "No valid broadcast supplied";
    }
    return replyStr;
}
Example #3
0
BString ObjectController::handleShutdownGalaxy(BString message) const
{
    int8 replyData[128];

    if (AdminManager::Instance()->shutdownPending())
    {
        sprintf(replyData,"Shutdown already in progress");
    }
    else
    {
        sprintf(replyData,"OK");
        // Get time for shutdown
        //
        int32 minutesToShutdown;
        int32 elementCount = sscanf(message.getAnsi(), "%3d", &minutesToShutdown);
        // string planet(rawData);
        if (elementCount > 0)
        {
            // We have no idea of how much white space are inserted in string...
            BString ansiData;
            int32 index = indexOfNextField(message);
            if (index < 0)
            {
                // We may not have any "next field", it's optional here.
                index = 0;
                ansiData = "";
            }
            else
            {
                // Now we can get the broadcaste from the message.
                // Remove first field from message.
                ansiData.setLength(message.getLength());
                message.substring(ansiData, static_cast<uint16>(index), message.getLength());
            }

            // Validate the timeout.
            if (minutesToShutdown >= 0)
            {
                // Any valid message?
                int8 rawData[128];
                elementCount = sscanf(ansiData.getAnsi(), "%80s", rawData);
                // Send request to all zones, via chatserver.
                this->scheduleShutdown(minutesToShutdown*60, ansiData);
            }
            else
            {
                sprintf(replyData,"%d is not valid shutdown time", minutesToShutdown);
            }
        }
        else
        {
            sprintf(replyData,"No shutdown time supplied");
        }
    }
    return replyData;
}
Example #4
0
BString ObjectController::handleBroadcastPlanet(BString message) const
{
    // Get planet name
    int8 rawData[128];
    rawData[0] = 0;

    int32 elementCount = sscanf(message.getAnsi(), "%80s", rawData);
    BString planet(rawData);
    if (elementCount > 0)
    {
        // Yes. Validate the planet name.
        int32 planetId = gWorldManager->getPlanetIdByNameLike(planet);
        if (planetId >= 0)
        {
            // We have no idea of how much white space are inserted in string...
            int32 index = indexOfNextField(message);
            if (index > 0)
            {
                // Now we can get the broadcaste from the message.
                // Remove planet name from message.
                BString ansiData;
                ansiData.setLength(message.getLength());
                message.substring(ansiData, static_cast<uint16>(index), message.getLength());

                // Any valid message?
                elementCount = sscanf(ansiData.getAnsi(), "%80s", rawData);
                if (elementCount > 0)
                {
                    // string planetName(gWorldManager->getPlanetNameById(planetId));

                    this->broadcastGalaxyMessage(ansiData, planetId);
                    sprintf(rawData,"OK");
                }
                else
                {
                    sprintf(rawData,"No broadcast supplied");
                }
            }
            else
            {
                sprintf(rawData,"No valid broadcast supplied");
            }
        }
        else
        {
            sprintf(rawData,"%s is not valid planet name", planet.getAnsi());
        }
    }
    else
    {
        sprintf(rawData,"Missing planet name");
    }
    return rawData;
}
Example #5
0
BString ObjectController::removeWhiteSpace(BString str) const
{
    int32 index = indexOfFirstField(str);
    if (index > 0)
    {
        // Remove white space from start of message.
        BString resultStr;
        resultStr.setLength(str.getLength());
        str.substring(resultStr, static_cast<uint16>(index), str.getLength());
        return resultStr;
    }
    // Nothing we can do about that string... good or bad.
    return str;
}
Example #6
0
BString ObjectController::skipToNextField(BString str) const
{
    int32 index = indexOfNextField(str);
    if (index < 0)
    {
        // Not all commands have payload.
        index = str.getLength();
    }

    // Remove white space from start of message.
    BString resultStr;
    resultStr.setLength(str.getLength());
    str.substring(resultStr, static_cast<uint16>(index), str.getLength());
    return resultStr;
}
Example #7
0
void ObjectController::_handleAdminSysMsg(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties)
{
    bool status = false;

    BString dataStr;
    message->getStringUnicode16(dataStr);

    PlayerObject* player = dynamic_cast<PlayerObject*>(mObject);
    if ((player) && (player->isConnected()))
    {
        // gMessageLib->sendSystemMessage(player, dataStr, true);

        dataStr.convert(BSTRType_ANSI);
        gLogger->log(LogManager::DEBUG,"Admin (%s): %s", player->getFirstName().getAnsi(), dataStr.getAnsi());
    }
    else
    {
        dataStr.convert(BSTRType_ANSI);
        gLogger->log(LogManager::DEBUG,"Admin (anon): %s", dataStr.getAnsi());
    }

    int8 rawData[128];
    rawData[0] = 0;

    if (dataStr.getLength())
    {
        int32 elementCount = sscanf(dataStr.getAnsi(), "%80s", rawData);
        BString adminCommand(rawData);
        if (elementCount > 0)
        {
            int32 commandIndex = this->getAdminCommandFunction(adminCommand);
            if (commandIndex >= 0)
            {
                // We have a valid command name, but strip it. It can be an abreviation.
                int32 index = indexOfNextField(dataStr);
                if (index < 0)
                {
                    // Not all commands have payload.
                    index = dataStr.getLength();
                }
                BString ansiData;
                ansiData.setLength(dataStr.getLength());
                dataStr.substring(ansiData,static_cast<uint16>(index), dataStr.getLength());

                // Now ADD a proper spelled command. It HAS to match the crc.
                BString newCommandString;
                newCommandString.setLength(adminCommands[commandIndex].command.getLength() + ansiData.getLength() + 1);
                sprintf(newCommandString.getAnsi(),"%s %s", adminCommands[commandIndex].command.getAnsi(), ansiData.getAnsi());

                // Execute the command.
                BString opcodeStr(adminCommands[commandIndex].command);
                opcodeStr.toLower();
                newCommandString.convert(BSTRType_Unicode16);

                // Now let's parse it BACK to objectcontroller, so we can continue to maintain access rights control as initial designed.
                gMessageFactory->StartMessage();
                gMessageFactory->addUint32(0);						// clientTicks, We do not have these, here.
                gMessageFactory->addUint32(0);						// sequence number, we really need this
                gMessageFactory->addUint32(opcodeStr.getCrc());		// opCode for new command.
                gMessageFactory->addUint64(targetId);
                gMessageFactory->addString(newCommandString);
                Message* newMessage = gMessageFactory->EndMessage();
                newMessage->ResetIndex();
                this->enqueueCommandMessage(newMessage);

                status = true;
            }
            else
            {
                // Invalid command.
                sprintf(rawData,"Admin: [%s No such command]", adminCommand.getAnsi());
            }
        }
        else
        {
            sprintf(rawData,"Admin: [Unexpected error]");
        }
    }
    else
    {
        sprintf(rawData,"Admin: [Missing command]");
    }

    // Send reply to caller.
    if (!status)
    {
        this->sendAdminFeedback(rawData);
    }
}