From 74f23fd3d0e1fb3be8e5419193d57d91746c887a Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 27 Mar 2009 13:12:24 -0600 Subject: Clean up chat and chat tabs some more --- src/gui/widgets/whispertab.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'src/gui/widgets/whispertab.cpp') diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 1c63d1c9..0ae042df 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -19,38 +19,28 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "whispertab.h" -#include "../../beingmanager.h" -#include "../../commandhandler.h" -#include "../../channel.h" -#include "../../configuration.h" -#include "../../game.h" -#include "../../localplayer.h" +#include "localplayer.h" + +#include "gui/palette.h" #ifdef TMWSERV_SUPPORT -#include "../../net/tmwserv/chatserver/chatserver.h" -#include "../../net/tmwserv/gameserver/player.h" +#include "net/tmwserv/chatserver/chatserver.h" #else -#include "../../party.h" -#include "../../net/messageout.h" -#include "../../net/ea/protocol.h" +#include "party.h" +#include "net/messageout.h" +#include "net/ea/protocol.h" #endif -#include "../../resources/iteminfo.h" -#include "../../resources/itemdb.h" - -#include "../../utils/dtor.h" -#include "../../utils/gettext.h" -#include "../../utils/strprintf.h" -#include "../../utils/stringutils.h" +#include "utils/gettext.h" +#include "utils/strprintf.h" WhisperTab::WhisperTab(const std::string &nick) : ChatTab(nick), mNick(nick) { + setForegroundColor(guiPalette->getColor(Palette::WHISPER)); } WhisperTab::~WhisperTab() @@ -58,7 +48,7 @@ WhisperTab::~WhisperTab() chatWindow->removeWhisper(mNick); } -void WhisperTab::sendChat(const std::string &msg) { +void WhisperTab::handleInput(const std::string &msg) { if (msg.length() == 0) { chatLog(_("Cannot send empty chat!"), BY_SERVER, false); return; @@ -78,7 +68,7 @@ void WhisperTab::sendChat(const std::string &msg) { msg.c_str()), BY_PLAYER, false); } -void WhisperTab::handleCommand(const std::string msg) +void WhisperTab::handleCommand(std::string msg) { if (msg == "close") delete this; -- cgit v1.2.3-70-g09d2 From 712ca58c011123505c807266dcc8d9d84ca1aa44 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 27 Mar 2009 19:44:23 +0100 Subject: Made eAthena's Network class statically accessible Now the instance doesn't need to be passed into the MessageOut class anymore. Expect a lot of cleanup in the next commit. --- src/beingmanager.cpp | 3 +-- src/commandhandler.cpp | 6 ++---- src/engine.cpp | 3 +-- src/game.cpp | 3 +-- src/gui/buy.cpp | 3 +-- src/gui/buysell.cpp | 3 +-- src/gui/char_select.cpp | 9 +++------ src/gui/npc_text.cpp | 6 ++---- src/gui/npcintegerdialog.cpp | 3 +-- src/gui/npclistdialog.cpp | 3 +-- src/gui/npcstringdialog.cpp | 3 +-- src/gui/popupmenu.cpp | 3 +-- src/gui/sell.cpp | 4 +--- src/gui/storagewindow.cpp | 9 +++------ src/gui/trade.cpp | 18 ++++++------------ src/gui/widgets/chattab.cpp | 7 ++----- src/gui/widgets/whispertab.cpp | 3 +-- src/localplayer.cpp | 42 ++++++++++++++---------------------------- src/main.cpp | 10 +++------- src/net/ea/network.cpp | 9 +++++++++ src/net/ea/network.h | 6 +++++- src/net/messageout.cpp | 11 +++-------- src/net/messageout.h | 4 +--- src/npc.cpp | 3 +-- src/party.cpp | 12 ++++-------- 25 files changed, 69 insertions(+), 117 deletions(-) (limited to 'src/gui/widgets/whispertab.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index d72c4ee4..ae9ee787 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -120,8 +120,7 @@ Being *BeingManager::createBeing(int id, Uint16 job) // Player or NPC if (job <= 1000 || (job >= 4001 && job <= 4049)) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0094); + MessageOut outMsg(0x0094); outMsg.writeInt32(id);//readLong(2)); } #endif diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 14c5434a..73e41554 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -142,8 +142,7 @@ void CommandHandler::handleAnnounce(const std::string &args) #ifdef TMWSERV_SUPPORT Net::ChatServer::announce(args); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0099); + MessageOut outMsg(0x0099); outMsg.writeInt16(args.length() + 4); outMsg.writeString(args, args.length()); #endif @@ -332,8 +331,7 @@ void CommandHandler::handleWho() #ifdef TMWSERV_SUPPORT //TODO #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00c1); + MessageOut outMsg(0x00c1); #endif } diff --git a/src/engine.cpp b/src/engine.cpp index da4eb336..13563e66 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -151,8 +151,7 @@ void Engine::changeMap(const std::string &mapPath) #ifdef EATHENA_SUPPORT // Send "map loaded" - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_MAP_LOADED); + MessageOut outMsg(CMSG_MAP_LOADED); #endif } diff --git a/src/game.cpp b/src/game.cpp index 4687ed1f..5b389c3f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -468,8 +468,7 @@ Game::Game(Network *network): * packet is handled by the older version, but its response * is ignored by the client */ - MessageOut msg(mNetwork); - msg.writeInt16(CMSG_CLIENT_PING); + MessageOut msg(CMSG_CLIENT_PING); msg.writeInt32(tick_time); engine->changeMap(map_path); diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 6df2ae25..003e730e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -199,8 +199,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) Net::GameServer::Player::tradeWithNPC (mShopItems->at(selectedItem)->getId(), mAmountItems); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_REQUEST); + MessageOut outMsg(CMSG_NPC_BUY_REQUEST); outMsg.writeInt16(8); outMsg.writeInt16(mAmountItems); outMsg.writeInt16(mShopItems->at(selectedItem)->getId()); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index b9a6a1dc..f45a5adb 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -97,8 +97,7 @@ void BuySellDialog::action(const gcn::ActionEvent &event) } #ifdef EATHENA_SUPPORT - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeInt32(current_npc); outMsg.writeInt8(action); #endif diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 4ab3d9ef..b6cd47d4 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -348,8 +348,7 @@ void CharSelectDialog::attemptCharDelete() Net::AccountServer::Account::deleteCharacter(mCharInfo->getPos()); #else // Request character deletion - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0068); + MessageOut outMsg(0x0068); outMsg.writeInt32(mCharInfo->getEntry()->mCharId); outMsg.writeString("a@a.com", 40); #endif @@ -362,8 +361,7 @@ void CharSelectDialog::attemptCharSelect() Net::AccountServer::Account::selectCharacter(mCharInfo->getPos()); #else // Request character selection - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0066); + MessageOut outMsg(0x0066); outMsg.writeInt8(mCharInfo->getPos()); #endif mCharInfo->lock(); @@ -693,8 +691,7 @@ int CharCreateDialog::getDistributedPoints() void CharCreateDialog::attemptCharCreate() { // Send character infos - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0067); + MessageOut outMsg(0x0067); outMsg.writeString(getName(), 24); outMsg.writeInt8(5); outMsg.writeInt8(5); diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 9fa57be8..bf7b60ed 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -136,8 +136,7 @@ void NpcTextDialog::nextDialog(int npcID) #ifdef TMWSERV_SUPPORT Net::GameServer::Player::talkToNPC(npcID, false); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(npcID); #endif } @@ -145,8 +144,7 @@ void NpcTextDialog::nextDialog(int npcID) void NpcTextDialog::closeDialog(int npcID) { #ifdef EATHENA_SUPPORT - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_CLOSE); + MessageOut outMsg(CMSG_NPC_CLOSE); outMsg.writeInt32(npcID); #endif } diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index a7ae2748..4dae8d83 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -127,8 +127,7 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) NPC::isTalking = false; #ifdef EATHENA_SUPPORT - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + MessageOut outMsg(CMSG_NPC_INT_RESPONSE); outMsg.writeInt32(current_npc); outMsg.writeInt32(mValueField->getValue()); #endif diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index ff91c9fc..6df0979f 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -143,8 +143,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event) #ifdef TMWSERV_SUPPORT Net::GameServer::Player::selectFromNPC(current_npc, choice); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(current_npc); outMsg.writeInt8(choice); #endif diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index c84de015..7297d7e8 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -95,8 +95,7 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) mValueField->setText(""); #ifdef EATHENA_SUPPORT - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + MessageOut outMsg(CMSG_NPC_STR_RESPONSE); outMsg.writeInt16(text.length() + 9); outMsg.writeInt32(current_npc); outMsg.writeString(text, text.length()); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 5b5b2b8c..1f36ef45 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -297,8 +297,7 @@ void PopupMenu::handleLink(const std::string &link) being && being->getType() == Being::PLAYER) { - MessageOut outMsg(player_node->getNetwork()); - outMsg.writeInt16(CMSG_PARTY_INVITE); + MessageOut outMsg(CMSG_PARTY_INVITE); outMsg.writeInt32(being->getId()); } #endif diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index e7671110..648bff08 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -207,15 +207,13 @@ void SellDialog::action(const gcn::ActionEvent &event) (mShopItems->at(selectedItem)->getId(), mAmountItems); #else // Attempt sell - MessageOut outMsg(mNetwork); - ShopItem *item = mShopItems->at(selectedItem); int sellCount; mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); mMaxItems -= mAmountItems; while (mAmountItems > 0) { - outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_SELL_REQUEST); outMsg.writeInt16(8); outMsg.writeInt16(item->getCurrentInvIndex()); // This order is important, item->getCurrentInvIndex() would return diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 1289a4e7..847886cb 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -190,22 +190,19 @@ Item* StorageWindow::getSelectedItem() const void StorageWindow::addStore(Item* item, int ammount) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_MOVE_TO_STORAGE); + MessageOut outMsg(CMSG_MOVE_TO_STORAGE); outMsg.writeInt16(item->getInvIndex()); outMsg.writeInt32(ammount); } void StorageWindow::removeStore(Item* item, int ammount) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CSMG_MOVE_FROM_STORAGE); + MessageOut outMsg(CSMG_MOVE_FROM_STORAGE); outMsg.writeInt16(item->getInvIndex()); outMsg.writeInt32(ammount); } void StorageWindow::close() { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_CLOSE_STORAGE); + MessageOut outMsg(CMSG_CLOSE_STORAGE); } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 4ecdede8..6cba1c41 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -252,8 +252,7 @@ void TradeWindow::tradeItem(Item *item, int quantity) // function. Detect the actual server version, and re-enable this // for that version only. //addItem(item->getId(), true, quantity, item->isEquipment()); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); outMsg.writeInt32(quantity); #endif @@ -329,8 +328,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) #ifdef TMWSERV_SUPPORT Net::GameServer::Player::acceptTrade(false); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); + MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST); #endif } #ifdef EATHENA_SUPPORT @@ -342,8 +340,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) { mMoneyField->setText(toString(tempInt)); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(0); outMsg.writeInt32(tempInt); } @@ -352,8 +349,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) mMoneyField->setText(""); } mMoneyField->setEnabled(false); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_ADD_COMPLETE); + MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE); } #endif else if (event.getId() == "trade") @@ -362,8 +358,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) Net::GameServer::Player::acceptTrade(true); setStatus(PROPOSING); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_OK); + MessageOut outMsg(CMSG_TRADE_OK); #endif } #ifdef TMWSERV_SUPPORT @@ -382,7 +377,6 @@ void TradeWindow::close() #ifdef TMWSERV_SUPPORT Net::GameServer::Player::acceptTrade(false); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); + MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST); #endif } diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 715aaf20..c4b2196b 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -239,9 +239,7 @@ void ChatTab::chatInput(std::string &msg) chatLog(_("Trying to send a blank party message."), BY_SERVER, true); return; } - MessageOut outMsg(chatWindow->mNetwork); - - outMsg.writeInt16(CMSG_PARTY_MESSAGE); + MessageOut outMsg(CMSG_PARTY_MESSAGE); outMsg.writeInt16(length + 4); outMsg.writeString(msg, length); return; @@ -306,8 +304,7 @@ void ChatTab::handleInput(const std::string &msg) { #else std::string mes = player_node->getName() + " : " + msg; - MessageOut outMsg(chatWindow->mNetwork); - outMsg.writeInt16(CMSG_CHAT_MESSAGE); + MessageOut outMsg(CMSG_CHAT_MESSAGE); // Added + 1 in order to let eAthena parse admin commands correctly outMsg.writeInt16(mes.length() + 4 + 1); outMsg.writeString(mes, mes.length() + 1); diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 0ae042df..1621e965 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -57,8 +57,7 @@ void WhisperTab::handleInput(const std::string &msg) { #ifdef TMWSERV_SUPPORT Net::ChatServer::privMsg(mNick, msg); #else - MessageOut outMsg(chatWindow->mNetwork); - outMsg.writeInt16(CMSG_CHAT_WHISPER); + MessageOut outMsg(CMSG_CHAT_WHISPER); outMsg.writeInt16(msg.length() + 28); outMsg.writeString(mNick, 24); outMsg.writeString(msg, msg.length()); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f8fad1e8..8b2d6907 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -399,8 +399,7 @@ void LocalPlayer::equipItem(Item *item) #ifdef TMWSERV_SUPPORT Net::GameServer::Player::equip(item->getInvIndex()); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PLAYER_EQUIP); + MessageOut outMsg(CMSG_PLAYER_EQUIP); outMsg.writeInt16(item->getInvIndex()); outMsg.writeInt16(0); #endif @@ -428,8 +427,7 @@ void LocalPlayer::unequipItem(Item *item) if (!item) return; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PLAYER_UNEQUIP); + MessageOut outMsg(CMSG_PLAYER_UNEQUIP); outMsg.writeInt16(item->getInvIndex()); // Tidy equipment directly to avoid weapon still shown bug, for instance @@ -438,8 +436,7 @@ void LocalPlayer::unequipItem(Item *item) void LocalPlayer::useItem(Item *item) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PLAYER_INVENTORY_USE); + MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE); outMsg.writeInt16(item->getInvIndex()); outMsg.writeInt32(item->getId()); // Note: id is dest of item, usually player_node->account_ID ?? @@ -453,8 +450,7 @@ void LocalPlayer::dropItem(Item *item, int quantity) Net::GameServer::Player::drop(item->getInvIndex(), quantity); #else // TODO: Fix wrong coordinates of drops, serverside? - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PLAYER_INVENTORY_DROP); + MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP); outMsg.writeInt16(item->getInvIndex()); outMsg.writeInt16(quantity); #endif @@ -488,8 +484,7 @@ void LocalPlayer::pickUp(FloorItem *item) int id = item->getId(); Net::GameServer::Player::pickUp(id >> 16, id & 0xFFFF); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_ITEM_PICKUP); + MessageOut outMsg(CMSG_ITEM_PICKUP); outMsg.writeInt32(item->getId()); #endif mPickUpTarget = NULL; @@ -689,9 +684,8 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) effectManager->trigger(15,x,y); #else char temp[4] = ""; - MessageOut outMsg(mNetwork); set_coordinates(temp, x, y, mDirection); - outMsg.writeInt16(0x0085); + MessageOut outMsg(0x0085); outMsg.writeString(temp, 3); #endif } @@ -734,8 +728,7 @@ void LocalPlayer::stopWalking(bool sendToServer) #ifdef EATHENA_SUPPORT void LocalPlayer::raiseAttribute(Attribute attr) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_STAT_UPDATE_REQUEST); + MessageOut outMsg(CMSG_STAT_UPDATE_REQUEST); switch (attr) { @@ -771,8 +764,7 @@ void LocalPlayer::raiseSkill(Uint16 skillId) if (mSkillPoint <= 0) return; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_SKILL_LEVELUP_REQUEST); + MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST); outMsg.writeInt16(skillId); } #endif @@ -795,8 +787,7 @@ void LocalPlayer::toggleSit() setAction(newAction); Net::GameServer::Player::changeAction(newAction); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0089); + MessageOut outMsg(0x0089); outMsg.writeInt32(0); outMsg.writeInt8((newAction == SIT) ? 2 : 3); #endif @@ -810,8 +801,7 @@ void LocalPlayer::emote(Uint8 emotion) // XXX Convert for new server #ifdef EATHENA_SUPPORT - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00bf); + MessageOut outMsg(0x00bf); outMsg.writeInt8(emotion); #endif } @@ -822,8 +812,7 @@ void LocalPlayer::tradeReply(bool accept) if (!accept) mTrading = false; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_RESPONSE); + MessageOut outMsg(CMSG_TRADE_RESPONSE); outMsg.writeInt8(accept ? 3 : 4); } #endif @@ -837,8 +826,7 @@ void LocalPlayer::trade(Being *being) const tradePartnerID = being->getId(); Net::GameServer::Player::requestTrade(tradePartnerID); #else - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_REQUEST); + MessageOut outMsg(CMSG_TRADE_REQUEST); outMsg.writeInt32(being->getId()); #endif } @@ -957,8 +945,7 @@ void LocalPlayer::attack(Being *target, bool keep) sound.playSfx("sfx/fist-swish.ogg"); } - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0089); + MessageOut outMsg(0x0089); outMsg.writeInt32(target->getId()); outMsg.writeInt8(0); @@ -983,8 +970,7 @@ void LocalPlayer::revive() { // XXX Convert for new server #ifdef EATHENA_SUPPORT - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00b2); + MessageOut outMsg(0x00b2); outMsg.writeInt8(0); #endif } diff --git a/src/main.cpp b/src/main.cpp index 321a4ee0..bd17ce9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -752,8 +752,7 @@ static void accountLogin(Network *network, LoginData *loginData) loginData->username, loginData->password); #else - MessageOut outMsg(network); - outMsg.writeInt16(0x0064); + MessageOut outMsg(0x0064); outMsg.writeInt32(0); // client version outMsg.writeString(loginData->username, 24); outMsg.writeString(loginData->password, 24); @@ -807,8 +806,7 @@ static void charLogin(Network *network, LoginData *loginData) charServerHandler.setLoginData(loginData); // Send login infos - MessageOut outMsg(network); - outMsg.writeInt16(0x0065); + MessageOut outMsg(0x0065); outMsg.writeInt32(loginData->account_ID); outMsg.writeInt32(loginData->session_ID1); outMsg.writeInt32(loginData->session_ID2); @@ -827,8 +825,6 @@ static void mapLogin(Network *network, LoginData *loginData) player_node->getName().c_str()); config.setValue("lastCharacter", player_node->getName()); - MessageOut outMsg(network); - logger->log("Trying to connect to map server..."); logger->log("Map: %s", map_path.c_str()); @@ -836,7 +832,7 @@ static void mapLogin(Network *network, LoginData *loginData) network->registerHandler(&mapLoginHandler); // Send login infos - outMsg.writeInt16(0x0072); + MessageOut outMsg(0x0072); outMsg.writeInt32(loginData->account_ID); outMsg.writeInt32(player_node->mCharId); outMsg.writeInt32(loginData->session_ID1); diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index e17b8f3b..4aecb268 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -91,6 +91,8 @@ int networkThread(void *data) return 0; } +Network *Network::mInstance = 0; + Network::Network(): mSocket(0), mAddress(), mPort(0), @@ -102,6 +104,7 @@ Network::Network(): mWorkerThread(0) { mMutex = SDL_CreateMutex(); + mInstance = this; } Network::~Network() @@ -112,6 +115,7 @@ Network::~Network() disconnect(); SDL_DestroyMutex(mMutex); + mInstance = 0; delete[] mInBuffer; delete[] mOutBuffer; @@ -420,6 +424,11 @@ void Network::receive() SDLNet_FreeSocketSet(set); } +Network *Network::instance() +{ + return mInstance; +} + void Network::setError(const std::string &error) { logger->log("Network error: %s", error.c_str()); diff --git a/src/net/ea/network.h b/src/net/ea/network.h index 651b1182..40d563aa 100644 --- a/src/net/ea/network.h +++ b/src/net/ea/network.h @@ -85,7 +85,9 @@ class Network NET_ERROR }; - protected: + private: + static Network *instance(); + void setError(const std::string &error); Uint16 readWord(int pos); @@ -113,6 +115,8 @@ class Network typedef std::map MessageHandlers; typedef MessageHandlers::iterator MessageHandlerIterator; MessageHandlers mMessageHandlers; + + static Network *mInstance; }; #endif diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 4cb4dc36..35e9a425 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -33,21 +33,16 @@ #include #include -#ifdef TMWSERV_SUPPORT MessageOut::MessageOut(short id): mData(0), -#else -MessageOut::MessageOut(Network *network): - mNetwork(network), -#endif mDataSize(0), mPos(0) { -#ifdef TMWSERV_SUPPORT - writeInt16(id); -#else +#ifdef EATHENA_SUPPORT + mNetwork = Network::instance(); mData = mNetwork->mOutBuffer + mNetwork->mOutSize; #endif + writeInt16(id); } #ifdef TMWSERV_SUPPORT diff --git a/src/net/messageout.h b/src/net/messageout.h index 1ddd040d..9dc31525 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -43,15 +43,13 @@ class MessageOut /** * Constructor. */ -#ifdef TMWSERV_SUPPORT MessageOut(short id); +#ifdef TMWSERV_SUPPORT /** * Destructor. */ ~MessageOut(); -#else - MessageOut(Network *network); #endif void writeInt8(Sint8 value); /**< Writes a byte. */ diff --git a/src/npc.cpp b/src/npc.cpp index b75d74b3..98c3e0eb 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -129,8 +129,7 @@ void NPC::talk() if (!mNetwork) return; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_TALK); + MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeInt32(mId); outMsg.writeInt8(0); #endif diff --git a/src/party.cpp b/src/party.cpp index 51a86360..4a7912ee 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -56,8 +56,7 @@ void Party::respond(const std::string &command, const std::string &args) localChatTab->chatLog(_("Not yet implemented!"), BY_SERVER); return; /* - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PARTY_SETTINGS); + MessageOut outMsg(CMSG_PARTY_SETTINGS); outMsg.writeInt16(0); // Experience outMsg.writeInt16(0); // Item */ @@ -72,16 +71,14 @@ void Party::create(const std::string &party) localChatTab->chatLog(_("Party name is missing."), BY_SERVER); return; } - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PARTY_CREATE); + MessageOut outMsg(CMSG_PARTY_CREATE); outMsg.writeString(party.substr(0, 23), 24); mCreating = true; } void Party::leave(const std::string &args) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PARTY_LEAVE); + MessageOut outMsg(CMSG_PARTY_LEAVE); localChatTab->chatLog(_("Left party."), BY_SERVER); mInParty = false; } @@ -137,8 +134,7 @@ void Party::invitedAsk(const std::string &nick, int gender, void Party::InviteListener::action(const gcn::ActionEvent &event) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_PARTY_INVITED); + MessageOut outMsg(CMSG_PARTY_INVITED); outMsg.writeInt32(player_node->getId()); bool accept = event.getId() == "yes"; outMsg.writeInt32(accept ? 1 : 0); -- cgit v1.2.3-70-g09d2 From f67237cb69599753192c301f0f2eb38b88f7b57a Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 27 Mar 2009 16:24:01 -0600 Subject: Clean up some ifdefs and start cleanup of parties --- src/Makefile.am | 6 +- src/commandhandler.cpp | 2 +- src/engine.cpp | 16 +-- src/engine.h | 2 +- src/game.cpp | 5 +- src/gui/widgets/whispertab.cpp | 1 - src/map.cpp | 4 - src/net/ea/gui/partytab.cpp | 53 ++++++++++ src/net/ea/gui/partytab.h | 49 +++++++++ src/net/ea/party.cpp | 215 ++++++++++++++++++++++++++++++++++++++ src/net/ea/party.h | 74 +++++++++++++ src/net/ea/playerhandler.cpp | 5 +- src/net/tmwserv/playerhandler.cpp | 3 - src/party.cpp | 215 -------------------------------------- src/party.h | 74 ------------- 15 files changed, 404 insertions(+), 320 deletions(-) create mode 100644 src/net/ea/gui/partytab.cpp create mode 100644 src/net/ea/gui/partytab.h create mode 100644 src/net/ea/party.cpp create mode 100644 src/net/ea/party.h delete mode 100644 src/party.cpp delete mode 100644 src/party.h (limited to 'src/gui/widgets/whispertab.cpp') diff --git a/src/Makefile.am b/src/Makefile.am index 4c5893ac..3768b7cd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -461,6 +461,8 @@ tmw_SOURCES += \ net/ea/network.h \ net/ea/npchandler.cpp \ net/ea/npchandler.h \ + net/ea/party.cpp \ + net/ea/party.h \ net/ea/partyhandler.cpp \ net/ea/partyhandler.h \ net/ea/playerhandler.cpp \ @@ -470,9 +472,7 @@ tmw_SOURCES += \ net/ea/skillhandler.cpp \ net/ea/skillhandler.h \ net/ea/tradehandler.cpp \ - net/ea/tradehandler.h \ - party.cpp \ - party.h + net/ea/tradehandler.h endif # set the include path found by configure diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index a2de2c63..5431cf88 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -34,8 +34,8 @@ #include "net/tmwserv/chatserver/chatserver.h" #include "net/tmwserv/gameserver/player.h" #else -#include "party.h" #include "net/messageout.h" +#include "net/ea/party.h" #include "net/ea/protocol.h" #endif diff --git a/src/engine.cpp b/src/engine.cpp index d13fbf3f..04d06e38 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -33,11 +33,6 @@ #include "gui/minimap.h" #include "gui/viewport.h" -#ifdef EATHENA_SUPPORT -#include "net/messageout.h" -#include "net/ea/protocol.h" -#endif - #include "resources/mapreader.h" #include "resources/monsterdb.h" #include "resources/resourcemanager.h" @@ -54,7 +49,7 @@ Engine::~Engine() delete mCurrentMap; } -void Engine::changeMap(const std::string &mapPath) +bool Engine::changeMap(const std::string &mapPath) { // Clean up floor items, beings and particles floorItemManager->clear(); @@ -71,11 +66,7 @@ void Engine::changeMap(const std::string &mapPath) mMapName = mapPath; // Store full map path in global var -#ifdef TMWSERV_SUPPORT map_path = "maps/" + mapPath + ".tmx"; -#else - map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx"; -#endif ResourceManager *resman = ResourceManager::getInstance(); if (!resman->exists(map_path)) map_path += ".gz"; @@ -143,10 +134,7 @@ void Engine::changeMap(const std::string &mapPath) mCurrentMap = newMap; -#ifdef EATHENA_SUPPORT - // Send "map loaded" - MessageOut outMsg(CMSG_MAP_LOADED); -#endif + return true; } void Engine::logic() diff --git a/src/engine.h b/src/engine.h index eafce3b9..963270e8 100644 --- a/src/engine.h +++ b/src/engine.h @@ -53,7 +53,7 @@ class Engine /** * Sets the currently active map. */ - void changeMap(const std::string &mapName); + bool changeMap(const std::string &mapName); /** * Performs engine logic. This method is called 100 times per second. diff --git a/src/game.cpp b/src/game.cpp index 856a5c11..6b9a829f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -43,9 +43,6 @@ #include "log.h" #include "npc.h" #include "particle.h" -#ifdef EATHENA_SUPPORT -#include "party.h" -#endif #include "player_relations.h" #include "gui/widgets/chattab.h" @@ -110,6 +107,7 @@ #include "net/ea/inventoryhandler.h" #include "net/ea/itemhandler.h" #include "net/ea/npchandler.h" +#include "net/ea/party.h" #include "net/ea/playerhandler.h" #include "net/ea/tradehandler.h" #include "net/ea/protocol.h" @@ -450,6 +448,7 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + MessageOut outMsg(CMSG_MAP_LOADED); #endif setupWindow->setInGame(true); diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 1621e965..9e6d9336 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -28,7 +28,6 @@ #ifdef TMWSERV_SUPPORT #include "net/tmwserv/chatserver/chatserver.h" #else -#include "party.h" #include "net/messageout.h" #include "net/ea/protocol.h" #endif diff --git a/src/map.cpp b/src/map.cpp index 59e6201f..8f736424 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -141,11 +141,7 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, // tiles have been drawn if (mIsFringeLayer) { -#ifdef TMWSERV_SUPPORT while (si != sprites.end() && (*si)->getPixelY() <= y * 32) -#else - while (si != sprites.end() && (*si)->getPixelY() <= y * 32) -#endif { (*si)->draw(graphics, -scrollX, -scrollY); si++; diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp new file mode 100644 index 00000000..a55d2492 --- /dev/null +++ b/src/net/ea/gui/partytab.cpp @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright (C) 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "partytab.h" + +#include "net/messageout.h" + +#include "net/ea/party.h" +#include "net/ea/protocol.h" + +#include "resources/iteminfo.h" +#include "resources/itemdb.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/strprintf.h" +#include "utils/stringutils.h" + +PartyTab::PartyTab() : ChatTab(_("Party")) +{ +} + +PartyTab::~PartyTab() +{ +} + +void PartyTab::handleInput(std::string &msg) { + // TODO +} + +void PartyTab::handleCommand(std::string &msg) { + // TODO +} diff --git a/src/net/ea/gui/partytab.h b/src/net/ea/gui/partytab.h new file mode 100644 index 00000000..b2aaca68 --- /dev/null +++ b/src/net/ea/gui/partytab.h @@ -0,0 +1,49 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef CHANNELTAB_H +#define CHANNELTAB_H + +#include "gui/widgets/chattab.h" + +/** + * A tab for a chat channel. + */ +class PartyTab : public ChatTab +{ + public: + /** + * Constructor. + */ + PartyTab(); + + /** + * Destructor. + */ + ~PartyTab(); + + protected: + void handleInput(const std::string &msg); + + void handleCommand(std::string msg); +}; + +#endif // CHANNELTAB_H diff --git a/src/net/ea/party.cpp b/src/net/ea/party.cpp new file mode 100644 index 00000000..2295cb81 --- /dev/null +++ b/src/net/ea/party.cpp @@ -0,0 +1,215 @@ +/* + * The Mana World + * Copyright (C) 2008 Lloyd Bryant + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "being.h" +#include "localplayer.h" +#include "party.h" + +#include "gui/widgets/chattab.h" +#include "gui/chat.h" +#include "gui/confirm_dialog.h" + +#include "net/messageout.h" +#include "net/ea/protocol.h" + +#include "utils/gettext.h" +#include "utils/strprintf.h" + +Party::Party() : + mInviteListener(&mInParty) +{ +} + +void Party::respond(const std::string &command, const std::string &args) +{ + if (command == "new" || command == "create") + { + create(args); + return; + } + if (command == "leave") + { + leave(args); + return; + } + if (command == "settings") + { + localChatTab->chatLog(_("Not yet implemented!"), BY_SERVER); + return; + /* + MessageOut outMsg(CMSG_PARTY_SETTINGS); + outMsg.writeInt16(0); // Experience + outMsg.writeInt16(0); // Item + */ + } + localChatTab->chatLog(_("Party command not known."), BY_SERVER); +} + +void Party::create(const std::string &party) +{ + if (party.empty()) + { + localChatTab->chatLog(_("Party name is missing."), BY_SERVER); + return; + } + MessageOut outMsg(CMSG_PARTY_CREATE); + outMsg.writeString(party.substr(0, 23), 24); + mCreating = true; +} + +void Party::leave(const std::string &args) +{ + MessageOut outMsg(CMSG_PARTY_LEAVE); + localChatTab->chatLog(_("Left party."), BY_SERVER); + mInParty = false; +} + +void Party::createResponse(bool ok) +{ + if (ok) + { + localChatTab->chatLog(_("Party successfully created."), BY_SERVER); + mInParty = true; + } + else + { + localChatTab->chatLog(_("Could not create party."), BY_SERVER); + } +} + +void Party::inviteResponse(const std::string &nick, int status) +{ + switch (status) + { + case 0: + localChatTab->chatLog(strprintf(_("%s is already a member of a party."), + nick.c_str()), BY_SERVER); + break; + case 1: + localChatTab->chatLog(strprintf(_("%s refused your invitation."), + nick.c_str()), BY_SERVER); + break; + case 2: + localChatTab->chatLog(strprintf(_("%s is now a member of your party."), + nick.c_str()), BY_SERVER); + break; + } +} + +void Party::invitedAsk(const std::string &nick, int gender, + const std::string &partyName) +{ + mPartyName = partyName; /* Quick and nasty - needs redoing */ + if (nick.empty()) + { + localChatTab->chatLog(_("You can\'t have a blank party name!"), BY_SERVER); + return; + } + mCreating = false; + ConfirmDialog *dlg = new ConfirmDialog(_("Invite to party"), + strprintf(_("%s invites you to join" + " the %s party, do you accept?"), + nick.c_str(), partyName.c_str())); + dlg->addActionListener(&mInviteListener); +} + +void Party::InviteListener::action(const gcn::ActionEvent &event) +{ + MessageOut outMsg(CMSG_PARTY_INVITED); + outMsg.writeInt32(player_node->getId()); + bool accept = event.getId() == "yes"; + outMsg.writeInt32(accept ? 1 : 0); + *mInParty = *mInParty || accept; +} + +void Party::leftResponse(const std::string &nick) +{ + localChatTab->chatLog(strprintf(_("%s has left your party."), nick.c_str()), + BY_SERVER); +} + +void Party::receiveChat(Being *being, const std::string &msg) +{ + if (!being) + { + return; + } + if (being->getType() != Being::PLAYER) + { + localChatTab->chatLog(_("Party chat received, but being is not a player"), + BY_SERVER); + return; + } + being->setSpeech(msg, SPEECH_TIME); + localChatTab->chatLog(being->getName() + " : " + msg, BY_PARTY); +} + +void Party::help(const std::string &args) +{ + // Strip "party " from the front + std::string msg = args.substr(6, args.length()); + + if (msg.empty()) + { + localChatTab->chatLog(_("Command: /party "), BY_SERVER); + localChatTab->chatLog(_("where can be one of:"), BY_SERVER); + localChatTab->chatLog(_(" /new"), BY_SERVER); + localChatTab->chatLog(_(" /create"), BY_SERVER); + localChatTab->chatLog(_(" /prefix"), BY_SERVER); + localChatTab->chatLog(_(" /leave"), BY_SERVER); + localChatTab->chatLog(_("This command implements the partying function."), + BY_SERVER); + localChatTab->chatLog(_("Type /help party for further help."), + BY_SERVER); + return; + } + if (msg == "new" || msg == "create") + { + localChatTab->chatLog(_("Command: /party new "), BY_SERVER); + localChatTab->chatLog(_("Command: /party create "), BY_SERVER); + localChatTab->chatLog(_("These commands create a new party chatLog(_("Command: /party prefix "), BY_SERVER); + localChatTab->chatLog(_("This command sets the party prefix character."), + BY_SERVER); + localChatTab->chatLog(_("Any message preceded by is sent to " + "the party instead of everyone."), BY_SERVER); + localChatTab->chatLog(_("Command: /party prefix"), BY_SERVER); + localChatTab->chatLog(_("This command reports the current party prefix " + "character."), BY_SERVER); + return; + } + //if (msg == "settings") + //if (msg == "info") + if (msg == "leave") + { + localChatTab->chatLog(_("Command: /party leave"), BY_SERVER); + localChatTab->chatLog(_("This command causes the player to leave the party."), + BY_SERVER); + return; + } + localChatTab->chatLog(_("Unknown /party command."), BY_SERVER); + localChatTab->chatLog(_("Type /help party for a list of options."), BY_SERVER); +} diff --git a/src/net/ea/party.h b/src/net/ea/party.h new file mode 100644 index 00000000..25af80b3 --- /dev/null +++ b/src/net/ea/party.h @@ -0,0 +1,74 @@ +/* + * The Mana World + * Copyright (C) 2008 Lloyd Bryant + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PARTY_H +#define PARTY_H + +#include + +#include + +class PartyHandler; +class Being; +class ChatWindow; + +class Party +{ + public: + Party(); + void respond(const std::string &command, const std::string &args); + + void create(const std::string &party); + void leave(const std::string &args); + + void createResponse(bool ok); + void inviteResponse(const std::string &nick, int status); + void invitedAsk(const std::string &nick, int gender, + const std::string &partyName); + void leftResponse(const std::string &nick); + void receiveChat(Being *being, const std::string &msg); + + void help(const std::string &args); + + private: + std::string mPartyName; + bool mInParty; + bool mCreating; /**< Used to give an appropriate response to + failure */ + PartyHandler *handler; + + class InviteListener : public gcn::ActionListener + { + public: + InviteListener(bool *inParty) : + mInParty(inParty) + {} + void action(const gcn::ActionEvent &event); + + private: + bool *mInParty; + }; + InviteListener mInviteListener; +}; + +extern Party *playerParty; + +#endif diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index bf775f51..05f74630 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -24,6 +24,7 @@ #include "net/ea/protocol.h" #include "net/messagein.h" +#include "net/messageout.h" #include "engine.h" #include "localplayer.h" @@ -193,7 +194,9 @@ void PlayerHandler::handleMessage(MessageIn &msg) nearby = (engine->getCurrentMapName() == mapPath); // Switch the actual map, deleting the previous one if necessary - engine->changeMap(mapPath); + mapPath = mapPath.substr(0, mapPath.rfind(".")); + if (engine->changeMap(mapPath)) + MessageOut outMsg(CMSG_MAP_LOADED); float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index f02ed4c1..106894a1 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -85,9 +85,6 @@ namespace { npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); -#ifdef EATHENA_SUPPORT - buySellDialog->setVisible(false); -#endif current_npc = 0; } } deathListener; diff --git a/src/party.cpp b/src/party.cpp deleted file mode 100644 index 2295cb81..00000000 --- a/src/party.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008 Lloyd Bryant - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "being.h" -#include "localplayer.h" -#include "party.h" - -#include "gui/widgets/chattab.h" -#include "gui/chat.h" -#include "gui/confirm_dialog.h" - -#include "net/messageout.h" -#include "net/ea/protocol.h" - -#include "utils/gettext.h" -#include "utils/strprintf.h" - -Party::Party() : - mInviteListener(&mInParty) -{ -} - -void Party::respond(const std::string &command, const std::string &args) -{ - if (command == "new" || command == "create") - { - create(args); - return; - } - if (command == "leave") - { - leave(args); - return; - } - if (command == "settings") - { - localChatTab->chatLog(_("Not yet implemented!"), BY_SERVER); - return; - /* - MessageOut outMsg(CMSG_PARTY_SETTINGS); - outMsg.writeInt16(0); // Experience - outMsg.writeInt16(0); // Item - */ - } - localChatTab->chatLog(_("Party command not known."), BY_SERVER); -} - -void Party::create(const std::string &party) -{ - if (party.empty()) - { - localChatTab->chatLog(_("Party name is missing."), BY_SERVER); - return; - } - MessageOut outMsg(CMSG_PARTY_CREATE); - outMsg.writeString(party.substr(0, 23), 24); - mCreating = true; -} - -void Party::leave(const std::string &args) -{ - MessageOut outMsg(CMSG_PARTY_LEAVE); - localChatTab->chatLog(_("Left party."), BY_SERVER); - mInParty = false; -} - -void Party::createResponse(bool ok) -{ - if (ok) - { - localChatTab->chatLog(_("Party successfully created."), BY_SERVER); - mInParty = true; - } - else - { - localChatTab->chatLog(_("Could not create party."), BY_SERVER); - } -} - -void Party::inviteResponse(const std::string &nick, int status) -{ - switch (status) - { - case 0: - localChatTab->chatLog(strprintf(_("%s is already a member of a party."), - nick.c_str()), BY_SERVER); - break; - case 1: - localChatTab->chatLog(strprintf(_("%s refused your invitation."), - nick.c_str()), BY_SERVER); - break; - case 2: - localChatTab->chatLog(strprintf(_("%s is now a member of your party."), - nick.c_str()), BY_SERVER); - break; - } -} - -void Party::invitedAsk(const std::string &nick, int gender, - const std::string &partyName) -{ - mPartyName = partyName; /* Quick and nasty - needs redoing */ - if (nick.empty()) - { - localChatTab->chatLog(_("You can\'t have a blank party name!"), BY_SERVER); - return; - } - mCreating = false; - ConfirmDialog *dlg = new ConfirmDialog(_("Invite to party"), - strprintf(_("%s invites you to join" - " the %s party, do you accept?"), - nick.c_str(), partyName.c_str())); - dlg->addActionListener(&mInviteListener); -} - -void Party::InviteListener::action(const gcn::ActionEvent &event) -{ - MessageOut outMsg(CMSG_PARTY_INVITED); - outMsg.writeInt32(player_node->getId()); - bool accept = event.getId() == "yes"; - outMsg.writeInt32(accept ? 1 : 0); - *mInParty = *mInParty || accept; -} - -void Party::leftResponse(const std::string &nick) -{ - localChatTab->chatLog(strprintf(_("%s has left your party."), nick.c_str()), - BY_SERVER); -} - -void Party::receiveChat(Being *being, const std::string &msg) -{ - if (!being) - { - return; - } - if (being->getType() != Being::PLAYER) - { - localChatTab->chatLog(_("Party chat received, but being is not a player"), - BY_SERVER); - return; - } - being->setSpeech(msg, SPEECH_TIME); - localChatTab->chatLog(being->getName() + " : " + msg, BY_PARTY); -} - -void Party::help(const std::string &args) -{ - // Strip "party " from the front - std::string msg = args.substr(6, args.length()); - - if (msg.empty()) - { - localChatTab->chatLog(_("Command: /party "), BY_SERVER); - localChatTab->chatLog(_("where can be one of:"), BY_SERVER); - localChatTab->chatLog(_(" /new"), BY_SERVER); - localChatTab->chatLog(_(" /create"), BY_SERVER); - localChatTab->chatLog(_(" /prefix"), BY_SERVER); - localChatTab->chatLog(_(" /leave"), BY_SERVER); - localChatTab->chatLog(_("This command implements the partying function."), - BY_SERVER); - localChatTab->chatLog(_("Type /help party for further help."), - BY_SERVER); - return; - } - if (msg == "new" || msg == "create") - { - localChatTab->chatLog(_("Command: /party new "), BY_SERVER); - localChatTab->chatLog(_("Command: /party create "), BY_SERVER); - localChatTab->chatLog(_("These commands create a new party chatLog(_("Command: /party prefix "), BY_SERVER); - localChatTab->chatLog(_("This command sets the party prefix character."), - BY_SERVER); - localChatTab->chatLog(_("Any message preceded by is sent to " - "the party instead of everyone."), BY_SERVER); - localChatTab->chatLog(_("Command: /party prefix"), BY_SERVER); - localChatTab->chatLog(_("This command reports the current party prefix " - "character."), BY_SERVER); - return; - } - //if (msg == "settings") - //if (msg == "info") - if (msg == "leave") - { - localChatTab->chatLog(_("Command: /party leave"), BY_SERVER); - localChatTab->chatLog(_("This command causes the player to leave the party."), - BY_SERVER); - return; - } - localChatTab->chatLog(_("Unknown /party command."), BY_SERVER); - localChatTab->chatLog(_("Type /help party for a list of options."), BY_SERVER); -} diff --git a/src/party.h b/src/party.h deleted file mode 100644 index 25af80b3..00000000 --- a/src/party.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008 Lloyd Bryant - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PARTY_H -#define PARTY_H - -#include - -#include - -class PartyHandler; -class Being; -class ChatWindow; - -class Party -{ - public: - Party(); - void respond(const std::string &command, const std::string &args); - - void create(const std::string &party); - void leave(const std::string &args); - - void createResponse(bool ok); - void inviteResponse(const std::string &nick, int status); - void invitedAsk(const std::string &nick, int gender, - const std::string &partyName); - void leftResponse(const std::string &nick); - void receiveChat(Being *being, const std::string &msg); - - void help(const std::string &args); - - private: - std::string mPartyName; - bool mInParty; - bool mCreating; /**< Used to give an appropriate response to - failure */ - PartyHandler *handler; - - class InviteListener : public gcn::ActionListener - { - public: - InviteListener(bool *inParty) : - mInParty(inParty) - {} - void action(const gcn::ActionEvent &event); - - private: - bool *mInParty; - }; - InviteListener mInviteListener; -}; - -extern Party *playerParty; - -#endif -- cgit v1.2.3-70-g09d2