|
|
@@ -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<ChatCommandAttribute, ChatConnectionEngine.CommandHandler> _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) |
|
|
|