summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-01 14:13:11 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-01 14:13:11 -0600
commitb987a2806dbcd87a23850901f6f0b86f0801086c (patch)
treee373f4869436f830c2cdeeeaf34a941560ded3fe
parent6ef22b50f3d0c2410af5bd2543bedc0b3d692f83 (diff)
downloadMana-b987a2806dbcd87a23850901f6f0b86f0801086c.tar.gz
Mana-b987a2806dbcd87a23850901f6f0b86f0801086c.tar.bz2
Mana-b987a2806dbcd87a23850901f6f0b86f0801086c.tar.xz
Mana-b987a2806dbcd87a23850901f6f0b86f0801086c.zip
Create a few more handlers for eAthena
Map, chat, and admin have been finished (to the degree they handle all existing cases).
-rw-r--r--src/Makefile.am4
-rw-r--r--src/commandhandler.cpp22
-rw-r--r--src/engine.cpp9
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/widgets/chattab.cpp13
-rw-r--r--src/gui/widgets/whispertab.cpp10
-rw-r--r--src/main.cpp6
-rw-r--r--src/net/ea/chathandler.cpp79
-rw-r--r--src/net/ea/chathandler.h28
-rw-r--r--src/net/ea/maploginhandler.cpp78
-rw-r--r--src/net/ea/maploginhandler.h35
-rw-r--r--src/net/ea/playerhandler.cpp3
-rw-r--r--src/net/ea/protocol.h6
13 files changed, 142 insertions, 153 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 78766e32..94c573fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -471,8 +471,8 @@ tmw_SOURCES += \
net/ea/itemhandler.h \
net/ea/loginhandler.cpp \
net/ea/loginhandler.h \
- net/ea/maploginhandler.cpp \
- net/ea/maploginhandler.h \
+ net/ea/maphandler.cpp \
+ net/ea/maphandler.h \
net/ea/network.cpp \
net/ea/network.h \
net/ea/npchandler.cpp \
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 63633693..03b192f9 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -30,12 +30,14 @@
#include "gui/widgets/chattab.h"
#include "gui/chat.h"
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/chatserver/chatserver.h"
#include "net/tmwserv/gameserver/player.h"
#else
-#include "net/messageout.h"
-#include "net/ea/protocol.h"
+#include "net/ea/adminhandler.h"
+#include "net/ea/chathandler.h"
+#include "net/ea/maphandler.h"
#endif
#include "utils/gettext.h"
@@ -133,12 +135,11 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
void CommandHandler::handleAnnounce(const std::string &args, ChatTab *tab)
{
+ // Net::getAdminHandler()->announce(args);
#ifdef TMWSERV_SUPPORT
Net::ChatServer::announce(args);
#else
- MessageOut outMsg(0x0099);
- outMsg.writeInt16(args.length() + 4);
- outMsg.writeString(args, args.length());
+ adminHandler->announce(args);
#endif
}
@@ -318,10 +319,11 @@ void CommandHandler::handleWhere(const std::string &args, ChatTab *tab)
void CommandHandler::handleWho(const std::string &args, ChatTab *tab)
{
+ // Net::getMapHandler()->who();
#ifdef TMWSERV_SUPPORT
//TODO
#else
- MessageOut outMsg(0x00c1);
+ mapHandler->who();
#endif
}
@@ -480,8 +482,12 @@ void CommandHandler::handleParty(const std::string &args, ChatTab *tab)
void CommandHandler::handleMe(const std::string &args, ChatTab *tab)
{
- std::string action = strprintf("*%s*", args.c_str());
- chatWindow->chatInput(action);
+ // Net::getChatHandler()->me(args);
+#ifdef TMWServ_SUPPORT
+ // TODO
+#else
+ chatHandler->me(args);
+#endif
}
void CommandHandler::handleRecord(const std::string &args, ChatTab *tab)
diff --git a/src/engine.cpp b/src/engine.cpp
index 04d06e38..faa6a452 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -33,6 +33,11 @@
#include "gui/minimap.h"
#include "gui/viewport.h"
+#include "net/net.h"
+#ifdef EATHENA_SUPPORT
+#include "net/ea/maphandler.h"
+#endif
+
#include "resources/mapreader.h"
#include "resources/monsterdb.h"
#include "resources/resourcemanager.h"
@@ -134,6 +139,10 @@ bool Engine::changeMap(const std::string &mapPath)
mCurrentMap = newMap;
+ // Net::getMapHandler()->mapLoaded(mapPath);
+#ifdef EATHENA_SUPPORT
+ mapHandler->mapLoaded(mapPath);
+#endif
return true;
}
diff --git a/src/game.cpp b/src/game.cpp
index 496bdeef..9b6524f2 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -107,6 +107,7 @@
#include "net/ea/equipmenthandler.h"
#include "net/ea/inventoryhandler.h"
#include "net/ea/itemhandler.h"
+#include "net/ea/maphandler.h"
#include "net/ea/npchandler.h"
#include "net/ea/playerhandler.h"
#include "net/ea/partyhandler.h"
@@ -447,7 +448,6 @@ Game::Game(Network *network):
map_path = map_path.substr(0, map_path.rfind("."));
engine->changeMap(map_path);
- MessageOut outMsg(CMSG_MAP_LOADED);
#endif
setupWindow->setInGame(true);
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 43248e8b..bd0504b5 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -30,12 +30,12 @@
#include "gui/recorder.h"
#include "gui/scrollarea.h"
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/chatserver/chatserver.h"
#include "net/tmwserv/gameserver/player.h"
#else
-#include "net/messageout.h"
-#include "net/ea/protocol.h"
+#include "net/ea/chathandler.h"
#endif
#include "resources/iteminfo.h"
@@ -276,16 +276,11 @@ void ChatTab::clearText()
}
void ChatTab::handleInput(const std::string &msg) {
+ // Net::getChatHandler()->talk(msg);
#ifdef TMWSERV_SUPPORT
Net::GameServer::Player::say(msg);
#else
- std::string mes = player_node->getName() + " : " + msg;
-
- 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);
- return;
+ chatHandler->talk(msg);
#endif
}
diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp
index 75131bda..a641f0ad 100644
--- a/src/gui/widgets/whispertab.cpp
+++ b/src/gui/widgets/whispertab.cpp
@@ -25,11 +25,11 @@
#include "gui/palette.h"
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/chatserver/chatserver.h"
#else
-#include "net/messageout.h"
-#include "net/ea/protocol.h"
+#include "net/ea/chathandler.h"
#endif
#include "utils/gettext.h"
@@ -53,13 +53,11 @@ void WhisperTab::handleInput(const std::string &msg) {
return;
}
+ // Net::getChatHandler()->privateMessage(mNick, msg);
#ifdef TMWSERV_SUPPORT
Net::ChatServer::privMsg(mNick, msg);
#else
- MessageOut outMsg(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(msg.length() + 28);
- outMsg.writeString(mNick, 24);
- outMsg.writeString(msg, msg.length());
+ chatHandler->privateMessage(mNick, msg);
#endif
chatLog(strprintf(_("%s: %s"), player_node->getName().c_str(),
diff --git a/src/main.cpp b/src/main.cpp
index 37ef00a2..05518e19 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -71,7 +71,7 @@
#include "net/ea/charserverhandler.h"
#include "net/ea/loginhandler.h"
#include "net/ea/network.h"
-#include "net/ea/maploginhandler.h"
+#include "net/ea/maphandler.h"
#include "net/messageout.h"
#endif
@@ -187,7 +187,6 @@ std::string updatesDir;
#ifdef EATHENA_SUPPORT
LoginHandler loginHandler;
-MapLoginHandler mapLoginHandler;
#endif
SDL_Surface *icon;
@@ -828,7 +827,8 @@ static void mapLogin(Network *network, LoginData *loginData)
logger->log("Map: %s", map_path.c_str());
network->connect(loginData->hostname, loginData->port);
- network->registerHandler(&mapLoginHandler);
+ //network->registerHandler(mapHandler);
+ network->registerHandler(new MapHandler);
// Send login infos
MessageOut outMsg(0x0072);
diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp
index 6aca58a3..3628784d 100644
--- a/src/net/ea/chathandler.cpp
+++ b/src/net/ea/chathandler.cpp
@@ -24,6 +24,7 @@
#include "net/ea/protocol.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "being.h"
#include "beingmanager.h"
@@ -34,13 +35,14 @@
#include "utils/gettext.h"
#include "utils/stringutils.h"
+#include "utils/strprintf.h"
#include <string>
-extern Being *player_node;
-
#define SERVER_NAME "Server"
+ChatHandler *chatHandler;
+
ChatHandler::ChatHandler()
{
static const Uint16 _messages[] = {
@@ -49,11 +51,11 @@ ChatHandler::ChatHandler()
SMSG_WHISPER,
SMSG_WHISPER_RESPONSE,
SMSG_GM_CHAT,
- SMSG_WHO_ANSWER,
0x10c, // MVP
0
};
handledMessages = _messages;
+ chatHandler = this;
}
void ChatHandler::handleMessage(MessageIn &msg)
@@ -159,11 +161,6 @@ void ChatHandler::handleMessage(MessageIn &msg)
break;
}
- case SMSG_WHO_ANSWER:
- localChatTab->chatLog("Online users: " + toString(msg.readInt32()),
- BY_SERVER);
- break;
-
case 0x010c:
// Display MVP player
msg.readInt32(); // id
@@ -171,3 +168,69 @@ void ChatHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void ChatHandler::talk(const std::string &text)
+{
+ std::string mes = player_node->getName() + " : " + text;
+
+ MessageOut outMsg(CMSG_CHAT_MESSAGE);
+ // Added + 1 in order to let eAthena parse admin commands correctly
+ outMsg.writeInt16(text.length() + 4 + 1);
+ outMsg.writeString(text, text.length() + 1);
+}
+
+void ChatHandler::me(const std::string &text)
+{
+ std::string action = strprintf("*%s*", text.c_str());
+
+ talk(text);
+}
+
+void ChatHandler::privateMessage(const std::string &recipient,
+ const std::string &text)
+{
+ MessageOut outMsg(CMSG_CHAT_WHISPER);
+ outMsg.writeInt16(text.length() + 28);
+ outMsg.writeString(recipient, 24);
+ outMsg.writeString(text, text.length());
+}
+
+void ChatHandler::channelList()
+{
+ // TODO
+}
+
+void ChatHandler::enterChannel(int channelId, const std::string &password)
+{
+ // TODO
+}
+
+void ChatHandler::quitChannel(int channelId)
+{
+ // TODO
+}
+
+void ChatHandler::sendToChannel(int channelId, const std::string &text)
+{
+ // TODO
+}
+
+void ChatHandler::userList(int channelId)
+{
+ // TODO
+}
+
+void ChatHandler::setChannelTopic(int channelId, const std::string &text)
+{
+ // TODO
+}
+
+void ChatHandler::setUserMode(int channelId, const std::string &name, int mode)
+{
+ // TODO
+}
+
+void ChatHandler::kickUser(int channelId, const std::string &name)
+{
+ // TODO
+}
diff --git a/src/net/ea/chathandler.h b/src/net/ea/chathandler.h
index 93e3e272..99c580dd 100644
--- a/src/net/ea/chathandler.h
+++ b/src/net/ea/chathandler.h
@@ -23,13 +23,39 @@
#define NET_EA_CHATHANDLER_H
#include "net/messagehandler.h"
+#include "net/net.h"
-class ChatHandler : public MessageHandler
+class ChatHandler : public MessageHandler, public Net::ChatHandler
{
public:
ChatHandler();
virtual void handleMessage(MessageIn &msg);
+
+ virtual void talk(const std::string &text);
+
+ virtual void me(const std::string &text);
+
+ virtual void privateMessage(const std::string &recipient,
+ const std::string &text);
+
+ virtual void channelList();
+
+ virtual void enterChannel(int channelId, const std::string &password);
+
+ virtual void quitChannel(int channelId);
+
+ virtual void sendToChannel(int channelId, const std::string &text);
+
+ virtual void userList(int channelId);
+
+ virtual void setChannelTopic(int channelId, const std::string &text);
+
+ virtual void setUserMode(int channelId, const std::string &name, int mode);
+
+ virtual void kickUser(int channelId, const std::string &name);
};
+extern ChatHandler *chatHandler;
+
#endif // NET_EA_CHATHANDLER_H
diff --git a/src/net/ea/maploginhandler.cpp b/src/net/ea/maploginhandler.cpp
deleted file mode 100644
index 78f021b0..00000000
--- a/src/net/ea/maploginhandler.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 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 "net/ea/maploginhandler.h"
-
-#include "net/ea/protocol.h"
-
-#include "net/messagein.h"
-
-#include "localplayer.h"
-#include "log.h"
-#include "main.h"
-
-#include "utils/gettext.h"
-
-MapLoginHandler::MapLoginHandler()
-{
- static const Uint16 _messages[] = {
- SMSG_CONNECTION_PROBLEM,
- SMSG_LOGIN_SUCCESS,
- 0
- };
- handledMessages = _messages;
-}
-
-void MapLoginHandler::handleMessage(MessageIn &msg)
-{
- int code;
- unsigned char direction;
-
- switch (msg.getId())
- {
- case SMSG_CONNECTION_PROBLEM:
- code = msg.readInt8();
- logger->log("Connection problem: %i", code);
-
- switch (code) {
- case 0:
- errorMessage = _("Authentication failed");
- break;
- case 2:
- errorMessage = _("This account is already logged in");
- break;
- default:
- errorMessage = _("Unknown connection error");
- break;
- }
- state = STATE_ERROR;
- break;
-
- case SMSG_LOGIN_SUCCESS:
- msg.readInt32(); // server tick
- msg.readCoordinates(player_node->mX, player_node->mY, direction);
- msg.skip(2); // unknown
- logger->log("Protocol: Player start position: (%d, %d), Direction: %d",
- player_node->mX, player_node->mY, direction);
- state = STATE_GAME;
- break;
- }
-}
diff --git a/src/net/ea/maploginhandler.h b/src/net/ea/maploginhandler.h
deleted file mode 100644
index 33ac9ee7..00000000
--- a/src/net/ea/maploginhandler.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 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 NET_EA_MAPLOGINHANDLER_H
-#define NET_EA_MAPLOGINHANDLER_H
-
-#include "net/messagehandler.h"
-
-class MapLoginHandler : public MessageHandler
-{
- public:
- MapLoginHandler();
-
- virtual void handleMessage(MessageIn &msg);
-};
-
-#endif // NET_EA_MAPLOGINHANDLER_H
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index cb3ed089..f0876a6e 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -199,8 +199,7 @@ void PlayerHandler::handleMessage(MessageIn &msg)
// Switch the actual map, deleting the previous one if necessary
mapPath = mapPath.substr(0, mapPath.rfind("."));
- if (engine->changeMap(mapPath))
- MessageOut outMsg(CMSG_MAP_LOADED);
+ engine->changeMap(mapPath);
float scrollOffsetX = 0.0f;
float scrollOffsetY = 0.0f;
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index 8a4d6135..5a2260e6 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -121,6 +121,7 @@ static const int STORAGE_OFFSET = 1;
* Packets from client to server *
**********************************/
#define CMSG_CLIENT_PING 0x007e /**< Send to server with tick */
+#define CMSG_CLIENT_QUIT 0x018A
#define CMSG_TRADE_RESPONSE 0x00e6
#define CMSG_ITEM_PICKUP 0x009f
#define CMSG_MAP_LOADED 0x007d
@@ -161,6 +162,11 @@ static const int STORAGE_OFFSET = 1;
#define CSMG_MOVE_FROM_STORAGE 0x00f5 /** Remove item from storage */
#define CMSG_CLOSE_STORAGE 0x00f7 /** Request storage close */
+#define CMSG_ADMIN_ANNOUNCE 0x0099
+#define CMSG_ADMIN_LOCAL_ANNOUNCE 0x019C
+#define CMSG_ADMIN_HIDE 0x019D
+#define CMSG_ADMIN_KICK 0x00CC
+
/** Encodes coords and direction in 3 bytes data */
void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction);