eqemu-server/ucs/chatchannel.h
Vayle 29473aa7f5
[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>
2023-01-18 22:42:09 -06:00

101 lines
3.2 KiB
C++

#ifndef CHATCHANNEL_H
#define CHATCHANNEL_H
//#include "clientlist.h"
#include "../common/linked_list.h"
#include "../common/timer.h"
#include <string>
#include <vector>
class Client;
#define SYSTEM_OWNER std::string("*System*")
class ChatChannel {
public:
ChatChannel(std::string inName, std::string inOwner, std::string inPassword, bool inPermanent, int inMinimumStatus = 0);
~ChatChannel();
void AddClient(Client *c);
bool RemoveClient(Client *c);
bool IsClientInChannel(Client *c);
int MemberCount(int Status);
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 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);
bool IsInvitee(std::string Invitee);
void AddModerator(const std::string &Moderator);
void RemoveModerator(const std::string &Moderator);
bool IsModerator(std::string Moderator);
void AddVoice(const std::string &Voiced);
void RemoveVoice(const std::string &Voiced);
bool HasVoice(std::string Voiced);
inline bool IsModerated() { return m_moderated; }
void SetModerated(bool inModerated);
friend class ChatChannelList;
private:
std::string m_name;
std::string m_owner;
std::string m_password;
bool m_permanent;
bool m_moderated;
int m_minimum_status;
Timer m_delete_timer;
LinkedList<Client*> m_clients_in_channel;
std::vector<std::string> m_moderators;
std::vector<std::string> m_invitees;
std::vector<std::string> m_voiced;
};
class ChatChannelList {
public:
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;
};
std::string CapitaliseName(std::string inString);
#endif