Browse Source

Minor improvements to chat commands

tags/v0.0.3
NGnius (Graham) 1 year ago
parent
commit
89089c9397
3 changed files with 22 additions and 16 deletions
  1. +1
    -1
      CLre_server/Tweaks/Chat/ChatConnectionEngine.cs
  2. +20
    -14
      CLre_server/Tweaks/Chat/ChatListener.cs
  3. +1
    -1
      CLre_server/Tweaks/Chat/ModeratorCommands.cs

+ 1
- 1
CLre_server/Tweaks/Chat/ChatConnectionEngine.cs View File

@@ -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)


+ 20
- 14
CLre_server/Tweaks/Chat/ChatListener.cs View File

@@ -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)


+ 1
- 1
CLre_server/Tweaks/Chat/ModeratorCommands.cs View File

@@ -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...");
}
}



Loading…
Cancel
Save