示例#1
0
        private void TryHost()
        {
            if (direct && !TryParseIp(addressBuffer, out settings.bindAddress, out settings.bindPort))
            {
                return;
            }

            if (!direct)
            {
                settings.bindAddress = null;
            }

            if (!lan)
            {
                settings.lanAddress = null;
            }

            if (file == null)
            {
                ClientUtil.HostServer(settings, false);
            }
            else if (file.replay)
            {
                HostFromReplay(settings);
            }
            else
            {
                HostFromSave(settings);
            }

            Close(true);
        }
示例#2
0
        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");
            }
        }
示例#3
0
        public ConnectingWindow(string address, int port)
        {
            this.address = address;
            this.port    = port;

            ClientUtil.TryConnect(address, port);
        }
示例#4
0
        public ConnectingWindow(IPAddress address, int port)
        {
            this.address = address;
            this.port    = port;

            addressStr = address?.ToString();

            ClientUtil.TryConnect(address, port);
        }
示例#5
0
        private void HostFromReplay(ServerSettings settings)
        {
            TickPatch.disableSkipCancel = true;

            Replay.LoadReplay(file.fileName, true, () =>
            {
                ClientUtil.HostServer(settings, true);
            });
        }
示例#6
0
        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 HostFromReplay(ServerSettings settings)
        {
            void ReplayLoaded() => ClientUtil.HostServer(settings, true, withSimulation, debugMode: debugMode);

            if (file != null)
            {
                Replay.LoadReplay(file.file, true, ReplayLoaded, cancel: GenScene.GoToMainMenu, simTextKey: "MpSimulatingServer");
            }
            else
            {
                ReplayLoaded();
            }
        }
示例#8
0
        private void HostFromSave(ServerSettings settings)
        {
            LongEventHandler.QueueLongEvent(() =>
            {
                MemoryUtility.ClearAllMapsAndWorld();
                Current.Game                     = new Game();
                Current.Game.InitData            = new GameInitData();
                Current.Game.InitData.gameToLoad = file.displayName;

                LongEventHandler.ExecuteWhenFinished(() =>
                {
                    LongEventHandler.QueueLongEvent(() => ClientUtil.HostServer(settings, false, debugMode: debugMode), "MpLoading", false, null);
                });
            }, "Play", "LoadingLongEvent", true, null);
        }
示例#9
0
        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();
        }
示例#10
0
        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}");
                }
            }
        }
        public void HandleModList(ByteReader data)
        {
            Multiplayer.session.mods.remoteRwVersion = data.ReadString();
            Multiplayer.session.mods.remoteModNames  = data.ReadPrefixedStrings();

            var defs = ClientUtil.CollectDefInfos();

            Multiplayer.session.mods.defInfo = defs;

            var response = new ByteWriter();

            response.WriteInt32(defs.Count);

            foreach (var kv in defs)
            {
                response.WriteString(kv.Key);
                response.WriteInt32(kv.Value.count);
                response.WriteInt32(kv.Value.hash);
            }

            connection.Send(Packets.Client_Defs, response.ToArray());
        }
示例#12
0
        private void TryHost()
        {
            if (settings.direct && !TryParseIp(settings.directAddress, out settings.bindAddress4, out settings.bindAddress6, out settings.bindPort))
            {
                return;
            }

            if (settings.gameName.NullOrEmpty())
            {
                Messages.Message("MpInvalidGameName".Translate(), MessageTypeDefOf.RejectInput, false);
                return;
            }

            if (!settings.direct)
            {
                settings.bindAddress4 = null;
                settings.bindAddress6 = null;
            }

            if (!settings.lan)
            {
                settings.lanAddress = null;
            }

            if (file?.replay ?? Multiplayer.IsReplay)
            {
                HostFromReplay(settings);
            }
            else if (file == null)
            {
                ClientUtil.HostServer(settings, false, debugMode: debugMode, logDesyncTraces: logDesyncTraces);
            }
            else
            {
                HostFromSave(settings);
            }

            Close(true);
        }
示例#13
0
        private void DrawSteam(Rect inRect)
        {
            string info = null;

            if (!SteamManager.Initialized)
            {
                info = "MpNotConnectedToSteam".Translate();
            }
            else if (friends.Count == 0)
            {
                info = "MpNoFriendsPlaying".Translate();
            }

            if (info != null)
            {
                using (MpStyle.Set(TextAnchor.MiddleCenter))
                    Widgets.Label(new Rect(0, 8, inRect.width, 40f), info);

                inRect.yMin += 40f;
            }

            float margin  = 80;
            Rect  outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 20);

            float height   = friends.Count * 40;
            Rect  viewRect = new Rect(0, 0, outRect.width - 16f, height);

            Widgets.BeginScrollView(outRect, ref steamScroll, viewRect, true);

            float y = 0;
            int   i = 0;

            foreach (SteamPersona friend in friends)
            {
                Rect entryRect = new Rect(0, y, viewRect.width, 40);
                if (i % 2 == 0)
                {
                    Widgets.DrawAltRect(entryRect);
                }

                if (Event.current.type == EventType.Repaint)
                {
                    GUI.DrawTextureWithTexCoords(new Rect(5, entryRect.y + 4, 32, 32), SteamImages.GetTexture(friend.avatar), new Rect(0, 1, 1, -1));
                }

                using (MpStyle.Set(TextAnchor.MiddleLeft))
                    Widgets.Label(entryRect.Right(45).Up(5), friend.username);

                using (MpStyle.Set(GameFont.Tiny))
                    using (MpStyle.Set(TextAnchor.MiddleLeft))
                        using (MpStyle.Set(SteamGreen))
                            Widgets.Label(entryRect.Right(45).Down(8), "MpPlayingRimWorld".Translate());

                if (friend.serverHost != CSteamID.Nil)
                {
                    Rect playButton = new Rect(entryRect.xMax - 85, entryRect.y + 5, 80, 40 - 10);
                    if (Widgets.ButtonText(playButton, "MpJoinButton".Translate()))
                    {
                        Close(false);
                        ClientUtil.TrySteamConnectWithWindow(friend.serverHost);
                    }
                }
                else
                {
                    Rect playButton = new Rect(entryRect.xMax - 125, entryRect.y + 5, 120, 40 - 10);
                    Widgets.ButtonText(playButton, "MpNotInMultiplayer".Translate(), false, false, false);
                }

                y += entryRect.height;
                i++;
            }

            Widgets.EndScrollView();
        }