summaryrefslogtreecommitdiff
path: root/src/net
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
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')
-rw-r--r--src/net/chathandler.cpp76
-rw-r--r--src/net/chatserver/chatserver.cpp15
-rw-r--r--src/net/chatserver/chatserver.h5
-rw-r--r--src/net/protocol.h9
4 files changed, 97 insertions, 8 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:
diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp
index 32979ea5..f24e4cd5 100644
--- a/src/net/chatserver/chatserver.cpp
+++ b/src/net/chatserver/chatserver.cpp
@@ -81,14 +81,14 @@ void Net::ChatServer::privMsg(const std::string &recipient,
}
void Net::ChatServer::registerChannel(const std::string &name,
- const std::string &annoucement, const std::string &password,
+ const std::string &announcement, const std::string &password,
char isPrivate)
{
MessageOut msg(PCMSG_REGISTER_CHANNEL);
msg.writeByte(isPrivate);
msg.writeString(name);
- msg.writeString(annoucement);
+ msg.writeString(announcement);
msg.writeString(password);
connection->send(msg);
@@ -103,11 +103,11 @@ void Net::ChatServer::unregisterChannel(short channel)
connection->send(msg);
}
-void Net::ChatServer::enterChannel(short channel, const std::string &password)
+void Net::ChatServer::enterChannel(const std::string &channel, const std::string &password)
{
MessageOut msg(PCMSG_ENTER_CHANNEL);
- msg.writeShort(channel);
+ msg.writeString(channel);
msg.writeString(password);
connection->send(msg);
@@ -121,3 +121,10 @@ void Net::ChatServer::quitChannel(short channel)
connection->send(msg);
}
+
+void Net::ChatServer::getChannelList()
+{
+ MessageOut msg(PCMSG_LIST_CHANNELS);
+
+ connection->send(msg);
+}
diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h
index cf86baf3..c4e0003d 100644
--- a/src/net/chatserver/chatserver.h
+++ b/src/net/chatserver/chatserver.h
@@ -48,9 +48,12 @@ namespace Net
void unregisterChannel(short channel);
- void enterChannel(short channel, const std::string &password);
+ void enterChannel(const std::string &channel, const std::string &password);
void quitChannel(short channel);
+
+ void getChannelList();
+
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 78a42e42..eb27af7d 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -119,7 +119,7 @@ enum {
// Login/Register
PAMSG_REGISTER = 0x0000, // L version, S username, S password, S email
APMSG_REGISTER_RESPONSE = 0x0002, // B error
- PAMSG_UNREGISTER = 0x0003, // S username, S password
+ PAMSG_UNREGISTER = 0x0003, // -
APMSG_UNREGISTER_RESPONSE = 0x0004, // B error
PAMSG_LOGIN = 0x0010, // L version, S username, S password
APMSG_LOGIN_RESPONSE = 0x0012, // B error
@@ -175,6 +175,7 @@ enum {
PGMSG_USE_ITEM = 0x0300, // L item id
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
+ GPMSG_BEING_DEAD = 0xDEAD, // W being id
// Chat
CPMSG_ERROR = 0x0401, // B error
@@ -186,14 +187,16 @@ enum {
PCMSG_PRIVMSG = 0x0412, // S user, S text
// -- Channeling
PCMSG_REGISTER_CHANNEL = 0x0413, // B pub/priv, S name, S announcement, S password
- CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0414, // B error
+ CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0414, // B error, W channel, S channel
PCMSG_UNREGISTER_CHANNEL = 0x0415, // W channel
CPMSG_UNREGISTER_CHANNEL_RESPONSE = 0x0416, // B error
CPMSG_CHANNEL_EVENT = 0x0418, // W channel, B event, S user
PCMSG_ENTER_CHANNEL = 0x0419, // W channel, S password
- CPMSG_ENTER_CHANNEL_RESPONSE = 0x0420, // B error
+ CPMSG_ENTER_CHANNEL_RESPONSE = 0x0420, // B error, W channel, S channel
PCMSG_QUIT_CHANNEL = 0x0421, // W channel
CPMSG_QUIT_CHANNEL_RESPONSE = 0x0422, // B error
+ PCMSG_LIST_CHANNELS = 0x0423, // -
+ CPMSG_LIST_CHANNELS_RESPONSE = 0x0424, // W number of channels, S channels
XXMSG_INVALID = 0x7FFF
};