Skip to content

Commit

Permalink
fix(server): improve chat command colours
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMcAssey committed Jan 12, 2025
1 parent db4e0be commit 0f456fa
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
7 changes: 4 additions & 3 deletions GLOKON.Baiters.Core/BaitersServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public bool TryGetPlayer(ulong steamId, out Player? player)

public void KickPlayer(ulong steamId)
{
SendPacket(new("kick"), DataChannel.GameState, steamId);
SendPacket(new("peer_was_kicked")
{
["user_id"] = (long)steamId,
Expand All @@ -174,8 +175,8 @@ public void KickPlayer(ulong steamId)

if (_players.TryGetValue(steamId, out var player) && player != null)
{
SendMessage($"Kicked {player.FisherName}", steamId: steamId);
SendMessage($"{player.FisherName} was kicked from the lobby!");
SendMessage($"Kicked {player.FisherName}", MessageColour.Error, steamId);
SendMessage($"{player.FisherName} was kicked from the lobby!", MessageColour.Error);
}
}

Expand Down Expand Up @@ -217,7 +218,7 @@ public void SpawnActor(Actor actor)
SendActor(actorId, actor);
}

public void SendMessage(string message, string color = "ffffff", ulong? steamId = null)
public void SendMessage(string message, string color = MessageColour.Default, ulong? steamId = null)
{
SendPacket(new("message")
{
Expand Down
7 changes: 4 additions & 3 deletions GLOKON.Baiters.Core/Chat/ChatManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GLOKON.Baiters.Core.Configuration;
using GLOKON.Baiters.Core.Constants;
using Microsoft.Extensions.Options;
using System.Collections.Concurrent;

Expand All @@ -21,14 +22,14 @@ public ChatManager(IOptions<WebFishingOptions> _options, BaitersServer server)
return;
}

server.SendMessage("-- Help --", "0f0f0f", sender);
server.SendMessage("-- Help --", MessageColour.Information, sender);

foreach (var chatCommand in _commands)
{
server.SendMessage(string.Format("- {0}: {1}", chatCommand.Key, chatCommand.Value.HelpText), "0f0f0f", sender);
server.SendMessage(string.Format("- {0}: {1}", chatCommand.Key, chatCommand.Value.HelpText), MessageColour.Information, sender);
}

server.SendMessage("----", "0f0f0f", sender);
server.SendMessage("----", MessageColour.Information, sender);
});
}

Expand Down
11 changes: 11 additions & 0 deletions GLOKON.Baiters.Core/Constants/MessageColour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GLOKON.Baiters.Core.Constants
{
public sealed class MessageColour
{
public const string Default = "ffffff";
public const string Success = "16a34a";
public const string Warning = "ca8a04";
public const string Error = "dc2626";
public const string Information = "2563eb";
}
}
4 changes: 2 additions & 2 deletions GLOKON.Baiters.Core/Packets/Handlers/InstanceActorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void Handle(ulong sender, Packet data)
if (server.TryGetPlayer(sender, out var playerToKick) && playerToKick != null)
{
// Kick the player because the spawned in a actor that only the server should be able to spawn!
server.SendPacket(new("kick"), DataChannel.GameState, sender);
server.SendMessage($"{playerToKick.FisherName} was kicked for trying to spawn fish & items");
server.KickPlayer(sender);
server.SendMessage($"{playerToKick.FisherName} was kicked for trying to spawn fish & items", MessageColour.Error);
}
}
else
Expand Down
7 changes: 4 additions & 3 deletions GLOKON.Baiters.Core/Packets/Handlers/NewPlayerJoinHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace GLOKON.Baiters.Core.Packets.Handlers
{
internal class NewPlayerJoinHandler(BaitersServer server, string? joinMessage) : IPacketHandler
internal class NewPlayerJoinHandler(BaitersServer server, string commandPrefix, string? joinMessage) : IPacketHandler
{
public void Handle(ulong sender, Packet data)
{
if (!string.IsNullOrEmpty(joinMessage))
{
server.SendMessage(joinMessage, steamId: sender);
server.SendMessage(joinMessage, MessageColour.Information, sender);
}

server.SendPacket(new("recieve_host")
Expand All @@ -22,7 +22,8 @@ public void Handle(ulong sender, Packet data)

if (server.IsAdmin(sender))
{
server.SendMessage("!!You are an admin!!", "0f0f0f", sender);
server.SendMessage("##You are an admin##", MessageColour.Success, sender);
server.SendMessage(string.Format("Use '{0}help' to find out what commands are available", commandPrefix), MessageColour.Success, sender);
}

Task.Run(async () =>
Expand Down
2 changes: 1 addition & 1 deletion GLOKON.Baiters.Core/Packets/PacketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PacketManager(IOptions<WebFishingOptions> options, BaitersServer server)
public void Setup()
{
handlers.Add("handshake", new HandshakeHandler(server));
handlers.Add("new_player_join", new NewPlayerJoinHandler(server, options.JoinMessage));
handlers.Add("new_player_join", new NewPlayerJoinHandler(server, options.CommandPrefix, options.JoinMessage));
handlers.Add("instance_actor", new InstanceActorHandler(server));
handlers.Add("actor_update", new ActorUpdateHandler(server));
handlers.Add("actor_animation_update", new ActorAnimationUpdateHandler(server));
Expand Down
11 changes: 6 additions & 5 deletions GLOKON.Baiters.Plugins.BanManager/BanManagerPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GLOKON.Baiters.Core;
using GLOKON.Baiters.Core.Constants;
using GLOKON.Baiters.Core.Plugins;
using Newtonsoft.Json;
using Serilog;
Expand Down Expand Up @@ -42,14 +43,14 @@ public override void OnInit()

if (commandParams.Length < 1)
{
GM.Server.SendMessage("Invalid ban command, not enough parameters", steamId: sender);
GM.Server.SendMessage("Invalid ban command, not enough parameters", MessageColour.Error, sender);
return;
}

bool didParseSteamId = ulong.TryParse(commandParams[0], out var steamId);
if (!didParseSteamId)
{
GM.Server.SendMessage("Invalid SteamID, could not be parsed", steamId: sender);
GM.Server.SendMessage("Invalid SteamID, could not be parsed", MessageColour.Error, sender);
return;
}

Expand All @@ -70,14 +71,14 @@ public override void OnInit()
});
GM.Chat.ListenFor("ban.list", "List all players that are currently banned", (sender, commandParams) =>
{
GM.Server.SendMessage("-- Help --", "0f0f0f", sender);
GM.Server.SendMessage("-- Ban List --", MessageColour.Information, sender);

foreach (var playerBan in _playerBans)
{
GM.Server.SendMessage(string.Format("[{0}] {1}: {2}", playerBan.Key, playerBan.Value.FisherName, playerBan.Value.Reason ?? "(No Reason Given)"), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("[{0}] {1}: {2}", playerBan.Key, playerBan.Value.FisherName, playerBan.Value.Reason ?? "(No Reason Given)"), MessageColour.Information, sender);
}

GM.Server.SendMessage("----", "0f0f0f", sender);
GM.Server.SendMessage("----", MessageColour.Information, sender);
});
}

Expand Down
35 changes: 18 additions & 17 deletions GLOKON.Baiters.Plugins.ChatCommand/ChatCommandPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GLOKON.Baiters.Core;
using GLOKON.Baiters.Core.Constants;
using GLOKON.Baiters.Core.Plugins;
using System.Reflection;

Expand All @@ -22,14 +23,14 @@ public override void OnInit()
return;
}

GM.Server.SendMessage(string.Format("-- Players ({0}/{1}) --", GM.Server.Players.Count(), GM.Options.MaxPlayers), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("-- Players ({0}/{1}) --", GM.Server.Players.Count(), GM.Options.MaxPlayers), MessageColour.Information, sender);

foreach (var player in GM.Server.Players)
{
GM.Server.SendMessage(string.Format("- [{0}] {1}", player.Key, player.Value.FisherName), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("- [{0}] {1}", player.Key, player.Value.FisherName), MessageColour.Information, sender);
}

GM.Server.SendMessage("----", "0f0f0f", sender);
GM.Server.SendMessage("----", MessageColour.Information, sender);
});

GM.Chat.ListenFor("spawn", "Spawn a new element on the server", (sender, commandParams) =>
Expand All @@ -41,18 +42,18 @@ public override void OnInit()

if (commandParams.Length < 1)
{
GM.Server.SendMessage("Invalid spawn command, not enough parameters", steamId: sender);
GM.Server.SendMessage("Invalid spawn command, not enough parameters", MessageColour.Error, sender);
return;
}

string spawnType = commandParams[0].ToLower();
if (GM.Spawner.Spawn(spawnType))
{
GM.Server.SendMessage(string.Format("Spawned a {0}", spawnType), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("Spawned a {0}", spawnType), MessageColour.Information, sender);
}
else
{
GM.Server.SendMessage(string.Format("Cannot spawn a {0}", spawnType), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("Cannot spawn a {0}", spawnType), MessageColour.Information, sender);
}
});

Expand All @@ -63,7 +64,7 @@ public override void OnInit()
return;
}

GM.Server.SendMessage(string.Format("Spawnable: {0}", string.Join(", ", ActorSpawner.Spawnable)), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("Spawnable: {0}", string.Join(", ", ActorSpawner.Spawnable)), MessageColour.Information, sender);
});

GM.Chat.ListenFor("kick", "Kick a player by providing their SteamID", (sender, commandParams) =>
Expand All @@ -75,14 +76,14 @@ public override void OnInit()

if (commandParams.Length < 1)
{
GM.Server.SendMessage("Invalid kick command, not enough parameters", steamId: sender);
GM.Server.SendMessage("Invalid kick command, not enough parameters", MessageColour.Error, sender);
return;
}

bool didParseSteamId = ulong.TryParse(commandParams[0], out var steamId);
if (!didParseSteamId)
{
GM.Server.SendMessage("Invalid SteamID, could not be parsed", steamId: sender);
GM.Server.SendMessage("Invalid SteamID, could not be parsed", MessageColour.Error, sender);
return;
}

Expand All @@ -98,18 +99,18 @@ public override void OnInit()

if (commandParams.Length < 2)
{
GM.Server.SendMessage("Invalid say command, not enough parameters", steamId: sender);
GM.Server.SendMessage("Invalid say command, not enough parameters", MessageColour.Error, sender);
return;
}

bool didParseSteamId = ulong.TryParse(commandParams[0], out var steamId);
if (!didParseSteamId)
{
GM.Server.SendMessage("Invalid SteamID, could not be parsed", steamId: sender);
GM.Server.SendMessage("Invalid SteamID, could not be parsed", MessageColour.Error, sender);
return;
}

GM.Server.SendMessage(string.Format("ADMIN: {0}", string.Join(" ", commandParams.Skip(1).ToArray())), "ff0000", steamId);
GM.Server.SendMessage(string.Format("ADMIN: {0}", string.Join(" ", commandParams.Skip(1).ToArray())), MessageColour.Warning, steamId);
});

GM.Chat.ListenFor("say.all", "Send all players a message", (sender, commandParams) =>
Expand All @@ -121,11 +122,11 @@ public override void OnInit()

if (commandParams.Length < 1)
{
GM.Server.SendMessage("Invalid say.all command, not enough parameters", steamId: sender);
GM.Server.SendMessage("Invalid say.all command, not enough parameters", MessageColour.Error, sender);
return;
}

GM.Server.SendMessage(string.Format("ADMIN: {0}", string.Join(" ", commandParams)), "ff0000");
GM.Server.SendMessage(string.Format("ADMIN: {0}", string.Join(" ", commandParams)), MessageColour.Warning);
});

GM.Chat.ListenFor("plugins", "Show all the plugins loaded", (sender, commandParams) =>
Expand All @@ -135,14 +136,14 @@ public override void OnInit()
return;
}

GM.Server.SendMessage("-- Plugins --", "0f0f0f", sender);
GM.Server.SendMessage("-- Plugins --", MessageColour.Information, sender);

foreach (var plugin in PluginLoader.Plugins)
{
GM.Server.SendMessage(string.Format("- {0}:{1} by {2}", plugin.Name, plugin.Version, plugin.Author), "0f0f0f", sender);
GM.Server.SendMessage(string.Format("- {0}:{1} by {2}", plugin.Name, plugin.Version, plugin.Author), MessageColour.Information, sender);
}

GM.Server.SendMessage("----", "0f0f0f", sender);
GM.Server.SendMessage("----", MessageColour.Information, sender);
});
}

Expand Down

0 comments on commit 0f456fa

Please sign in to comment.