ChatChannel* ChatChannelList::CreateChannel(std::string Name, std::string Owner, std::string Password, bool Permanent, int MinimumStatus) { ChatChannel *NewChannel = new ChatChannel(CapitaliseName(Name), Owner, Password, Permanent, MinimumStatus); ChatChannels.Insert(NewChannel); return NewChannel; }
void Database::RemoveFriendOrIgnore(int charID, int type, std::string name) { std::string query = StringFormat("DELETE FROM `friends` WHERE `charid` = %i " "AND `type` = %i AND `name` = '%s'", charID, type, CapitaliseName(name).c_str()); auto results = QueryDatabase(query); if(!results.Success()) _log(UCS__ERROR, "Error removing friend/ignore, query was %s", query.c_str()); else _log(UCS__TRACE, "Removed Friend/Ignore entry for charid %i, type %i, name %s from database.", charID, type, name.c_str()); }
void Database::AddFriendOrIgnore(int charID, int type, std::string name) { std::string query = StringFormat("INSERT INTO `friends` (`charid`, `type`, `name`) " "VALUES('%i', %i, '%s')", charID, type, CapitaliseName(name).c_str()); auto results = QueryDatabase(query); if(!results.Success()) _log(UCS__ERROR, "Error adding friend/ignore, query was %s : %s", query.c_str(), results.ErrorMessage().c_str()); else _log(UCS__TRACE, "Wrote Friend/Ignore entry for charid %i, type %i, name %s to database.", charID, type, name.c_str()); }
void Database::RemoveFriendOrIgnore(int CharID, int Type, std::string Name) { const char *FriendsQuery="DELETE FROM `friends` WHERE `charid`=%i AND `type`=%i and `name`='%s'"; char errbuf[MYSQL_ERRMSG_SIZE]; char* query = 0; if(!RunQuery(query, MakeAnyLenString(&query, FriendsQuery, CharID, Type, CapitaliseName(Name).c_str()), errbuf, 0, 0)) _log(UCS__ERROR, "Error removing friend/ignore, query was %s", query); else _log(UCS__TRACE, "Removed Friend/Ignore entry for charid %i, type %i, name %s from database.", CharID, Type, Name.c_str()); safe_delete_array(query); }
void Database::AddFriendOrIgnore(int CharID, int Type, std::string Name) { const char *FriendsQuery="INSERT INTO `friends` (`charid`, `type`, `name`) VALUES ('%i', %i, '%s')"; char errbuf[MYSQL_ERRMSG_SIZE]; char* query = 0; if(!RunQuery(query, MakeAnyLenString(&query, FriendsQuery, CharID, Type, CapitaliseName(Name).c_str()), errbuf, 0, 0)) _log(UCS__ERROR, "Error adding friend/ignore, query was %s : %s", query, errbuf); else _log(UCS__TRACE, "Wrote Friend/Ignore entry for charid %i, type %i, name %s to database.", CharID, Type, Name.c_str()); safe_delete_array(query); }
ChatChannel* ChatChannelList::FindChannel(std::string Name) { std::string NormalisedName = CapitaliseName(Name); LinkedListIterator<ChatChannel*> iterator(ChatChannels); iterator.Reset(); while(iterator.MoreElements()) { ChatChannel *CurrentChannel = iterator.GetData(); if(CurrentChannel && (CurrentChannel->Name == NormalisedName)) return iterator.GetData(); iterator.Advance(); } return nullptr; }
ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client *c) { if(!c) return nullptr; if((ChannelName.length() > 0) && (isdigit(ChannelName[0]))) { c->GeneralChannelMessage("The channel name can not begin with a number."); return nullptr; } std::string NormalisedName, Password; std::string::size_type Colon = ChannelName.find_first_of(":"); if(Colon == std::string::npos) NormalisedName = CapitaliseName(ChannelName); else { NormalisedName = CapitaliseName(ChannelName.substr(0, Colon)); Password = ChannelName.substr(Colon + 1); } if((NormalisedName.length() > 64) || (Password.length() > 64)) { c->GeneralChannelMessage("The channel name or password cannot exceed 64 characters."); return nullptr; } _log(UCS__TRACE, "AddClient to channel [%s] with password [%s]", NormalisedName.c_str(), Password.c_str()); ChatChannel *RequiredChannel = FindChannel(NormalisedName); if(!RequiredChannel) RequiredChannel = CreateChannel(NormalisedName, c->GetName(), Password, false, 0); if(RequiredChannel->GetMinStatus() > c->GetAccountStatus()) { std::string Message = "You do not have the required account status to join channel " + NormalisedName; c->GeneralChannelMessage(Message); return nullptr; } if(RequiredChannel->IsClientInChannel(c)) return nullptr; if(RequiredChannel->IsInvitee(c->GetName())) { RequiredChannel->AddClient(c); RequiredChannel->RemoveInvitee(c->GetName()); return RequiredChannel; } if(RequiredChannel->CheckPassword(Password) || RequiredChannel->IsOwner(c->GetName()) || RequiredChannel->IsModerator(c->GetName()) || c->IsChannelAdmin()) { RequiredChannel->AddClient(c); return RequiredChannel; } c->GeneralChannelMessage("Incorrect password for channel " + (NormalisedName)); return nullptr; }