diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commandhandler.cpp | 51 | ||||
-rw-r--r-- | src/commandhandler.h | 10 | ||||
-rw-r--r-- | src/gui/guildlistbox.cpp | 4 | ||||
-rw-r--r-- | src/net/chathandler.cpp | 54 | ||||
-rw-r--r-- | src/net/chatserver/chatserver.cpp | 22 | ||||
-rw-r--r-- | src/net/chatserver/chatserver.h | 4 | ||||
-rw-r--r-- | src/net/chatserver/guild.cpp | 13 | ||||
-rw-r--r-- | src/net/chatserver/guild.h | 6 | ||||
-rw-r--r-- | src/net/guildhandler.cpp | 22 | ||||
-rw-r--r-- | src/net/protocol.h | 11 |
10 files changed, 183 insertions, 14 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 8e6003f9..7ec48f46 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -89,6 +89,10 @@ void CommandHandler::handleCommand(const std::string &command) { handleParty(args); } + else if (type == "op") + { + handleOp(args); + } else { chatWindow->chatLog("Unknown command"); @@ -161,6 +165,13 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("This command makes you enter <channel>."); chatWindow->chatLog("If <channel> doesn't exist, it's created."); } + else if (args == "kick") + { + chatWindow->chatLog("Command: /kick <nick>"); + chatWindow->chatLog("This command makes <nick> leave the channel."); + chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " + "double quotes (\")."); + } else if (args == "list") { chatWindow->chatLog("Command: /list"); @@ -173,6 +184,15 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " "double quotes (\")."); } + else if (args == "op") + { + chatWindow->chatLog("Command: /op <nick>"); + chatWindow->chatLog("This command makes <nick> a channel operator."); + chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " + "double quotes (\")."); + chatWindow->chatLog("Channel operators can kick and op other users " + "from the channel."); + } else if (args == "party") { chatWindow->chatLog("Command: /party <nick>"); @@ -287,3 +307,34 @@ void CommandHandler::handleParty(const std::string &args) player_node->inviteToParty(args); } } + +void CommandHandler::handleOp(const std::string &args) +{ + if (Channel *channel = channelManager->findByName(chatWindow->getFocused())) + { + // set the user mode 'o' to op a user + if (args != "") + { + Net::ChatServer::setUserMode(channel->getId(), args, 'o'); + } + } + else + { + chatWindow->chatLog("Unable to set this user's mode", BY_CHANNEL); + } +} + +void CommandHandler::handleKick(const std::string &args) +{ + if (Channel *channel = channelManager->findByName(chatWindow->getFocused())) + { + if (args != "") + { + Net::ChatServer::kickUser(channel->getId(), args); + } + } + else + { + chatWindow->chatLog("Unable to kick user", BY_CHANNEL); + } +} diff --git a/src/commandhandler.h b/src/commandhandler.h index 0e8d9dd7..10a4376f 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -108,6 +108,16 @@ class CommandHandler */ void handleParty(const std::string &args); + /** + * Handle a op command. + */ + void handleOp(const std::string &args); + + /** + * Handle a kick command. + */ + void handleKick(const std::string &args); + }; extern CommandHandler *commandHandler; diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp index 13c0ede7..659f1a63 100644 --- a/src/gui/guildlistbox.cpp +++ b/src/gui/guildlistbox.cpp @@ -111,6 +111,10 @@ void GuildListBox::mousePressed(gcn::MouseEvent &event) distributeActionEvent(); } // TODO: Add guild functions, ie private messaging + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + // Show context menu + } } void GuildListBox::setOnlineStatus(const std::string &user, bool online) diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 43ca5a71..0cb59403 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -67,7 +67,7 @@ void ChatHandler::handleMessage(MessageIn &msg) case GPMSG_SAY: handleGameChatMessage(msg); break; - + case CPMSG_ENTER_CHANNEL_RESPONSE: handleEnterChannelResponse(msg); break; @@ -95,7 +95,7 @@ void ChatHandler::handleMessage(MessageIn &msg) case CPMSG_LIST_CHANNELUSERS_RESPONSE: handleListChannelUsersResponse(msg); break; - + case CPMSG_CHANNEL_EVENT: handleChannelEvent(msg); } @@ -105,15 +105,15 @@ void ChatHandler::handleGameChatMessage(MessageIn &msg) { short id = msg.readInt16(); std::string chatMsg = msg.readString(); - + if (id == 0) { chatWindow->chatLog(chatMsg, BY_SERVER); return; } - + Being *being = beingManager->findBeing(id); - + if (being) { chatWindow->chatLog(being->getName() + " : " + chatMsg, @@ -137,17 +137,23 @@ void ChatHandler::handleEnterChannelResponse(MessageIn &msg) channelManager->addChannel(channel); chatWindow->createNewChannelTab(channelName); chatWindow->chatLog("Topic: " + announcement, BY_CHANNEL, channelName); - + std::string user; + std::string userModes; chatWindow->chatLog("Players in this channel:", BY_CHANNEL, channelName); while(msg.getUnreadLength()) { user = msg.readString(); if (user == "") return; + userModes = msg.readString(); + if (userModes.find('o') != std::string::npos) + { + user = "@" + user; + } chatWindow->chatLog(user, BY_CHANNEL, channelName); } - + } else { @@ -180,7 +186,7 @@ void ChatHandler::handlePrivateMessage(MessageIn &msg) if (!chatWindow->tabExists(userNick)) { chatWindow->createNewChannelTab(userNick); - + } chatWindow->chatLog(userNick + ": " + chatMsg, BY_OTHER, userNick); } @@ -214,6 +220,7 @@ void ChatHandler::handleListChannelUsersResponse(MessageIn &msg) { std::string channel = msg.readString(); std::string userNick; + std::string userModes; chatWindow->chatLog("Players in this channel:", BY_CHANNEL, channel); while(msg.getUnreadLength()) { @@ -222,6 +229,11 @@ void ChatHandler::handleListChannelUsersResponse(MessageIn &msg) { break; } + userModes = msg.readString(); + if (userModes.find('o') != std::string::npos) + { + userNick = "@" + userNick; + } chatWindow->chatLog(userNick, BY_CHANNEL, channel); } } @@ -232,7 +244,7 @@ void ChatHandler::handleChannelEvent(MessageIn &msg) char eventId = msg.readInt8(); std::string line = msg.readString(); Channel *channel = channelManager->findById(channelId); - + if(channel) { switch(eventId) @@ -240,7 +252,7 @@ void ChatHandler::handleChannelEvent(MessageIn &msg) case CHAT_EVENT_NEW_PLAYER: line += " entered the channel."; break; - + case CHAT_EVENT_LEAVING_PLAYER: line += " left the channel."; break; @@ -248,11 +260,29 @@ void ChatHandler::handleChannelEvent(MessageIn &msg) case CHAT_EVENT_TOPIC_CHANGE: line = "Topic: " + line; break; - + + case CHAT_EVENT_MODE_CHANGE: + { + int first = line.find(":"); + int second = line.find(":", first+1); + std::string user1 = line.substr(0, first); + std::string user2 = line.substr(first+1, second); + std::string mode = line.substr(second+1, line.length()); + line = user1 + " has set mode " + mode + " on user " + user2; + } break; + + case CHAT_EVENT_KICKED_PLAYER: + { + int first = line.find(":"); + std::string user1 = line.substr(0, first); + std::string user2 = line.substr(first+1, line.length()); + line = user1 + " has kicked " + user2; + } break; + default: line = "Unknown channel event."; } - + chatWindow->chatLog(line, BY_CHANNEL, channel->getName()); } } diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp index a2dbefbb..f302a0ef 100644 --- a/src/net/chatserver/chatserver.cpp +++ b/src/net/chatserver/chatserver.cpp @@ -124,3 +124,25 @@ void Net::ChatServer::setChannelTopic(short channel, const std::string &topic) connection->send(msg); } + +void Net::ChatServer::setUserMode(short channel, const std::string &user, + unsigned char mode) +{ + MessageOut msg(PCMSG_USER_MODE); + + msg.writeInt16(channel); + msg.writeString(user); + msg.writeInt8(mode); + + connection->send(msg); +} + +void Net::ChatServer::kickUser(short channel, const std::string &user) +{ + MessageOut msg(PCMSG_KICK_USER); + + msg.writeInt16(channel); + msg.writeString(user); + + connection->send(msg); +} diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h index 56ad46ca..10de1213 100644 --- a/src/net/chatserver/chatserver.h +++ b/src/net/chatserver/chatserver.h @@ -52,6 +52,10 @@ namespace Net void setChannelTopic(short channel, const std::string &topic); + void setUserMode(short channel, const std::string &user, unsigned char mode); + + void kickUser(short channel, const std::string &user); + } } diff --git a/src/net/chatserver/guild.cpp b/src/net/chatserver/guild.cpp index c1114065..fb400d5d 100644 --- a/src/net/chatserver/guild.cpp +++ b/src/net/chatserver/guild.cpp @@ -73,6 +73,19 @@ void Net::ChatServer::Guild::getGuildMembers(short guildId) Net::ChatServer::connection->send(msg); } +void Net::ChatServer::Guild::promoteMember(const std::string &name, + short guildId, short level) +{ + logger->log("Sending PCMSG_GUILD_PROMOTE_MEMBER"); + MessageOut msg(PCMSG_GUILD_PROMOTE_MEMBER); + + msg.writeInt16(guildId); + msg.writeString(name); + msg.writeInt8(level); + + Net::ChatServer::connection->send(msg); +} + void Net::ChatServer::Guild::quitGuild(short guildId) { logger->log("Sending PCMSG_GUILD_QUIT"); diff --git a/src/net/chatserver/guild.h b/src/net/chatserver/guild.h index 5800c738..354ecd82 100644 --- a/src/net/chatserver/guild.h +++ b/src/net/chatserver/guild.h @@ -54,6 +54,12 @@ namespace Net void getGuildMembers(short guildId); /** + * Promote guild member + */ + void promoteMember(const std::string &name, short guildId, + short level); + + /** * Quit guild. */ void quitGuild(short guildId); diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 51393168..f6677cd8 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -65,8 +65,13 @@ void GuildHandler::handleMessage(MessageIn &msg) if(msg.readInt8() == ERRMSG_OK) { // TODO - Acknowledge guild was created + chatWindow->chatLog("Guild created."); joinedGuild(msg); } + else + { + chatWindow->chatLog("Error creating guild."); + } } break; case CPMSG_GUILD_INVITE_RESPONSE: @@ -75,6 +80,7 @@ void GuildHandler::handleMessage(MessageIn &msg) if(msg.readInt8() == ERRMSG_OK) { // TODO - Acknowledge invite was sent + chatWindow->chatLog("Invite sent."); } } break; @@ -169,6 +175,22 @@ void GuildHandler::handleMessage(MessageIn &msg) guildWindow->openAcceptDialog(inviterName, guildName); } break; + case CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE: + { + logger->log("Received CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE"); + + if (msg.readInt8() == ERRMSG_OK) + { + // promotion succeeded + chatWindow->chatLog("Member was promoted successfully"); + } + else + { + // promotion failed + chatWindow->chatLog("Failed to promote member"); + } + } + case CPMSG_GUILD_REJOIN: { logger->log("Received CPMSG_GUILD_REJOIN"); diff --git a/src/net/protocol.h b/src/net/protocol.h index 9213d329..bd4eaa17 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -142,6 +142,8 @@ enum { CPMSG_GUILD_UPDATE_LIST = 0x0358, // W id, S name, B event PCMSG_GUILD_QUIT = 0x0360, // W id CPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error + PCMSG_GUILD_PROMOTE_MEMBER = 0x0365, // W guild, S name, B rights + CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE = 0x0366, // B error CPMSG_GUILD_INVITED = 0x0370, // S char name, S guild name, W id CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, W rights, W channel, S announce @@ -172,8 +174,11 @@ enum { 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 + CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S channel, { S user, B mode } PCMSG_TOPIC_CHANGE = 0x0462, // W channel id, S topic + // -- User mode + PCMSG_USER_MODE = 0x0465, // W channel id, S name, B mode + PCMSG_KICK_USER = 0x0466, // W channel id, S name XXMSG_INVALID = 0x7FFF }; @@ -262,7 +267,9 @@ enum { enum { CHAT_EVENT_NEW_PLAYER = 0, CHAT_EVENT_LEAVING_PLAYER, - CHAT_EVENT_TOPIC_CHANGE + CHAT_EVENT_TOPIC_CHANGE, + CHAT_EVENT_MODE_CHANGE, + CHAT_EVENT_KICKED_PLAYER }; // Guild member event values |