From c7e57369f066ee9b7f9f62eacb19e2d10f8e13c5 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 15 May 2009 12:09:45 +0200 Subject: Fixed a possible crash on logging in to the map server The Game instance was created too late, in some cases after messages were received by the BeingHandler. This caused crashes since the BeingHandler tried to use the BeingManager, which hadn't been created yet. --- src/net/ea/maphandler.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/net') diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/maphandler.cpp index 76b3c480..c7ff0ec7 100644 --- a/src/net/ea/maphandler.cpp +++ b/src/net/ea/maphandler.cpp @@ -27,6 +27,7 @@ #include "net/messagein.h" #include "net/messageout.h" +#include "game.h" #include "localplayer.h" #include "log.h" #include "main.h" @@ -37,6 +38,7 @@ #include "utils/stringutils.h" Net::MapHandler *mapHandler; +extern Game *game; namespace EAthena { @@ -65,6 +67,7 @@ void MapHandler::handleMessage(MessageIn &msg) logger->log("Protocol: Player start position: (%d, %d), Direction: %d", player_node->mX, player_node->mY, direction); state = STATE_GAME; + game = new Game; break; case SMSG_SERVER_PING: -- cgit v1.2.3-70-g09d2 From 72660d2c33773f0f74663efe6f9ac47648cdf283 Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 18 May 2009 18:18:23 +0100 Subject: Added target combat --- src/gui/viewport.cpp | 8 ++------ src/localplayer.cpp | 21 ++++++++++++++------- src/localplayer.h | 4 +--- src/main.cpp | 2 +- src/net/ea/playerhandler.cpp | 4 ++-- src/net/ea/playerhandler.h | 2 +- src/net/playerhandler.h | 2 +- src/net/tmwserv/gameserver/player.cpp | 7 ------- src/net/tmwserv/gameserver/player.h | 1 - src/net/tmwserv/playerhandler.cpp | 6 ++++-- src/net/tmwserv/playerhandler.h | 2 +- src/net/tmwserv/protocol.h | 2 +- 12 files changed, 28 insertions(+), 33 deletions(-) (limited to 'src/net') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 2c3f4007..cbde95c4 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -358,19 +358,15 @@ void Viewport::mousePressed(gcn::MouseEvent &event) keyboard.isKeyActive(keyboard.KEY_ATTACK)) { player_node->setGotoTarget(being); -//TODO: This can be changed when TMWServ moves to target based combat -#ifdef TMWSERV_SUPPORT - player_node->attack(); -#else + player_node->attack(being, !keyboard.isKeyActive(keyboard.KEY_TARGET)); -#endif } else { #ifdef TMWSERV_SUPPORT - player_node->setDestination(event.getX() + (int) mPixelViewX, + player_node->setDestination(event.getX() + (int) mPixelViewX, event.getY() + (int) mPixelViewY); #else player_node->setDestination(tilex, tiley); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index e9bc30f2..4c34394b 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -606,7 +606,7 @@ void LocalPlayer::emote(Uint8 emotion) } #ifdef TMWSERV_SUPPORT - +/* void LocalPlayer::attack() { if (mLastAction != -1) @@ -656,13 +656,14 @@ void LocalPlayer::attack() } Net::GameServer::Player::attack(getSpriteDirection()); } - +*/ void LocalPlayer::useSpecial(int special) { Net::GameServer::Player::useSpecial(special); } -#else +#endif +//#else void LocalPlayer::attack(Being *target, bool keep) { @@ -676,9 +677,13 @@ void LocalPlayer::attack(Being *target, bool keep) mLastTarget = -1; setTarget(target); } - +#ifdef TMWSERV_SUPPORT + int dist_x = target->getPixelX(); + int dist_y = target->getPixelY(); +#else int dist_x = target->mX - mX; int dist_y = target->mY - mY; +#endif // Must be standing to attack if (mAction != STAND) @@ -699,8 +704,12 @@ void LocalPlayer::attack(Being *target, bool keep) setDirection(LEFT); } +#ifdef TMWSERV_SUPPORT + mLastAction = tick_time; +#else mWalkTime = tick_time; mTargetTime = tick_time; +#endif setAction(ATTACK); @@ -715,14 +724,12 @@ void LocalPlayer::attack(Being *target, bool keep) sound.playSfx("sfx/fist-swish.ogg"); } - Net::getPlayerHandler()->attack(target); + Net::getPlayerHandler()->attack(target->getId()); if (!keep) stopAttack(); } -#endif // no TMWSERV_SUPPORT - void LocalPlayer::stopAttack() { if (mTarget) diff --git a/src/localplayer.h b/src/localplayer.h index 4a85dd75..85681e03 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -214,11 +214,9 @@ class LocalPlayer : public Player void setTrading(bool trading) { mTrading = trading; } #ifdef TMWSERV_SUPPORT - void attack(); void useSpecial(int id); -#else - void attack(Being *target = NULL, bool keep = false); #endif + void attack(Being *target = NULL, bool keep = false); /** * Triggers whether or not to show the name as a GM name. diff --git a/src/main.cpp b/src/main.cpp index fb061818..f15eeccc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -307,7 +307,7 @@ static void setUpdatesDir() static void initHomeDir(const Options &options) { homeDir = options.homeDir; - + if (homeDir.empty()) { homeDir = std::string(PHYSFS_getUserDir()) + diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index b7131f0a..8cc4b44f 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -422,10 +422,10 @@ void PlayerHandler::handleMessage(MessageIn &msg) } } -void PlayerHandler::attack(Being *being) +void PlayerHandler::attack(int id) { MessageOut outMsg(CMSG_PLAYER_ATTACK); - outMsg.writeInt32(being->getId()); + outMsg.writeInt32(id); outMsg.writeInt8(0); } diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h index 94ae952f..4429d856 100644 --- a/src/net/ea/playerhandler.h +++ b/src/net/ea/playerhandler.h @@ -35,7 +35,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler void handleMessage(MessageIn &msg); - void attack(Being *being); + void attack(int id); void emote(int emoteId); diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 0998da04..c51c59c0 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -31,7 +31,7 @@ namespace Net { class PlayerHandler { public: - virtual void attack(Being *being) = 0; + virtual void attack(int id) = 0; virtual void emote(int emoteId) = 0; diff --git a/src/net/tmwserv/gameserver/player.cpp b/src/net/tmwserv/gameserver/player.cpp index 3f05c954..93853681 100644 --- a/src/net/tmwserv/gameserver/player.cpp +++ b/src/net/tmwserv/gameserver/player.cpp @@ -58,13 +58,6 @@ void Net::GameServer::Player::moveItem(int oldSlot, int newSlot, int amount) Net::GameServer::connection->send(msg); } -void Net::GameServer::Player::attack(int direction) -{ - MessageOut msg(PGMSG_ATTACK); - msg.writeInt8(direction); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::useSpecial(int special) { MessageOut msg(PGMSG_USE_SPECIAL); diff --git a/src/net/tmwserv/gameserver/player.h b/src/net/tmwserv/gameserver/player.h index eddd9102..24b25dc7 100644 --- a/src/net/tmwserv/gameserver/player.h +++ b/src/net/tmwserv/gameserver/player.h @@ -43,7 +43,6 @@ namespace Net void walk(int x, int y); void pickUp(int x, int y); void moveItem(int oldSlot, int newSlot, int amount); - void attack(int direction); void useSpecial(int special); void requestTrade(int id); void acceptTrade(bool accept); diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index b697e8a8..543d18d8 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -332,9 +332,11 @@ void PlayerHandler::handleMapChangeMessage(MessageIn &msg) viewport->scrollBy(scrollOffsetX, scrollOffsetY); } -void PlayerHandler::attack(Being *being) +void PlayerHandler::attack(int id) { - // TODO + MessageOut msg(PGMSG_ATTACK); + msg.writeInt16(id); + Net::GameServer::connection->send(msg); } void PlayerHandler::emote(int emoteId) diff --git a/src/net/tmwserv/playerhandler.h b/src/net/tmwserv/playerhandler.h index 5524415e..238da182 100644 --- a/src/net/tmwserv/playerhandler.h +++ b/src/net/tmwserv/playerhandler.h @@ -34,7 +34,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler void handleMessage(MessageIn &msg); - void attack(Being *being); + void attack(int id); void emote(int emoteId); diff --git a/src/net/tmwserv/protocol.h b/src/net/tmwserv/protocol.h index 7fa3b372..0f2a1b0d 100644 --- a/src/net/tmwserv/protocol.h +++ b/src/net/tmwserv/protocol.h @@ -106,7 +106,7 @@ enum { GPMSG_BEING_DIR_CHANGE = 0x0273, // W being id, B direction GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position, B speed] [, W*2 destination] }* GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* - PGMSG_ATTACK = 0x0290, // B direction + PGMSG_ATTACK = 0x0290, // W being id PGMSG_USE_SPECIAL = 0x0292, // B specialID GPMSG_BEING_ATTACK = 0x0291, // W being id PGMSG_SAY = 0x02A0, // S text -- cgit v1.2.3-70-g09d2 From e975b11e1885457295a51778d8337b097549228d Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 19 May 2009 15:58:58 +0100 Subject: Fixed targeting and warn on attack-range not being found in itemdb. Tried to make the client continue attacking (it does not need to send attack packets, but just continue playing attack animation and sounds). Now logs a warning when a weapon is found without an attack-range (I keep finding weapons with an attack-range of 0 which makes it hard to target monsters). --- src/gui/viewport.cpp | 12 ++---------- src/localplayer.cpp | 14 +++++--------- src/net/tmwserv/protocol.h | 6 ++++-- src/resources/itemdb.cpp | 4 ++++ 4 files changed, 15 insertions(+), 21 deletions(-) (limited to 'src/net') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index cbde95c4..787723c0 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -357,20 +357,12 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (player_node->withinAttackRange(being) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) { - player_node->setGotoTarget(being); - player_node->attack(being, !keyboard.isKeyActive(keyboard.KEY_TARGET)); - } else { -#ifdef TMWSERV_SUPPORT - player_node->setDestination(event.getX() + (int) mPixelViewX, - event.getY() + (int) mPixelViewY); -#else - player_node->setDestination(tilex, tiley); -#endif + player_node->setGotoTarget(being); } break; default: @@ -399,9 +391,9 @@ void Viewport::mousePressed(gcn::MouseEvent &event) event.getY() + (int) mPixelViewY); } #else - player_node->stopAttack(); player_node->setDestination(tilex, tiley); #endif + player_node->stopAttack(); mPlayerFollowMouse = true; } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b9f4b850..31b963ab 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -209,18 +209,14 @@ void LocalPlayer::logic() // Find whether target is in range const int rangeX = abs(mTarget->getPosition().x - getPosition().x); const int rangeY = abs(mTarget->getPosition().y - getPosition().y); - const int attackRange = getAttackRange(); - const int inRange = rangeX > attackRange || rangeY > attackRange - ? 1 : 0; #else // Find whether target is in range const int rangeX = abs(mTarget->mX - mX); const int rangeY = abs(mTarget->mY - mY); +#endif const int attackRange = getAttackRange(); const int inRange = rangeX > attackRange || rangeY > attackRange ? 1 : 0; -#endif - mTarget->setTargetAnimation( mTargetCursor[inRange][mTarget->getTargetCursorSize()]); @@ -290,9 +286,7 @@ void LocalPlayer::nextStep() if (mGoingToTarget && mTarget && withinAttackRange(mTarget)) { mAction = Being::STAND; -#ifdef EATHENA_SUPPORT attack(mTarget, true); -#endif mGoingToTarget = false; mPath.clear(); return; @@ -703,11 +697,11 @@ void LocalPlayer::attack(Being *target, bool keep) #else int dist_x = target->mX - mX; int dist_y = target->mY - mY; -#endif // Must be standing to attack if (mAction != STAND) return; +#endif if (abs(dist_y) >= abs(dist_x)) { @@ -744,10 +738,12 @@ void LocalPlayer::attack(Being *target, bool keep) sound.playSfx("sfx/fist-swish.ogg"); } +#ifdef EATHENA_SUPPORT Net::getPlayerHandler()->attack(target->getId()); if (!keep) stopAttack(); +#endif } void LocalPlayer::stopAttack() @@ -872,7 +868,7 @@ int LocalPlayer::getAttackRange() const ItemInfo info = weapon->getInfo(); return info.getAttackRange(); } - return 32; // unarmed range + return 48; // unarmed range #else return mAttackRange; #endif diff --git a/src/net/tmwserv/protocol.h b/src/net/tmwserv/protocol.h index 0f2a1b0d..6124263a 100644 --- a/src/net/tmwserv/protocol.h +++ b/src/net/tmwserv/protocol.h @@ -162,9 +162,11 @@ enum { CPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error PCMSG_GUILD_PROMOTE_MEMBER = 0x0365, // W guild, S name, B rights CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE = 0x0366, // B error + PCMSG_GUILD_KICK_MEMBER = 0x0370, // W guild, S name + CPMSG_GUILD_KICK_MEMBER_RESPONSE = 0x0371, // B error - CPMSG_GUILD_INVITED = 0x0370, // S char name, S guild name, W id - CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, W rights, W channel, S announce + CPMSG_GUILD_INVITED = 0x0388, // S char name, S guild name, W id + CPMSG_GUILD_REJOIN = 0x0389, // S name, W guild, W rights, W channel, S announce // Party PCMSG_PARTY_INVITE = 0x03A0, // S name diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 99907ca7..fa31c556 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -210,6 +210,10 @@ void ItemDB::load() } } + if (weaponType > 0) + if (attackRange == 0) + logger->log("ItemDB: Missing attack range from weapon %i!", id); + #define CHECK_PARAM(param, error_value) \ if (param == error_value) \ logger->log("ItemDB: Missing " #param " attribute for item %i!",id) -- cgit v1.2.3-70-g09d2