summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-07-22 13:43:58 +0000
committerDavid Athay <ko2fan@gmail.com>2008-07-22 13:43:58 +0000
commit8be5590e63235f10bc037ab4c05d589e4df6a9fe (patch)
tree90006fb0243917c7db81d3311841f4a6e3113e6f /src
parent55be8c761bc2f5658aba9e7775461fc562f6d21c (diff)
downloadmanaserv-8be5590e63235f10bc037ab4c05d589e4df6a9fe.tar.gz
manaserv-8be5590e63235f10bc037ab4c05d589e4df6a9fe.tar.bz2
manaserv-8be5590e63235f10bc037ab4c05d589e4df6a9fe.tar.xz
manaserv-8be5590e63235f10bc037ab4c05d589e4df6a9fe.zip
Add permissions to guild members
Diffstat (limited to 'src')
-rw-r--r--src/chat-server/chathandler.cpp33
-rw-r--r--src/chat-server/guild.cpp77
-rw-r--r--src/chat-server/guild.hpp70
-rw-r--r--src/defines.h2
4 files changed, 152 insertions, 30 deletions
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index f2c48e33..946be36a 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -326,12 +326,12 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg)
ChatChannel *channel = NULL;
if(chatChannelManager->channelExists(channelName) ||
chatChannelManager->tryNewPublicChannel(channelName))
- {
+ {
channel = chatChannelManager->getChannel(channelName);
}
if (!channel)
- {
+ {
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
else if (!channel->getPassword().empty() &&
@@ -532,7 +532,7 @@ ChatHandler::handleGuildInvitation(ChatClient &client, MessageIn &msg)
{
// check permissions of inviter, and that they arent inviting themself,
// and arent someone already in the guild
- if (guild->checkLeader(client.characterName) &&
+ if (guild->canInvite(client.characterName) &&
(client.characterName != character) &&
!guild->checkInGuild(character))
{
@@ -615,11 +615,11 @@ ChatHandler::handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg)
{
reply.writeByte(ERRMSG_OK);
reply.writeShort(guildId);
- for(std::list<std::string>::const_iterator itr = guild->getMembers()->begin();
- itr != guild->getMembers()->end(); ++itr)
+ for(std::list<GuildMember*>::const_iterator itr = guild->getMembers().begin();
+ itr != guild->getMembers().end(); ++itr)
{
- reply.writeString((*itr));
- reply.writeByte(mPlayerMap.find((*itr)) != mPlayerMap.end());
+ reply.writeString((*itr)->getName());
+ reply.writeByte(mPlayerMap.find((*itr)->getName()) != mPlayerMap.end());
}
}
}
@@ -655,6 +655,8 @@ ChatHandler::handleGuildQuit(ChatClient &client, MessageIn &msg)
}
else
{
+ // guild manager checks if the member is the last in the guild
+ // and removes the guild if so
guildManager->removeGuildMember(guild, client.characterName);
sendGuildListUpdate(guild->getName(), client.characterName, GUILD_EVENT_LEAVING_PLAYER);
}
@@ -737,15 +739,12 @@ void ChatHandler::sendGuildRejoin(ChatClient &client)
for (unsigned int i = 0; i != guilds.size(); ++i)
{
Guild *guild = guilds[i];
- short leader = 0;
+ short permissions;
if (!guild)
{
return;
}
- if (guild->checkLeader(client.characterName))
- {
- leader = 1;
- }
+ permissions = guild->getUserPermissions(client.characterName);
std::string guildName = guild->getName();
@@ -753,7 +752,7 @@ void ChatHandler::sendGuildRejoin(ChatClient &client)
MessageOut msg(CPMSG_GUILD_REJOIN);
msg.writeString(guildName);
msg.writeShort(guild->getId());
- msg.writeByte(leader);
+ msg.writeShort(permissions);
// get channel id of guild channel
ChatChannel *channel = joinGuildChannel(guildName, client);
@@ -806,12 +805,12 @@ void ChatHandler::sendGuildListUpdate(const std::string &guildName,
msg.writeString(characterName);
msg.writeByte(eventId);
std::map<std::string, ChatClient*>::const_iterator chr;
- std::list<std::string> *members = guild->getMembers();
+ std::list<GuildMember*> members = guild->getMembers();
- for (std::list<std::string>::const_iterator itr = members->begin();
- itr != members->end(); ++itr)
+ for (std::list<GuildMember*>::const_iterator itr = members.begin();
+ itr != members.end(); ++itr)
{
- chr = mPlayerMap.find((*itr));
+ chr = mPlayerMap.find((*itr)->getName());
if (chr != mPlayerMap.end())
{
chr->second->send(msg);
diff --git a/src/chat-server/guild.cpp b/src/chat-server/guild.cpp
index 7a2a43d9..3110b05f 100644
--- a/src/chat-server/guild.cpp
+++ b/src/chat-server/guild.cpp
@@ -24,6 +24,26 @@
#include <algorithm>
+GuildMember::GuildMember(std::string name) :
+ mName(name),
+ mPermissions(0)
+{
+}
+
+std::string GuildMember::getName() const
+{
+ return mName;
+}
+
+void GuildMember::setPermission(int perm)
+{
+ mPermissions = perm;
+}
+
+int GuildMember::getPermissions() const
+{
+ return mPermissions;
+}
Guild::Guild(const std::string &name) :
mName(name)
@@ -36,18 +56,32 @@ Guild::~Guild()
void Guild::addMember(const std::string &playerName)
{
- mMembers.push_back(playerName);
+ GuildMember *member = new GuildMember(playerName);
+ mMembers.push_back(member);
+ if (checkInvited(playerName))
+ {
+ mInvited.remove(playerName);
+ }
}
void Guild::removeMember(const std::string &playerName)
{
- mMembers.remove(playerName);
+ GuildMember *member = getMember(playerName);
+ if (member)
+ mMembers.remove(member);
}
bool Guild::checkLeader(const std::string &playerName)
{
- std::string leaderName = mMembers.front();
- return leaderName == playerName;
+ // check that guild member permissions is set to LEADER
+ int leader = 0;
+ GuildMember *member = getMember(playerName);
+ if (member)
+ leader = member->getPermissions();
+ if (leader == GuildMember::LEADER)
+ return true;
+ return false;
+
}
bool Guild::checkInvited(const std::string &playerName)
@@ -62,5 +96,38 @@ void Guild::addInvited(const std::string &playerName)
bool Guild::checkInGuild(const std::string &playerName)
{
- return std::find(mMembers.begin(), mMembers.end(), playerName) != mMembers.end();
+ GuildMember *member = getMember(playerName);
+ return member ? true : false;
+}
+
+GuildMember* Guild::getMember(const std::string &playerName)
+{
+ std::list<GuildMember*>::iterator itr = mMembers.begin(), itr_end = mMembers.end();
+ while (itr != itr_end)
+ {
+ if ((*itr)->getName() == playerName)
+ {
+ return (*itr);
+ }
+
+ ++itr;
+ }
+
+ return NULL;
+}
+
+bool Guild::canInvite(const std::string &playerName)
+{
+ // Guild members with permissions above NONE can invite
+ // Check that guild members permissions are not NONE
+ GuildMember *member = getMember(playerName);
+ if (member->getPermissions() > GuildMember::NONE)
+ return true;
+ return false;
+}
+
+int Guild::getUserPermissions(const std::string &playerName)
+{
+ GuildMember *member = getMember(playerName);
+ return member->getPermissions();
}
diff --git a/src/chat-server/guild.hpp b/src/chat-server/guild.hpp
index 67a6817b..c5952fd9 100644
--- a/src/chat-server/guild.hpp
+++ b/src/chat-server/guild.hpp
@@ -27,13 +27,53 @@
#include <list>
/**
+ * Guild members
+ */
+
+class GuildMember
+{
+ public:
+ /**
+ * Permissions
+ * Members with NONE cannot invite users or set permissions
+ * Members with COMMANDER can invite other users but
+ * cannot set permissions
+ * Members with LEADER can invite users and set permissions
+ */
+ enum { NONE = 0, COMMANDER, LEADER };
+
+ /**
+ * Constructor
+ */
+ GuildMember(std::string name);
+
+ /**
+ * Get name
+ */
+ std::string getName() const;
+
+ /**
+ * Set permissions
+ */
+ void setPermission(int perm);
+
+ /**
+ * Get permissions
+ */
+ int getPermissions() const;
+
+ private:
+ std::string mName;
+ int mPermissions;
+
+};
+
+/**
* A guild and its members.
*/
class Guild
{
public:
- typedef std::list<std::string> GuildMembers;
-
/**
* Constructor.
*/
@@ -86,12 +126,12 @@ class Guild
*/
int getId() const
{ return mId; }
-
+
/**
* Returns a list of the members in this guild.
*/
- GuildMembers* getMembers()
- { return &mMembers; }
+ std::list<GuildMember*> getMembers()
+ { return mMembers; }
/**
* Returns the total number of members in the guild.
@@ -104,11 +144,27 @@ class Guild
*/
bool checkInGuild(const std::string &playerName);
+ /**
+ * Returns whether a user can invite
+ */
+ bool canInvite(const std::string &name);
+
+ /**
+ * Returns a users permissions
+ */
+ int getUserPermissions(const std::string &name);
+
+ protected:
+ /**
+ * Return a member based on their character name
+ */
+ GuildMember* getMember(const std::string &playerName);
+
private:
short mId;
std::string mName;
- GuildMembers mMembers;
- GuildMembers mInvited;
+ std::list<GuildMember*> mMembers;
+ std::list<std::string> mInvited;
};
#endif
diff --git a/src/defines.h b/src/defines.h
index b893970a..d419ce67 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -198,7 +198,7 @@ enum {
CPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error
CPMSG_GUILD_INVITED = 0x0370, // S char name, S guild name, W id
- CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, B rights, W channel
+ CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, W rights, W channel, S announce
// Party
PCMSG_PARTY_INVITE = 0x03A0, // S name