Skip to content

Commit 6c478f1

Browse files
committed
v2.0.0 (Host Only)
Just fixed commands being hijacked by other clients when they shouldn't be. Also date won't get sent to all clients if the player isn't host
1 parent c627063 commit 6c478f1

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

OnlineAdditions/Patches/Assembly-CSharp/ChatInputV2/CheckForServerCode.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ internal class ChatInputV2__CheckForServerCode
2121
[HarmonyPrefix]
2222
internal static bool CheckForCommands(ChatInputV2 __instance, string text)
2323
{
24-
Mod.Log.LogInfo(text);
24+
//Mod.Log.LogInfo(text);
25+
//Mod.Log.LogInfo("Came From Host?: " + Mod.Instance.cameFromHost);
2526
if (string.IsNullOrEmpty(text) || text.Length > 0 && text[0] != '/')
2627
{
2728
Mod.Log.LogInfo("Not a command!");
@@ -48,10 +49,18 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
4849

4950
if (key != null)
5051
{
51-
Mod.Log.LogInfo("Command is: " + key);
52+
//Mod.Log.LogInfo("Command is: " + key);
5253
if (key == "date")
5354
{
54-
StaticTransceivedEvent<ChatMessage.Data>.Broadcast(new ChatMessage.Data("Current date: " + DateTime.Now.ToString()));
55+
if (Mod.Instance.amIHost)
56+
{
57+
StaticTransceivedEvent<ChatMessage.Data>.Broadcast(new ChatMessage.Data("Current Date of Host: " + DateTime.Now.ToString()));
58+
}
59+
else
60+
{
61+
__instance.AddChat("Current Date of Client: " + DateTime.Now.ToString());
62+
}
63+
5564
return false;
5665
}
5766

@@ -95,7 +104,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
95104
return false;
96105
}
97106

98-
if (key == "playercount" && Mod.Instance.amIHost)
107+
if (key == "playercount" && Mod.Instance.amIHost && Mod.Instance.cameFromHost)
99108
{
100109
if(string.IsNullOrEmpty(str))
101110
{
@@ -113,7 +122,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
113122
return true;
114123
}
115124

116-
if (key == "private" && Mod.Instance.amIHost)
125+
if (key == "private" && Mod.Instance.amIHost && Mod.Instance.cameFromHost)
117126
{
118127
if (!string.IsNullOrEmpty(str))
119128
{
@@ -134,7 +143,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
134143
return false;
135144
}
136145

137-
if (key == "public" && Mod.Instance.amIHost)
146+
if (key == "public" && Mod.Instance.amIHost && Mod.Instance.cameFromHost)
138147
{
139148
G.Sys.NetworkingManager_.password_ = "";
140149
G.Sys.NetworkingManager_.privateServer_ = false;
@@ -146,7 +155,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
146155

147156
if (key == "server")
148157
{
149-
if (!string.IsNullOrEmpty(str) && !flag)
158+
if (!string.IsNullOrEmpty(str) && !flag && Mod.Instance.amIHost && Mod.Instance.cameFromHost)
150159
{
151160
G.Sys.NetworkingManager_.serverTitle_ = str;
152161
G.Sys.NetworkingManager_.ReportToMasterServer();
@@ -159,7 +168,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
159168
return false;
160169
}
161170

162-
if (key == "shuffle" && Mod.Instance.amIHost)
171+
if (key == "shuffle" && Mod.Instance.amIHost && Mod.Instance.cameFromHost)
163172
{
164173
if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify)
165174
{
@@ -194,7 +203,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
194203
return false;
195204
}
196205

197-
if (key == "timeout" && Mod.Instance.amIHost && !Mod.Instance.allPlayersFinished)
206+
if (key == "timeout" && Mod.Instance.amIHost && Mod.Instance.cameFromHost && !Mod.Instance.allPlayersFinished)
198207
{
199208
int time;
200209
if (flag)
@@ -211,7 +220,7 @@ internal static bool CheckForCommands(ChatInputV2 __instance, string text)
211220
return false;
212221
}
213222

214-
if (key == "canceltimeout" && Mod.Instance.amIHost && !Mod.Instance.allPlayersFinished)
223+
if (key == "canceltimeout" && Mod.Instance.amIHost && Mod.Instance.cameFromHost && !Mod.Instance.allPlayersFinished)
215224
{
216225
StaticTransceivedEvent<FinalCountdownCancel.Data>.Broadcast(new FinalCountdownCancel.Data());
217226
Mod.Instance.countdownActive = false;

OnlineAdditions/Patches/Assembly-CSharp/ChatInputV2/OnEventChatMessage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ internal static void CheckingForServerCode(ChatInputV2 __instance, AddMessage.Da
2020
messageFrom = regexName.Matches(data.message_)[0].Value;
2121
if (messageFrom != Mod.Instance.playerName)
2222
{
23+
Mod.Instance.cameFromHost = false;
2324
messageText = regexMessage.Matches(data.message_)[0].Value;
2425
int num1 = messageText.IndexOf(" ");
2526
string key = messageText.Substring(num1 + 1, messageText.Length - (num1 + 1));
2627
//Mod.Log.LogInfo(messageText);
2728
//Mod.Log.LogInfo(key);
2829
__instance.CheckForServerCode(key);
2930
}
31+
else
32+
{
33+
Mod.Instance.cameFromHost = true;
34+
}
3035
}
3136
}
3237
}

OnlineAdditions/Plugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public sealed class Mod : BaseUnityPlugin
4949
//Public Variables
5050
public bool allPlayersFinished { get; set; }
5151
public bool amIHost { get; set; }
52+
public bool cameFromHost { get; set; }
5253
public bool commandFromHost { get; set; }
5354
public bool countdownActive { get; set; }
5455
public bool playerFinished { get; set; }

0 commit comments

Comments
 (0)