Go to the documentation of this file.
41 m_protocolVersion = 0;
42 m_clientCustomOs = -1;
45 m_denyBotCall =
false;
51 m_canReportBugs =
false;
66 m_protocolGame =
nullptr;
69 void Game::resetGameStates()
72 m_denyBotCall =
false;
77 m_canReportBugs =
false;
82 m_followingCreature =
nullptr;
83 m_attackingCreature =
nullptr;
84 m_localPlayer =
nullptr;
89 for(
auto& it : m_containers) {
97 m_pingEvent =
nullptr;
102 m_walkEvent =
nullptr;
105 if(m_checkConnectionEvent) {
106 m_checkConnectionEvent->
cancel();
107 m_checkConnectionEvent =
nullptr;
110 m_containers.clear();
121 if(ec != asio::error::eof)
135 m_protocolGame =
nullptr;
202 g_lua.callGlobalField(
"g_game",
"onConnectionFailing", true);
203 m_connectionFailWarned = true;
205 g_lua.callGlobalField(
"g_game",
"onConnectionFailing", false);
206 m_connectionFailWarned = false;
216 if(m_connectionFailWarned) {
218 m_connectionFailWarned =
false;
225 m_characterName =
"";
241 m_gmActions = actions;
252 m_fightMode = fightMode;
253 m_chaseMode = chaseMode;
254 m_safeFight = safeMode;
275 if(m_pingReceived == m_pingSent)
297 void Game::processOpenContainer(
int containerId,
const ItemPtr& containerItem,
const std::string& name,
int capacity,
bool hasParent,
const std::vector<ItemPtr>& items,
bool isUnlocked,
bool hasPages,
int containerSize,
int firstIndex)
301 m_containers[containerId] = container;
302 container->onAddItems(items);
306 container->onOpen(previousContainer);
309 if(previousContainer)
310 previousContainer->onClose();
320 m_containers[containerId] =
nullptr;
321 container->onClose();
331 container->onAddItem(item, slot);
341 container->onUpdateItem(slot, item);
351 container->onRemoveItem(slot, lastItem);
409 m_vips[id] =
Vip(name, status, description, iconId, notifyLogin);
410 g_lua.
callGlobalField(
"g_game",
"onAddVip",
id, name, status, description, iconId, notifyLogin);
415 std::get<1>(m_vips[
id]) = status;
435 const std::vector<std::tuple<int, std::string> >& mountList)
441 Outfit outfit = currentOutfit;
443 virtualOutfitCreature->
setOutfit(outfit);
453 mountOutfit.
setId(0);
459 virtualMountCreature->
setOutfit(mountOutfit);
462 g_lua.
callGlobalField(
"g_game",
"onOpenOutfitWindow", virtualOutfitCreature, outfitList, virtualMountCreature, mountList);
495 void Game::processEditText(
uint id,
int itemId,
int maxLength,
const std::string& text,
const std::string& writer,
const std::string& date)
515 void Game::processModalDialog(
uint32 id, std::string title, std::string message, std::vector<std::tuple<int, std::string> > buttonList,
int enterButton,
int escapeButton, std::vector<std::tuple<int, std::string> > choiceList,
bool priority)
517 g_lua.
callGlobalField(
"g_game",
"onModalDialog",
id, title, message, buttonList, enterButton, escapeButton, choiceList, priority);
531 void Game::loginWorld(
const std::string& account,
const std::string& password,
const std::string& worldName,
const std::string& worldHost,
int worldPort,
const std::string& characterName,
const std::string& authenticatorToken,
const std::string& sessionKey)
536 if(m_protocolVersion == 0)
543 m_localPlayer->
setName(characterName);
546 m_protocolGame->
login(account, password, worldHost, (
uint16)worldPort, characterName, authenticatorToken, sessionKey);
547 m_characterName = characterName;
548 m_worldName = worldName;
600 if(!m_localPlayer->
canWalk(direction)) {
601 if(m_lastWalkDir != direction) {
604 if(ticks <= 0) { ticks = 1; }
608 m_walkEvent =
nullptr;
620 m_localPlayer->
preWalk(direction);
624 auto canChangeFloorDown = [&]() ->
bool {
635 auto canChangeFloorUp = [&]() ->
bool {
648 if(canChangeFloorDown() || canChangeFloorUp() ||
649 (!toTile || toTile->
isEmpty())) {
669 m_lastWalkDir = direction;
675 return walk(direction,
true);
684 if(dirs.size() > 127) {
685 g_logger.
error(
"Auto walk path too great, the maximum number of directions is 127");
696 auto it = dirs.begin();
698 if(!m_localPlayer->
canWalk(direction))
703 m_localPlayer->
preWalk(direction);
792 if(thing->isCreature() && isBattleList && m_protocolVersion >= 961)
795 m_protocolGame->
sendLook(thing->getPosition(), thing->getId(), thing->getStackPos());
806 uint id = thing->getId();
807 if(thing->isCreature()) {
812 m_protocolGame->
sendMove(thing->getPosition(), id, thing->getStackPos(), toPos, count);
820 Position position = thing->getPosition();
829 m_protocolGame->
sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackPos());
837 Position pos = thing->getPosition();
865 if(toThing->isCreature())
878 if(toThing->isCreature())
881 m_protocolGame->
sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackPos());
886 for(
auto& it : m_containers) {
890 ItemPtr item = container->findItemById(itemId, subType);
904 if(!previousContainer)
907 id = previousContainer->getId();
942 if(creature && creature == m_attackingCreature)
948 setAttackingCreature(creature);
951 if(m_protocolVersion >= 963) {
953 m_seq = creature->
getId();
966 if(creature && creature == m_followingCreature)
972 setFollowingCreature(creature);
975 if(m_protocolVersion >= 963) {
977 m_seq = creature->
getId();
990 setFollowingCreature(
nullptr);
992 setAttackingCreature(
nullptr);
1012 m_protocolGame->
sendTalk(mode, channelId,
"", message);
1019 m_protocolGame->
sendTalk(mode, 0, receiver, message);
1146 auto it = m_vips.find(playerId);
1147 if(it == m_vips.end())
1153 void Game::editVip(
int playerId,
const std::string& description,
int iconId,
bool notifyLogin)
1158 auto it = m_vips.find(playerId);
1159 if(it == m_vips.end())
1162 std::get<2>(m_vips[playerId]) = description;
1163 std::get<3>(m_vips[playerId]) = iconId;
1164 std::get<4>(m_vips[playerId]) = notifyLogin;
1167 m_protocolGame->
sendEditVip(playerId, description, iconId, notifyLogin);
1174 if(m_chaseMode == chaseMode)
1176 m_chaseMode = chaseMode;
1185 if(m_fightMode == fightMode)
1187 m_fightMode = fightMode;
1196 if(m_safeFight == on)
1209 if(m_pvpMode == pvpMode)
1211 m_pvpMode = pvpMode;
1222 if(m_unjustifiedPoints == unjustifiedPoints)
1225 m_unjustifiedPoints = unjustifiedPoints;
1233 if(m_openPvpSituations == openPvpSituations)
1236 m_openPvpSituations = openPvpSituations;
1339 void Game::reportRuleViolation(
const std::string& target,
int reason,
int action,
const std::string& comment,
const std::string& statement,
int statementId,
bool ipBanishment)
1343 m_protocolGame->
sendRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment);
1346 void Game::debugReport(
const std::string& a,
const std::string& b,
const std::string& c,
const std::string& d)
1451 if(!m_protocolGame || !m_protocolGame->
isConnected())
1454 if(m_pingReceived != m_pingSent)
1457 m_denyBotCall =
false;
1459 m_denyBotCall =
true;
1473 #ifdef BOT_PROTECTION
1498 if(m_protocolVersion == version)
1504 if(version != 0 && (version < 740 || version > 1099))
1507 m_protocolVersion = version;
1516 if(m_clientVersion == version)
1522 if(version != 0 && (version < 740 || version > 1099))
1528 if(version >= 770) {
1534 if(version >= 780) {
1543 if(version >= 790) {
1547 if(version >= 840) {
1553 if(version >= 841) {
1558 if(version >= 854) {
1562 if(version >= 860) {
1566 if(version >= 862) {
1570 if(version >= 870) {
1576 if(version >= 910) {
1586 if(version >= 940) {
1590 if(version >= 953) {
1595 if(version >= 960) {
1600 if(version >= 963) {
1604 if(version >= 980) {
1609 if(version >= 981) {
1614 if(version >= 984) {
1619 if(version >= 1000) {
1624 if(version >= 1035) {
1629 if(version >= 1036) {
1634 if(version >= 1038) {
1638 if(version >= 1050) {
1642 if(version >= 1053) {
1646 if(version >= 1054) {
1650 if(version >= 1055) {
1654 if(version >= 1057) {
1658 if(version >= 1061) {
1662 if(version >= 1071) {
1666 if(version >= 1072) {
1670 if(version >= 1074) {
1674 if(version >= 1080) {
1678 if(version >= 1092) {
1682 if(version >= 1093) {
1686 if(version >= 1094) {
1690 m_clientVersion = version;
1695 void Game::setAttackingCreature(
const CreaturePtr& creature)
1697 if(creature != m_attackingCreature) {
1699 m_attackingCreature = creature;
1705 void Game::setFollowingCreature(
const CreaturePtr& creature)
1708 m_followingCreature = creature;
1715 std::string formatedName = name;
1718 for(
char &i: formatedName) {
1728 return formatedName;
1734 while(m_containers[
id] !=
nullptr)
1741 if(m_clientCustomOs >= 0)
1742 return m_clientCustomOs;
void openRuleViolation(const std::string &reporter)
int findEmptyContainerId()
Position translatedToDirection(Otc::Direction direction)
void editList(uint id, int doorId, const std::string &text)
void sendChangeMapAwareRange(int xrange, int yrange)
void look(const ThingPtr &thing, bool isBattleList=false)
void loginWorld(const std::string &account, const std::string &password, const std::string &worldName, const std::string &worldHost, int worldPort, const std::string &characterName, const std::string &authenticatorToken, const std::string &sessionKey)
void cancelRuleViolation()
void sendCancelAttackAndFollow()
void close(const ContainerPtr &container)
void processQuestLine(int questId, const std::vector< std::tuple< std::string, std::string > > &questMissions)
void processModalDialog(uint32 id, std::string title, std::string message, std::vector< std::tuple< int, std::string > > buttonList, int enterButton, int escapeButton, std::vector< std::tuple< int, std::string > > choiceList, bool priority)
void processWalkCancel(Otc::Direction direction)
void leaveChannel(int channelId)
void cancelWalk(Otc::Direction direction=Otc::InvalidDirection)
void processOpenChannel(int channelId, const std::string &name)
bool canWalk(Otc::Direction direction)
void processTextMessage(Otc::MessageMode mode, const std::string &text)
void browseField(const Position &position)
void sendExcludeFromOwnChannel(const std::string &name)
void processOpenOutfitWindow(const Outfit ¤tOutfit, const std::vector< std::tuple< int, std::string, int > > &outfitList, const std::vector< std::tuple< int, std::string > > &mountList)
const TilePtr & getTile()
void sendBugReport(const std::string &comment)
void closeRuleViolation(const std::string &reporter)
void inspectNpcTrade(const ItemPtr &item)
void processDeath(int deathType, int penality)
void sendJoinChannel(int channelId)
void processEditList(uint id, int doorId, const std::string &text)
void sendCloseNpcChannel()
void sendLeaveChannel(int channelId)
void processQuestLog(const std::vector< std::tuple< int, std::string, bool > > &questList)
void inviteToOwnChannel(const std::string &name)
void setClientVersion(int version)
void lockWalk(int millis=250)
void processRuleViolationChannel(int channelId)
void setProtocolVersion(int version)
void sendCancelRuleViolation()
void requestItemInfo(const ItemPtr &item, int index)
EventDispatcher g_dispatcher
bool isWalkable(bool ignoreCreatures=false)
void move(const ThingPtr &thing, const Position &toPos, int count)
void setDirection(Otc::Direction direction)
void processInventoryChange(int slot, const ItemPtr &item)
void sendSeekInContainer(int cid, int index)
void processTutorialHint(int id)
void sendOpenOwnChannel()
void sendUseOnCreature(const Position &pos, int thingId, int stackpos, uint creatureId)
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
void processPlayerGoods(int money, const std::vector< std::tuple< ItemPtr, int > > &goods)
void processEditText(uint id, int itemId, int maxLength, const std::string &text, const std::string &writer, const std::string &date)
@ GameLoginPacketEncryption
void openParent(const ContainerPtr &container)
void sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack)
void processGMActions(const std::vector< uint8 > &actions)
void setPVPMode(Otc::PVPModes pvpMode)
void processLoginToken(bool unknown)
void error(const std::string &what)
void openPrivateChannel(const std::string &receiver)
void processAddAutomapFlag(const Position &pos, int icon, const std::string &message)
void setFightMode(Otc::FightModes fightMode)
void turn(Otc::Direction direction)
void useInventoryItem(int itemId)
void useWith(const ItemPtr &item, const ThingPtr &toThing)
const TilePtr & getTile(const Position &pos)
void sendMove(const Position &fromPos, int thingId, int stackpos, const Position &toPos, int count)
void processLoginAdvice(const std::string &message)
void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr &item)
void processOpenOwnPrivateChannel(int channelId, const std::string &name)
void equipItem(const ItemPtr &item)
void processLoginError(const std::string &error)
void sendPassLeadership(uint creatureId)
void sendRotateItem(const Position &pos, int thingId, int stackpos)
bool walk(Otc::Direction direction, bool dash=false)
void partyInvite(int creatureId)
void sendAnswerModalDialog(uint32 dialog, int button, int choice)
stdext::shared_object_ptr< Creature > CreaturePtr
void processCloseNpcTrade()
void sendAddVip(const std::string &name)
void sendDebugReport(const std::string &a, const std::string &b, const std::string &c, const std::string &d)
std::string traceback(const std::string &errorMessage="", int level=0)
void sendInviteToOwnChannel(const std::string &name)
void processPendingGame()
ItemPtr findItemInContainers(uint itemId, int subType)
void sendRuleViolation(const std::string &target, int reason, int action, const std::string &comment, const std::string &statement, int statementId, bool ipBanishment)
void processRemoveAutomapFlag(const Position &pos, int icon, const std::string &message)
void sendFollow(uint creatureId, uint seq)
void requestStoreOffers(const std::string &categoryName, int serviceType=0)
void buildMessageModesMap(int version)
int open(const ItemPtr &item, const ContainerPtr &previousContainer)
void preWalk(Otc::Direction direction)
@ GameForceFirstAutoWalkStep
void partyShareExperience(bool active)
void partyJoin(int creatureId)
void requestTrade(const ItemPtr &item, const CreaturePtr &creature)
void sendOpenTransactionHistory(int entriesPerPage)
void sendBuyStoreOffer(int offerId, int productType, const std::string &name)
void requestQuestLine(int questId)
void processContainerRemoveItem(int containerId, int slot, const ItemPtr &lastItem)
void sendCloseContainer(int containerId)
void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped)
void sendShareExperience(bool active)
void sendRequestItemInfo(int itemId, int subType, int index)
void sendEditVip(uint playerId, const std::string &description, int iconId, bool notifyLogin)
void sendRequestStoreOffers(const std::string &categoryName, int serviceType)
void buyItem(const ItemPtr &item, int amount, bool ignoreCapacity, bool buyWithBackpack)
void sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight, Otc::PVPModes pvpMode)
ScheduledEventPtr cycleEvent(const std::function< void()> &callback, int delay)
void sendInspectNpcTrade(int itemId, int count)
void use(const ThingPtr &thing)
void sendLookCreature(uint creatureId)
void answerModalDialog(uint32 dialog, int button, int choice)
void setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints)
void sendEditList(uint id, int doorId, const std::string &text)
void sendAutoWalk(const std::vector< Otc::Direction > &path)
void sendRemoveVip(uint playerId)
void processOpenContainer(int containerId, const ItemPtr &containerItem, const std::string &name, int capacity, bool hasParent, const std::vector< ItemPtr > &items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
@ GamePlayerRegenerationTime
void sendCloseRuleViolation(const std::string &reporter)
void setChaseMode(Otc::ChaseModes chaseMode)
@ GameContainerPagination
void inspectTrade(bool counterOffer, int index)
void sendRequestQuestLog()
void setName(const std::string &name)
void follow(CreaturePtr creature)
void sendRequestTrade(const Position &pos, int thingId, int stackpos, uint creatureId)
void talkPrivate(Otc::MessageMode mode, const std::string &receiver, const std::string &message)
void sendInviteToParty(uint creatureId)
void processCloseContainer(int containerId)
void forceWalk(Otc::Direction direction)
bool getFeature(Otc::GameFeature feature)
void sendAttack(uint creatureId, uint seq)
bool hasElevation(int elevation=1)
void talkChannel(Otc::MessageMode mode, int channelId, const std::string &message)
void sendOpenRuleViolation(const std::string &reporter)
bool dashWalk(Otc::Direction direction)
@ GameIngameStoreServiceType
void processConnectionError(const boost::system::error_code &ec)
void sendTalk(Otc::MessageMode mode, int channelId, const std::string &receiver, const std::string &message)
void sendInspectTrade(bool counterOffer, int index)
void openStore(int serviceType=0, const std::string &category="")
void throw_exception(const std::string &what)
Throws a generic exception.
void editVip(int playerId, const std::string &description, int iconId, bool notifyLogin)
void sendEquipItem(int itemId, int countOrSubType)
void processRuleViolationLock()
void processContainerAddItem(int containerId, const ItemPtr &item, int slot)
void sellItem(const ItemPtr &item, int amount, bool ignoreEquipped)
void sendLook(const Position &position, int thingId, int stackpos)
@ GameOfflineTrainingTime
void excludeFromOwnChannel(const std::string &name)
void processVipAdd(uint id, const std::string &name, uint status, const std::string &description, int iconId, bool notifyLogin)
void sendRevokeInvitation(uint creatureId)
void sendMountStatus(bool mount)
void refreshContainer(const ContainerPtr &container)
void enableFeature(Otc::GameFeature feature)
void partyRevokeInvitation(int creatureId)
void processOpenPrivateChannel(const std::string &name)
void talk(const std::string &message)
void processChannelList(const std::vector< std::tuple< int, std::string > > &channelList)
stdext::shared_object_ptr< Container > ContainerPtr
void setOpenPvpSituations(int openPvpSituations)
void changeMapAwareRange(int xrange, int yrange)
void transferCoins(const std::string &recipient, int amount)
void processRuleViolationRemove(const std::string &name)
@ GameIngameStoreHighlights
std::string formatCreatureName(const std::string &name)
void sendBrowseField(const Position &position)
void sendUseItemWith(const Position &fromPos, int itemId, int fromStackPos, const Position &toPos, int toThingId, int toStackPos)
void sendTransferCoins(const std::string &recipient, int amount)
void sendJoinParty(uint creatureId)
void processContainerUpdateItem(int containerId, int slot, const ItemPtr &item)
void setSafeFight(bool on)
void sendOpenPrivateChannel(const std::string &receiver)
void sendRequestTransactionHistory(int page, int entriesPerPage)
void buyStoreOffer(int offerId, int productType, const std::string &name="")
void processCounterTrade(const std::string &name, const std::vector< ItemPtr > &items)
void sendEditText(uint id, const std::string &text)
std::tuple< std::string, uint, std::string, int, bool > Vip
void processVipStateChange(uint id, uint status)
int getStepDuration(bool ignoreDiagonal=false, Otc::Direction dir=Otc::InvalidDirection)
void openTransactionHistory(int entriesPerPage)
void reportBug(const std::string &comment)
void processRuleViolationCancel(const std::string &name)
void changeOutfit(const Outfit &outfit)
void setPosition(const Position &position)
void sendRequestQuestLine(int questId)
stdext::shared_object_ptr< LocalPlayer > LocalPlayerPtr
void removeVip(int playerId)
void sendChangeOutfit(const Outfit &outfit)
ContainerPtr getContainer(int index)
void processTalk(const std::string &name, int level, Otc::MessageMode mode, const std::string &text, int channelId, const Position &pos)
bool canPerformGameAction()
void processUpdateNeeded(const std::string &signature)
void cancelAttackAndFollow()
void sendOpenStore(int serviceType, const std::string &category)
void processAttackCancel(uint seq)
void seekInContainer(int cid, int index)
ScheduledEventPtr scheduleEvent(const std::function< void()> &callback, int delay)
void setOutfit(const Outfit &outfit)
void joinChannel(int channelId)
void login(const std::string &accountName, const std::string &accountPassword, const std::string &host, uint16 port, const std::string &characterName, const std::string &authenticatorToken, const std::string &sessionKey)
stdext::shared_object_ptr< ProtocolGame > ProtocolGamePtr
void sendUseItem(const Position &position, int itemId, int stackpos, int index)
void requestTransactionHistory(int page, int entriesPerPage)
void rotate(const ThingPtr &thing)
void editText(uint id, const std::string &text)
void sendRequestChannels()
bool checkBotProtection()
void processLoginWait(const std::string &message, int time)
void moveToParentContainer(const ThingPtr &thing, int count)
void attack(CreaturePtr creature)
ThingTypeManager g_things
void reportRuleViolation(const std::string &target, int reason, int action, const std::string &comment, const std::string &statement, int statementId, bool ipBanishment)
void processPlayerHelpers(int helpers)
void useInventoryItemWith(int itemId, const ThingPtr &toThing)
void processOwnTrade(const std::string &name, const std::vector< ItemPtr > &items)
void debugReport(const std::string &a, const std::string &b, const std::string &c, const std::string &d)
void autoWalk(std::vector< Otc::Direction > dirs)
void processOpenNpcTrade(const std::vector< std::tuple< ItemPtr, std::string, int, int, int > > &items)
void cleanDynamicThings()
void addVip(const std::string &name)
void setPendingGame(bool pending)
void processCloseChannel(int channelId)
void processPlayerModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeMode, Otc::PVPModes pvpMode)
void sendUpContainer(int containerId)
bool isValidDatId(uint16 id, ThingCategory category)
void partyPassLeadership(int creatureId)
void sendRefreshContainer(int containerId)