More UCS refactoring

This commit is contained in:
Michael Cook (mackal) 2016-05-17 16:52:04 -04:00
parent 29da15f38c
commit 1a7a5aa8c8
3 changed files with 26 additions and 43 deletions

View File

@ -23,6 +23,7 @@
#include "clientlist.h" #include "clientlist.h"
#include "database.h" #include "database.h"
#include <cstdlib> #include <cstdlib>
#include <algorithm>
extern Database database; extern Database database;
extern uint32 ChatMessagesSent; extern uint32 ChatMessagesSent;
@ -307,17 +308,15 @@ bool ChatChannel::RemoveClient(Client *c) {
return true; return true;
} }
void ChatChannel::SendOPList(Client *c) { void ChatChannel::SendOPList(Client *c)
{
if(!c) return; if (!c)
return;
c->GeneralChannelMessage("Channel " + Name + " op-list: (Owner=" + Owner + ")"); c->GeneralChannelMessage("Channel " + Name + " op-list: (Owner=" + Owner + ")");
std::list<std::string>::iterator Iterator; for (auto &&m : Moderators)
c->GeneralChannelMessage(m);
for(Iterator = Moderators.begin(); Iterator != Moderators.end(); ++Iterator)
c->GeneralChannelMessage((*Iterator));
} }
void ChatChannel::SendChannelMembers(Client *c) { void ChatChannel::SendChannelMembers(Client *c) {
@ -607,10 +606,9 @@ bool ChatChannel::IsInvitee(std::string Invitee) {
return false; return false;
} }
void ChatChannel::AddModerator(std::string Moderator) { void ChatChannel::AddModerator(const std::string &Moderator)
{
if(!IsModerator(Moderator)) { if (!IsModerator(Moderator)) {
Moderators.push_back(Moderator); Moderators.push_back(Moderator);
Log.Out(Logs::Detail, Logs::UCS_Server, "Added %s as moderator to channel %s", Moderator.c_str(), Name.c_str()); Log.Out(Logs::Detail, Logs::UCS_Server, "Added %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
@ -618,34 +616,19 @@ void ChatChannel::AddModerator(std::string Moderator) {
} }
void ChatChannel::RemoveModerator(std::string Moderator) { void ChatChannel::RemoveModerator(const std::string &Moderator)
{
auto it = std::find(std::begin(Moderators), std::end(Moderators), Moderator);
std::list<std::string>::iterator Iterator; if (it != std::end(Moderators)) {
Moderators.erase(it);
for(Iterator = Moderators.begin(); Iterator != Moderators.end(); ++Iterator) { Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
if((*Iterator) == Moderator) {
Moderators.erase(Iterator);
Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
return;
}
} }
} }
bool ChatChannel::IsModerator(std::string Moderator) { bool ChatChannel::IsModerator(std::string Moderator)
{
std::list<std::string>::iterator Iterator; return std::find(std::begin(Moderators), std::end(Moderators), Moderator) != std::end(Moderators);
for(Iterator = Moderators.begin(); Iterator != Moderators.end(); ++Iterator) {
if((*Iterator) == Moderator)
return true;
}
return false;
} }
void ChatChannel::AddVoice(std::string inVoiced) { void ChatChannel::AddVoice(std::string inVoiced) {

View File

@ -6,6 +6,7 @@
#include "../common/timer.h" #include "../common/timer.h"
#include <string> #include <string>
#include <list> #include <list>
#include <vector>
class Client; class Client;
@ -21,9 +22,9 @@ public:
bool IsClientInChannel(Client *c); bool IsClientInChannel(Client *c);
int MemberCount(int Status); int MemberCount(int Status);
std::string GetName() { return Name; } const std::string &GetName() { return Name; }
void SendMessageToChannel(std::string Message, Client* Sender); void SendMessageToChannel(std::string Message, Client* Sender);
bool CheckPassword(std::string inPassword) { return ((Password.length() == 0) || (Password == inPassword)); } bool CheckPassword(std::string inPassword) { return Password.empty() || Password == inPassword; }
void SetPassword(std::string inPassword); void SetPassword(std::string inPassword);
bool IsOwner(std::string Name) { return (Owner == Name); } bool IsOwner(std::string Name) { return (Owner == Name); }
void SetOwner(std::string inOwner); void SetOwner(std::string inOwner);
@ -34,8 +35,8 @@ public:
void AddInvitee(std::string Invitee); void AddInvitee(std::string Invitee);
void RemoveInvitee(std::string Invitee); void RemoveInvitee(std::string Invitee);
bool IsInvitee(std::string Invitee); bool IsInvitee(std::string Invitee);
void AddModerator(std::string Moderator); void AddModerator(const std::string &Moderator);
void RemoveModerator(std::string Modeerator); void RemoveModerator(const std::string &Moderator);
bool IsModerator(std::string Moderator); bool IsModerator(std::string Moderator);
void AddVoice(std::string Voiced); void AddVoice(std::string Voiced);
void RemoveVoice(std::string Voiced); void RemoveVoice(std::string Voiced);
@ -60,7 +61,7 @@ private:
LinkedList<Client*> ClientsInChannel; LinkedList<Client*> ClientsInChannel;
std::list<std::string> Moderators; std::vector<std::string> Moderators;
std::list<std::string> Invitees; std::list<std::string> Invitees;
std::list<std::string> Voiced; std::list<std::string> Voiced;

View File

@ -574,7 +574,6 @@ void Clientlist::CheckForStaleConnections(Client *c) {
void Clientlist::Process() void Clientlist::Process()
{ {
std::shared_ptr<EQStream> eqs; std::shared_ptr<EQStream> eqs;
while ((eqs = chatsf->Pop())) { while ((eqs = chatsf->Pop())) {
@ -610,7 +609,7 @@ void Clientlist::Process()
bool KeyValid = true; bool KeyValid = true;
while (KeyValid && !(*it)->GetForceDisconnect() && (app = (EQApplicationPacket *)(*it)->ClientStream->PopPacket())) { while (KeyValid && !(*it)->GetForceDisconnect() && (app = (*it)->ClientStream->PopPacket())) {
EmuOpcode opcode = app->GetOpcode(); EmuOpcode opcode = app->GetOpcode();
switch (opcode) { switch (opcode) {