summaryrefslogtreecommitdiff
path: root/src/guild.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/guild.cpp')
-rw-r--r--src/guild.cpp176
1 files changed, 163 insertions, 13 deletions
diff --git a/src/guild.cpp b/src/guild.cpp
index be4a5204..3b30ec23 100644
--- a/src/guild.cpp
+++ b/src/guild.cpp
@@ -21,30 +21,114 @@
#include "guild.h"
-Guild::Guild(short id, short rights):
+GuildMember::GuildMember(int guildId, int id, const std::string &name):
+ mName(name), mId(id), mOnline(false)
+{
+ mGuild = Guild::getGuild(guildId);
+};
+
+GuildMember::GuildMember(int guildId, int id):
+ mId(id), mOnline(false)
+{
+ mGuild = Guild::getGuild(guildId);
+};
+
+GuildMember::GuildMember(int guildId, const std::string &name):
+ mName(name), mId(0), mOnline(false)
+{
+ mGuild = Guild::getGuild(guildId);
+};
+
+Guild::GuildMap Guild::guilds;
+
+Guild::Guild(short id):
mId(id),
mCanInviteUsers(false)
{
- // to invite, rights must be greater than 0
- if (rights > 0)
- mCanInviteUsers = true;
+ guilds[id] = this;
}
-void Guild::addMember(const std::string &name)
+void Guild::addMember(GuildMember *member)
{
- if (!isMember(name))
+ if (member->mGuild > 0 && member->mGuild != this)
+ {
+ throw "Member in another guild!";
+ }
+
+ if (!isMember(member))
{
- mMembers.push_back(name);
+ mMembers.push_back(member);
+ member->mGuild = this;
+ }
+}
+
+GuildMember *Guild::getMember(int id)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mId == id)
+ {
+ return (*itr);
+ }
+ ++itr;
+ }
+
+ return NULL;
+}
+
+GuildMember *Guild::getMember(std::string name)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mName == name)
+ {
+ return (*itr);
+ }
+ ++itr;
+ }
+
+ return NULL;
+}
+
+void Guild::removeMember(GuildMember *member)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mId == member->mId && (*itr)->mName == member->mName)
+ {
+ mMembers.erase(itr);
+ }
+ ++itr;
+ }
+}
+
+void Guild::removeMember(int id)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mId == id)
+ {
+ mMembers.erase(itr);
+ }
+ ++itr;
}
}
void Guild::removeMember(const std::string &name)
{
- std::vector<std::string>::iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while(itr != itr_end)
{
- if((*itr) == name)
+ if((*itr)->mName == name)
{
mMembers.erase(itr);
}
@@ -52,13 +136,70 @@ void Guild::removeMember(const std::string &name)
}
}
+std::string Guild::getElementAt(int index)
+{
+ GuildMember *m = mMembers[index];
+ if (m->mOnline)
+ {
+ return "* " + m->mName;
+ }
+ else
+ {
+ return m->mName;
+ }
+}
+
+void Guild::setRights(short rights)
+{
+ // to invite, rights must be greater than 0
+ if (rights > 0)
+ {
+ mCanInviteUsers = true;
+ }
+}
+
+bool Guild::isMember(GuildMember *member) const
+{
+ if (member->mGuild > 0 && member->mGuild != this)
+ return false;
+
+ MemberList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while (itr != itr_end)
+ {
+ if ((*itr)->mId == member->mId && (*itr)->mName == member->mName)
+ {
+ return true;
+ }
+ ++itr;
+ }
+
+ return false;
+}
+
+bool Guild::isMember(int id) const
+{
+ MemberList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while (itr != itr_end)
+ {
+ if ((*itr)->mId == id)
+ {
+ return true;
+ }
+ ++itr;
+ }
+
+ return false;
+}
+
bool Guild::isMember(const std::string &name) const
{
- std::vector<std::string>::const_iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
+ MemberList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr) == name)
+ if ((*itr)->mName == name)
{
return true;
}
@@ -67,3 +208,12 @@ bool Guild::isMember(const std::string &name) const
return false;
}
+
+Guild *Guild::getGuild(int id)
+{
+ GuildMap::iterator it = guilds.find(id);
+ if (it != guilds.end())
+ return it->second;
+
+ return new Guild(id);
+}