Skip to content

Commit

Permalink
Leverage New Server Chat Feature
Browse files Browse the repository at this point in the history
- Adds SendChatMessageToAll method
- Uses the server chat feature for chat messages rather than whoever is first player (i.e., Player[0])
  • Loading branch information
data-bomb committed Sep 5, 2024
1 parent ea34d51 commit c1fe88c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions Si_AdminMod/HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,22 @@ public static void AlertAdminAction(Player? adminPlayer, string action)
broadcastPlayer.SendChatMessage(chatPrefix + GetAdminColor() + adminName + "</color> " + action, false);
}

public static void SendChatMessageToTeam(Team team, params string[] messages)
public static void SendChatMessageToAll(params string[] messages)
{
Player broadcastPlayer = FindBroadcastPlayer(team);
for (int i = 0; i < Player.Players.Count; i++)
{
Player? player = Player.Players[i];
if (player == null)
{
continue;
}

NetworkSendChat(player, false, messages);
}
}

public static void SendChatMessageToTeam(Team team, params string[] messages)
{
for (int i = 0; i < Player.Players.Count; i++)
{
Player? player = Player.Players[i];
Expand All @@ -112,7 +124,7 @@ public static void SendChatMessageToTeam(Team team, params string[] messages)

if (player.Team == team)
{
NetworkSendChat(player, broadcastPlayer, messages);
NetworkSendChat(player, true, messages);
}
}
}
Expand Down Expand Up @@ -177,8 +189,7 @@ public static void SendChatMessageToPlayer(Player? player, params string[] messa
return;
}

Player broadcastPlayer = FindBroadcastPlayer();
NetworkSendChat(player, broadcastPlayer, messages);
NetworkSendChat(player, true, messages);
}
public static void SendConsoleMessageToPlayer(Player? player, params string[] messages)
{
Expand All @@ -193,14 +204,14 @@ public static void SendConsoleMessageToPlayer(Player? player, params string[] me
NetworkSendConsole(player, messages);
}

private static void NetworkSendChat(Player recipient, Player sender, params string[] messages)
private static void NetworkSendChat(Player recipient, bool teamOnly, params string[] messages)
{
GameByteStreamWriter gameByteStreamWriter = GameByteStreamWriter.GetGameByteStreamWriter(0U, "Si_AdminMod::NetworkSendChat", true);
gameByteStreamWriter.WriteByte((byte)ENetworkPacketType.ChatMessage);
gameByteStreamWriter.WriteUInt64((ulong)sender.PlayerID);
gameByteStreamWriter.WriteByte((byte)sender.PlayerChannel);
gameByteStreamWriter.WriteUInt64((ulong)NetworkID.CurrentUserID);
gameByteStreamWriter.WriteByte((byte)0);
gameByteStreamWriter.WriteString(String.Concat(messages));
gameByteStreamWriter.WriteBool(false); // teamOnly
gameByteStreamWriter.WriteBool(teamOnly); // teamOnly
gameByteStreamWriter.WriteBool(true); // isServerMessage

uint byteDataSize = (uint)gameByteStreamWriter.GetByteDataSize();
Expand Down
2 changes: 1 addition & 1 deletion Si_AdminMod/ModAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Drawing;

[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.943", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.958", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]

// Color.Cyan
Expand Down

0 comments on commit c1fe88c

Please sign in to comment.