mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
message rpc size limit setting
This commit is contained in:
1 parent
0d72539bbc
commit
3ef660659c
10 files changed
+38
-40
No files matched your search
+1
-1
@@ -7,7 +7,7 @@
|
||||
<Description>EHR</Description>
|
||||
<Authors>Gurge44</Authors>
|
||||
<langVersion>preview</langVersion>
|
||||
<AmongUs>D:\AmongUs</AmongUs>
|
||||
<AmongUs>C:\Program Files\Epic Games\AmongUs</AmongUs>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>True</Optimize>
|
||||
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
|
||||
|
||||
@@ -88,7 +88,6 @@ public class Main : BasePlugin
|
||||
public static Dictionary<byte, float> AllPlayerKillCooldown = [];
|
||||
public static Dictionary<byte, Vent> LastEnteredVent = [];
|
||||
public static Dictionary<byte, Vector2> LastEnteredVentLocation = [];
|
||||
public static readonly List<(string Message, byte ReceiverID, string Title)> MessagesToSend = [];
|
||||
public static bool IsChatCommand;
|
||||
public static bool DoBlockNameChange;
|
||||
public static int UpdateTime;
|
||||
|
||||
@@ -118,7 +118,7 @@ public class CustomRpcSender
|
||||
throw new InvalidOperationException(errorMsg);
|
||||
}
|
||||
|
||||
if (stream.Length > 1450 && sendOption == SendOption.Reliable && !dispose) Logger.Warn($"Large reliable packet \"{name}\" is sending ({stream.Length} bytes)", "CustomRpcSender");
|
||||
if (stream.Length >= 1500 && sendOption == SendOption.Reliable && !dispose) Logger.Warn($"Large reliable packet \"{name}\" is sending ({stream.Length} bytes)", "CustomRpcSender");
|
||||
else Logger.Info($"\"{name}\" is finished (Length: {stream.Length}, dispose: {dispose}, sendOption: {sendOption})", "CustomRpcSender");
|
||||
|
||||
if (!dispose)
|
||||
|
||||
+4
-4
@@ -198,10 +198,10 @@ public class CustomLogger
|
||||
{
|
||||
if (multiLine) message = message.Replace("\\n", "<br>");
|
||||
|
||||
if (message.Contains("<b>")) message += "</b>";
|
||||
if (message.Contains("<u>")) message += "</u>";
|
||||
if (message.Contains("<i>")) message += "</i>";
|
||||
if (message.Contains("<s>")) message += "</s>";
|
||||
if (message.Contains("<b")) message += "</b>";
|
||||
if (message.Contains("<u")) message += "</u>";
|
||||
if (message.Contains("<i")) message += "</i>";
|
||||
if (message.Contains("<s")) message += "</s>";
|
||||
|
||||
var logEntry = $"""
|
||||
<div class='log-entry {level.ToLower()}'>
|
||||
|
||||
@@ -677,6 +677,7 @@ public static class Options
|
||||
public static OptionItem PostLobbyCodeToEHRWebsite;
|
||||
public static OptionItem StoreCompletedAchievementsOnEHRDatabase;
|
||||
public static OptionItem AllCrewRolesHaveVanillaColor;
|
||||
public static OptionItem MessageRpcSizeLimit;
|
||||
public static OptionItem ShowAntiBlackoutWarning;
|
||||
public static OptionItem AllowConsole;
|
||||
public static OptionItem NoGameEnd;
|
||||
@@ -1452,6 +1453,9 @@ public static class Options
|
||||
|
||||
AllCrewRolesHaveVanillaColor = new BooleanOptionItem(19424, "AllCrewRolesHaveVanillaColor", false, TabGroup.SystemSettings)
|
||||
.SetHeader(true);
|
||||
|
||||
MessageRpcSizeLimit = new IntegerOptionItem(19425, "MessageRpcSizeLimit", new(500, 100000, 100), 1400, TabGroup.SystemSettings)
|
||||
.SetHeader(true);
|
||||
|
||||
RoleAssigningAlgorithm = new StringOptionItem(19409, "RoleAssigningAlgorithm", RoleAssigningAlgorithms, 4, TabGroup.SystemSettings, true)
|
||||
.SetHeader(true)
|
||||
|
||||
+21
-8
@@ -1698,7 +1698,7 @@ public static class Utils
|
||||
sender.SendMessage(dispose: sender.stream.Length <= 3);
|
||||
}
|
||||
|
||||
public static CustomRpcSender SendMessage(string text, byte sendTo = byte.MaxValue, string title = "", bool noSplit = false, CustomRpcSender writer = null, bool final = false, bool multiple = false, SendOption sendOption = SendOption.Reliable)
|
||||
public static CustomRpcSender SendMessage(string text, byte sendTo = byte.MaxValue, string title = "", bool noSplit = false, CustomRpcSender writer = null, bool final = false, bool multiple = false, SendOption sendOption = SendOption.Reliable, bool addtoHistory = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1733,7 +1733,7 @@ public static class Utils
|
||||
text = text.Replace("color=", string.Empty);
|
||||
title = title.Replace("color=", string.Empty);
|
||||
|
||||
PlayerControl sender = GameStates.IsLobby ? PlayerControl.LocalPlayer : Main.AllAlivePlayerControls.MinBy(x => x.PlayerId) ?? Main.AllPlayerControls.MinBy(x => x.PlayerId) ?? PlayerControl.LocalPlayer;
|
||||
PlayerControl sender = !addtoHistory ? PlayerControl.LocalPlayer : Main.AllAlivePlayerControls.MinBy(x => x.PlayerId) ?? Main.AllPlayerControls.MinBy(x => x.PlayerId) ?? PlayerControl.LocalPlayer;
|
||||
|
||||
if (sendTo != byte.MaxValue && receiver.IsLocalPlayer())
|
||||
{
|
||||
@@ -1750,7 +1750,7 @@ public static class Utils
|
||||
}
|
||||
catch { Logger.Info(" Message sent", "SendMessage"); }
|
||||
|
||||
ChatUpdatePatch.LastMessages.Add((text, sendTo, title, TimeStamp));
|
||||
if (addtoHistory) ChatUpdatePatch.LastMessages.Add((text, sendTo, title, TimeStamp));
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -1759,7 +1759,7 @@ public static class Utils
|
||||
if (writer == null || writer.CurrentState == CustomRpcSender.State.Finished)
|
||||
writer = CustomRpcSender.Create("Utils.SendMessage(1)", sendOption);
|
||||
|
||||
const int fullRpcSizeLimit = 1400;
|
||||
int fullRpcSizeLimit = Options.MessageRpcSizeLimit.GetInt();
|
||||
int textRpcSize = text.Length * 2;
|
||||
int titleRpcSize = title.Length * 2 + 4;
|
||||
int resetNameRpcSize = sender.Data.PlayerName.Length * 2 + 4;
|
||||
@@ -1779,6 +1779,14 @@ public static class Utils
|
||||
else
|
||||
{
|
||||
titleRpcSizeLimit = (fullRpcSizeLimit - 8 - resetNameRpcSize) * 2;
|
||||
|
||||
if (titleRpcSizeLimit - 4 < 1)
|
||||
{
|
||||
Logger.SendInGame(GetString("MessageTooLong"));
|
||||
if (!multiple) writer.SendMessage(dispose: true);
|
||||
return writer;
|
||||
}
|
||||
|
||||
string[] lines = title.Split('\n');
|
||||
var shortenedTitle = string.Empty;
|
||||
|
||||
@@ -1851,8 +1859,7 @@ public static class Utils
|
||||
}
|
||||
catch { Logger.Info(" Message sent", "SendMessage"); }
|
||||
|
||||
ChatUpdatePatch.LastMessages.Add(("\n", sendTo, tempTitle, TimeStamp));
|
||||
|
||||
if (addtoHistory) ChatUpdatePatch.LastMessages.Add(("\n", sendTo, tempTitle, TimeStamp));
|
||||
return writer;
|
||||
}
|
||||
}
|
||||
@@ -1861,6 +1868,13 @@ public static class Utils
|
||||
titleRpcSize = title.Length * 2 + 4;
|
||||
int textRpcSizeLimit = fullRpcSizeLimit - titleRpcSize - resetNameRpcSize;
|
||||
|
||||
if (textRpcSizeLimit < 1 && textRpcSize >= textRpcSizeLimit && !noSplit)
|
||||
{
|
||||
Logger.SendInGame(GetString("MessageTooLong"));
|
||||
if (!multiple) writer.SendMessage(dispose: true);
|
||||
return writer;
|
||||
}
|
||||
|
||||
if (textRpcSize >= textRpcSizeLimit && !noSplit)
|
||||
{
|
||||
string[] lines = text.Split('\n');
|
||||
@@ -1957,8 +1971,7 @@ public static class Utils
|
||||
}
|
||||
catch (Exception e) { ThrowException(e); }
|
||||
|
||||
ChatUpdatePatch.LastMessages.Add((text, sendTo, title, TimeStamp));
|
||||
|
||||
if (addtoHistory) ChatUpdatePatch.LastMessages.Add((text, sendTo, title, TimeStamp));
|
||||
return writer;
|
||||
|
||||
void RestartMessageIfTooLong()
|
||||
|
||||
@@ -345,7 +345,7 @@ internal static class ChatCommands
|
||||
if (!Main.AllPlayerNames.TryGetValue(PlayerControl.LocalPlayer.PlayerId, out string name))
|
||||
Utils.ApplySuffix(PlayerControl.LocalPlayer, out name);
|
||||
|
||||
Utils.SendMessage(text.Insert(0, new('\n', name.Count(x => x == '\n'))), title: name);
|
||||
Utils.SendMessage(text.Insert(0, new('\n', name.Count(x => x == '\n'))), title: name, addtoHistory: false);
|
||||
|
||||
canceled = true;
|
||||
__instance.freeChatField.textArea.Clear();
|
||||
@@ -1791,7 +1791,6 @@ internal static class ChatCommands
|
||||
|
||||
if (!player.IsHost() && !IsPlayerModerator(player.FriendCode)) return;
|
||||
|
||||
if (!player.IsModdedClient()) ChatManager.SendPreviousMessagesToAll();
|
||||
if (args.Length > 1) Utils.SendMessage(args[1..].Join(delimiter: " "), title: $"<color=#ff0000>{GetString(player.IsHost() ? "MessageFromTheHost" : "SayTitle")}</color>");
|
||||
}
|
||||
|
||||
@@ -3182,32 +3181,18 @@ internal static class ChatUpdatePatch
|
||||
}
|
||||
|
||||
LastMessages.RemoveAll(x => Utils.TimeStamp - x.SendTimeStamp > 10);
|
||||
|
||||
if (!AmongUsClient.Instance.AmHost || Main.MessagesToSend.Count == 0 || (Main.MessagesToSend[0].ReceiverID == byte.MaxValue && Main.MessageWait.Value > __instance.timeSinceLastMessage) || DoBlockChat) return;
|
||||
|
||||
PlayerControl player = Main.AllAlivePlayerControls.MinBy(x => x.PlayerId) ?? Main.AllPlayerControls.MinBy(x => x.PlayerId) ?? PlayerControl.LocalPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
(string msg, byte sendTo, string title) = Main.MessagesToSend[0];
|
||||
Main.MessagesToSend.RemoveAt(0);
|
||||
|
||||
SendMessage(player, msg, sendTo, title);
|
||||
|
||||
__instance.timeSinceLastMessage = 0f;
|
||||
|
||||
LastMessages.Add((msg, sendTo, title, Utils.TimeStamp));
|
||||
}
|
||||
|
||||
internal static void SendLastMessages(CustomRpcSender sender)
|
||||
{
|
||||
PlayerControl player = Main.AllAlivePlayerControls.MinBy(x => x.PlayerId) ?? Main.AllPlayerControls.MinBy(x => x.PlayerId) ?? PlayerControl.LocalPlayer;
|
||||
PlayerControl player = GameStates.IsLobby ? Main.AllPlayerControls.Without(PlayerControl.LocalPlayer).RandomElement() : Main.AllAlivePlayerControls.MinBy(x => x.PlayerId) ?? Main.AllPlayerControls.MinBy(x => x.PlayerId) ?? PlayerControl.LocalPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
foreach ((string msg, byte sendTo, string title, _) in LastMessages)
|
||||
SendMessage(player, msg, sendTo, title, sender);
|
||||
}
|
||||
|
||||
internal static void SendMessage(PlayerControl player, string msg, byte sendTo, string title, CustomRpcSender sender = null)
|
||||
private static void SendMessage(PlayerControl player, string msg, byte sendTo, string title, CustomRpcSender sender = null)
|
||||
{
|
||||
int clientId = sendTo == byte.MaxValue ? -1 : Utils.GetPlayerById(sendTo).GetClientId();
|
||||
|
||||
|
||||
@@ -264,13 +264,9 @@ public static class ChatManager
|
||||
|
||||
private static void SendRPC(CustomRpcSender writer, InnerNetObject senderPlayer, string senderMessage, int targetClientId = -1)
|
||||
{
|
||||
writer.StartMessage(targetClientId);
|
||||
|
||||
writer.StartRpc(senderPlayer.NetId, (byte)RpcCalls.SendChat)
|
||||
writer.AutoStartRpc(senderPlayer.NetId, (byte)RpcCalls.SendChat, targetClientId)
|
||||
.Write(senderMessage)
|
||||
.EndRpc();
|
||||
|
||||
writer.EndMessage();
|
||||
}
|
||||
|
||||
public static void ClearChatForSpecificPlayer(PlayerControl target)
|
||||
|
||||
@@ -268,7 +268,6 @@ internal static class OnPlayerLeftPatch
|
||||
Main.SayStartTimes.Remove(__instance.ClientId);
|
||||
Main.SayBanwordsTimes.Remove(__instance.ClientId);
|
||||
Main.PlayerVersion.Remove(data?.Character?.PlayerId ?? byte.MaxValue);
|
||||
Logger.Info($"{Main.MessagesToSend.RemoveAll(x => x.ReceiverID != byte.MaxValue && x.ReceiverID == data?.Character.PlayerId)} sending messages were canceled", "OnPlayerLeftPatchPostfix");
|
||||
|
||||
if (data != null && data.Character != null)
|
||||
{
|
||||
|
||||
@@ -2805,6 +2805,7 @@
|
||||
"SpectateCommand.Removed": "<#ffab1b>-</color> You are no longer spectating.",
|
||||
"SpectateCommand.Success": "<#00ff00>✓</color> You are now spectating for the next game.",
|
||||
"ReadyClientsInfo": "\\nReady clients: {0} (Timeout in {1}s)",
|
||||
"MessageTooLong": "Failed to send chat message. The size of the RPC would've exceeded the limit specified in System Settings.",
|
||||
"Vision": "Vision",
|
||||
"Outside": "Outside",
|
||||
"UnsupportedVersion": "Unsupported Among Us version.\\nPlease update Among Us.",
|
||||
@@ -2899,7 +2900,8 @@
|
||||
"JudgeCanTrialSidekick": "Can trial <color=#00b4eb>Sidekick</color>",
|
||||
"JudgeCanTrialInfected": "Can trial <color=#7B8968>Infected</color>",
|
||||
"JudgeCanTrialContagious": "Can trial <color=#2E8B57>Contagious</color>",
|
||||
"AllCrewRolesHaveVanillaColor": "All <#8cffff>Crewmate</color> roles have <#8cffff>the vanilla Crewmate color</color>",
|
||||
"MessageRpcSizeLimit": "Message RPC Size Limit (Higher limit = increased risk of disconnects but fewer message splits - if you never disconnect randomly, up to 15000 can be safe)",
|
||||
"AllCrewRolesHaveVanillaColor": "All <#8cffff>Crewmate</color> roles have <#8cffff>the vanilla Crewmate color</color> <#ffff00>(REQUIRES RESTART)</color>",
|
||||
"StoreCompletedAchievementsOnEHRDatabase": "Store completed achievements on the EHR database (to maintain progress in case of a reinstall or an update)",
|
||||
"PostLobbyCodeToEHRDiscordServer": "Post the lobby code to the EHR Website",
|
||||
"Message.LobbyCodeSent": "<size=90%><#00ffa5>✓</color> <#00a5ff>The lobby code has been sent to the EHR website. This will help others find EHR lobbies.</color></size>\\n<size=70%>You can disable this feature in the settings (System Settings tab).</size>",
|
||||
|
||||
Reference in new issue
Block a user