[Rules] Add rule to allow players to permanently save chat channels to database, up to a limit. (#2706)

* Initial code

* Tweak

* Rule description tweak

* More channel work

* More adjustments

* Auto-join saved permanent player channels

* Fix UCS crash if player has no channels to load from table.

* Implemented channel blocking feature

* Update database when player channel's owner or password change

* First round of requested changes.

* Logic tweak to ensure player channels are sets to permanent when appropraite

* name_filter table integration and some refactoring

* Use new `reserved_channel_names` table to block specific channel names.

* Remove some legacy channel block code

* Setup required SQL update to create  `reserved_channel_names`  table.

* Update db_update_manifest.txt

* Update db_update_manifest.txt

* Update chatchannel.cpp

* Code review

* Database to UCSDatabase

* Repository SaveChatChannel

* CurrentPlayerChannelCount repository

* Cleanup name filter

* CreateChannel

* Update websocketpp

* Increment CURRENT_BINARY_DATABASE_VERSION

Set to 9216

* Minor tweaks to blocked channel name checks & other related areas.

- Enforce blocked channel names on channel creation.
- Also enforce blocked channel names on channel join.
- Add channel status check to Debug logging.
- Minor formatting adjustments.
- Add single quotes to column name value in query.

* Minor log change

* Increment DB Version

* Formatting Tweaks

- Made formatting adjustments consistent with KinglyKrab's recommended changes.
- This compiles successfully with these changes, but unable to test the changes until this weekend.

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Vayle
2023-01-18 23:42:09 -05:00
committed by GitHub
parent 03a27b02ff
commit 29473aa7f5
16 changed files with 1409 additions and 286 deletions
+36 -26
View File
@@ -9,6 +9,8 @@
class Client;
#define SYSTEM_OWNER std::string("*System*")
class ChatChannel {
public:
@@ -21,15 +23,19 @@ public:
bool IsClientInChannel(Client *c);
int MemberCount(int Status);
const std::string &GetName() { return Name; }
void SendMessageToChannel(std::string Message, Client* Sender);
bool CheckPassword(std::string inPassword) { return Password.empty() || Password == inPassword; }
void SetPassword(std::string inPassword);
bool IsOwner(std::string Name) { return (Owner == Name); }
void SetOwner(std::string inOwner);
const std::string &GetName() { return m_name; }
void SendMessageToChannel(const std::string& Message, Client* Sender);
bool CheckPassword(const std::string& in_password) { return m_password.empty() || m_password == in_password; }
void SetPassword(const std::string& in_password);
bool IsOwner(const std::string& name) { return (m_owner == name); }
const std::string& GetPassword() { return m_password; }
void SetOwner(std::string& inOwner);
std::string& GetOwnerName();
void SetTemporary();
void SetPermanent();
void SendChannelMembers(Client *c);
int GetMinStatus() { return MinimumStatus; }
bool ReadyToDelete() { return DeleteTimer.Check(); }
int GetMinStatus() { return m_minimum_status; }
bool ReadyToDelete() { return m_delete_timer.Check(); }
void SendOPList(Client *c);
void AddInvitee(const std::string &Invitee);
void RemoveInvitee(std::string Invitee);
@@ -40,48 +46,52 @@ public:
void AddVoice(const std::string &Voiced);
void RemoveVoice(const std::string &Voiced);
bool HasVoice(std::string Voiced);
inline bool IsModerated() { return Moderated; }
inline bool IsModerated() { return m_moderated; }
void SetModerated(bool inModerated);
friend class ChatChannelList;
private:
std::string Name;
std::string Owner;
std::string Password;
std::string m_name;
std::string m_owner;
std::string m_password;
bool Permanent;
bool Moderated;
bool m_permanent;
bool m_moderated;
int MinimumStatus;
int m_minimum_status;
Timer DeleteTimer;
Timer m_delete_timer;
LinkedList<Client*> ClientsInChannel;
LinkedList<Client*> m_clients_in_channel;
std::vector<std::string> Moderators;
std::vector<std::string> Invitees;
std::vector<std::string> Voiced;
std::vector<std::string> m_moderators;
std::vector<std::string> m_invitees;
std::vector<std::string> m_voiced;
};
class ChatChannelList {
public:
ChatChannel* CreateChannel(std::string Name, std::string Owner, std::string Passwordi, bool Permanent, int MinimumStatus = 0);
ChatChannel* FindChannel(std::string Name);
ChatChannel* AddClientToChannel(std::string Channel, Client *c);
ChatChannel* RemoveClientFromChannel(std::string Channel, Client *c);
void RemoveClientFromAllChannels(Client *c);
ChatChannel* CreateChannel(const std::string& name, const std::string& owner, const std::string& password, bool permanent, int minimum_status, bool save_to_database = false);
ChatChannel* FindChannel(std::string name);
ChatChannel* AddClientToChannel(std::string channel_name, Client* c, bool command_directed = false);
ChatChannel* RemoveClientFromChannel(const std::string& in_channel_name, Client* c, bool command_directed = false);
void RemoveChannel(ChatChannel *Channel);
void RemoveAllChannels();
void SendAllChannels(Client *c);
void Process();
static inline std::vector<std::string> GetBlockedChannelNames() { return m_blocked_channel_names; }
static inline void ClearChannelBlockList() { m_blocked_channel_names.clear(); };
static void AddToChannelBlockList(const std::string& channel_name);
static bool IsOnChannelBlockList(const std::string& channel_name);
static inline void SetChannelBlockList(std::vector<std::string> new_list) { m_blocked_channel_names = new_list; }
private:
LinkedList<ChatChannel*> ChatChannels;
static inline std::vector<std::string> m_blocked_channel_names;
};