Skip to content

Commit

Permalink
Don't allow connection to public servers with mismatched version
Browse files Browse the repository at this point in the history
  • Loading branch information
silentbaws committed Aug 5, 2020
1 parent 134bdc6 commit 2b95014
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
14 changes: 9 additions & 5 deletions XLMultiplayer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,13 @@ public static IEnumerator StartUpdatingServerList() {

private static void ClickServerItem(ServerListItem target) {
if(!serverClickWatch.IsRunning || serverClickWatch.Elapsed.TotalMilliseconds > 1000f) {
UnityModManager.Logger.Log($"Attempting to connect to server {target.ServerName.text} with ip {target.ipAddress} port {target.port}");
JoinServer(target.ipAddress, target.port, NewMultiplayerMenu.Instance.usernameFields[0].text);
serverClickWatch.Restart();
if (target.ServerVersion.text.Trim().ToLower().Equals(modEntry.Version.ToString())) {
UnityModManager.Logger.Log($"Attempting to connect to server {target.ServerName.text} with ip {target.ipAddress} port {target.port}");
JoinServer(target.ipAddress, target.port, NewMultiplayerMenu.Instance.usernameFields[0].text);
serverClickWatch.Restart();
} else {
utilityMenu.SendImportantChat($"<color=#f22><b>Unable to connect to server because it's version {target.ServerVersion.text} does not match client version {modEntry.Version.ToString()}</b></color>", 15000);
}
}
}

Expand Down Expand Up @@ -609,7 +613,7 @@ private static void DisplayVolume() {
}

[HarmonyPatch(typeof(ReplayEditorController), "OnDisable")]
static class MultiplayReplayDisablePatch {
static class Multiplay34ReplayDisablePatch {
static void Prefix() {
if (Main.multiplayerController != null) {
foreach (MultiplayerRemotePlayerController controller in Main.multiplayerController.remoteControllers) {
Expand Down Expand Up @@ -639,7 +643,7 @@ static bool Prefix(ReplayPlaybackController __instance) {
}

[HarmonyPatch(typeof(ReplayEditorController), "Update")]
static class MultiplayReplayUpdatePatch {
static class MultiplayerReplayUpdatePatch {
static void Postfix(ReplayEditorController __instance) {
foreach (MultiplayerRemotePlayerController controller in Main.remoteReplayControllers) {
controller.replayController.TimeScale = ReplayEditorController.Instance.playbackController.TimeScale;
Expand Down
20 changes: 11 additions & 9 deletions XLMultiplayer/MultiplayerUtilityMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,18 @@ private void DisplayChat(int windowId) {
}

chatStyle2.wordWrap = true;
if (Main.multiplayerController.chatMessages != null && Main.multiplayerController.chatMessages.Count > 0) {
int difference = Main.multiplayerController.chatMessages.Count - previousMessageCount;
float scrollDifference = 0f;
for (int i = Main.multiplayerController.chatMessages.Count - difference; i < Main.multiplayerController.chatMessages.Count; i++) {
chat += Main.multiplayerController.chatMessages[i] + "\n";
scrollDifference += chatStyle2.CalcHeight(new GUIContent(Main.multiplayerController.chatMessages[i]), chatWindowRect.width - 26) / chatStyle2.CalcHeight(new GUIContent("a"), chatWindowRect.width - 26) * chatStyle2.lineHeight;
if (Main.multiplayerController != null) {
if (Main.multiplayerController.chatMessages != null && Main.multiplayerController.chatMessages.Count > 0) {
int difference = Main.multiplayerController.chatMessages.Count - previousMessageCount;
float scrollDifference = 0f;
for (int i = Main.multiplayerController.chatMessages.Count - difference; i < Main.multiplayerController.chatMessages.Count; i++) {
chat += Main.multiplayerController.chatMessages[i] + "\n";
scrollDifference += chatStyle2.CalcHeight(new GUIContent(Main.multiplayerController.chatMessages[i]), chatWindowRect.width - 26) / chatStyle2.CalcHeight(new GUIContent("a"), chatWindowRect.width - 26) * chatStyle2.lineHeight;
}
previousMessageCount = Main.multiplayerController.chatMessages.Count;
if (chatStyle2.CalcHeight(new GUIContent(chat), chatWindowRect.width - 26) > chatWindowRect.height - 43)
chatScrollPosition.y += scrollDifference;
}
previousMessageCount = Main.multiplayerController.chatMessages.Count;
if (chatStyle2.CalcHeight(new GUIContent(chat), chatWindowRect.width - 26) > chatWindowRect.height - 43)
chatScrollPosition.y += scrollDifference;
}

// Create the chat window
Expand Down

0 comments on commit 2b95014

Please sign in to comment.