summaryrefslogtreecommitdiff
path: root/src/net/chathandler.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2007-02-27 16:39:17 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2007-02-27 16:39:17 +0000
commit7a6e4d3c87ca4d7cc851af47fd9ebb616168f4c9 (patch)
treea880298777fcbb47a897e45ce6344ddbdf61b210 /src/net/chathandler.cpp
parentec72908d291fff37486a70d1624cfcece23b9bf7 (diff)
downloadmana-7a6e4d3c87ca4d7cc851af47fd9ebb616168f4c9.tar.gz
mana-7a6e4d3c87ca4d7cc851af47fd9ebb616168f4c9.tar.bz2
mana-7a6e4d3c87ca4d7cc851af47fd9ebb616168f4c9.tar.xz
mana-7a6e4d3c87ca4d7cc851af47fd9ebb616168f4c9.zip
Implementation of chat channels by Trapdoor.
Diffstat (limited to 'src/net/chathandler.cpp')
-rw-r--r--src/net/chathandler.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp
index f765f0f4..076be056 100644
--- a/src/net/chathandler.cpp
+++ b/src/net/chathandler.cpp
@@ -25,6 +25,7 @@
#include <SDL_types.h>
#include <string>
+#include <iostream>
#include "messagein.h"
#include "protocol.h"
@@ -43,6 +44,11 @@ ChatHandler::ChatHandler()
{
static const Uint16 _messages[] = {
GPMSG_SAY,
+ CPMSG_REGISTER_CHANNEL_RESPONSE,
+ CPMSG_ENTER_CHANNEL_RESPONSE,
+ CPMSG_LIST_CHANNELS_RESPONSE,
+ CPMSG_PUBMSG,
+ CPMSG_QUIT_CHANNEL_RESPONSE,
/*
SMSG_BEING_CHAT,
SMSG_PLAYER_CHAT,
@@ -59,6 +65,9 @@ void ChatHandler::handleMessage(MessageIn &msg)
{
Being *being;
std::string chatMsg;
+ short channelId;
+ std::string userNick;
+ std::string channelName;
//Sint16 chatMsgLength;
switch (msg.getId())
@@ -76,7 +85,74 @@ void ChatHandler::handleMessage(MessageIn &msg)
chatWindow->chatLog("John Doe : " + chatMsg, BY_OTHER);
}
break;
+ case CPMSG_REGISTER_CHANNEL_RESPONSE:
+ if(msg.readByte() == ERRMSG_OK)
+ {
+ channelId = msg.readShort();
+ std::string channelName = msg.readString();
+ chatWindow->chatLog("Registered Channel " + channelName, BY_SERVER);
+ chatWindow->addChannel(channelId, channelName);
+ chatWindow->createNewChannelTab(channelName);
+ }
+ else
+ {
+ chatWindow->chatLog("Error registering channel", BY_SERVER);
+ }
+ break;
+ case CPMSG_ENTER_CHANNEL_RESPONSE:
+ if(msg.readByte() == ERRMSG_OK)
+ {
+ channelId = msg.readShort();
+ channelName = msg.readString();
+ std::string announcement = msg.readString();
+ std::vector<std::string> userList;
+ while(msg.getUnreadLength())
+ {
+ userList.push_back(msg.readString());
+ }
+ chatWindow->addChannel(channelId, channelName);
+ chatWindow->createNewChannelTab(channelName);
+ chatWindow->chatLog(announcement, BY_SERVER, channelName);
+ }
+ else
+ {
+ chatWindow->chatLog("Error joining channel", BY_SERVER);
+ }
+ break;
+
+ case CPMSG_LIST_CHANNELS_RESPONSE:
+ chatWindow->chatLog("Listing Channels", BY_SERVER);
+ while(msg.getUnreadLength())
+ {
+ channelName = msg.readString();
+ std::ostringstream numUsers;
+ numUsers << msg.readShort();
+ if(channelName != "")
+ {
+ channelName += " - ";
+ channelName += numUsers.str();
+ chatWindow->chatLog(channelName, BY_SERVER);
+ }
+ }
+ chatWindow->chatLog("End of channel list", BY_SERVER);
+ break;
+ case CPMSG_PUBMSG:
+ channelId = msg.readShort();
+ userNick = msg.readString();
+ chatMsg = msg.readString();
+
+ chatWindow->sendToChannel(channelId, userNick, chatMsg);
+ break;
+
+ case CPMSG_QUIT_CHANNEL_RESPONSE:
+ if(msg.readByte() == ERRMSG_OK)
+ {
+ channelId = msg.readShort();
+ // remove the chat tab
+ chatWindow->removeChannel(channelId);
+ }
+ break;
/*
// Received speech from being
case SMSG_BEING_CHAT: