From f6f031fa4db6fa0ccd6e0b433f61479e9fd85477 Mon Sep 17 00:00:00 2001 From: Roderic Morris Date: Tue, 10 Jun 2008 00:45:21 +0000 Subject: add commandhandler class and fix / add some commands --- src/commandhandler.cpp | 189 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 src/commandhandler.cpp (limited to 'src/commandhandler.cpp') diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp new file mode 100644 index 00000000..07184f66 --- /dev/null +++ b/src/commandhandler.cpp @@ -0,0 +1,189 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + + +#include "commandhandler.h" +#include "channelmanager.h" +#include "channel.h" +#include "game.h" +#include "gui/chat.h" +#include "net/chatserver/chatserver.h" +#include "net/gameserver/player.h" + +void CommandHandler::handleCommand(const std::string &command) +{ + std::string::size_type pos = command.find(' '); + std::string type(command, 0, pos); + std::string args(command, pos == std::string::npos ? command.size() : pos + 1); + + if (type == "announce") + { + handleAnnounce(args); + } + else if (type == "help") + { + handleHelp(); + } + else if (type == "where") + { + handleWhere(); + } + else if (type == "who") + { + handleWho(); + } + else if (type == "msg") + { + handleMsg(args); + } + else if (type == "channel") + { + handleChannel(args); + } + else if (type == "join") + { + handleJoin(args); + } + else if (type == "listchannels") + { + handleListChannels(); + } + else if (type == "listusers") + { + handleListUsers(); + } + else if (type == "quit") + { + handleQuit(); + } + else if (type == "admin") + { + Net::GameServer::Player::say("/" + args); + } + else if (type == "clear") + { + handleClear(); + } + else + { + chatWindow->chatLog("Unknown command"); + } +} + +void CommandHandler::handleAnnounce(const std::string &args) +{ + Net::ChatServer::announce(args); +} + +void CommandHandler::handleHelp() +{ + chatWindow->chatLog("-- Help --"); + chatWindow->chatLog("/help > Display this help."); + chatWindow->chatLog("/announce > Global announcement (GM only)"); + chatWindow->chatLog("/where > Display map name"); + chatWindow->chatLog("/who > Display number of online users"); + chatWindow->chatLog("/msg > Send a private message to a user"); + chatWindow->chatLog("/listchannels > Display all public channels"); + 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("/quit > Leave a channel"); + chatWindow->chatLog("/admin > Send a command to the server (GM only)"); + chatWindow->chatLog("/clear > Clears this window"); +} + +void CommandHandler::handleWhere() +{ + chatWindow->chatLog(map_path, BY_SERVER); +} + +void CommandHandler::handleWho() +{ + +} + +void CommandHandler::handleMsg(const std::string &args) +{ + std::string::size_type pos = args.find(' '); + std::string recipient(args, 0, pos); + std::string text(args, pos+1); + Net::ChatServer::privMsg(recipient, text); +} + +void CommandHandler::handleChannel(const std::string &args) +{ + std::string::size_type pos = args.find(" "); + std::string name(args, 0, pos); + std::string password; + std::string announcement; + if(pos == std::string::npos) + { + password = std::string(); + announcement = std::string(); + } + else + { + password = std::string(args, pos + 1, args.find(" ", pos + 1) - pos - 1); + pos = args.find("\""); + announcement = std::string(args, pos == std::string::npos ? args.size() : + pos + 1, args.size() - pos - 2); + } + chatWindow->chatLog("Requesting to register channel " + name); + Net::ChatServer::registerChannel(name, announcement, password); +} + +void CommandHandler::handleJoin(const std::string &args) +{ + std::string::size_type pos = args.find(' '); + std::string name(args, 0, pos); + std::string password(args, pos+1); + chatWindow->chatLog("Requesting to join channel " + name); + Net::ChatServer::enterChannel(name, password); +} + +void CommandHandler::handleListChannels() +{ + Net::ChatServer::getChannelList(); +} + +void CommandHandler::handleListUsers() +{ + Net::ChatServer::getUserList(chatWindow->getFocused()); +} + +void CommandHandler::handleQuit() +{ + if (Channel *channel = channelManager->findByName(chatWindow->getFocused())) + { + Net::ChatServer::quitChannel(channel->getId()); + } + else + { + chatWindow->chatLog("Unable to quit this channel", BY_CHANNEL); + } +} + +void CommandHandler::handleClear() +{ + chatWindow->clearTab(chatWindow->getFocused()); +} -- cgit v1.2.3-70-g09d2 From a34a4692200eaf5b3ec8a7de75699a46aefd8b98 Mon Sep 17 00:00:00 2001 From: Roderic Morris Date: Wed, 25 Jun 2008 21:12:44 +0000 Subject: handle topic changes and guild events --- ChangeLog | 8 ++++++++ src/commandhandler.cpp | 17 +++++++++++++++++ src/commandhandler.h | 6 ++++++ src/net/chathandler.cpp | 8 +++++++- src/net/chatserver/chatserver.cpp | 14 ++++++++++++-- src/net/chatserver/chatserver.h | 4 +++- src/net/guildhandler.cpp | 33 +++++++++++++++++++++++++++------ src/net/protocol.h | 24 +++++++++++++++++------- 8 files changed, 97 insertions(+), 17 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 47d0b364..6f0988da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-06-25 Roderic Morris + + * 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 * 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 @@ -93,6 +93,11 @@ class CommandHandler */ void handleListUsers(); + /** + * Handle a topic command. + */ + void handleTopic(const std::string &args); + /** * Handle a quit command. */ @@ -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 -- cgit v1.2.3-70-g09d2 From 183bc340bd3e062a4c6df4d66cc2843582bcec94 Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 7 Jul 2008 12:53:24 +0000 Subject: Added help for each command based on mantis bug #359, thanks to Scraggy --- ChangeLog | 5 +++ src/commandhandler.cpp | 117 ++++++++++++++++++++++++++++++++++++++++--------- src/commandhandler.h | 30 ++++++------- 3 files changed, 116 insertions(+), 36 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 65d7ef84..2200e328 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-07-07 David Athay + + * src/commandhandler.hpp, src/commandhandler.cpp: Added help for each + command based on mantis bug #359, thanks to Scraggy. + 2008-07-05 David Athay * src/game.cpp, src/gui/gui.cpp: Allow foreign keyboards to use alt key diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 465f572d..7e20deff 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -20,8 +20,8 @@ * * $Id$ */ - - + + #include "commandhandler.h" #include "channelmanager.h" #include "channel.h" @@ -42,7 +42,7 @@ void CommandHandler::handleCommand(const std::string &command) } else if (type == "help") { - handleHelp(); + handleHelp(args); } else if (type == "where") { @@ -56,19 +56,21 @@ void CommandHandler::handleCommand(const std::string &command) { handleMsg(args); } + /* else if (type == "channel") { handleChannel(args); } + */ else if (type == "join") { handleJoin(args); } - else if (type == "listchannels") + else if (type == "list") { handleListChannels(); } - else if (type == "listusers") + else if (type == "users") { handleListUsers(); } @@ -99,22 +101,95 @@ void CommandHandler::handleAnnounce(const std::string &args) Net::ChatServer::announce(args); } -void CommandHandler::handleHelp() +void CommandHandler::handleHelp(const std::string &args) { - chatWindow->chatLog("-- Help --"); - chatWindow->chatLog("/help > Display this help."); - chatWindow->chatLog("/announce > Global announcement (GM only)"); - chatWindow->chatLog("/where > Display map name"); - chatWindow->chatLog("/who > Display number of online users"); - chatWindow->chatLog("/msg > Send a private message to a user"); - chatWindow->chatLog("/listchannels > Display all public channels"); - 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"); + chatWindow->chatLog("-- Help --", BY_SERVER); + if (args == "") + { + chatWindow->chatLog("-- Help --"); + chatWindow->chatLog("/help > Display this help."); + chatWindow->chatLog("/announce > Global announcement (GM only)"); + chatWindow->chatLog("/where > Display map name"); + chatWindow->chatLog("/who > Display number of online users"); + chatWindow->chatLog("/msg > Send a private message to a user"); + chatWindow->chatLog("/list > Display all public channels"); + chatWindow->chatLog("/users > 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"); + chatWindow->chatLog("For more information, type /help "); + } + else if (args == "admin") + { + chatWindow->chatLog("Command: /admin "); + chatWindow->chatLog("*** only available to a GM ***"); + chatWindow->chatLog("This command sends an admin command to the server."); + } + else if (args == "announce") + { + chatWindow->chatLog("Command: /announce "); + chatWindow->chatLog("*** only available to a GM ***"); + chatWindow->chatLog("This command sends the message to " + "all players currently online."); + } + else if (args == "clear") + { + chatWindow->chatLog("Command: /clear"); + chatWindow->chatLog("This command clears the chat log of previous chat."); + } + else if (args == "help") + { + chatWindow->chatLog("Command: /help"); + chatWindow->chatLog("This command displays a list of all commands available."); + chatWindow->chatLog("Command: /help "); + chatWindow->chatLog("This command displays help on ."); + } + else if (args == "join") + { + chatWindow->chatLog("Command: /join "); + chatWindow->chatLog("This command makes you enter ."); + } + else if (args == "list") + { + chatWindow->chatLog("Command: /list"); + chatWindow->chatLog("This command shows a list of all channels."); + } + else if (args == "msg") + { + chatWindow->chatLog("Command: /msg "); + chatWindow->chatLog("This command sends the text to ."); + chatWindow->chatLog("If the has spaces in it, enclose it in " + "double quotes (\")."); + } + else if (args == "topic") + { + chatWindow->chatLog("Command: /topic "); + chatWindow->chatLog("This command sets the topic to ."); + } + else if (args == "users") + { + chatWindow->chatLog("Command: /users "); + chatWindow->chatLog("This command shows the users in ."); + } + else if (args == "where") + { + chatWindow->chatLog("Command: /where"); + chatWindow->chatLog("This command displays the name of the current map."); + } + else if (args == "who") + { + chatWindow->chatLog("Command: /who"); + chatWindow->chatLog("This command displays the number of players currently " + "online."); + } + else + { + chatWindow->chatLog("Unknown command."); + chatWindow->chatLog("Type /help for a list of commands."); + } } void CommandHandler::handleWhere() @@ -124,7 +199,7 @@ void CommandHandler::handleWhere() void CommandHandler::handleWho() { - + } void CommandHandler::handleMsg(const std::string &args) diff --git a/src/commandhandler.h b/src/commandhandler.h index c415ba4f..ef6da33d 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -20,7 +20,7 @@ * * $Id$ */ - + #ifndef _TMW_COMMANDHANDLER_H #define _TMW_COMMANDHANDLER_H @@ -36,63 +36,63 @@ class CommandHandler * Constructor */ CommandHandler() {} - + /** * Destructor */ ~CommandHandler() {} - + /** * Parse and handle the given command. */ void handleCommand(const std::string &command); - + private: /** * Handle an announce command. */ void handleAnnounce(const std::string &args); - + /** * Handle a help command. */ - void handleHelp(); - + void handleHelp(const std::string &args); + /** * Handle a where command. */ void handleWhere(); - + /** * Handle a who command. */ void handleWho(); - + /** * Handle a msg command. */ void handleMsg(const std::string &args); - + /** * Handle a channel command. */ void handleChannel(const std::string &args); - + /** * Handle a join command. */ void handleJoin(const std::string &args); - + /** * Handle a listchannels command. */ void handleListChannels(); - + /** * Handle a listusers command. */ void handleListUsers(); - + /** * Handle a topic command. */ @@ -102,7 +102,7 @@ class CommandHandler * Handle a quit command. */ void handleQuit(); - + /** * Handle a clear command. */ -- cgit v1.2.3-70-g09d2 From 9bf9b2c706290b61af0f66f11ff1b3cd37d72904 Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 7 Jul 2008 14:34:40 +0000 Subject: Added /party command. --- ChangeLog | 2 ++ src/commandhandler.cpp | 21 +++++++++++++++++++++ src/commandhandler.h | 5 +++++ src/gui/popupmenu.cpp | 2 +- src/localplayer.cpp | 4 ++-- src/localplayer.h | 2 +- 6 files changed, 32 insertions(+), 4 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 2200e328..9dee8ee7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * src/commandhandler.hpp, src/commandhandler.cpp: Added help for each command based on mantis bug #359, thanks to Scraggy. + * src/localplayer.cpp, src/commandhandler.cpp, src/gui/popupmenu.cpp, + src/commandhandler.h, src/localplayer.h: Added /party command. 2008-07-05 David Athay diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 7e20deff..1dadc236 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -26,6 +26,7 @@ #include "channelmanager.h" #include "channel.h" #include "game.h" +#include "localplayer.h" #include "gui/chat.h" #include "net/chatserver/chatserver.h" #include "net/gameserver/player.h" @@ -90,6 +91,10 @@ void CommandHandler::handleCommand(const std::string &command) { handleClear(); } + else if (type == "party") + { + handleParty(args); + } else { chatWindow->chatLog("Unknown command"); @@ -120,6 +125,7 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("/quit > Leave a channel"); chatWindow->chatLog("/admin > Send a command to the server (GM only)"); chatWindow->chatLog("/clear > Clears this window"); + chatWindow->chatLog("/party > Invite a user to party"); chatWindow->chatLog("For more information, type /help "); } else if (args == "admin") @@ -164,6 +170,13 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("If the has spaces in it, enclose it in " "double quotes (\")."); } + else if (args == "party") + { + chatWindow->chatLog("Command: /party "); + chatWindow->chatLog("This command invites to party with you."); + chatWindow->chatLog("If the has spaces in it, enclose it in " + "double quotes (\")."); + } else if (args == "topic") { chatWindow->chatLog("Command: /topic "); @@ -279,3 +292,11 @@ void CommandHandler::handleClear() { chatWindow->clearTab(chatWindow->getFocused()); } + +void CommandHandler::handleParty(const std::string &args) +{ + if (args != "") + { + player_node->inviteToParty(args); + } +} diff --git a/src/commandhandler.h b/src/commandhandler.h index ef6da33d..5c019450 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -108,6 +108,11 @@ class CommandHandler */ void handleClear(); + /** + * Handle a party command. + */ + void handleParty(const std::string &args); + }; extern CommandHandler *commandHandler; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 01f48ccc..2888382b 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -150,7 +150,7 @@ void PopupMenu::handleLink(const std::string& link) // Add player to your party else if (link == "party") { - player_node->inviteToParty(mBeing); + player_node->inviteToParty(mBeing->getName()); } /* diff --git a/src/localplayer.cpp b/src/localplayer.cpp index dbcb1d42..00ea6a49 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -149,9 +149,9 @@ void LocalPlayer::inviteToGuild(Being *being) } } -void LocalPlayer::inviteToParty(Being *being) +void LocalPlayer::inviteToParty(const std::string &name) { - Net::ChatServer::Party::invitePlayer(being->getName()); + Net::ChatServer::Party::invitePlayer(name); } void LocalPlayer::clearInventory() diff --git a/src/localplayer.h b/src/localplayer.h index 64dec1b2..0b4b66ed 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -162,7 +162,7 @@ class LocalPlayer : public Player /** * Invite a player to join their party */ - void inviteToParty(Being *being); + void inviteToParty(const std::string &name); void clearInventory(); void setInvItem(int index, int id, int amount); -- cgit v1.2.3-70-g09d2 From e91747e5025d5e37b2b856e30d6fb5da6968364c Mon Sep 17 00:00:00 2001 From: Roderic Morris Date: Mon, 7 Jul 2008 16:59:55 +0000 Subject: get rid of channel registering related code --- ChangeLog | 6 ++++++ src/commandhandler.cpp | 38 ++++++++------------------------------ src/commandhandler.h | 5 ----- src/net/chathandler.cpp | 34 ---------------------------------- src/net/chathandler.h | 5 ----- src/net/chatserver/chatserver.cpp | 11 ----------- src/net/chatserver/chatserver.h | 3 --- src/net/protocol.h | 2 -- 8 files changed, 14 insertions(+), 90 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 9dee8ee7..1da6e966 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-07 Roderic Morris + + * src/net/chathandler.cpp, src/net/chathandler.h, src/commandhandler.h, + src/commandhandler.cpp, src/net/protocol.h, src/net/chatserver/chatserver.cpp, + src/net/chatserver/chatserver.h: Get rid of channel registering related code. + 2008-07-07 David Athay * src/commandhandler.hpp, src/commandhandler.cpp: Added help for each diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 1dadc236..8f0aa907 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -57,12 +57,6 @@ void CommandHandler::handleCommand(const std::string &command) { handleMsg(args); } - /* - else if (type == "channel") - { - handleChannel(args); - } - */ else if (type == "join") { handleJoin(args); @@ -119,8 +113,7 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("/msg > Send a private message to a user"); chatWindow->chatLog("/list > Display all public channels"); chatWindow->chatLog("/users > Lists the users in the current channel"); -// chatWindow->chatLog("/channel > Register a new channel"); - chatWindow->chatLog("/join > Join an already registered channel"); + chatWindow->chatLog("/join > Join or create a 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)"); @@ -157,6 +150,7 @@ void CommandHandler::handleHelp(const std::string &args) { chatWindow->chatLog("Command: /join "); chatWindow->chatLog("This command makes you enter ."); + chatWindow->chatLog("If doesn't exist, it's created."); } else if (args == "list") { @@ -177,6 +171,12 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("If the has spaces in it, enclose it in " "double quotes (\")."); } + else if (args == "quit") + { + chatWindow->chatLog("Command: /quit"); + chatWindow->chatLog("This command leaves the current channel."); + chatWindow->chatLog("If you're the last person in the channel, it will be deleted."); + } else if (args == "topic") { chatWindow->chatLog("Command: /topic "); @@ -223,28 +223,6 @@ void CommandHandler::handleMsg(const std::string &args) Net::ChatServer::privMsg(recipient, text); } -void CommandHandler::handleChannel(const std::string &args) -{ - std::string::size_type pos = args.find(" "); - std::string name(args, 0, pos); - std::string password; - std::string announcement; - if(pos == std::string::npos) - { - password = std::string(); - announcement = std::string(); - } - else - { - password = std::string(args, pos + 1, args.find(" ", pos + 1) - pos - 1); - pos = args.find("\""); - announcement = std::string(args, pos == std::string::npos ? args.size() : - pos + 1, args.size() - pos - 2); - } - chatWindow->chatLog("Requesting to register channel " + name); - Net::ChatServer::registerChannel(name, announcement, password); -} - void CommandHandler::handleJoin(const std::string &args) { std::string::size_type pos = args.find(' '); diff --git a/src/commandhandler.h b/src/commandhandler.h index 5c019450..0e8d9dd7 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -73,11 +73,6 @@ class CommandHandler */ void handleMsg(const std::string &args); - /** - * Handle a channel command. - */ - void handleChannel(const std::string &args); - /** * Handle a join command. */ diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index ce4a91da..43ca5a71 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -47,7 +47,6 @@ ChatHandler::ChatHandler() { static const Uint16 _messages[] = { GPMSG_SAY, - CPMSG_REGISTER_CHANNEL_RESPONSE, CPMSG_ENTER_CHANNEL_RESPONSE, CPMSG_LIST_CHANNELS_RESPONSE, CPMSG_PUBMSG, @@ -69,10 +68,6 @@ void ChatHandler::handleMessage(MessageIn &msg) handleGameChatMessage(msg); break; - case CPMSG_REGISTER_CHANNEL_RESPONSE: - handleRegisterChannelResponse(msg); - break; - case CPMSG_ENTER_CHANNEL_RESPONSE: handleEnterChannelResponse(msg); break; @@ -131,35 +126,6 @@ void ChatHandler::handleGameChatMessage(MessageIn &msg) } } -void ChatHandler::handleRegisterChannelResponse(MessageIn &msg) -{ - char error = msg.readInt8(); - if(error == ERRMSG_OK) - { - short channelId = msg.readInt16(); - std::string channelName = msg.readString(); - std::string channelAnnouncement = msg.readString(); - chatWindow->chatLog("Registered Channel " + channelName); - channelManager->addChannel(new Channel(channelId, - channelName, - channelAnnouncement)); - chatWindow->createNewChannelTab(channelName); - chatWindow->chatLog("Topic: " + channelAnnouncement, BY_CHANNEL, channelName); - - } - else - { - if (error == ERRMSG_INVALID_ARGUMENT) - { - chatWindow->chatLog("Error registering channel - Invalid Channel Name given", BY_SERVER); - } - else - { - chatWindow->chatLog("Error registering channel", BY_SERVER); - } - } -} - void ChatHandler::handleEnterChannelResponse(MessageIn &msg) { if(msg.readInt8() == ERRMSG_OK) diff --git a/src/net/chathandler.h b/src/net/chathandler.h index 874998d9..7ca4d50d 100644 --- a/src/net/chathandler.h +++ b/src/net/chathandler.h @@ -42,11 +42,6 @@ class ChatHandler : public MessageHandler */ void handleGameChatMessage(MessageIn &msg); - /** - * Handle channel registration responses. - */ - void handleRegisterChannelResponse(MessageIn &msg); - /** * Handle channel entry responses. */ diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp index c6df7c83..a2dbefbb 100644 --- a/src/net/chatserver/chatserver.cpp +++ b/src/net/chatserver/chatserver.cpp @@ -80,17 +80,6 @@ void Net::ChatServer::privMsg(const std::string &recipient, connection->send(msg); } -void Net::ChatServer::registerChannel(const std::string &name, - const std::string &topic, const std::string &password) -{ - MessageOut msg(PCMSG_REGISTER_CHANNEL); - msg.writeString(name); - msg.writeString(topic); - msg.writeString(password); - - connection->send(msg); -} - void Net::ChatServer::enterChannel(const std::string &channel, const std::string &password) { MessageOut msg(PCMSG_ENTER_CHANNEL); diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h index dac19e88..56ad46ca 100644 --- a/src/net/chatserver/chatserver.h +++ b/src/net/chatserver/chatserver.h @@ -42,9 +42,6 @@ namespace Net void privMsg(const std::string &recipient, const std::string &text); - void registerChannel(const std::string &name, - const std::string &topic, const std::string &password); - void enterChannel(const std::string &channel, const std::string &password); void quitChannel(short channel); diff --git a/src/net/protocol.h b/src/net/protocol.h index 76a8ffab..89713591 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -163,8 +163,6 @@ enum { PCMSG_ANNOUNCE = 0x0411, // S text PCMSG_PRIVMSG = 0x0412, // S user, S text // -- Channeling - 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 topic, S userlist -- cgit v1.2.3-70-g09d2 From 993b43e87e2d53e8ae8ea31c43f04a19613a6d09 Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 14 Jul 2008 16:52:59 +0000 Subject: Added admin commands to /help and added registration of party handler --- ChangeLog | 5 +++++ src/commandhandler.cpp | 11 ++++++++++- src/game.cpp | 3 +++ src/game.h | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 1da6e966..eee2a19d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-07-14 David Athay + + * src/game.cpp, src/commandhandler.cpp, src/game.h: Added admin commands + to /help. Added registering party handler. + 2008-07-07 Roderic Morris * src/net/chathandler.cpp, src/net/chathandler.h, src/commandhandler.h, diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 8f0aa907..8e6003f9 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -102,7 +102,6 @@ void CommandHandler::handleAnnounce(const std::string &args) void CommandHandler::handleHelp(const std::string &args) { - chatWindow->chatLog("-- Help --", BY_SERVER); if (args == "") { chatWindow->chatLog("-- Help --"); @@ -126,6 +125,16 @@ void CommandHandler::handleHelp(const std::string &args) chatWindow->chatLog("Command: /admin "); chatWindow->chatLog("*** only available to a GM ***"); chatWindow->chatLog("This command sends an admin command to the server."); + chatWindow->chatLog(" can be:"); + chatWindow->chatLog("reload "); + chatWindow->chatLog("warp "); + chatWindow->chatLog("item "); + chatWindow->chatLog("drop "); + chatWindow->chatLog("money "); + chatWindow->chatLog("spawn "); + chatWindow->chatLog("goto "); + chatWindow->chatLog("recall "); + chatWindow->chatLog("ban "); } else if (args == "announce") { diff --git a/src/game.cpp b/src/game.cpp index dcc2ba0a..f0209b73 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -81,6 +81,7 @@ #include "net/itemhandler.h" #include "net/network.h" #include "net/npchandler.h" +#include "net/partyhandler.h" #include "net/playerhandler.h" #include "net/tradehandler.h" @@ -269,6 +270,7 @@ Game::Game(): mInventoryHandler(new InventoryHandler()), mItemHandler(new ItemHandler()), mNpcHandler(new NPCHandler()), + mPartyHandler(new PartyHandler()), mPlayerHandler(new PlayerHandler()), mTradeHandler(new TradeHandler()), mLogicCounterId(0), mSecondsCounterId(0) @@ -313,6 +315,7 @@ Game::Game(): Net::registerHandler(mInventoryHandler.get()); Net::registerHandler(mItemHandler.get()); Net::registerHandler(mNpcHandler.get()); + Net::registerHandler(mPartyHandler.get()); Net::registerHandler(mPlayerHandler.get()); Net::registerHandler(mTradeHandler.get()); } diff --git a/src/game.h b/src/game.h index 28feae44..cdfe025b 100644 --- a/src/game.h +++ b/src/game.h @@ -67,6 +67,7 @@ class Game : public ConfigListener MessageHandlerPtr mInventoryHandler; MessageHandlerPtr mItemHandler; MessageHandlerPtr mNpcHandler; + MessageHandlerPtr mPartyHandler; MessageHandlerPtr mPlayerHandler; MessageHandlerPtr mTradeHandler; -- cgit v1.2.3-70-g09d2 From b9d9ae443874efd4968a6efcf5ce050f213c497b Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 13 Aug 2008 15:28:07 +0000 Subject: Added permission levels to guilds, and operator permissions to channels. --- ChangeLog | 9 +++++++ src/commandhandler.cpp | 51 ++++++++++++++++++++++++++++++++++++ src/commandhandler.h | 10 ++++++++ src/gui/guildlistbox.cpp | 4 +++ src/net/chathandler.cpp | 54 ++++++++++++++++++++++++++++++--------- src/net/chatserver/chatserver.cpp | 22 ++++++++++++++++ src/net/chatserver/chatserver.h | 4 +++ src/net/chatserver/guild.cpp | 13 ++++++++++ src/net/chatserver/guild.h | 6 +++++ src/net/guildhandler.cpp | 22 ++++++++++++++++ src/net/protocol.h | 11 ++++++-- 11 files changed, 192 insertions(+), 14 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index aa702680..9164bdf7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-08-13 David Athay + + * src/commandhandler.cpp, src/gui/guildlistbox.cpp, + src/commandhandler.h, src/net/guildhandler.cpp, src/net/protocol.h, + src/net/chathandler.cpp, src/net/chatserver/guild.cpp, + src/net/chatserver/chatserver.cpp, src/net/chatserver/guild.h, + src/net/chatserver/chatserver.h: Added permission levels to guilds, and + operator permissions to channels. + 2008-08-12 Bjørn Lindeijer * INSTALL, autogen.sh: Removed autogen.sh and tell people in the 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 ."); chatWindow->chatLog("If doesn't exist, it's created."); } + else if (args == "kick") + { + chatWindow->chatLog("Command: /kick "); + chatWindow->chatLog("This command makes leave the channel."); + chatWindow->chatLog("If the 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 has spaces in it, enclose it in " "double quotes (\")."); } + else if (args == "op") + { + chatWindow->chatLog("Command: /op "); + chatWindow->chatLog("This command makes a channel operator."); + chatWindow->chatLog("If the 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 "); @@ -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 @@ -53,6 +53,12 @@ namespace Net */ void getGuildMembers(short guildId); + /** + * Promote guild member + */ + void promoteMember(const std::string &name, short guildId, + short level); + /** * Quit guild. */ 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 -- cgit v1.2.3-70-g09d2 From 438be47fa7078cd235bda7d2461024ddc222c026 Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 15 Oct 2008 15:45:14 +0000 Subject: src/localplayer.cpp src/net/beinghandler.cpp src/net/protocol.h src/net/gameserver/player.h src/net/gameserver/player.cpp src/net/beinghandler.h ChangeLog tmw.cbp --- ChangeLog | 7 +++++++ src/commandhandler.cpp | 11 +++++++++++ src/localplayer.cpp | 2 +- src/net/beinghandler.cpp | 10 ++++++++++ src/net/beinghandler.h | 1 + src/net/gameserver/player.cpp | 22 ++++++++++++++++++++++ src/net/gameserver/player.h | 3 +++ src/net/protocol.h | 8 ++++++++ tmw.cbp | 4 ++++ 9 files changed, 67 insertions(+), 1 deletion(-) (limited to 'src/commandhandler.cpp') diff --git a/ChangeLog b/ChangeLog index f5f95cb3..5d2417f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-10-15 David Athay + + * src/localplayer.cpp, src/net/beinghandler.cpp, src/net/protocol.h, + src/net/gameserver/player.h, src/net/gameserver/player.cpp, + src/net/beinghandler.h, tmw.cbp: Added communicating change of + direction to server. + 2008-10-10 Bjørn Lindeijer * src/gui/shop.cpp, src/gui/shop.h, src/resources/itemdb.cpp, diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 7ec48f46..58b8905d 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -93,6 +93,17 @@ void CommandHandler::handleCommand(const std::string &command) { handleOp(args); } + else if (type == "post") + { + std::string::size_type pos = args.find(' '); + std::string recipient(args, 0, pos); + std::string text(args, pos+1); + Net::GameServer::Player::sendLetter(recipient, text); + } + else if (type == "check") + { + Net::GameServer::Player::getLetters(); + } else { chatWindow->chatLog("Unknown command"); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f596a8d9..d272caaf 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -283,7 +283,7 @@ void LocalPlayer::walk(unsigned char dir) else if (dir) { // If the being can't move, just change direction - // TODO: Communicate this to the server (waiting on tmwserv) + Net::GameServer::Player::changeDir(dir); setDirection(dir); } } diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 7e37aa27..fc3c7d1e 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -55,6 +55,7 @@ BeingHandler::BeingHandler() GPMSG_BEINGS_DAMAGE, GPMSG_BEING_ACTION_CHANGE, GPMSG_BEING_LOOKS_CHANGE, + GPMSG_BEING_DIR_CHANGE, 0 }; handledMessages = _messages; @@ -85,6 +86,9 @@ void BeingHandler::handleMessage(MessageIn &msg) case GPMSG_BEING_LOOKS_CHANGE: handleBeingLooksChangeMessage(msg); break; + case GPMSG_BEING_DIR_CHANGE: + handleBeingDirChangeMessage(msg); + break; } } @@ -319,3 +323,9 @@ void BeingHandler::handleBeingLooksChangeMessage(MessageIn &msg) handleLooks(static_cast< Player * >(being), msg); } +void BeingHandler::handleBeingDirChangeMessage(MessageIn &msg) +{ + Being *being = beingManager->findBeing(msg.readInt16()); + if (!being) return; + being->setDirection(msg.readInt8()); +} diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h index d2a332a8..8ac07017 100644 --- a/src/net/beinghandler.h +++ b/src/net/beinghandler.h @@ -41,6 +41,7 @@ class BeingHandler : public MessageHandler void handleBeingsDamageMessage(MessageIn &msg); void handleBeingActionChangeMessage(MessageIn &msg); void handleBeingLooksChangeMessage(MessageIn &msg); + void handleBeingDirChangeMessage(MessageIn &msg); }; #endif diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp index d8050d2b..28fd954a 100644 --- a/src/net/gameserver/player.cpp +++ b/src/net/gameserver/player.cpp @@ -160,6 +160,21 @@ void Net::GameServer::Player::tradeWithNPC(int item, int amount) Net::GameServer::connection->send(msg); } +void Net::GameServer::Player::sendLetter(const std::string &player, + const std::string &text) +{ + MessageOut msg(PGMSG_SEND_POST); + msg.writeString(player); + msg.writeString(text); + Net::GameServer::connection->send(msg); +} + +void Net::GameServer::Player::getLetters() +{ + MessageOut msg(PGMSG_GET_POST); + Net::GameServer::connection->send(msg); +} + void Net::GameServer::Player::raiseAttribute(int attribute) { MessageOut msg(PGMSG_RAISE_ATTRIBUTE); @@ -179,3 +194,10 @@ void Net::GameServer::Player::respawn() MessageOut msg(PGMSG_RESPAWN); Net::GameServer::connection->send(msg); } + +void Net::GameServer::Player::changeDir(unsigned char dir) +{ + MessageOut msg(PGMSG_DIRECTION_CHANGE); + msg.writeInt8(dir); + Net::GameServer::connection->send(msg); +} diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h index eea15c2b..fa8c1376 100644 --- a/src/net/gameserver/player.h +++ b/src/net/gameserver/player.h @@ -59,10 +59,13 @@ namespace Net void tradeItem(int slot, int amount); void tradeMoney(int amount); void tradeWithNPC(int item, int amount); + void sendLetter(const std::string &player, const std::string &text); + void getLetters(); void raiseAttribute(int attribute); void lowerAttribute(int attribute); void respawn(); static RespawnRequestListener respawnListener; + void changeDir(unsigned char dir); } } } diff --git a/src/net/protocol.h b/src/net/protocol.h index bd4eaa17..f766d2da 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -99,6 +99,8 @@ enum { PGMSG_WALK = 0x0260, // W*2 destination PGMSG_ACTION_CHANGE = 0x0270, // B Action GPMSG_BEING_ACTION_CHANGE = 0x0271, // W being id, B action + PGMSG_DIRECTION_CHANGE = 0x0272, // B Direction + GPMSG_BEING_DIR_CHANGE = 0x0273, // W being id, B direction GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position, B speed] [, W*2 destination] }* GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* PGMSG_ATTACK = 0x0290, // B direction @@ -180,6 +182,12 @@ enum { PCMSG_USER_MODE = 0x0465, // W channel id, S name, B mode PCMSG_KICK_USER = 0x0466, // W channel id, S name + // Post + PGMSG_SEND_POST = 0x04A0, // S player, S letter, { W attachment id } + GPMSG_SEND_POST_RESPONSE = 0x04A1, // B error + PGMSG_GET_POST = 0x04A2, // + GPMSG_GET_POST_RESPONSE = 0x04A3, // { L sender id, S letter, { W attachment id } } + XXMSG_INVALID = 0x7FFF }; diff --git a/tmw.cbp b/tmw.cbp index d3381da3..a6d2f7df 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -217,6 +217,8 @@ + +