summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--src/commandhandler.cpp17
-rw-r--r--src/commandhandler.h6
-rw-r--r--src/net/chathandler.cpp8
-rw-r--r--src/net/chatserver/chatserver.cpp14
-rw-r--r--src/net/chatserver/chatserver.h4
-rw-r--r--src/net/guildhandler.cpp33
-rw-r--r--src/net/protocol.h24
8 files changed, 97 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 47d0b364..6f0988da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-06-25 Roderic Morris <roderic@ccs.neu.edu>
+
+ * src/commandhandler.cpp, src/commandhandler.h, src/net/chathandler.cpp,
+ src/net/chatserver/chatserver.cpp, src/net/chatserver/chatserver.h:
+ Handle setting channel topics.
+ * src/net/guildhandler.cpp, src/net/protocol.h: Handle guild list update
+ events, and update protocol definitions.
+
2008-06-14 Roderic Morris <roderic@ccs.neu.edu>
* src/gui/viewport.cpp, data/graphics/images/CMakeLists.txt,
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 07184f66..465f572d 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -76,6 +76,10 @@ void CommandHandler::handleCommand(const std::string &command)
{
handleQuit();
}
+ else if (type == "topic")
+ {
+ handleTopic(args);
+ }
else if (type == "admin")
{
Net::GameServer::Player::say("/" + args);
@@ -107,6 +111,7 @@ void CommandHandler::handleHelp()
chatWindow->chatLog("/listusers > Lists the users in the current channel");
chatWindow->chatLog("/channel > Register a new channel");
chatWindow->chatLog("/join > Join an already registered channel");
+ chatWindow->chatLog("/topic > Set the topic of the current channel");
chatWindow->chatLog("/quit > Leave a channel");
chatWindow->chatLog("/admin > Send a command to the server (GM only)");
chatWindow->chatLog("/clear > Clears this window");
@@ -171,6 +176,18 @@ void CommandHandler::handleListUsers()
Net::ChatServer::getUserList(chatWindow->getFocused());
}
+void CommandHandler::handleTopic(const std::string &args)
+{
+ if (Channel *channel = channelManager->findByName(chatWindow->getFocused()))
+ {
+ Net::ChatServer::setChannelTopic(channel->getId(), args);
+ }
+ else
+ {
+ chatWindow->chatLog("Unable to set this channel's topic", BY_CHANNEL);
+ }
+}
+
void CommandHandler::handleQuit()
{
if (Channel *channel = channelManager->findByName(chatWindow->getFocused()))
diff --git a/src/commandhandler.h b/src/commandhandler.h
index b409c5f5..c415ba4f 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -94,6 +94,11 @@ class CommandHandler
void handleListUsers();
/**
+ * Handle a topic command.
+ */
+ void handleTopic(const std::string &args);
+
+ /**
* Handle a quit command.
*/
void handleQuit();
@@ -102,6 +107,7 @@ class CommandHandler
* Handle a clear command.
*/
void handleClear();
+
};
extern CommandHandler *commandHandler;
diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp
index ac91c553..ce4a91da 100644
--- a/src/net/chathandler.cpp
+++ b/src/net/chathandler.cpp
@@ -144,6 +144,8 @@ void ChatHandler::handleRegisterChannelResponse(MessageIn &msg)
channelName,
channelAnnouncement));
chatWindow->createNewChannelTab(channelName);
+ chatWindow->chatLog("Topic: " + channelAnnouncement, BY_CHANNEL, channelName);
+
}
else
{
@@ -168,7 +170,7 @@ void ChatHandler::handleEnterChannelResponse(MessageIn &msg)
Channel *channel = new Channel(channelId, channelName, announcement);
channelManager->addChannel(channel);
chatWindow->createNewChannelTab(channelName);
- chatWindow->chatLog("Announcement: " + announcement, BY_CHANNEL, channelName);
+ chatWindow->chatLog("Topic: " + announcement, BY_CHANNEL, channelName);
std::string user;
chatWindow->chatLog("Players in this channel:", BY_CHANNEL, channelName);
@@ -276,6 +278,10 @@ void ChatHandler::handleChannelEvent(MessageIn &msg)
case CHAT_EVENT_LEAVING_PLAYER:
line += " left the channel.";
break;
+
+ case CHAT_EVENT_TOPIC_CHANGE:
+ line = "Topic: " + line;
+ break;
default:
line = "Unknown channel event.";
diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp
index fbf7355f..c6df7c83 100644
--- a/src/net/chatserver/chatserver.cpp
+++ b/src/net/chatserver/chatserver.cpp
@@ -81,11 +81,11 @@ void Net::ChatServer::privMsg(const std::string &recipient,
}
void Net::ChatServer::registerChannel(const std::string &name,
- const std::string &announcement, const std::string &password)
+ const std::string &topic, const std::string &password)
{
MessageOut msg(PCMSG_REGISTER_CHANNEL);
msg.writeString(name);
- msg.writeString(announcement);
+ msg.writeString(topic);
msg.writeString(password);
connection->send(msg);
@@ -125,3 +125,13 @@ void Net::ChatServer::getUserList(const std::string &channel)
connection->send(msg);
}
+
+void Net::ChatServer::setChannelTopic(short channel, const std::string &topic)
+{
+ MessageOut msg(PCMSG_TOPIC_CHANGE);
+
+ msg.writeInt16(channel);
+ msg.writeString(topic);
+
+ connection->send(msg);
+}
diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h
index 411d5e7b..dac19e88 100644
--- a/src/net/chatserver/chatserver.h
+++ b/src/net/chatserver/chatserver.h
@@ -43,7 +43,7 @@ namespace Net
void privMsg(const std::string &recipient, const std::string &text);
void registerChannel(const std::string &name,
- const std::string &announcement, const std::string &password);
+ const std::string &topic, const std::string &password);
void enterChannel(const std::string &channel, const std::string &password);
@@ -53,6 +53,8 @@ namespace Net
void getUserList(const std::string &channel);
+ void setChannelTopic(short channel, const std::string &topic);
+
}
}
diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp
index 97453c39..151abe03 100644
--- a/src/net/guildhandler.cpp
+++ b/src/net/guildhandler.cpp
@@ -94,6 +94,7 @@ void GuildHandler::handleMessage(MessageIn &msg)
if(msg.readInt8() == ERRMSG_OK)
{
std::string guildMember;
+ bool online;
std::string guildName;
Guild *guild;
@@ -108,16 +109,15 @@ void GuildHandler::handleMessage(MessageIn &msg)
while(msg.getUnreadLength())
{
guildMember = msg.readString();
+ online = msg.readInt8();
if(guildMember != "")
{
guild->addMember(guildMember);
- guildWindow->setOnline(guildName, guildMember, false);
+ guildWindow->setOnline(guildName, guildMember, online);
}
}
guildWindow->updateTab();
-
- //Net::ChatServer::getUserList(guildName);
}
} break;
@@ -126,12 +126,33 @@ void GuildHandler::handleMessage(MessageIn &msg)
logger->log("Received CPMSG_GUILD_UPDATE_LIST");
short guildId = msg.readInt16();
std::string guildMember = msg.readString();
+ char eventId = msg.readInt8();
Guild *guild = player_node->getGuild(guildId);
if (guild)
{
- guild->addMember(guildMember);
- guildWindow->setOnline(guild->getName(), guildMember, true);
+ switch(eventId)
+ {
+ case GUILD_EVENT_NEW_PLAYER:
+ guild->addMember(guildMember);
+ guildWindow->setOnline(guild->getName(), guildMember, true);
+ break;
+
+ case GUILD_EVENT_LEAVING_PLAYER:
+ guild->removeMember(guildMember);
+ break;
+
+ case GUILD_EVENT_ONLINE_PLAYER:
+ guildWindow->setOnline(guild->getName(), guildMember, true);
+ break;
+
+ case GUILD_EVENT_OFFLINE_PLAYER:
+ guildWindow->setOnline(guild->getName(), guildMember, false);
+ break;
+
+ default:
+ logger->log("Invalid guild event");
+ }
}
guildWindow->updateTab();
@@ -195,5 +216,5 @@ void GuildHandler::joinedGuild(MessageIn &msg)
Channel *channel = new Channel(channelId, guildName, announcement);
channelManager->addChannel(channel);
chatWindow->createNewChannelTab(guildName);
- chatWindow->chatLog("Announcement: " + announcement, BY_CHANNEL, guildName);
+ chatWindow->chatLog("Topic: " + announcement, BY_CHANNEL, guildName);
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 3d3f47cf..76a8ffab 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -137,8 +137,8 @@ enum {
PCMSG_GUILD_ACCEPT = 0x0354, // W id
CPMSG_GUILD_ACCEPT_RESPONSE = 0x0355, // B error, W guild, B rights, W channel
PCMSG_GUILD_GET_MEMBERS = 0x0356, // W id
- CPMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0357, // S names
- CPMSG_GUILD_UPDATE_LIST = 0x0358, // W id, S name
+ CPMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0357, // S names, B online
+ CPMSG_GUILD_UPDATE_LIST = 0x0358, // W id, S name, B event
PCMSG_GUILD_QUIT = 0x0360, // W id
CPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error
@@ -163,17 +163,18 @@ enum {
PCMSG_ANNOUNCE = 0x0411, // S text
PCMSG_PRIVMSG = 0x0412, // S user, S text
// -- Channeling
- PCMSG_REGISTER_CHANNEL = 0x0420, // S name, S announcement, S password
- CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0421, // B error, W id, S name, S announcement
- CPMSG_CHANNEL_EVENT = 0x0430, // W channel, B event, S user
+ PCMSG_REGISTER_CHANNEL = 0x0420, // S name, S topic, S password
+ CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0421, // B error, W id, S name, S topic
+ CPMSG_CHANNEL_EVENT = 0x0430, // W channel, B event, S info
PCMSG_ENTER_CHANNEL = 0x0440, // S channel, S password
- CPMSG_ENTER_CHANNEL_RESPONSE = 0x0441, // B error, W id, S name, S announcement, S userlist
+ CPMSG_ENTER_CHANNEL_RESPONSE = 0x0441, // B error, W id, S name, S topic, S userlist
PCMSG_QUIT_CHANNEL = 0x0443, // W channel id
CPMSG_QUIT_CHANNEL_RESPONSE = 0x0444, // B error, W channel id
PCMSG_LIST_CHANNELS = 0x0445, // -
CPMSG_LIST_CHANNELS_RESPONSE = 0x0446, // S names, W number of users
PCMSG_LIST_CHANNELUSERS = 0x0460, // S channel
CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S channel, S users
+ PCMSG_TOPIC_CHANGE = 0x0462, // W channel id, S topic
XXMSG_INVALID = 0x7FFF
};
@@ -261,7 +262,16 @@ enum {
// Chat channels event values
enum {
CHAT_EVENT_NEW_PLAYER = 0,
- CHAT_EVENT_LEAVING_PLAYER
+ CHAT_EVENT_LEAVING_PLAYER,
+ CHAT_EVENT_TOPIC_CHANGE
+};
+
+// Guild member event values
+enum {
+ GUILD_EVENT_NEW_PLAYER = 0,
+ GUILD_EVENT_LEAVING_PLAYER,
+ GUILD_EVENT_ONLINE_PLAYER,
+ GUILD_EVENT_OFFLINE_PLAYER
};
#endif