2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-08-28 15:17:58 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
#include "protocolgame.h"
|
|
|
|
|
2012-07-14 03:10:24 +02:00
|
|
|
#include "localplayer.h"
|
|
|
|
#include "thingtypemanager.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "effect.h"
|
|
|
|
#include "missile.h"
|
|
|
|
#include "tile.h"
|
|
|
|
#include "luavaluecasts.h"
|
2011-08-29 16:14:21 +02:00
|
|
|
#include <framework/core/eventdispatcher.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMessage(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-11 20:02:57 +02:00
|
|
|
int opcode = 0;
|
|
|
|
int prevOpcode = 0;
|
|
|
|
|
2011-12-01 23:25:32 +01:00
|
|
|
try {
|
2012-05-14 23:36:54 +02:00
|
|
|
while(!msg->eof()) {
|
|
|
|
opcode = msg->getU8();
|
|
|
|
|
|
|
|
// try to parse in lua first
|
2012-07-18 01:49:21 +02:00
|
|
|
int readPos = msg->getReadPos();
|
2012-05-14 23:36:54 +02:00
|
|
|
if(callLuaField<bool>("onOpcode", opcode, msg))
|
|
|
|
continue;
|
2012-07-18 01:49:21 +02:00
|
|
|
else
|
|
|
|
msg->setReadPos(readPos); // restore read pos
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-05-17 17:24:41 +02:00
|
|
|
if(!m_gameInitialized && opcode > Proto::GameServerFirstGameOpcode)
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.warning("received a game opcode from the server, but the game is not initialized yet, this is a server side bug");
|
2012-05-11 21:25:29 +02:00
|
|
|
|
2012-05-02 02:41:42 +02:00
|
|
|
switch(opcode) {
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerInitGame:
|
2012-02-08 00:54:33 +01:00
|
|
|
parseInitGame(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-10 03:55:56 +01:00
|
|
|
case Proto::GameServerGMActions:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseGMActions(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerLoginError:
|
2011-11-11 21:26:10 +01:00
|
|
|
parseLoginError(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerLoginAdvice:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseLoginAdvice(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerLoginWait:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseLoginWait(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerPing:
|
2012-07-18 01:49:21 +02:00
|
|
|
case Proto::GameServerPingBack:
|
|
|
|
if((opcode == Proto::GameServerPing && g_game.getProtocolVersion() >= 953) ||
|
|
|
|
(opcode == Proto::GameServerPingBack && g_game.getProtocolVersion() < 953))
|
2012-05-29 00:04:44 +02:00
|
|
|
parsePingBack(msg);
|
|
|
|
else
|
|
|
|
parsePing(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-05-12 06:52:16 +02:00
|
|
|
case Proto::GameServerChallange:
|
|
|
|
parseChallange(msg);
|
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerDeath:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseDeath(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerFullMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMapDescription(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMapTopRow:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseMapMoveNorth(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMapRightRow:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseMapMoveEast(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMapBottomRow:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseMapMoveSouth(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMapLeftRow:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseMapMoveWest(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerUpdateTile:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseUpdateTile(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreateOnMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTileAddThing(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerChangeOnMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTileTransformThing(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerDeleteOnMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTileRemoveThing(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMoveCreature:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureMove(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerOpenContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenContainer(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCloseContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCloseContainer(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreateContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseContainerAddItem(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerChangeInContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseContainerUpdateItem(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerDeleteInContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseContainerRemoveItem(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerSetInventory:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseAddInventoryItem(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerDeleteInventory:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseRemoveInventoryItem(msg);
|
|
|
|
break;
|
2012-02-09 04:45:19 +01:00
|
|
|
case Proto::GameServerOpenNpcTrade:
|
|
|
|
parseOpenNpcTrade(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerPlayerGoods:
|
2012-02-09 04:45:19 +01:00
|
|
|
parsePlayerGoods(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCloseNpcTrade:
|
2012-02-09 04:45:19 +01:00
|
|
|
parseCloseNpcTrade(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-09 04:45:19 +01:00
|
|
|
case Proto::GameServerOwnTrade:
|
2012-05-01 04:59:17 +02:00
|
|
|
parseOwnTrade(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-09 04:45:19 +01:00
|
|
|
case Proto::GameServerCounterTrade:
|
2012-05-01 04:59:17 +02:00
|
|
|
parseCounterTrade(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCloseTrade:
|
2012-02-09 04:45:19 +01:00
|
|
|
parseCloseTrade(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerAmbient:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseWorldLight(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerGraphicalEffect:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMagicEffect(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerTextEffect:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseAnimatedText(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMissleEffect:
|
2011-11-12 07:24:32 +01:00
|
|
|
parseDistanceMissile(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerMarkCreature:
|
2012-02-09 04:45:19 +01:00
|
|
|
parseCreatureMark(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-05-12 13:55:22 +02:00
|
|
|
case Proto::GameServerTrappers:
|
|
|
|
parseTrappers(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreatureHealth:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureHealth(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreatureLight:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureLight(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreatureOutfit:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureOutfit(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreatureSpeed:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSpeed(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreatureSkull:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSkulls(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCreatureParty:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureShields(msg);
|
|
|
|
break;
|
2012-03-18 21:59:00 +01:00
|
|
|
case Proto::GameServerCreatureUnpass:
|
2012-04-28 17:12:02 +02:00
|
|
|
parseCreatureUnpass(msg);
|
2012-03-18 21:59:00 +01:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerEditText:
|
2012-02-09 04:45:19 +01:00
|
|
|
parseEditText(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerEditList:
|
2012-02-09 04:45:19 +01:00
|
|
|
parseEditList(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerPlayerData:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerStats(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerPlayerSkills:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerSkills(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerPlayerState:
|
2012-02-09 04:45:19 +01:00
|
|
|
parsePlayerState(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerClearTarget:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerCancelAttack(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerTalk:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSpeak(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerChannels:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseChannelList(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerOpenChannel:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenChannel(msg);
|
|
|
|
break;
|
2012-02-02 23:29:44 +01:00
|
|
|
case Proto::GameServerOpenPrivateChannel:
|
|
|
|
parseOpenPrivateChannel(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-10 03:46:20 +01:00
|
|
|
case Proto::GameServerRuleViolationChannel:
|
2012-05-01 00:24:50 +02:00
|
|
|
parseRuleViolationChannel(msg);
|
2012-01-10 03:46:20 +01:00
|
|
|
break;
|
|
|
|
case Proto::GameServerRuleViolationRemove:
|
2012-05-01 00:24:50 +02:00
|
|
|
parseRuleViolationRemove(msg);
|
2012-01-10 03:46:20 +01:00
|
|
|
break;
|
|
|
|
case Proto::GameServerRuleViolationCancel:
|
2012-05-01 00:24:50 +02:00
|
|
|
parseRuleViolationCancel(msg);
|
2012-01-10 03:46:20 +01:00
|
|
|
break;
|
|
|
|
case Proto::GameServerRuleViolationLock:
|
2012-05-01 00:24:50 +02:00
|
|
|
parseRuleViolationLock(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerOpenOwnChannel:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseOpenOwnPrivateChannel(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerCloseChannel:
|
2012-02-02 23:29:44 +01:00
|
|
|
parseCloseChannel(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerTextMessage:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTextMessage(msg);
|
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerCancelWalk:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCancelWalk(msg);
|
|
|
|
break;
|
2012-05-12 13:55:22 +02:00
|
|
|
case Proto::GameServerWalkWait:
|
|
|
|
parseWalkWait(msg);
|
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerFloorChangeUp:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseFloorChangeUp(msg);
|
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerFloorChangeDown:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseFloorChangeDown(msg);
|
|
|
|
break;
|
2012-02-09 04:45:19 +01:00
|
|
|
case Proto::GameServerChooseOutfit:
|
|
|
|
parseOpenOutfitWindow(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerVipAdd:
|
|
|
|
parseVipAdd(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerVipLogin:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseVipLogin(msg);
|
|
|
|
break;
|
2012-02-08 22:23:15 +01:00
|
|
|
case Proto::GameServerVipLogout:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseVipLogout(msg);
|
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerTutorialHint:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseTutorialHint(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerAutomapFlag:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseAutomapFlag(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerQuestLog:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseQuestLog(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-01-08 19:29:41 +01:00
|
|
|
case Proto::GameServerQuestLine:
|
2012-02-08 22:23:15 +01:00
|
|
|
parseQuestLine(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-05-12 13:55:22 +02:00
|
|
|
// PROTOCOL>=870
|
2012-05-12 06:52:16 +02:00
|
|
|
case Proto::GameServerSpellDelay:
|
2012-05-12 03:44:13 +02:00
|
|
|
parseSpellDelay(msg);
|
|
|
|
break;
|
2012-05-12 06:52:16 +02:00
|
|
|
case Proto::GameServerSpellGroupDelay:
|
2012-05-12 03:44:13 +02:00
|
|
|
parseSpellGroupDelay(msg);
|
|
|
|
break;
|
2012-05-12 13:55:22 +02:00
|
|
|
case Proto::GameServerMultiUseDelay:
|
|
|
|
parseMultiUseDelay(msg);
|
|
|
|
break;
|
|
|
|
// PROTOCOL>=910
|
2012-05-12 06:52:16 +02:00
|
|
|
case Proto::GameServerPlayerDataBasic:
|
|
|
|
parsePlayerInfo(msg);
|
|
|
|
break;
|
|
|
|
case Proto::GameServerChannelEvent:
|
2012-05-12 03:44:13 +02:00
|
|
|
parseChannelEvent(msg);
|
|
|
|
break;
|
2012-05-12 13:55:22 +02:00
|
|
|
case Proto::GameServerItemInfo:
|
|
|
|
parseItemInfo(msg);
|
2012-05-12 03:44:13 +02:00
|
|
|
break;
|
2012-05-12 06:52:16 +02:00
|
|
|
case Proto::GameServerPlayerInventory:
|
2012-05-12 03:44:13 +02:00
|
|
|
parsePlayerInventory(msg);
|
|
|
|
break;
|
2012-05-12 13:55:22 +02:00
|
|
|
// otclient ONLY
|
2012-05-12 03:44:13 +02:00
|
|
|
case Proto::GameServerExtendedOpcode:
|
2012-05-02 02:41:42 +02:00
|
|
|
parseExtendedOpcode(msg);
|
|
|
|
break;
|
2011-08-15 16:11:24 +02:00
|
|
|
default:
|
2012-05-28 15:06:26 +02:00
|
|
|
stdext::throw_exception("unknown opcode");
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2011-12-01 23:25:32 +01:00
|
|
|
}
|
2012-05-11 20:02:57 +02:00
|
|
|
prevOpcode = opcode;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2012-05-28 15:06:26 +02:00
|
|
|
} catch(stdext::exception& e) {
|
2012-06-06 16:10:35 +02:00
|
|
|
g_logger.error(stdext::format("ProtocolGame parse message exception (%d bytes unread, last opcode is %d, prev opcode is %d): %s",
|
|
|
|
msg->getUnreadSize(), opcode, prevOpcode, e.what()));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseInitGame(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-12 06:52:16 +02:00
|
|
|
m_gameInitialized = true;
|
2012-05-14 23:36:54 +02:00
|
|
|
uint playerId = msg->getU32();
|
|
|
|
int serverBeat = msg->getU16();
|
|
|
|
bool canReportBugs = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
m_localPlayer->setId(playerId);
|
2012-05-01 00:24:50 +02:00
|
|
|
g_game.processGameStart(m_localPlayer, serverBeat, canReportBugs);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseGMActions(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-01 00:24:50 +02:00
|
|
|
std::vector<uint8> actions;
|
2012-05-29 00:04:44 +02:00
|
|
|
|
|
|
|
int numViolationReasons;
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 860)
|
2012-05-29 00:04:44 +02:00
|
|
|
numViolationReasons = 20;
|
2012-07-18 01:49:21 +02:00
|
|
|
else if(g_game.getProtocolVersion() >= 854)
|
2012-05-29 00:04:44 +02:00
|
|
|
numViolationReasons = 19;
|
|
|
|
else
|
|
|
|
numViolationReasons = 32;
|
|
|
|
|
|
|
|
for(int i = 0; i < numViolationReasons; ++i)
|
2012-05-14 23:36:54 +02:00
|
|
|
actions.push_back(msg->getU8());
|
2012-05-01 00:24:50 +02:00
|
|
|
g_game.processGMActions(actions);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseLoginError(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string error = msg->getString();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
g_game.processLoginError(error);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseLoginAdvice(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string message = msg->getString();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
g_game.processLoginAdvice(message);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseLoginWait(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string message = msg->getString();
|
|
|
|
int time = msg->getU8();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
g_game.processLoginWait(message, time);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePing(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.processPing();
|
2012-05-12 13:55:22 +02:00
|
|
|
sendPingBack();
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePingBack(const InputMessagePtr& msg)
|
2012-05-12 13:55:22 +02:00
|
|
|
{
|
|
|
|
// nothing to do
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseChallange(const InputMessagePtr& msg)
|
2012-05-12 06:52:16 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint timestamp = msg->getU32();
|
|
|
|
uint8 random = msg->getU8();
|
2012-05-12 06:52:16 +02:00
|
|
|
sendLoginPacket(timestamp, random);
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseDeath(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
int penality = 100;
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GamePenalityOnDeath))
|
|
|
|
penality = msg->getU8();
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.processDeath(penality);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMapDescription(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position pos = getPosition(msg);
|
2011-08-30 03:34:00 +02:00
|
|
|
g_map.setCentralPosition(pos);
|
2012-01-30 19:18:10 +01:00
|
|
|
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMapMoveNorth(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-30 03:34:00 +02:00
|
|
|
Position pos = g_map.getCentralPosition();
|
|
|
|
pos.y--;
|
|
|
|
|
2012-01-30 19:18:10 +01:00
|
|
|
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, 1);
|
2011-08-30 03:34:00 +02:00
|
|
|
g_map.setCentralPosition(pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMapMoveEast(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-30 03:34:00 +02:00
|
|
|
Position pos = g_map.getCentralPosition();
|
|
|
|
pos.x++;
|
|
|
|
|
2012-01-30 19:18:10 +01:00
|
|
|
setMapDescription(msg, pos.x + Otc::AWARE_X_RIGHT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, 1, Otc::AWARE_Y_TILES);
|
2011-08-30 03:34:00 +02:00
|
|
|
g_map.setCentralPosition(pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMapMoveSouth(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-30 03:34:00 +02:00
|
|
|
Position pos = g_map.getCentralPosition();
|
|
|
|
pos.y++;
|
|
|
|
|
2012-01-30 19:18:10 +01:00
|
|
|
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y + Otc::AWARE_Y_BOTTOM_TILES, pos.z, Otc::AWARE_X_TILES, 1);
|
2011-08-30 03:34:00 +02:00
|
|
|
g_map.setCentralPosition(pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMapMoveWest(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-30 03:34:00 +02:00
|
|
|
Position pos = g_map.getCentralPosition();
|
|
|
|
pos.x--;
|
|
|
|
|
2012-01-30 19:18:10 +01:00
|
|
|
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, 1, Otc::AWARE_Y_TILES);
|
2011-08-30 03:34:00 +02:00
|
|
|
g_map.setCentralPosition(pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseUpdateTile(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position tilePos = getPosition(msg);
|
2012-05-15 02:04:04 +02:00
|
|
|
int thingId = msg->peekU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
if(thingId == 0xFF01) {
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16();
|
2012-01-09 06:23:39 +01:00
|
|
|
} else {
|
2011-08-15 16:11:24 +02:00
|
|
|
setTileDescription(msg, tilePos);
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseTileAddThing(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position pos = getPosition(msg);
|
2012-05-11 20:02:57 +02:00
|
|
|
int stackPos = -1;
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 854)
|
2012-05-29 00:04:44 +02:00
|
|
|
stackPos = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
ThingPtr thing = getThing(msg);
|
2011-08-31 22:22:57 +02:00
|
|
|
g_map.addThing(thing, pos, stackPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseTileTransformThing(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position pos = getPosition(msg);
|
|
|
|
int stackPos = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
ThingPtr thing = getThing(msg);
|
2012-05-12 22:16:33 +02:00
|
|
|
if(thing) {
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!g_map.removeThingByPos(pos, stackPos))
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not remove thing");
|
2011-08-31 22:22:57 +02:00
|
|
|
g_map.addThing(thing, pos, stackPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseTileRemoveThing(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position pos = getPosition(msg);
|
|
|
|
int stackPos = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!g_map.removeThingByPos(pos, stackPos))
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not remove thing");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position oldPos = getPosition(msg);
|
|
|
|
int oldStackpos = msg->getU8();
|
|
|
|
Position newPos = getPosition(msg);
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-01-30 01:00:12 +01:00
|
|
|
ThingPtr thing = g_map.getThing(oldPos, oldStackpos);
|
2011-12-28 12:00:09 +01:00
|
|
|
if(!thing) {
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get thing");
|
2011-12-28 12:00:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
CreaturePtr creature = thing->asCreature();
|
2011-12-28 12:00:09 +01:00
|
|
|
if(!creature) {
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("thing is not a creature");
|
2011-12-28 12:00:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-05 21:34:49 +01:00
|
|
|
// update map tiles
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!g_map.removeThing(thing))
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not remove thing");
|
2012-07-09 13:37:47 +02:00
|
|
|
|
2012-07-15 16:28:15 +02:00
|
|
|
int stackPos = -2;
|
|
|
|
|
|
|
|
// older protocols stores creatures in reverse order
|
2012-07-18 01:49:21 +02:00
|
|
|
if(!g_game.getProtocolVersion() >= 854)
|
2012-07-15 16:28:15 +02:00
|
|
|
stackPos = -1;
|
|
|
|
|
|
|
|
g_map.addThing(thing, newPos, stackPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int containerId = msg->getU8();
|
|
|
|
ItemPtr containerItem = getItem(msg);
|
|
|
|
std::string name = msg->getString();
|
|
|
|
int capacity = msg->getU8();
|
|
|
|
bool hasParent = (msg->getU8() != 0);
|
|
|
|
int itemCount = msg->getU8();
|
2012-01-12 20:25:58 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
std::vector<ItemPtr> items(itemCount);
|
|
|
|
for(int i = 0; i < itemCount; i++)
|
2012-05-14 23:36:54 +02:00
|
|
|
items[i] = getItem(msg);
|
2012-01-20 03:33:11 +01:00
|
|
|
|
2012-05-12 06:52:16 +02:00
|
|
|
g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int containerId = msg->getU8();
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processCloseContainer(containerId);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseContainerAddItem(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int containerId = msg->getU8();
|
|
|
|
ItemPtr item = getItem(msg);
|
2012-01-13 01:31:39 +01:00
|
|
|
g_game.processContainerAddItem(containerId, item);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseContainerUpdateItem(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int containerId = msg->getU8();
|
|
|
|
int slot = msg->getU8();
|
|
|
|
ItemPtr item = getItem(msg);
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processContainerUpdateItem(containerId, slot, item);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseContainerRemoveItem(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int containerId = msg->getU8();
|
|
|
|
int slot = msg->getU8();
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processContainerRemoveItem(containerId, slot);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseAddInventoryItem(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int slot = msg->getU8();
|
|
|
|
ItemPtr item = getItem(msg);
|
2012-01-09 06:23:39 +01:00
|
|
|
g_game.processInventoryChange(slot, item);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseRemoveInventoryItem(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int slot = msg->getU8();
|
2012-01-09 06:23:39 +01:00
|
|
|
g_game.processInventoryChange(slot, ItemPtr());
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
std::vector<std::tuple<ItemPtr, std::string, int, int, int>> items;
|
2012-05-12 03:44:13 +02:00
|
|
|
std::string npcName;
|
|
|
|
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GameNameOnNpcTrade))
|
|
|
|
npcName = msg->getString();
|
2012-05-12 03:44:13 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int listCount = msg->getU8();
|
2012-01-12 20:20:18 +01:00
|
|
|
for(int i = 0; i < listCount; ++i) {
|
2012-05-14 23:36:54 +02:00
|
|
|
uint16 itemId = msg->getU16();
|
|
|
|
uint8 count = msg->getU8();
|
2012-04-28 17:30:19 +02:00
|
|
|
|
|
|
|
ItemPtr item = Item::create(itemId);
|
|
|
|
item->setCountOrSubType(count);
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
|
|
|
int weight = msg->getU32();
|
|
|
|
int buyPrice = msg->getU32();
|
|
|
|
int sellPrice = msg->getU32();
|
2012-02-09 04:45:19 +01:00
|
|
|
items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
g_game.processOpenNpcTrade(items);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
std::vector<std::tuple<ItemPtr, int>> goods;
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int money = msg->getU32();
|
|
|
|
int size = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
for(int i = 0; i < size; i++) {
|
2012-05-14 23:36:54 +02:00
|
|
|
int itemId = msg->getU16();
|
|
|
|
int count = msg->getU8();
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
goods.push_back(std::make_tuple(Item::create(itemId), count));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
g_game.processPlayerGoods(money, goods);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCloseNpcTrade(const InputMessagePtr&)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processCloseNpcTrade();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOwnTrade(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
|
|
|
int count = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
std::vector<ItemPtr> items(count);
|
2012-01-12 20:20:18 +01:00
|
|
|
for(int i = 0; i < count; i++)
|
2012-05-14 23:36:54 +02:00
|
|
|
items[i] = getItem(msg);
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-05-01 04:59:17 +02:00
|
|
|
g_game.processOwnTrade(name, items);
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCounterTrade(const InputMessagePtr& msg)
|
2012-05-01 04:59:17 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
|
|
|
int count = msg->getU8();
|
2012-05-01 04:59:17 +02:00
|
|
|
|
|
|
|
std::vector<ItemPtr> items(count);
|
|
|
|
for(int i = 0; i < count; i++)
|
2012-05-14 23:36:54 +02:00
|
|
|
items[i] = getItem(msg);
|
2012-05-01 04:59:17 +02:00
|
|
|
|
|
|
|
g_game.processCounterTrade(name, items);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCloseTrade(const InputMessagePtr&)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processCloseTrade();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseWorldLight(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
Light light;
|
2012-05-14 23:36:54 +02:00
|
|
|
light.intensity = msg->getU8();
|
|
|
|
light.color = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
g_map.setLight(light);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position pos = getPosition(msg);
|
2012-06-06 01:46:36 +02:00
|
|
|
int effectId;
|
|
|
|
if(g_game.getFeature(Otc::GameMagicEffectU16))
|
|
|
|
effectId = msg->getU16();
|
|
|
|
else
|
|
|
|
effectId = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-12-30 09:19:43 +01:00
|
|
|
EffectPtr effect = EffectPtr(new Effect());
|
|
|
|
effect->setId(effectId);
|
|
|
|
g_map.addThing(effect, pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseAnimatedText(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position position = getPosition(msg);
|
|
|
|
int color = msg->getU8();
|
|
|
|
std::string text = msg->getString();
|
2011-12-26 12:53:16 +01:00
|
|
|
|
|
|
|
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
|
|
|
|
animatedText->setColor(color);
|
|
|
|
animatedText->setText(text);
|
|
|
|
g_map.addThing(animatedText, position);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseDistanceMissile(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Position fromPos = getPosition(msg);
|
|
|
|
Position toPos = getPosition(msg);
|
|
|
|
int shotId = msg->getU8();
|
2011-11-08 02:44:30 +01:00
|
|
|
|
2012-01-30 01:00:12 +01:00
|
|
|
MissilePtr missile = MissilePtr(new Missile());
|
|
|
|
missile->setId(shotId);
|
|
|
|
missile->setPath(fromPos, toPos);
|
|
|
|
g_map.addThing(missile, fromPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureMark(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
int color = msg->getU8();
|
2011-11-13 23:23:21 +01:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
2012-02-08 03:11:57 +01:00
|
|
|
creature->addTimedSquare(color);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseTrappers(const InputMessagePtr& msg)
|
2012-05-12 13:55:22 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int numTrappers = msg->getU8();
|
2012-05-12 13:55:22 +02:00
|
|
|
|
|
|
|
if(numTrappers > 8)
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("too many trappers");
|
2012-05-12 13:55:22 +02:00
|
|
|
|
|
|
|
for(int i=0;i<numTrappers;++i) {
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2012-05-12 13:55:22 +02:00
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature) {
|
|
|
|
//TODO: set creature as trapper
|
|
|
|
} else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2012-05-12 13:55:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureHealth(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
int healthPercent = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setHealthPercent(healthPercent);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
Light light;
|
2012-05-14 23:36:54 +02:00
|
|
|
light.intensity = msg->getU8();
|
|
|
|
light.color = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setLight(light);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureOutfit(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
Outfit outfit = getOutfit(msg);
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setOutfit(outfit);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureSpeed(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
int speed = msg->getU16();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setSpeed(speed);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureSkulls(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
int skull = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setSkull(skull);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureShields(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
int shield = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setShield(shield);
|
2012-02-09 04:45:19 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureUnpass(const InputMessagePtr& msg)
|
2012-04-28 17:12:02 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
bool unpass = msg->getU8();
|
2012-04-28 17:12:02 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setPassable(!unpass);
|
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("could not get creature");
|
2012-04-28 17:12:02 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseEditText(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
int itemId = msg->getU16();
|
|
|
|
int maxLength = msg->getU16();
|
|
|
|
std::string text = msg->getString();
|
|
|
|
std::string writter = msg->getString();
|
|
|
|
std::string date = msg->getString();
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
g_game.processEditText(id, itemId, maxLength, text, writter, date);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseEditList(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int doorId = msg->getU8();
|
|
|
|
uint id = msg->getU32();
|
|
|
|
const std::string& text = msg->getString();
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-05-01 02:53:02 +02:00
|
|
|
g_game.processEditList(id, doorId, text);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg)
|
2012-05-12 06:52:16 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU8(); // is premium?
|
|
|
|
msg->getU8(); // profession
|
|
|
|
int numSpells = msg->getU16();
|
2012-05-12 06:52:16 +02:00
|
|
|
for(int i=0;i<numSpells;++i) {
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16(); // spell id
|
2012-05-12 06:52:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
double health = msg->getU16();
|
|
|
|
double maxHealth = msg->getU16();
|
2012-05-29 00:04:44 +02:00
|
|
|
|
|
|
|
double freeCapacity;
|
|
|
|
if(g_game.getFeature(Otc::GameDoubleFreeCapacity))
|
|
|
|
freeCapacity = msg->getU32() / 100.0;
|
|
|
|
else
|
|
|
|
freeCapacity = msg->getU16() / 100.0;
|
|
|
|
|
|
|
|
double totalCapacity;
|
|
|
|
if(g_game.getFeature(Otc::GameTotalCapacity))
|
|
|
|
totalCapacity = msg->getU32() / 100.0;
|
|
|
|
|
|
|
|
double experience;
|
|
|
|
if(g_game.getFeature(Otc::GameDoubleExperience))
|
|
|
|
experience = msg->getU64();
|
|
|
|
else
|
|
|
|
experience = msg->getU32();
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
double level = msg->getU16();
|
|
|
|
double levelPercent = msg->getU8();
|
|
|
|
double mana = msg->getU16();
|
|
|
|
double maxMana = msg->getU16();
|
|
|
|
double magicLevel = msg->getU8();
|
2012-05-29 00:04:44 +02:00
|
|
|
|
|
|
|
if(g_game.getFeature(Otc::GameSkillsBase))
|
|
|
|
msg->getU8(); // base magic level
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
double magicLevelPercent = msg->getU8();
|
|
|
|
double soul = msg->getU8();
|
|
|
|
double stamina = msg->getU16();
|
2012-01-11 22:21:52 +01:00
|
|
|
|
2012-05-11 21:25:29 +02:00
|
|
|
m_localPlayer->setHealth(health, maxHealth);
|
|
|
|
m_localPlayer->setFreeCapacity(freeCapacity);
|
|
|
|
m_localPlayer->setExperience(experience);
|
|
|
|
m_localPlayer->setLevel(level, levelPercent);
|
|
|
|
m_localPlayer->setMana(mana, maxMana);
|
|
|
|
m_localPlayer->setMagicLevel(magicLevel, magicLevelPercent);
|
|
|
|
m_localPlayer->setStamina(stamina);
|
|
|
|
m_localPlayer->setSoul(soul);
|
2012-05-12 03:44:13 +02:00
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 910)
|
|
|
|
m_localPlayer->setSpeed(msg->getU16());
|
2012-05-12 03:44:13 +02:00
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getFeature(Otc::GamePlayerRegenerationTime))
|
2012-07-18 08:04:57 +02:00
|
|
|
msg->getU16();
|
|
|
|
|
|
|
|
if(g_game.getFeature(Otc::GameOfflineTrainingTime))
|
|
|
|
msg->getU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-11-03 23:14:56 +01:00
|
|
|
for(int skill = 0; skill < Otc::LastSkill; skill++) {
|
2012-05-14 23:36:54 +02:00
|
|
|
int level = msg->getU8();
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GameSkillsBase))
|
|
|
|
msg->getU8(); // base
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int levelPercent = msg->getU8();
|
2011-11-03 23:14:56 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
m_localPlayer->setSkill((Otc::Skill)skill, level, levelPercent);
|
2011-11-03 23:14:56 +01:00
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerState(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int states = msg->getU16();
|
2012-05-12 03:44:13 +02:00
|
|
|
m_localPlayer->setStates(states);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 860)
|
2012-05-29 00:04:44 +02:00
|
|
|
msg->getU32(); // unknown
|
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
g_game.processAttackCancel();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseSpellDelay(const InputMessagePtr& msg)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16(); // spell id
|
|
|
|
msg->getU16(); // cooldown
|
|
|
|
msg->getU8(); // unknown
|
2012-05-01 00:24:50 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseSpellGroupDelay(const InputMessagePtr& msg)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16(); // spell id
|
|
|
|
msg->getU16(); // cooldown
|
|
|
|
msg->getU8(); // unknown
|
2012-05-01 00:24:50 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseMultiUseDelay(const InputMessagePtr& msg)
|
2012-05-12 13:55:22 +02:00
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCreatureSpeak(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU32(); // channel statement guid
|
2012-05-01 00:24:50 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
|
|
|
int level = msg->getU16();
|
|
|
|
int speakType = msg->getU8();
|
2011-12-07 16:33:00 +01:00
|
|
|
int channelId = 0;
|
2011-11-19 01:12:17 +01:00
|
|
|
Position creaturePos;
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-11 20:02:57 +02:00
|
|
|
switch(speakType) {
|
2012-02-03 01:25:18 +01:00
|
|
|
case Proto::ServerSpeakSay:
|
|
|
|
case Proto::ServerSpeakWhisper:
|
|
|
|
case Proto::ServerSpeakYell:
|
|
|
|
case Proto::ServerSpeakMonsterSay:
|
|
|
|
case Proto::ServerSpeakMonsterYell:
|
|
|
|
case Proto::ServerSpeakPrivateNpcToPlayer:
|
2012-05-14 23:36:54 +02:00
|
|
|
creaturePos = getPosition(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-03 01:25:18 +01:00
|
|
|
case Proto::ServerSpeakChannelYellow:
|
|
|
|
case Proto::ServerSpeakChannelWhite:
|
|
|
|
case Proto::ServerSpeakChannelRed:
|
|
|
|
case Proto::ServerSpeakChannelRed2:
|
|
|
|
case Proto::ServerSpeakChannelOrange:
|
2012-05-14 23:36:54 +02:00
|
|
|
channelId = msg->getU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-05-12 03:44:13 +02:00
|
|
|
case Proto::ServerSpeakPrivateFrom:
|
2012-02-03 01:25:18 +01:00
|
|
|
case Proto::ServerSpeakPrivatePlayerToNpc:
|
|
|
|
case Proto::ServerSpeakBroadcast:
|
2012-05-12 03:44:13 +02:00
|
|
|
case Proto::ServerSpeakPrivateRedFrom:
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2012-02-03 01:25:18 +01:00
|
|
|
case Proto::ServerSpeakRVRChannel:
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU32();
|
2012-01-08 16:42:23 +01:00
|
|
|
break;
|
2012-05-12 03:44:13 +02:00
|
|
|
//case Proto::ServerSpeakChannelManagement:
|
|
|
|
//case Proto::ServerSpeakSpell:
|
2011-08-15 16:11:24 +02:00
|
|
|
default:
|
2012-05-28 15:06:26 +02:00
|
|
|
stdext::throw_exception(stdext::format("unknown speak type %d", speakType));
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string message = msg->getString();
|
2012-05-11 20:02:57 +02:00
|
|
|
Otc::SpeakType type = Proto::translateSpeakTypeFromServer(speakType);
|
2011-11-04 00:34:32 +01:00
|
|
|
|
2012-02-03 01:25:18 +01:00
|
|
|
g_game.processCreatureSpeak(name, level, type, message, channelId, creaturePos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseChannelList(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int count = msg->getU8();
|
2012-07-15 13:49:28 +02:00
|
|
|
std::vector<std::tuple<int, std::string> > channelList;
|
2011-11-19 01:12:17 +01:00
|
|
|
for(int i = 0; i < count; i++) {
|
2012-05-14 23:36:54 +02:00
|
|
|
int id = msg->getU16();
|
|
|
|
std::string name = msg->getString();
|
2011-11-19 01:12:17 +01:00
|
|
|
channelList.push_back(std::make_tuple(id, name));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2011-11-19 01:12:17 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processChannelList(channelList);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int channelId = msg->getU16();
|
|
|
|
std::string name = msg->getString();
|
2011-11-19 01:12:17 +01:00
|
|
|
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GameChannelPlayerList)) {
|
|
|
|
int joinedPlayers = msg->getU16();
|
|
|
|
for(int i=0;i<joinedPlayers;++i)
|
|
|
|
msg->getString(); // player name
|
|
|
|
int invitedPlayers = msg->getU16();
|
|
|
|
for(int i=0;i<invitedPlayers;++i)
|
|
|
|
msg->getString(); // player name
|
|
|
|
}
|
2012-05-12 22:16:33 +02:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processOpenChannel(channelId, name);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOpenPrivateChannel(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
2012-02-02 23:29:44 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processOpenPrivateChannel(name);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOpenOwnPrivateChannel(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int channelId = msg->getU16();
|
|
|
|
std::string name = msg->getString();
|
2012-02-02 23:29:44 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processOpenOwnPrivateChannel(channelId, name);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCloseChannel(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int channelId = msg->getU16();
|
2012-02-02 23:29:44 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processCloseChannel(channelId);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseRuleViolationChannel(const InputMessagePtr& msg)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int channelId = msg->getU16();
|
2012-05-01 00:24:50 +02:00
|
|
|
|
|
|
|
g_game.processRuleViolationChannel(channelId);
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseRuleViolationRemove(const InputMessagePtr& msg)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
2012-05-01 00:24:50 +02:00
|
|
|
|
|
|
|
g_game.processRuleViolationRemove(name);
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseRuleViolationCancel(const InputMessagePtr& msg)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
2012-05-01 00:24:50 +02:00
|
|
|
|
|
|
|
g_game.processRuleViolationCancel(name);
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseRuleViolationLock(const InputMessagePtr& msg)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
|
|
|
g_game.processRuleViolationLock();
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseTextMessage(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-07-19 11:12:17 +02:00
|
|
|
msg->getU8(); // type
|
|
|
|
msg->getString(); // message
|
|
|
|
// this is now handled by game_textmessage module
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseCancelWalk(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Otc::Direction direction = (Otc::Direction)msg->getU8();
|
2012-01-09 06:23:39 +01:00
|
|
|
|
|
|
|
g_game.processWalkCancel(direction);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseWalkWait(const InputMessagePtr& msg)
|
2012-05-12 13:55:22 +02:00
|
|
|
{
|
|
|
|
//TODO: implement walk wait time
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16(); // time
|
2012-05-12 13:55:22 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseFloorChangeUp(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-30 03:34:00 +02:00
|
|
|
Position pos = g_map.getCentralPosition();
|
2011-08-15 23:02:52 +02:00
|
|
|
pos.z--;
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-01-12 20:20:18 +01:00
|
|
|
int skip = 0;
|
2012-01-30 19:18:10 +01:00
|
|
|
if(pos.z == Otc::SEA_FLOOR)
|
|
|
|
for(int i = Otc::SEA_FLOOR - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; i >= 0; i--)
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 8 - i, skip);
|
2012-01-30 19:18:10 +01:00
|
|
|
else if(pos.z > Otc::SEA_FLOOR)
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 3, skip);
|
2011-08-15 23:02:52 +02:00
|
|
|
|
2011-08-30 03:34:00 +02:00
|
|
|
pos.x++;
|
|
|
|
pos.y++;
|
|
|
|
g_map.setCentralPosition(pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseFloorChangeDown(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2011-08-30 03:34:00 +02:00
|
|
|
Position pos = g_map.getCentralPosition();
|
|
|
|
pos.z++;
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
int skip = 0;
|
2012-01-30 19:18:10 +01:00
|
|
|
if(pos.z == Otc::UNDERGROUND_FLOOR) {
|
2011-08-15 23:02:52 +02:00
|
|
|
int j, i;
|
2012-01-30 19:18:10 +01:00
|
|
|
for(i = pos.z, j = -1; i <= pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE; ++i, --j)
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, j, skip);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2012-01-30 19:18:10 +01:00
|
|
|
else if(pos.z > Otc::UNDERGROUND_FLOOR && pos.z < Otc::MAX_Z-1)
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, -3, skip);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-30 03:34:00 +02:00
|
|
|
pos.x--;
|
|
|
|
pos.y--;
|
|
|
|
g_map.setCentralPosition(pos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
Outfit currentOutfit = getOutfit(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
std::vector<std::tuple<int, std::string, int> > outfitList;
|
2012-05-14 23:36:54 +02:00
|
|
|
int outfitCount = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
for(int i = 0; i < outfitCount; i++) {
|
2012-05-14 23:36:54 +02:00
|
|
|
int outfitId = msg->getU16();
|
|
|
|
std::string outfitName = msg->getString();
|
|
|
|
int outfitAddons = msg->getU8();
|
2011-11-14 23:32:55 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2011-11-14 23:32:55 +01:00
|
|
|
|
2012-07-17 16:36:27 +02:00
|
|
|
std::vector<std::tuple<int, std::string> > mountList;
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GamePlayerMounts)) {
|
|
|
|
int mountCount = msg->getU8();
|
2012-07-15 13:49:28 +02:00
|
|
|
for(int i = 0; i < mountCount; ++i) {
|
|
|
|
int mountId = msg->getU16(); // mount type
|
|
|
|
std::string mountName = msg->getString(); // mount name
|
2012-07-15 16:28:15 +02:00
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
mountList.push_back(std::make_tuple(mountId, mountName));
|
2012-05-29 00:04:44 +02:00
|
|
|
}
|
2012-03-18 21:59:00 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
g_game.processOpenOutfitWindow(currentOutfit, outfitList, mountList);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseVipAdd(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
|
|
|
std::string name = msg->getString();
|
|
|
|
bool online = msg->getU8() != 0;
|
2011-09-02 06:29:00 +02:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processVipAdd(id, name, online);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseVipLogin(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processVipStateChange(id, true);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseVipLogout(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2012-02-09 04:45:19 +01:00
|
|
|
g_game.processVipStateChange(id, false);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseTutorialHint(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int id = msg->getU8(); // tutorial id
|
2012-05-01 00:24:50 +02:00
|
|
|
g_game.processTutorialHint(id);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
// ignored
|
2012-05-14 23:36:54 +02:00
|
|
|
getPosition(msg); // position
|
|
|
|
msg->getU8(); // icon
|
|
|
|
msg->getString(); // message
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseQuestLog(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-07-15 13:49:28 +02:00
|
|
|
std::vector<std::tuple<int, std::string, bool> > questList;
|
2012-05-14 23:36:54 +02:00
|
|
|
int questsCount = msg->getU16();
|
2012-01-12 20:20:18 +01:00
|
|
|
for(int i = 0; i < questsCount; i++) {
|
2012-05-14 23:36:54 +02:00
|
|
|
int id = msg->getU16();
|
|
|
|
std::string name = msg->getString();
|
|
|
|
bool completed = msg->getU8();
|
2012-02-09 04:45:19 +01:00
|
|
|
questList.push_back(std::make_tuple(id, name, completed));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
g_game.processQuestLog(questList);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseQuestLine(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
std::vector<std::tuple<std::string, std::string>> questMissions;
|
2012-05-14 23:36:54 +02:00
|
|
|
int questId = msg->getU16();
|
|
|
|
int missionCount = msg->getU8();
|
2012-01-12 20:20:18 +01:00
|
|
|
for(int i = 0; i < missionCount; i++) {
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string missionName = msg->getString();
|
|
|
|
std::string missionDescrition = msg->getString();
|
2012-02-09 04:45:19 +01:00
|
|
|
questMissions.push_back(std::make_tuple(missionName, missionDescrition));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
g_game.processQuestLine(questId, questMissions);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseChannelEvent(const InputMessagePtr& msg)
|
2012-05-12 03:44:13 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
msg->getU16(); // channel id
|
|
|
|
msg->getString(); // player name
|
|
|
|
msg->getU8(); // event type
|
2012-05-12 03:44:13 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseItemInfo(const InputMessagePtr& msg)
|
2012-05-12 03:44:13 +02:00
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parsePlayerInventory(const InputMessagePtr& msg)
|
2012-05-12 03:44:13 +02:00
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg)
|
2012-05-02 02:41:42 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int opcode = msg->getU8();
|
|
|
|
std::string buffer = msg->getString();
|
2012-05-02 02:41:42 +02:00
|
|
|
|
2012-06-06 16:10:35 +02:00
|
|
|
if(opcode == 0)
|
2012-05-17 17:24:41 +02:00
|
|
|
m_enableSendExtendedOpcode = true;
|
2012-06-06 16:10:35 +02:00
|
|
|
else
|
|
|
|
callLuaField("onExtendedOpcode", opcode, buffer);
|
2012-05-02 02:41:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
int startz, endz, zstep;
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-01-30 19:18:10 +01:00
|
|
|
if(z > Otc::SEA_FLOOR) {
|
|
|
|
startz = z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE;
|
|
|
|
endz = std::min(z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, (int)Otc::MAX_Z);
|
2011-08-15 16:11:24 +02:00
|
|
|
zstep = 1;
|
|
|
|
}
|
|
|
|
else {
|
2012-01-30 19:18:10 +01:00
|
|
|
startz = Otc::SEA_FLOOR;
|
2011-08-15 16:11:24 +02:00
|
|
|
endz = 0;
|
|
|
|
zstep = -1;
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int skip = 0;
|
2011-08-15 16:11:24 +02:00
|
|
|
for(int nz = startz; nz != endz + zstep; nz += zstep)
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = setFloorDescription(msg, x, y, nz, width, height, z - nz, skip);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int ProtocolGame::setFloorDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height, int offset, int skip)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-01-12 20:20:18 +01:00
|
|
|
for(int nx = 0; nx < width; nx++) {
|
|
|
|
for(int ny = 0; ny < height; ny++) {
|
2012-01-30 19:18:10 +01:00
|
|
|
Position tilePos(x + nx + offset, y + ny + offset, z);
|
|
|
|
|
|
|
|
// clean pre stored tiles
|
|
|
|
g_map.cleanTile(tilePos);
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
if(skip == 0) {
|
2012-05-15 02:04:04 +02:00
|
|
|
int tileOpt = msg->peekU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
if(tileOpt >= 0xFF00)
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = (msg->getU16() & 0xFF);
|
2011-08-15 16:11:24 +02:00
|
|
|
else {
|
2012-01-30 19:18:10 +01:00
|
|
|
setTileDescription(msg, tilePos);
|
2012-05-14 23:36:54 +02:00
|
|
|
skip = (msg->getU16() & 0xFF);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
skip--;
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 23:36:54 +02:00
|
|
|
return skip;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position position)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GameEnvironmentEffect))
|
|
|
|
msg->getU16(); // environment effect
|
|
|
|
|
2012-05-12 03:44:13 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
g_map.cleanTile(position);
|
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
int stackPos = 0;
|
2011-12-01 23:25:32 +01:00
|
|
|
while(true) {
|
2012-05-15 02:04:04 +02:00
|
|
|
int inspectItemId = msg->peekU16();
|
2012-05-12 03:44:13 +02:00
|
|
|
if(inspectItemId >= 0xFF00) {
|
2011-08-15 16:11:24 +02:00
|
|
|
return;
|
2012-05-12 03:44:13 +02:00
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
else {
|
2011-08-31 22:22:57 +02:00
|
|
|
if(stackPos >= 10)
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError(stdext::format("too many things, stackpos=%d, pos=%s", stackPos, stdext::to_string(position)));
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
ThingPtr thing = getThing(msg);
|
2012-07-15 07:46:56 +02:00
|
|
|
g_map.addThing(thing, position, -2);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2011-08-31 22:22:57 +02:00
|
|
|
stackPos++;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg)
|
2011-08-15 23:02:52 +02:00
|
|
|
{
|
|
|
|
Outfit outfit;
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int lookType = msg->getU16();
|
2012-05-11 20:02:57 +02:00
|
|
|
if(lookType != 0) {
|
2012-07-20 07:45:11 +02:00
|
|
|
outfit.setCategory(ThingCategoryCreature);
|
2012-05-14 23:36:54 +02:00
|
|
|
int head = msg->getU8();
|
|
|
|
int body = msg->getU8();
|
|
|
|
int legs = msg->getU8();
|
|
|
|
int feet = msg->getU8();
|
|
|
|
int addons = msg->getU8();
|
2011-11-13 09:46:19 +01:00
|
|
|
|
2012-05-11 20:02:57 +02:00
|
|
|
outfit.setId(lookType);
|
2011-11-13 09:46:19 +01:00
|
|
|
outfit.setHead(head);
|
|
|
|
outfit.setBody(body);
|
|
|
|
outfit.setLegs(legs);
|
|
|
|
outfit.setFeet(feet);
|
|
|
|
outfit.setAddons(addons);
|
2011-08-15 23:02:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-14 23:36:54 +02:00
|
|
|
int lookTypeEx = msg->getU16();
|
2012-05-11 20:02:57 +02:00
|
|
|
if(lookTypeEx == 0) {
|
2012-07-20 07:45:11 +02:00
|
|
|
outfit.setCategory(ThingCategoryEffect);
|
2012-01-10 01:36:18 +01:00
|
|
|
outfit.setId(13);
|
|
|
|
}
|
|
|
|
else {
|
2012-07-20 07:45:11 +02:00
|
|
|
outfit.setCategory(ThingCategoryItem);
|
2012-05-11 20:02:57 +02:00
|
|
|
outfit.setId(lookTypeEx);
|
2012-01-10 01:36:18 +01:00
|
|
|
}
|
2011-08-15 23:02:52 +02:00
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
if(g_game.getFeature(Otc::GamePlayerMounts)) {
|
|
|
|
int mount = msg->getU16(); // mount
|
|
|
|
outfit.setMount(mount);
|
|
|
|
}
|
2012-05-12 22:16:33 +02:00
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
return outfit;
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
ThingPtr ProtocolGame::getThing(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
|
|
|
ThingPtr thing;
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int id = msg->getU16();
|
2012-05-11 20:02:57 +02:00
|
|
|
|
2012-05-12 22:16:33 +02:00
|
|
|
if(id == 0)
|
2012-05-28 15:06:26 +02:00
|
|
|
stdext::throw_exception("invalid thing id");
|
2012-05-12 22:16:33 +02:00
|
|
|
else if(id == Proto::UnknownCreature || id == Proto::OutdatedCreature || id == Proto::Creature)
|
2012-05-14 23:36:54 +02:00
|
|
|
thing = getCreature(msg, id);
|
2012-05-12 22:16:33 +02:00
|
|
|
else // item
|
2012-05-14 23:36:54 +02:00
|
|
|
thing = getItem(msg, id);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-12 22:16:33 +02:00
|
|
|
return thing;
|
|
|
|
}
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
|
2012-05-12 22:16:33 +02:00
|
|
|
{
|
|
|
|
if(type == 0)
|
2012-05-14 23:36:54 +02:00
|
|
|
type = msg->getU16();
|
2012-05-12 22:16:33 +02:00
|
|
|
|
|
|
|
CreaturePtr creature;
|
|
|
|
bool known = (type != Proto::UnknownCreature);
|
|
|
|
|
|
|
|
if(type == Proto::OutdatedCreature || type == Proto::UnknownCreature) {
|
|
|
|
if(known) {
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2012-05-12 22:16:33 +02:00
|
|
|
creature = g_map.getCreatureById(id);
|
|
|
|
if(!creature)
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("server said that a creature is known, but it's not");
|
2012-05-12 22:16:33 +02:00
|
|
|
} else {
|
2012-05-14 23:36:54 +02:00
|
|
|
uint removeId = msg->getU32();
|
2012-05-12 22:16:33 +02:00
|
|
|
g_map.removeCreatureById(removeId);
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2012-05-12 03:44:13 +02:00
|
|
|
|
|
|
|
int creatureType;
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 910)
|
2012-05-29 00:04:44 +02:00
|
|
|
creatureType = msg->getU8();
|
|
|
|
else {
|
|
|
|
if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
|
|
|
|
creatureType = Proto::CreatureTypePlayer;
|
|
|
|
else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
|
|
|
|
creatureType = Proto::CreatureTypeMonster;
|
|
|
|
else
|
|
|
|
creatureType = Proto::CreatureTypeNpc;
|
|
|
|
}
|
2012-05-12 22:16:33 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
std::string name = msg->getString();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-05-12 22:16:33 +02:00
|
|
|
// every creature name must start with a capital letter
|
|
|
|
if(name.length() > 0)
|
2011-12-21 05:43:51 +01:00
|
|
|
name[0] = toupper(name[0]);
|
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
if(id == m_localPlayer->getId())
|
|
|
|
creature = m_localPlayer;
|
2012-05-12 03:44:13 +02:00
|
|
|
else if(creatureType == Proto::CreatureTypePlayer)
|
2012-01-09 06:23:39 +01:00
|
|
|
creature = PlayerPtr(new Player);
|
2012-05-12 03:44:13 +02:00
|
|
|
else if(creatureType == Proto::CreatureTypeMonster)
|
2012-01-09 06:23:39 +01:00
|
|
|
creature = MonsterPtr(new Monster);
|
2012-05-12 03:44:13 +02:00
|
|
|
else if(creatureType == Proto::CreatureTypeNpc)
|
2012-01-09 06:23:39 +01:00
|
|
|
creature = NpcPtr(new Npc);
|
2011-12-30 19:14:50 +01:00
|
|
|
else
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("creature type is invalid");
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-05-10 01:04:09 +02:00
|
|
|
if(creature) {
|
|
|
|
creature->setId(id);
|
|
|
|
creature->setName(name);
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-05-10 01:04:09 +02:00
|
|
|
g_map.addCreature(creature);
|
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int healthPercent = msg->getU8();
|
|
|
|
Otc::Direction direction = (Otc::Direction)msg->getU8();
|
|
|
|
Outfit outfit = getOutfit(msg);
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
Light light;
|
2012-05-14 23:36:54 +02:00
|
|
|
light.intensity = msg->getU8();
|
|
|
|
light.color = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
int speed = msg->getU16();
|
|
|
|
int skull = msg->getU8();
|
|
|
|
int shield = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// emblem is sent only when the creature is not known
|
2012-01-16 02:55:14 +01:00
|
|
|
int emblem = -1;
|
2012-05-11 20:02:57 +02:00
|
|
|
bool passable = false;
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getFeature(Otc::GameCreatureEmblems) && !known)
|
|
|
|
emblem = msg->getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 854)
|
2012-05-29 00:04:44 +02:00
|
|
|
passable = (msg->getU8() == 0);
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
if(creature) {
|
|
|
|
creature->setHealthPercent(healthPercent);
|
|
|
|
creature->setDirection(direction);
|
|
|
|
creature->setOutfit(outfit);
|
|
|
|
creature->setLight(light);
|
|
|
|
creature->setSpeed(speed);
|
|
|
|
creature->setSkull(skull);
|
|
|
|
creature->setShield(shield);
|
2012-01-16 02:55:14 +01:00
|
|
|
if(emblem != -1)
|
|
|
|
creature->setEmblem(emblem);
|
2012-01-09 06:23:39 +01:00
|
|
|
creature->setPassable(passable);
|
2012-01-17 06:36:25 +01:00
|
|
|
|
2012-05-10 15:06:06 +02:00
|
|
|
if(creature == m_localPlayer && !m_localPlayer->isKnown())
|
2012-01-17 06:36:25 +01:00
|
|
|
m_localPlayer->setKnown(true);
|
2012-01-09 06:23:39 +01:00
|
|
|
}
|
2012-05-12 22:16:33 +02:00
|
|
|
} else if(type == Proto::Creature) {
|
2012-05-14 23:36:54 +02:00
|
|
|
uint id = msg->getU32();
|
2012-05-12 22:16:33 +02:00
|
|
|
creature = g_map.getCreatureById(id);
|
2012-05-29 00:04:44 +02:00
|
|
|
|
|
|
|
if(!creature)
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.traceError("invalid creature");
|
2012-05-29 00:04:44 +02:00
|
|
|
|
|
|
|
Otc::Direction direction = (Otc::Direction)msg->getU8();
|
2012-05-12 22:16:33 +02:00
|
|
|
if(creature)
|
|
|
|
creature->turn(direction);
|
2012-05-29 00:04:44 +02:00
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(g_game.getProtocolVersion() >= 953) {
|
2012-05-29 00:04:44 +02:00
|
|
|
bool passable = msg->getU8();
|
|
|
|
|
|
|
|
if(creature)
|
|
|
|
creature->setPassable(passable);
|
|
|
|
}
|
|
|
|
|
2012-05-12 22:16:33 +02:00
|
|
|
} else {
|
2012-05-28 15:06:26 +02:00
|
|
|
stdext::throw_exception("invalid creature opcode");
|
2012-05-11 20:02:57 +02:00
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-12 22:16:33 +02:00
|
|
|
return creature;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-01-12 20:20:18 +01:00
|
|
|
if(id == 0)
|
2012-05-14 23:36:54 +02:00
|
|
|
id = msg->getU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
ItemPtr item = Item::create(id);
|
2012-05-12 03:44:13 +02:00
|
|
|
if(item->getId() == 0)
|
2012-06-21 19:54:20 +02:00
|
|
|
stdext::throw_exception("unable to create item with invalid id 0");
|
2012-05-12 03:44:13 +02:00
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(item->isStackable() || item->isFluidContainer() || item->isSplash() || item->isChargeable())
|
2012-05-14 23:36:54 +02:00
|
|
|
item->setCountOrSubType(msg->getU8());
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-05-29 00:04:44 +02:00
|
|
|
if(g_game.getFeature(Otc::GameItemAnimationPhase)) {
|
|
|
|
if(item->getAnimationPhases() > 1) {
|
|
|
|
// 0xfe => random phase
|
|
|
|
// 0xff => async?
|
|
|
|
msg->getU8();
|
|
|
|
}
|
2012-05-12 03:44:13 +02:00
|
|
|
}
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:36:54 +02:00
|
|
|
Position ProtocolGame::getPosition(const InputMessagePtr& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
2012-05-14 23:36:54 +02:00
|
|
|
uint16 x = msg->getU16();
|
|
|
|
uint16 y = msg->getU16();
|
|
|
|
uint8 z = msg->getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
return Position(x, y, z);
|
|
|
|
}
|