diff options
author | Roderic Morris <roderic@ccs.neu.edu> | 2008-06-25 21:12:44 +0000 |
---|---|---|
committer | Roderic Morris <roderic@ccs.neu.edu> | 2008-06-25 21:12:44 +0000 |
commit | a34a4692200eaf5b3ec8a7de75699a46aefd8b98 (patch) | |
tree | d73f15d55e7f784e99d92672f9ccbe69d64d7e69 /src/net | |
parent | a0b6e09737b7b416a38c08d8e1d6744a4cc12f7d (diff) | |
download | mana-a34a4692200eaf5b3ec8a7de75699a46aefd8b98.tar.gz mana-a34a4692200eaf5b3ec8a7de75699a46aefd8b98.tar.bz2 mana-a34a4692200eaf5b3ec8a7de75699a46aefd8b98.tar.xz mana-a34a4692200eaf5b3ec8a7de75699a46aefd8b98.zip |
handle topic changes and guild events
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/chathandler.cpp | 8 | ||||
-rw-r--r-- | src/net/chatserver/chatserver.cpp | 14 | ||||
-rw-r--r-- | src/net/chatserver/chatserver.h | 4 | ||||
-rw-r--r-- | src/net/guildhandler.cpp | 33 | ||||
-rw-r--r-- | src/net/protocol.h | 24 |
5 files changed, 66 insertions, 17 deletions
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 |