diff --git a/CLre_server/Tweaks/Chat/ChatConnectionEngine.cs b/CLre_server/Tweaks/Chat/ChatConnectionEngine.cs index ba8ff29..946ec18 100644 --- a/CLre_server/Tweaks/Chat/ChatConnectionEngine.cs +++ b/CLre_server/Tweaks/Chat/ChatConnectionEngine.cs @@ -44,7 +44,7 @@ namespace CLre_server.Tweaks.Chat auth.UserId = ChatHandler.PublicId; _chatListener= new ChatListener(_handlers); _chatClient = new ChatClient(_chatListener, ConnectionProtocol.Udp); - _chatListener._chatClient = _chatClient; + _chatListener.ChatClient = _chatClient; _chatClient.Connect(Game.Utilities.CardLifePhotonSettings.PhotonChatAppID, "1.0", auth); // run forever (until server shutsdown) while (_running) diff --git a/CLre_server/Tweaks/Chat/ChatListener.cs b/CLre_server/Tweaks/Chat/ChatListener.cs index 98f3263..a327f5f 100644 --- a/CLre_server/Tweaks/Chat/ChatListener.cs +++ b/CLre_server/Tweaks/Chat/ChatListener.cs @@ -7,7 +7,7 @@ namespace CLre_server.Tweaks.Chat { public class ChatListener: IChatClientListener { - internal ChatClient _chatClient; + internal ChatClient ChatClient; public static string ChatName; private Dictionary _handlers; @@ -18,12 +18,16 @@ namespace CLre_server.Tweaks.Chat public void DebugReturn(DebugLevel level, string message) { +#if DEBUG API.Utility.Logging.Log($"ServerChatLog<{level}>: {message}"); +#endif } public void OnDisconnected() { +#if DEBUG API.Utility.Logging.MetaLog("Chat disconnected"); +#endif } public void OnConnected() @@ -41,13 +45,17 @@ namespace CLre_server.Tweaks.Chat return; } - bool result = _chatClient.Subscribe(new[] {ChatName}, 10); + bool result = ChatClient.Subscribe(new[] {ChatName}, 10); +#if DEBUG API.Utility.Logging.MetaLog($"Subscribed to chat: {result}"); +#endif } public void OnChatStateChange(ChatState state) { +#if DEBUG API.Utility.Logging.MetaLog($"Chat state changed to {state}"); +#endif } public void OnGetMessages(string channelName, string[] senders, object[] messages) @@ -56,28 +64,20 @@ namespace CLre_server.Tweaks.Chat for (int i = 0; i < senders.Length; i++) { string message = messages[i].ToString(); + string username = stripUsernameTag(senders[i]); #if DEBUG - API.Utility.Logging.MetaLog($"Chat: `{senders[i]}` said `{messages[i]}` in `{channelName}`"); + API.Utility.Logging.MetaLog($"Chat: `{username}` said `{messages[i]}` in `{channelName}`"); #endif - if (messages[i].ToString().ToLower() == "hello server") - { - _chatClient.PublishMessage(channelName, $"Hi {senders[i]}!"); - } - else if (messages[i].ToString().ToLower() == "hello world") - { - _chatClient.PublishMessage(channelName, $"Hello fellow programmer {senders[i]}!"); - } - if (message.StartsWith("/")) { string command = message.Substring(1); - string username = stripUsernameTag(senders[i]); + foreach (ChatCommandAttribute cca in _handlers.Keys) { var match = cca.RegexMatch(senders[i], command); if (match.Success) { - _handlers[cca](match, _chatClient, username); + _handlers[cca](match, ChatClient, username); } } } @@ -94,17 +94,23 @@ namespace CLre_server.Tweaks.Chat public void OnSubscribed(string[] channels, bool[] results) { +#if DEBUG API.Utility.Logging.MetaLog($"Subscribed"); +#endif } public void OnUnsubscribed(string[] channels) { +#if DEBUG API.Utility.Logging.MetaLog($"Unsubscribed"); +#endif } public void OnStatusUpdate(string user, int status, bool gotMessage, object message) { +#if DEBUG API.Utility.Logging.MetaLog($"Status update: {user}->{status} ({gotMessage}:{message})"); +#endif } private string stripUsernameTag(string sender) diff --git a/CLre_server/Tweaks/Chat/ModeratorCommands.cs b/CLre_server/Tweaks/Chat/ModeratorCommands.cs index 58cc388..f6fabac 100644 --- a/CLre_server/Tweaks/Chat/ModeratorCommands.cs +++ b/CLre_server/Tweaks/Chat/ModeratorCommands.cs @@ -55,7 +55,7 @@ namespace CLre_server.Tweaks.Chat } else { - connection.PublishMessage(ChatListener.ChatName, "Ban failure: User not found :("); + connection.PublishMessage(ChatListener.ChatName, $"Ban warning: {target} was added to ban list but was not connected to this server..."); } }