private static void HandleRestartConnect() { if (Multiplayer.restartConnect == null) { return; } // No colon means the connect string is a steam user id if (!Multiplayer.restartConnect.Contains(':')) { if (ulong.TryParse(Multiplayer.restartConnect, out ulong steamUser)) { DoubleLongEvent(() => ClientUtil.TrySteamConnectWithWindow((CSteamID)steamUser, false), "MpConnecting"); } return; } var split = Multiplayer.restartConnect.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (split.Length == 2 && int.TryParse(split[1], out int port)) { DoubleLongEvent(() => ClientUtil.TryConnectWithWindow(split[0], port, false), "MpConnecting"); } }
private static void HandleCommandLine() { if (GenCommandLine.TryGetCommandLineArg("connect", out string addressPort) && Multiplayer.restartConnect == null) { int port = MultiplayerServer.DefaultPort; var split = addressPort.Split(':'); if (split.Length == 0) { addressPort = "127.0.0.1"; } else if (split.Length >= 1) { addressPort = split[0]; } if (split.Length == 2) { int.TryParse(split[1], out port); } DoubleLongEvent(() => ClientUtil.TryConnectWithWindow(addressPort, port, false), "Connecting"); } if (GenCommandLine.CommandLineArgPassed("arbiter")) { Multiplayer.username = "******"; Prefs.VolumeGame = 0; } if (GenCommandLine.TryGetCommandLineArg("replay", out string replay)) { DoubleLongEvent(() => { Replay.LoadReplay(Replay.ReplayFile(replay), true, () => { var rand = Find.Maps.Select(m => m.AsyncTime().randState).Select(s => $"{s} {(uint)s} {s >> 32}"); Log.Message($"timer {TickPatch.Timer}"); Log.Message($"world rand {Multiplayer.WorldComp.randState} {(uint)Multiplayer.WorldComp.randState} {Multiplayer.WorldComp.randState >> 32}"); Log.Message($"map rand {rand.ToStringSafeEnumerable()} | {Find.Maps.Select(m => m.AsyncTime().mapTicks).ToStringSafeEnumerable()}"); Application.Quit(); }); }, "Replay"); } if (GenCommandLine.CommandLineArgPassed("printsync")) { ExtendDirectXmlSaver.extend = true; DirectXmlSaver.SaveDataObject(new SyncContainer(), "SyncHandlers.xml"); ExtendDirectXmlSaver.extend = false; } }
private void DrawLan(Rect inRect) { using (MpStyle.Set(TextAnchor.MiddleCenter)) Widgets.Label(new Rect(inRect.x, 8f, inRect.width, 40), "MpLanSearching".Translate() + MpUI.FixedEllipsis()); inRect.yMin += 40f; float margin = 100; Rect outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 20); float height = servers.Count * 40; Rect viewRect = new Rect(0, 0, outRect.width - 16f, height); Widgets.BeginScrollView(outRect, ref lanScroll, viewRect, true); float y = 0; int i = 0; foreach (LanServer server in servers) { Rect entryRect = new Rect(0, y, viewRect.width, 40); if (i % 2 == 0) { Widgets.DrawAltRect(entryRect); } using (MpStyle.Set(TextAnchor.MiddleLeft)) Widgets.Label(entryRect.Right(5), "" + server.endpoint); Rect playButton = new Rect(entryRect.xMax - 75, entryRect.y + 5, 70, 40 - 10); if (Widgets.ButtonText(playButton, ">>")) { Close(false); Log.Message("Connecting to lan server"); var address = server.endpoint.Address.ToString(); var port = server.endpoint.Port; ClientUtil.TryConnectWithWindow(address, port); } y += entryRect.height; i++; } Widgets.EndScrollView(); }
private void DrawDirect(Rect inRect) { Multiplayer.settings.serverAddress = Widgets.TextField(new Rect(inRect.center.x - 200 / 2, 15f, 200, 35f), Multiplayer.settings.serverAddress); const float btnWidth = 115f; if (Widgets.ButtonText(new Rect(inRect.center.x - btnWidth / 2, 60f, btnWidth, 35f), "MpConnectButton".Translate())) { var addr = Multiplayer.settings.serverAddress.Trim(); var port = MultiplayerServer.DefaultPort; // If IPv4 or IPv6 address with optional port if (Endpoints.TryParse(addr, MultiplayerServer.DefaultPort, out var endpoint)) { addr = endpoint.Address.ToString(); port = endpoint.Port; } // Hostname with optional port else { var split = addr.Split(':'); addr = split[0]; if (split.Length == 2 && int.TryParse(split[1], out var parsedPort) && parsedPort is > IPEndPoint.MinPort and < IPEndPoint.MaxPort) { port = parsedPort; } } Log.Message("Connecting directly"); try { ClientUtil.TryConnectWithWindow(addr, port); Multiplayer.settings.Write(); Close(false); } catch (Exception e) { Messages.Message("MpInvalidAddress".Translate(), MessageTypeDefOf.RejectInput, false); Log.Error($"Exception while connecting directly {e}"); } } }