From 2c4d4ecc19fc8308b2772e4ffe6570ca362264d1 Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Mon, 19 Sep 2005 12:28:42 +0000 Subject: Got rid of writeSet() calls. --- src/being.cpp | 2 -- src/game.cpp | 25 +++++++------------------ src/gui/buy.cpp | 2 -- src/gui/buysell.cpp | 2 -- src/gui/char_select.cpp | 3 --- src/gui/char_server.cpp | 1 - src/gui/chat.cpp | 2 -- src/gui/login.cpp | 2 -- src/gui/npc.cpp | 2 -- src/gui/npc_text.cpp | 2 -- src/gui/popupmenu.cpp | 4 ---- src/gui/requesttrade.cpp | 2 -- src/gui/sell.cpp | 2 -- src/gui/skill.cpp | 2 -- src/gui/status.cpp | 2 -- src/gui/trade.cpp | 6 ------ src/inventory.cpp | 5 ----- src/net/messageout.cpp | 7 +++++-- src/net/network.cpp | 10 ---------- src/net/network.h | 1 - src/net/protocol.cpp | 4 ---- 21 files changed, 12 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 0a6f1043..ee9ff117 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -37,7 +37,6 @@ #include "gui/gui.h" #include "net/messageout.h" -#include "net/network.h" #include "net/protocol.h" #include "resources/resourcemanager.h" @@ -70,7 +69,6 @@ Being* createBeing(unsigned int id, unsigned short job, Map *map) MessageOut outMsg; outMsg.writeShort(0x0094); outMsg.writeLong(being->getId());//readLong(2)); - writeSet(6); } // If the being is a monster then load the monsterset else if (being->job >= 1002 && diff --git a/src/game.cpp b/src/game.cpp index 5c8b1d8b..dac21cb8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -141,7 +141,6 @@ class DeathNoticeListener : public gcn::ActionListener { MessageOut outMsg; outMsg.writeShort(0x00b2); outMsg.writeByte(0); - writeSet(3); deathNotice = NULL; } } deathNoticeListener; @@ -577,7 +576,6 @@ void do_input() MessageOut outMsg; outMsg.writeShort(0x009f); outMsg.writeLong(id); - writeSet(6); } used = true; } @@ -689,7 +687,6 @@ void do_input() MessageOut outMsg; outMsg.writeShort(0x00bf); outMsg.writeByte(emotion); - writeSet(3); action_time = false; used = true; } @@ -724,17 +721,14 @@ void do_input() { // Player default: attack case Being::PLAYER: + if (target != player_node) { - if (target != player_node) - { - autoTarget = target; - attack(target);/* - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_REQUEST); - outMsg.writeLong(target->getId()); - writeSet(6); - tradePartnerName = target->getName();*/ - } + autoTarget = target; + attack(target); + /*MessageOut outMsg; + outMsg.writeShort(CMSG_TRADE_REQUEST); + outMsg.writeLong(target->getId()); + tradePartnerName = target->getName();*/ } break; @@ -746,7 +740,6 @@ void do_input() outMsg.writeShort(CMSG_NPC_TALK); outMsg.writeLong(target->getId()); outMsg.writeByte(0); - writeSet(7); current_npc = target->getId(); } break; @@ -790,7 +783,6 @@ void do_input() MessageOut outMsg; outMsg.writeShort(0x009f); outMsg.writeLong(floorItemId); - writeSet(6); } } @@ -984,7 +976,6 @@ void do_input() MessageOut outMsg; outMsg.writeShort(CMSG_ITEM_PICKUP); outMsg.writeLong(id); - writeSet(6); } } else if (joy[JOY_BTN2] && action_time) @@ -1298,7 +1289,6 @@ void do_parse() MessageOut outMsg; outMsg.writeShort(CMSG_TRADE_RESPONSE); outMsg.writeByte(4); - writeSet(3); break; } @@ -1529,7 +1519,6 @@ void do_parse() // Send "map loaded" MessageOut outMsg; outMsg.writeShort(CMSG_MAP_LOADED); - writeSet(2); } break; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c825c82e..185709d1 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -39,7 +39,6 @@ #include "../resources/itemmanager.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" @@ -242,7 +241,6 @@ void BuyDialog::action(const std::string& eventId) outMsg.writeShort(8); outMsg.writeShort(m_amountItems); outMsg.writeShort(shopInventory[selectedItem].id); - writeSet(8); // update money ! m_money -= m_amountItems * shopInventory[selectedItem].price; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 47777ca0..1f40e7b5 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -28,7 +28,6 @@ #include "../game.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" BuySellDialog::BuySellDialog(): @@ -86,7 +85,6 @@ void BuySellDialog::action(const std::string& eventId) outMsg.writeShort(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(current_npc); outMsg.writeByte(actionId); - writeSet(7); } setVisible(false); diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 4b52f49e..9834dcf6 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -199,7 +199,6 @@ void CharSelectDialog::serverCharDelete() outMsg.writeShort(0x0068); outMsg.writeLong(char_info[0]->id); outMsg.writeString("a@a.com", 40); - writeSet(46); MessageIn msg = get_next_message(); @@ -229,7 +228,6 @@ void CharSelectDialog::serverCharSelect() MessageOut outMsg; outMsg.writeShort(0x0066); outMsg.writeByte(0); - writeSet(3); MessageIn msg = get_next_message(); @@ -426,7 +424,6 @@ void CharCreateDialog::serverCharCreate() outMsg.writeByte(0); outMsg.writeShort(playerBox->hairColor + 1); outMsg.writeShort(playerBox->hairStyle + 1); - writeSet(37); MessageIn msg = get_next_message(); diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 3b6312e4..c368727b 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -157,7 +157,6 @@ void server_char_server(int serverIndex) outMsg.writeLong(session_ID2); outMsg.writeShort(0); // unknown outMsg.writeByte(sex); - writeSet(17); // Skipping a mysterious 4 bytes while ((in_size < 4) || (out_size > 0)) flush(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 3ef6703c..70b39ae3 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -34,7 +34,6 @@ #include "../log.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" ChatWindow::ChatWindow(const std::string &logfile): @@ -222,7 +221,6 @@ char *ChatWindow::chat_send(std::string nick, std::string msg) outMsg.writeShort(packetId); outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); - writeSet(msg.length() + 4); return ""; } diff --git a/src/gui/login.cpp b/src/gui/login.cpp index bb762843..f5dc4f1e 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -343,8 +343,6 @@ int attemptLogin(const std::string& user, const std::string& pass) outMsg.writeString(user, 24); outMsg.writeString(pass, 24); outMsg.writeByte(0); // unknown - // TODO: still have to use writeSet as skip for reading - writeSet(55); // Receive reply MessageIn msg = get_next_message(); diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp index 122cffa6..16641916 100644 --- a/src/gui/npc.cpp +++ b/src/gui/npc.cpp @@ -30,7 +30,6 @@ #include "../game.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" NpcListDialog::NpcListDialog(): @@ -133,7 +132,6 @@ NpcListDialog::action(const std::string& eventId) outMsg.writeShort(CMSG_NPC_LIST_CHOICE); outMsg.writeLong(current_npc); outMsg.writeByte(choice); - writeSet(7); setVisible(false); reset(); current_npc = 0; diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 8596796f..9896f08e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -30,7 +30,6 @@ #include "../game.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" NpcTextDialog::NpcTextDialog(): @@ -84,7 +83,6 @@ NpcTextDialog::action(const std::string& eventId) MessageOut outMsg; outMsg.writeShort(CMSG_NPC_NEXT_REQUEST); outMsg.writeLong(current_npc); - writeSet(6); setText(""); setVisible(false); current_npc = 0; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 29b599aa..7f72702e 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -41,7 +41,6 @@ #include "../item.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" #include "../resources/iteminfo.h" @@ -136,7 +135,6 @@ void PopupMenu::handleLink(const std::string& link) outMsg.writeShort(CMSG_NPC_TALK); outMsg.writeLong(being->getId()); outMsg.writeByte(0); - writeSet(7); current_npc = being->getId(); } @@ -146,7 +144,6 @@ void PopupMenu::handleLink(const std::string& link) MessageOut outMsg; outMsg.writeShort(CMSG_TRADE_REQUEST); outMsg.writeLong(being->getId()); - writeSet(6); //tradePartner.flush(); //tradePartner << "Trade: You and " << being->name<< ""; tradePartnerName = being->getName(); @@ -182,7 +179,6 @@ void PopupMenu::handleLink(const std::string& link) MessageOut outMsg; outMsg.writeShort(CMSG_ITEM_PICKUP); outMsg.writeLong(floorItem->getId()); - writeSet(6); } // Look To action diff --git a/src/gui/requesttrade.cpp b/src/gui/requesttrade.cpp index 992b0c0f..e4423c59 100644 --- a/src/gui/requesttrade.cpp +++ b/src/gui/requesttrade.cpp @@ -29,7 +29,6 @@ #include "button.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" bool requestTradeDialogOpen = false; @@ -99,6 +98,5 @@ void RequestTradeDialog::action(const std::string& eventId) MessageOut outMsg; outMsg.writeShort(CMSG_TRADE_RESPONSE); outMsg.writeByte(choice); - writeSet(3); scheduleDelete(); } diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index c3596503..73880861 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -41,7 +41,6 @@ #include "../resources/itemmanager.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" @@ -237,7 +236,6 @@ void SellDialog::action(const std::string& eventId) outMsg.writeShort(8); outMsg.writeShort(shopInventory[selectedItem].index); outMsg.writeShort(m_amountItems); - writeSet(8); m_maxItems -= m_amountItems; m_amountItems = 0; diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 0059ec25..58eea2e7 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -32,7 +32,6 @@ #include "../playerinfo.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" char *skill_db[] = { @@ -129,7 +128,6 @@ void SkillDialog::action(const std::string& eventId) MessageOut outMsg; outMsg.writeShort(CMSG_SKILL_LEVELUP_REQUEST); outMsg.writeShort(skillList[selectedSkill]->id); - writeSet(4); } } else if (eventId == "skill") diff --git a/src/gui/status.cpp b/src/gui/status.cpp index f1eadafc..a601ff59 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -32,7 +32,6 @@ #include "../playerinfo.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" StatusWindow::StatusWindow(): @@ -448,6 +447,5 @@ void StatusWindow::action(const std::string& eventId) outMsg.writeShort(0x0012); } outMsg.writeByte(1); - writeSet(5); } } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index d4c91d19..19aaab9e 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -39,7 +39,6 @@ #include "../item.h" #include "../net/messageout.h" -#include "../net/network.h" #include "../net/protocol.h" #include "../resources/iteminfo.h" @@ -246,7 +245,6 @@ void TradeWindow::tradeItem(Item *item, int quantity) outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(quantity); - writeSet(8); } void TradeWindow::mouseClick(int x, int y, int button, int count) @@ -317,7 +315,6 @@ void TradeWindow::action(const std::string &eventId) { MessageOut outMsg; outMsg.writeShort(CMSG_TRADE_CANCEL_REQUEST); - writeSet(2); } else if (eventId == "ok") { @@ -333,19 +330,16 @@ void TradeWindow::action(const std::string &eventId) outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(0); outMsg.writeLong(tempInt); - writeSet(8); } else { moneyField->setText(""); } moneyField->setEnabled(false); MessageOut outMsg; outMsg.writeShort(CMSG_TRADE_ADD_COMPLETE); - writeSet(2); } else if (eventId == "trade") { MessageOut outMsg; outMsg.writeShort(CMSG_TRADE_OK); - writeSet(2); } } diff --git a/src/inventory.cpp b/src/inventory.cpp index f85e12ef..39860261 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -27,7 +27,6 @@ #include "item.h" #include "net/messageout.h" -#include "net/network.h" #include "net/protocol.h" Inventory::Inventory() @@ -98,7 +97,6 @@ int Inventory::useItem(Item *item) outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(item->getId()); // Note: id is dest of item, usually player_node->account_ID ?? - writeSet(8); return 0; } @@ -109,7 +107,6 @@ int Inventory::dropItem(Item *item, int quantity) outMsg.writeShort(CMSG_PLAYER_INVENTORY_DROP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(quantity); - writeSet(6); return 0; } @@ -119,7 +116,6 @@ void Inventory::equipItem(Item *item) outMsg.writeShort(CMSG_PLAYER_EQUIP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(0); - writeSet(6); } void Inventory::unequipItem(Item *item) @@ -127,7 +123,6 @@ void Inventory::unequipItem(Item *item) MessageOut outMsg; outMsg.writeShort(CMSG_PLAYER_UNEQUIP); outMsg.writeShort(item->getInvIndex()); - writeSet(4); // Tidy equipment directly to avoid weapon still shown bug, by instance Equipment::getInstance()->removeEquipment(item); diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index daf5ebf4..e7928a4d 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -36,8 +36,6 @@ MessageOut::MessageOut(): mDataSize(0), mPos(0) { - // TODO: data not to be already allocated, keep it this way unitl full - // conversion mData = out + out_size; } @@ -64,6 +62,7 @@ void MessageOut::writeByte(char value) expand(mPos + sizeof(char)); mData[mPos] = value; mPos += sizeof(char); + out_size += sizeof(char); } void MessageOut::writeShort(short value) @@ -76,6 +75,7 @@ void MessageOut::writeShort(short value) #endif //SDLNet_Write16(value, &mData[mPos]); mPos += sizeof(short); + out_size += sizeof(short); } void MessageOut::writeLong(long value) @@ -88,6 +88,7 @@ void MessageOut::writeLong(long value) #endif //SDLNet_Write32(value, &mData[mPos]); mPos += sizeof(long); + out_size += sizeof(long); } void MessageOut::writeString(const std::string &string, int length) @@ -110,12 +111,14 @@ void MessageOut::writeString(const std::string &string, int length) // Write the actual string memcpy(&mData[mPos], (void*)toWrite.c_str(), toWrite.length()); mPos += toWrite.length(); + out_size += toWrite.length(); // Pad remaining space with zeros if (length > (int)toWrite.length()) { memset(&mData[mPos], '\0', length - toWrite.length()); mPos += length - toWrite.length(); + out_size += length - toWrite.length(); } } diff --git a/src/net/network.cpp b/src/net/network.cpp index 570b31bb..7a3ecc09 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -279,16 +279,6 @@ get_next_message() return MessageIn(in, length); } -void writeSet(unsigned int value) -{ - if (out_size + value >= buffer_size) { - logger->log("Warning: Output buffer full"); - } - else { - out_size += value; - } -} - void skip(int len) { memcpy(in, in + len, in_size - len); diff --git a/src/net/network.h b/src/net/network.h index c6a4380b..47e71190 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -44,7 +44,6 @@ void flush(); MessageIn get_next_message(); extern char *out; -void writeSet(unsigned int value); void skip(int len); extern unsigned int in_size; /**< Amount of data in input buffer. */ diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index 318c446d..b56745fa 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -86,7 +86,6 @@ void map_start() outMsg.writeLong(session_ID1); outMsg.writeLong(session_ID2); outMsg.writeByte(sex); - writeSet(19); // Skip a mysterious 4 bytes while ((in_size < 4)|| (out_size > 0)) flush(); @@ -118,7 +117,6 @@ void map_start() // TODO: be able to reuse the same msg MessageOut newMsg; newMsg.writeShort(0x007d); - writeSet(2); } void walk(unsigned short x, unsigned short y, unsigned char direction) @@ -128,7 +126,6 @@ void walk(unsigned short x, unsigned short y, unsigned char direction) set_coordinates(temp, x, y, direction); outMsg.writeShort(0x0085); outMsg.writeString(temp, 3); - writeSet(5); } void action(char type, int id) @@ -137,7 +134,6 @@ void action(char type, int id) outMsg.writeShort(0x0089); outMsg.writeLong(id); outMsg.writeByte(type); - writeSet(7); } Being* attack(unsigned short x, unsigned short y, unsigned char direction) -- cgit v1.2.3-70-g09d2