summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-08-13 15:28:07 +0000
committerDavid Athay <ko2fan@gmail.com>2008-08-13 15:28:07 +0000
commitb9d9ae443874efd4968a6efcf5ce050f213c497b (patch)
tree453d80d3e1d251efb60968c36023413cb4faf452 /src/net
parent47247ac4e2f0860a34106f4b69049d91003ced29 (diff)
downloadmana-b9d9ae443874efd4968a6efcf5ce050f213c497b.tar.gz
mana-b9d9ae443874efd4968a6efcf5ce050f213c497b.tar.bz2
mana-b9d9ae443874efd4968a6efcf5ce050f213c497b.tar.xz
mana-b9d9ae443874efd4968a6efcf5ce050f213c497b.zip
Added permission levels to guilds, and operator permissions to channels.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/chathandler.cpp54
-rw-r--r--src/net/chatserver/chatserver.cpp22
-rw-r--r--src/net/chatserver/chatserver.h4
-rw-r--r--src/net/chatserver/guild.cpp13
-rw-r--r--src/net/chatserver/guild.h6
-rw-r--r--src/net/guildhandler.cpp22
-rw-r--r--src/net/protocol.h11
7 files changed, 118 insertions, 14 deletions
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