diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-09-02 02:20:48 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-09-02 02:20:48 +0300 |
commit | 7ccc1b5fe8988b2a51d3fb2f4422f95c98a8d6aa (patch) | |
tree | 6eb9f0aebf7e80242f5b8e23fb0ea2f98635a47a /src/net | |
parent | 1e302305d8777da7b40b1ae53ae33eab866b9e26 (diff) | |
download | plus-7ccc1b5fe8988b2a51d3fb2f4422f95c98a8d6aa.tar.gz plus-7ccc1b5fe8988b2a51d3fb2f4422f95c98a8d6aa.tar.bz2 plus-7ccc1b5fe8988b2a51d3fb2f4422f95c98a8d6aa.tar.xz plus-7ccc1b5fe8988b2a51d3fb2f4422f95c98a8d6aa.zip |
Use packet handlers from packet defines.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/eathena/network.cpp | 57 | ||||
-rw-r--r-- | src/net/packetfunction.h | 33 | ||||
-rw-r--r-- | src/net/packetinfo.h | 4 | ||||
-rw-r--r-- | src/net/recvpacketdefine.h | 5 | ||||
-rw-r--r-- | src/net/tmwa/network.cpp | 38 |
5 files changed, 129 insertions, 8 deletions
diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp index ee85b67d6..fdafd6baf 100644 --- a/src/net/eathena/network.cpp +++ b/src/net/eathena/network.cpp @@ -26,6 +26,57 @@ #include "net/packetinfo.h" +#include "net/ea/adminrecv.h" +#include "net/ea/beingrecv.h" +#include "net/ea/buysellrecv.h" +#include "net/ea/charserverrecv.h" +#include "net/ea/chatrecv.h" +#include "net/ea/gamerecv.h" +#include "net/ea/guildrecv.h" +#include "net/ea/inventoryrecv.h" +#include "net/ea/itemrecv.h" +#include "net/ea/loginrecv.h" +#include "net/ea/npcrecv.h" +#include "net/ea/partyrecv.h" +#include "net/ea/playerrecv.h" +#include "net/ea/skillrecv.h" +#include "net/ea/traderecv.h" + +#include "net/eathena/adminrecv.h" +#include "net/eathena/auctionrecv.h" +#include "net/eathena/bankrecv.h" +#include "net/eathena/battlegroundrecv.h" +#include "net/eathena/beingrecv.h" +#include "net/eathena/buyingstorerecv.h" +#include "net/eathena/buysellrecv.h" +#include "net/eathena/cashshoprecv.h" +#include "net/eathena/charserverrecv.h" +#include "net/eathena/chatrecv.h" +#include "net/eathena/elementalrecv.h" +#include "net/eathena/familyrecv.h" +#include "net/eathena/friendsrecv.h" +#include "net/eathena/gamerecv.h" +#include "net/eathena/generalrecv.h" +#include "net/eathena/guildrecv.h" +#include "net/eathena/homunculusrecv.h" +#include "net/eathena/inventoryrecv.h" +#include "net/eathena/itemrecv.h" +#include "net/eathena/loginrecv.h" +#include "net/eathena/mailrecv.h" +#include "net/eathena/maprecv.h" +#include "net/eathena/marketrecv.h" +#include "net/eathena/mercenaryrecv.h" +#include "net/eathena/npcrecv.h" +#include "net/eathena/partyrecv.h" +#include "net/eathena/petrecv.h" +#include "net/eathena/playerrecv.h" +#include "net/eathena/questrecv.h" +#include "net/eathena/rouletterecv.h" +#include "net/eathena/searchstorerecv.h" +#include "net/eathena/skillrecv.h" +#include "net/eathena/traderecv.h" +#include "net/eathena/vendingrecv.h" + #include "net/eathena/messagehandler.h" #include "net/eathena/messagein.h" #include "net/eathena/protocol.h" @@ -120,9 +171,9 @@ void Network::dispatchMessages() if (msgId < messagesSize) { - MessageHandler *const handler = mMessageHandlers[msgId]; - if (handler) - handler->handleMessage(msg); + PacketFuncPtr func = mPackets[msgId].func; + if (func) + func(msg); else logger->log("Unhandled packet: %u 0x%x", msgId, msgId); } diff --git a/src/net/packetfunction.h b/src/net/packetfunction.h new file mode 100644 index 000000000..a96140e04 --- /dev/null +++ b/src/net/packetfunction.h @@ -0,0 +1,33 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_PACKETFUNCTION_H +#define NET_PACKETFUNCTION_H + +#include "localconsts.h" + +namespace Net +{ + class MessageIn; +} + +typedef void (*PacketFuncPtr) (Net::MessageIn &msg); + +#endif // NET_PACKETFUNCTION_H diff --git a/src/net/packetinfo.h b/src/net/packetinfo.h index d1018b10f..cd16eb409 100644 --- a/src/net/packetinfo.h +++ b/src/net/packetinfo.h @@ -21,17 +21,21 @@ #ifndef NET_PACKETINFO_H #define NET_PACKETINFO_H +#include "net/packetfunction.h" + #include "localconsts.h" struct PacketInfo final { PacketInfo() : name(nullptr), + func(nullptr), len(0) { } const char *name; + PacketFuncPtr func; int len; }; diff --git a/src/net/recvpacketdefine.h b/src/net/recvpacketdefine.h index a62acc468..e40b5d7ac 100644 --- a/src/net/recvpacketdefine.h +++ b/src/net/recvpacketdefine.h @@ -21,8 +21,9 @@ #ifndef NET_RECVPACKETDEFINE_H #define NET_RECVPACKETDEFINE_H -#define packet(pname, pid, sz, func) \ +#define packet(pname, pid, sz, pfunc) \ mPackets[pid].name = #pname; \ - mPackets[pid].len = sz + mPackets[pid].len = sz; \ + mPackets[pid].func = pfunc #endif // NET_RECVPACKETDEFINE_H diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 0e97cbe46..cce906703 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -26,6 +26,38 @@ #include "net/packetinfo.h" +#include "net/ea/adminrecv.h" +#include "net/ea/beingrecv.h" +#include "net/ea/buysellrecv.h" +#include "net/ea/charserverrecv.h" +#include "net/ea/chatrecv.h" +#include "net/ea/gamerecv.h" +#include "net/ea/guildrecv.h" +#include "net/ea/inventoryrecv.h" +#include "net/ea/itemrecv.h" +#include "net/ea/loginrecv.h" +#include "net/ea/npcrecv.h" +#include "net/ea/partyrecv.h" +#include "net/ea/playerrecv.h" +#include "net/ea/skillrecv.h" +#include "net/ea/traderecv.h" + +#include "net/tmwa/beingrecv.h" +#include "net/tmwa/buysellrecv.h" +#include "net/tmwa/charserverrecv.h" +#include "net/tmwa/chatrecv.h" +#include "net/tmwa/gamerecv.h" +#include "net/tmwa/generalrecv.h" +#include "net/tmwa/guildrecv.h" +#include "net/tmwa/inventoryrecv.h" +#include "net/tmwa/itemrecv.h" +#include "net/tmwa/loginrecv.h" +#include "net/tmwa/partyrecv.h" +#include "net/tmwa/playerrecv.h" +#include "net/tmwa/questrecv.h" +#include "net/tmwa/skillrecv.h" +#include "net/tmwa/traderecv.h" + #include "net/tmwa/messagehandler.h" #include "net/tmwa/messagein.h" #include "net/tmwa/protocol.h" @@ -127,9 +159,9 @@ void Network::dispatchMessages() if (msgId < messagesSize) { - MessageHandler *const handler = mMessageHandlers[msgId]; - if (handler) - handler->handleMessage(msg); + PacketFuncPtr func = mPackets[msgId].func; + if (func) + func(msg); else logger->log("Unhandled packet: %u 0x%x", msgId, msgId); } |