diff options
Diffstat (limited to 'src/net/tmwserv/chathandler.cpp')
-rw-r--r-- | src/net/tmwserv/chathandler.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/net/tmwserv/chathandler.cpp b/src/net/tmwserv/chathandler.cpp index c95f6ac5..229f09be 100644 --- a/src/net/tmwserv/chathandler.cpp +++ b/src/net/tmwserv/chathandler.cpp @@ -35,9 +35,10 @@ #include "being.h" #include "beingmanager.h" -#include "game.h" #include "channel.h" #include "channelmanager.h" +#include "game.h" +#include "main.h" #include "gui/widgets/channeltab.h" #include "gui/chat.h" @@ -53,8 +54,13 @@ extern Being *player_node; Net::ChatHandler *chatHandler; +extern Net::Connection *chatServerConnection; + namespace TmwServ { +extern std::string netToken; +extern ServerInfo chatServer; + ChatHandler::ChatHandler() { static const Uint16 _messages[] = { @@ -68,6 +74,7 @@ ChatHandler::ChatHandler() CPMSG_LIST_CHANNELUSERS_RESPONSE, CPMSG_CHANNEL_EVENT, CPMSG_WHO_RESPONSE, + CPMSG_DISCONNECT_RESPONSE, 0 }; handledMessages = _messages; @@ -117,6 +124,28 @@ void ChatHandler::handleMessage(MessageIn &msg) case CPMSG_WHO_RESPONSE: handleWhoResponse(msg); break; + case CPMSG_DISCONNECT_RESPONSE: + { + int errMsg = msg.readInt8(); + // Successful logout + if (errMsg == ERRMSG_OK) + { + // TODO: Handle logout + } + else + { + switch (errMsg) { + case ERRMSG_NO_LOGIN: + errorMessage = "Chatserver: Not logged in"; + break; + default: + errorMessage = "Chatserver: Unknown error"; + break; + } + state = STATE_ERROR; + } + } + break; } } @@ -323,6 +352,21 @@ void ChatHandler::handleWhoResponse(MessageIn &msg) } } +void ChatHandler::connect() +{ + Net::ChatServer::connect(chatServerConnection, netToken); +} + +bool ChatHandler::isConnected() +{ + return chatServerConnection->isConnected(); +} + +void ChatHandler::disconnect() +{ + chatServerConnection->disconnect(); +} + void ChatHandler::talk(const std::string &text) { MessageOut msg(PGMSG_SAY); |