void ProtocolGame::parseItemTextWindow(InputMessage& msg)
{
    msg.getU32(); // windowId
    msg.getU16(); // itemid
    msg.getU16(); // max length
    msg.getString(); // text
    msg.getString(); // writter
    msg.getString(); // date
}
void ProtocolGame::parseOpenChannel(InputMessage& msg)
{
    int channelId = msg.getU16();
    std::string name = msg.getString();

    g_lua.callGlobalField("Game", "onOpenChannel", channelId, name);
}
void ProtocolGame::parseSafeTradeRequest(InputMessage& msg)
{
    msg.getString(); // name
    int count = msg.getU8();

    for(int i = 0; i < count; i++)
        internalGetItem(msg);
}
void ProtocolGame::parseVipState(InputMessage& msg)
{
    uint id = msg.getU32();
    std::string name = msg.getString();
    bool online = msg.getU8() != 0;

    g_lua.callGlobalField("Game", "onAddVip", id, name, online);
}
void ProtocolGame::parseTextMessage(InputMessage& msg)
{
    int type = msg.getU8();

    std::string typeDesc = Proto::translateTextMessageType(type);
    std::string message = msg.getString();

    g_game.processTextMessage(typeDesc, message);
}
void ProtocolGame::parseQuestList(InputMessage& msg)
{
    int questsCount = msg.getU16();
    for(int i = 0; i < questsCount; i++) {
        msg.getU16(); // quest id
        msg.getString(); // quest name
        msg.getU8(); // quest state
    }
}
void ProtocolGame::parseQuestPartList(InputMessage& msg)
{
    msg.getU16(); // quest id
    int missionCount = msg.getU8();
    for(int i = 0; i < missionCount; i++) {
        msg.getString(); // quest name
        msg.getString(); // quest description
    }
}
示例#8
0
void ProtocolLogin::parseCharacterList(InputMessage& inputMessage)
{
    typedef std::tuple<std::string, std::string, std::string, int> CharacterInfo;
    typedef std::vector<CharacterInfo> CharaterList;
    CharaterList charList;

    int numCharacters = inputMessage.getU8();
    for(int i = 0; i < numCharacters; ++i) {
        std::string name = inputMessage.getString();
        std::string world = inputMessage.getString();
        uint32 ip = inputMessage.getU32();
        uint16 port = inputMessage.getU16();
        charList.push_back(CharacterInfo(name, world, Fw::ip2str(ip), port));
    }
    int premDays = inputMessage.getU16();

    callLuaField("onCharacterList", charList, premDays);
}
void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
{
    msg.getU32(); // unkSpeak
    std::string name = msg.getString();
    int level = msg.getU16();
    int type = msg.getU8();
    int channelId = 0;
    Position creaturePos;

    switch(type) {
        case Proto::SpeakSay:
        case Proto::SpeakWhisper:
        case Proto::SpeakYell:
        case Proto::SpeakMonsterSay:
        case Proto::SpeakMonsterYell:
        case Proto::SpeakPrivateNpcToPlayer:
            creaturePos = parsePosition(msg);
            break;
        case Proto::SpeakChannelYellow:
        case Proto::SpeakChannelWhite:
        case Proto::SpeakChannelRed:
        case Proto::SpeakChannelRed2:
        case Proto::SpeakChannelOrange:
            channelId = msg.getU16();
            break;
        case Proto::SpeakPrivate:
        case Proto::SpeakPrivatePlayerToNpc:
        case Proto::SpeakBroadcast:
        case Proto::SpeakPrivateRed:
            break;
        case Proto::SpeakRVRChannel:
            msg.getU32();
            break;
        default:
            logTraceError("unknown speak type ", type);
            break;
    }

    std::string message = msg.getString();
    std::string typeDesc = Proto::translateSpeakType(type);

    g_game.processCreatureSpeak(name, level, typeDesc, message, channelId, creaturePos);
}
示例#10
0
void ProtocolGame::parseAnimatedText(InputMessage& msg)
{
    Position position = parsePosition(msg);
    int color = msg.getU8();
    std::string text = msg.getString();

    AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
    animatedText->setColor(color);
    animatedText->setText(text);

    g_map.addThing(animatedText, position);
}
示例#11
0
void ProtocolGame::parseOpenShopWindow(InputMessage& msg)
{
    int listCount = msg.getU8();
    for(int i = 0; i < listCount; ++i) {
        msg.getU16(); // item id
        msg.getU8(); // runecharges
        msg.getString(); // item name
        msg.getU32(); // weight
        msg.getU32(); // buy price
        msg.getU32(); // sell price
    }
}
示例#12
0
void ProtocolGame::parseChannelList(InputMessage& msg)
{
    int count = msg.getU8();
    std::vector<std::tuple<int, std::string> > channelList(count);
    for(int i = 0; i < count; i++) {
        int id = msg.getU16();
        std::string name = msg.getString();
        channelList.push_back(std::make_tuple(id, name));
    }

    g_lua.callGlobalField("Game", "onChannelList", channelList);
}
示例#13
0
void ProtocolGame::parseOpenContainer(InputMessage& msg)
{
    int containerId = msg.getU8();
    int itemId = msg.getU16();
    std::string name = msg.getString();
    int capacity = msg.getU8();
    bool hasParent = (msg.getU8() != 0);
    int itemCount = msg.getU8();

    std::vector<ItemPtr> items;
    items.reserve(itemCount);
    for(int i = 0; i < itemCount; i++) {
        ItemPtr item = internalGetItem(msg);
        items.push_back(item);
    }

    g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent, items);
}
示例#14
0
void ProtocolGame::parseOutfitWindow(InputMessage& msg)
{
    Outfit outfit = internalGetOutfit(msg);

    typedef std::tuple<int, std::string, int> OutfitInfo;
    std::vector<OutfitInfo> outfitList;

    uint8 outfitCount = msg.getU8();
    for(int i = 0; i < outfitCount; i++) {
        uint16 outfitId = msg.getU16();
        std::string outfitName = msg.getString();
        uint8 outfitAddons = msg.getU8();

        outfitList.push_back(OutfitInfo(outfitId, outfitName, outfitAddons));
    }

    CreaturePtr creature = CreaturePtr(new Creature);
    creature->setXPattern(2);
    creature->setOutfit(outfit);

    g_lua.callGlobalField("Game", "onOpenOutfitWindow", creature, outfitList);
}
示例#15
0
ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
{
    ThingPtr thing;

    int thingId = msg.getU16();
    assert(thingId != 0);
    if(thingId == 0x0061 || thingId == 0x0062) { // add new creature
        CreaturePtr creature;

        if(thingId == 0x0062) { //creature is known
            uint id = msg.getU32();

            CreaturePtr knownCreature = g_map.getCreatureById(id);
            if(knownCreature)
                creature = knownCreature;
            else
                logTraceError("server says creature is known, but its not on creatures list");
        } else if(thingId == 0x0061) { //creature is not known
            uint removeId = msg.getU32();
            uint id = msg.getU32();
            std::string name = msg.getString();

            if(name.length() > 0) // every creature name must start with a capital letter
                name[0] = toupper(name[0]);

            g_map.removeCreatureById(removeId);

            if(id == m_localPlayer->getId())
                creature = m_localPlayer;
            else if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
                creature = PlayerPtr(new Player);
            else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
                creature = MonsterPtr(new Monster);
            else if(id >= Proto::NpcStartId && id < Proto::NpcEndId)
                creature = NpcPtr(new Npc);
            else
                logTraceError("creature id is invalid");

            creature->setId(id);
            creature->setName(name);
        }

        uint8 healthPercent = msg.getU8();
        Otc::Direction direction = (Otc::Direction)msg.getU8();
        Outfit outfit = internalGetOutfit(msg);

        Light light;
        light.intensity = msg.getU8();
        light.color = msg.getU8();

        int speed = msg.getU16();
        int skull = msg.getU8();
        int shield = msg.getU8();

        int emblem = -1;
        if(thingId == 0x0061) // emblem is sent only in packet type 0x61
            emblem = msg.getU8();

        bool passable = (msg.getU8() == 0);

        if(creature) {
            creature->setHealthPercent(healthPercent);
            creature->setDirection(direction);
            creature->setOutfit(outfit);
            creature->setLight(light);
            creature->setSpeed(speed);
            creature->setSkull(skull);
            creature->setShield(shield);
            if(emblem != -1)
                creature->setEmblem(emblem);
            creature->setPassable(passable);
            creature->setDirection(direction);

            if(creature == m_localPlayer) {
                m_localPlayer->setKnown(true);
            }
        }

        thing = creature;
    } else if(thingId == 0x0063) { // creature turn
        parseCreatureTurn(msg);
    } else // item
        thing = internalGetItem(msg, thingId);

    return thing;
}
示例#16
0
void ProtocolLogin::parseMOTD(InputMessage& inputMessage)
{
    std::string motd = inputMessage.getString();
    callLuaField("onMotd", motd);
}
示例#17
0
void ProtocolLogin::parseError(InputMessage& inputMessage)
{
    std::string error = inputMessage.getString();
    callLuaField("onError", error, false);
}
示例#18
0
void ProtocolGame::parseFYIMessage(InputMessage& msg)
{
    msg.getString(); // message
}
示例#19
0
void ProtocolGame::parseWaitList(InputMessage& msg)
{
    msg.getString(); // message
    msg.getU8();// + 1 // time
}
示例#20
0
void ProtocolGame::parseAddMarker(InputMessage& msg)
{
    parsePosition(msg); // position
    msg.getU8(); // icon
    msg.getString(); // message
}
示例#21
0
void ProtocolGame::parseMessage(InputMessage& msg)
{
    try {
        while(!msg.eof()) {
            int opt = msg.getU8();

            switch(opt) {
            case Proto::GameServerInitGame:
                parsePlayerLogin(msg);
                break;
            case Proto::GameServerGMActions:
                parseGMActions(msg);
                break;
            case Proto::GameServerLoginError:
                parseLoginError(msg);
                break;
            case Proto::GameServerLoginAdvice:
                parseFYIMessage(msg);
                break;
            case Proto::GameServerLoginWait:
                parseWaitList(msg);
                break;
            case Proto::GameServerPing:
                parsePing(msg);
                break;
            //case Proto::GameServerChallange:
            case Proto::GameServerDead:
                parseDeath(msg);
                break;
            case Proto::GameServerFullMap:
                parseMapDescription(msg);
                break;
            case Proto::GameServerMapTopRow:
                parseMoveNorth(msg);
                break;
            case Proto::GameServerMapRightRow:
                parseMoveEast(msg);
                break;
            case Proto::GameServerMapBottomRow:
                parseMoveSouth(msg);
                break;
            case Proto::GameServerMapLeftRow:
                parseMoveWest(msg);
                break;
            case Proto::GameServerTileData:
                parseUpdateTile(msg);
                break;
            case Proto::GameServerCreateOnMap:
                parseTileAddThing(msg);
                break;
            case Proto::GameServerChangeOnMap:
                parseTileTransformThing(msg);
                break;
            case Proto::GameServerDeleteOnMap:
                parseTileRemoveThing(msg);
                break;
            case Proto::GameServerMoveCreature:
                parseCreatureMove(msg);
                break;
            case Proto::GameServerOpenContainer:
                parseOpenContainer(msg);
                break;
            case Proto::GameServerCloseContainer:
                parseCloseContainer(msg);
                break;
            case Proto::GameServerCreateContainer:
                parseContainerAddItem(msg);
                break;
            case Proto::GameServerChangeInContainer:
                parseContainerUpdateItem(msg);
                break;
            case Proto::GameServerDeleteInContainer:
                parseContainerRemoveItem(msg);
                break;
            case Proto::GameServerSetInventory:
                parseAddInventoryItem(msg);
                break;
            case Proto::GameServerDeleteInventory:
                parseRemoveInventoryItem(msg);
                break;
            case Proto::GameServerNpcOffer:
                parseOpenShopWindow(msg);
                break;
            case Proto::GameServerPlayerGoods:
                parsePlayerCash(msg);
                break;
            case Proto::GameServerCloseNpcTrade:
                parseCloseShopWindow(msg);
                break;
            case Proto::GameServerOwnOffer:
                parseSafeTradeRequest(msg);
                break;
            case Proto::GameServerCounterOffer:
                parseSafeTradeRequest(msg);
                break;
            case Proto::GameServerCloseTrade:
                parseSafeTradeClose(msg);
                break;
            case Proto::GameServerAmbient:
                parseWorldLight(msg);
                break;
            case Proto::GameServerGraphicalEffect:
                parseMagicEffect(msg);
                break;
            case Proto::GameServerTextEffect:
                parseAnimatedText(msg);
                break;
            case Proto::GameServerMissleEffect:
                parseDistanceMissile(msg);
                break;
            case Proto::GameServerMarkCreature:
                parseCreatureSquare(msg);
                break;
            //case Proto::GameServerTrappers
            case Proto::GameServerCreatureHealth:
                parseCreatureHealth(msg);
                break;
            case Proto::GameServerCreatureLight:
                parseCreatureLight(msg);
                break;
            case Proto::GameServerCreatureOutfit:
                parseCreatureOutfit(msg);
                break;
            case Proto::GameServerCreatureSpeed:
                parseCreatureSpeed(msg);
                break;
            case Proto::GameServerCreatureSkull:
                parseCreatureSkulls(msg);
                break;
            case Proto::GameServerCreatureParty:
                parseCreatureShields(msg);
                break;
            // case Proto::GameServerCreatureUnpass
            case Proto::GameServerEditText:
                parseItemTextWindow(msg);
                break;
            case Proto::GameServerEditList:
                parseHouseTextWindow(msg);
                break;
            case Proto::GameServerPlayerData:
                parsePlayerStats(msg);
                break;
            case Proto::GameServerPlayerSkills:
                parsePlayerSkills(msg);
                break;
            case Proto::GameServerPlayerState:
                parsePlayerIcons(msg);
                break;
            case Proto::GameServerClearTarget:
                parsePlayerCancelAttack(msg);
                break;
            //case Proto::GameServerSpellDelay:
            //case Proto::GameServerSpellGroupDelay:
            case Proto::GameServerTalk:
                parseCreatureSpeak(msg);
                break;
            case Proto::GameServerChannels:
                parseChannelList(msg);
                break;
            case Proto::GameServerOpenChannel:
                parseOpenChannel(msg);
                break;
            case Proto::GameServerPrivateChannel:
                parseOpenPrivatePlayerChat(msg);
                break;
            case Proto::GameServerRuleViolationChannel:
                msg.getU16();
                break;
            case Proto::GameServerRuleViolationRemove:
                msg.getString();
                break;
            case Proto::GameServerRuleViolationCancel:
                msg.getString();
                break;
            case Proto::GameServerRuleViolationLock:
                break;
            case Proto::GameServerOpenOwnChannel:
                parseCreatePrivateChannel(msg);
                break;
            case Proto::GameServerCloseChannel:
                parseClosePrivateChannel(msg);
                break;
            case Proto::GameServerMessage:
                parseTextMessage(msg);
                break;
            case Proto::GameServerSnapBack:
                parseCancelWalk(msg);
                break;
            //case Proto::GameServerWait:
            case Proto::GameServerTopFloor:
                parseFloorChangeUp(msg);
                break;
            case Proto::GameServerBottomFloor:
                parseFloorChangeDown(msg);
                break;
            case Proto::GameServerOutfit:
                parseOutfitWindow(msg);
                break;
            case Proto::GameServerBuddyData:
                parseVipState(msg);
                break;
            case Proto::GameServerBuddyLogin:
                parseVipLogin(msg);
                break;
            case Proto::GameServerBuddyLogout:
                parseVipLogout(msg);
                break;
            case Proto::GameServerTutorialHint:
                parseShowTutorial(msg);
                break;
            case Proto::GameServerAutomapFlag:
                parseAddMarker(msg);
                break;
            case Proto::GameServerQuestLog:
                parseQuestList(msg);
                break;
            case Proto::GameServerQuestLine:
                parseQuestPartList(msg);
                break;
            //case Proto::GameServerChannelEvent:
            //case Proto::GameServerObjectInfo:
            //case Proto::GameServerPlayerInventory:
            default:
                Fw::throwException("unknown opt byte ", (int)opt);
                break;
            }
        }
    } catch(Exception& e) {
        logTraceError(e.what());
    }
}
示例#22
0
void ProtocolGame::parseCreatePrivateChannel(InputMessage& msg)
{
    msg.getU16(); // channel id
    msg.getString(); // channel name
}
示例#23
0
void ProtocolGame::parseOpenPrivatePlayerChat(InputMessage& msg)
{
    msg.getString(); // name
}
示例#24
0
void ProtocolGame::parseHouseTextWindow(InputMessage& msg)
{
    msg.getU8(); // unknown
    msg.getU32(); // windowId
    msg.getString(); // text
}
示例#25
0
void ProtocolGame::parseLoginError(InputMessage& msg)
{
    std::string error = msg.getString();
    g_game.processLoginError(error);
}