예제 #1
0
        static void ShowModDebugInfo()
        {
            var info = new RemoteData();

            JoinData.ReadServerData(JoinData.WriteServerData(true), info);
            for (int i = 0; i < 200; i++)
            {
                info.remoteMods.Add(info.remoteMods.Last());
            }
            info.remoteFiles.Add("rwmt.multiplayer", new ModFile()
            {
                relPath = "/Test/Test.xml"
            });
            //info.remoteFiles.Add("ludeon.rimworld", new ModFile() { relPath = "/Test/Test.xml" });

            Find.WindowStack.Add(new JoinDataWindow(info));
        }
예제 #2
0
        public static void HostServer(ServerSettings settings, bool fromReplay, bool hadSimulation, bool asyncTime)
        {
            Log.Message($"Starting the server");

            var session = new MultiplayerSession();

            if (Multiplayer.session != null) // This is the case when hosting from a replay
            {
                session.dataSnapshot = Multiplayer.session.dataSnapshot;
            }

            Multiplayer.session = session;

            session.myFactionId         = Faction.OfPlayer.loadID;
            session.localServerSettings = settings;
            session.gameName            = settings.gameName;

            // Server already pre-inited in HostWindow
            var localServer = Multiplayer.LocalServer;

            MultiplayerServer.instance = Multiplayer.LocalServer;

            if (hadSimulation)
            {
                localServer.savedGame      = GZipStream.CompressBuffer(session.dataSnapshot.gameData);
                localServer.semiPersistent = GZipStream.CompressBuffer(session.dataSnapshot.semiPersistentData);
                localServer.mapData        = session.dataSnapshot.mapData.ToDictionary(kv => kv.Key, kv => GZipStream.CompressBuffer(kv.Value));
                localServer.mapCmds        = session.dataSnapshot.mapCmds.ToDictionary(kv => kv.Key, kv => kv.Value.Select(ScheduledCommand.Serialize).ToList());
            }

            localServer.commands.debugOnlySyncCmds = Sync.handlers.Where(h => h.debugOnly).Select(h => h.syncId).ToHashSet();
            localServer.commands.hostOnlySyncCmds  = Sync.handlers.Where(h => h.hostOnly).Select(h => h.syncId).ToHashSet();
            localServer.hostUsername  = Multiplayer.username;
            localServer.coopFactionId = Faction.OfPlayer.loadID;

            localServer.rwVersion  = VersionControl.CurrentVersionString;
            localServer.mpVersion  = MpVersion.Version;
            localServer.defInfos   = MultiplayerData.localDefInfos;
            localServer.serverData = JoinData.WriteServerData(settings.syncConfigs);

            if (settings.steam)
            {
                localServer.TickEvent += SteamIntegration.ServerSteamNetTick;
            }

            if (fromReplay)
            {
                localServer.gameTimer = TickPatch.Timer;
            }

            if (!fromReplay)
            {
                SetupGameFromSingleplayer();
            }

            foreach (var tickable in TickPatch.AllTickables)
            {
                tickable.Cmds.Clear();
            }

            Find.PlaySettings.usePlanetDayNightSystem = false;

            Multiplayer.RealPlayerFaction = Faction.OfPlayer;
            localServer.playerFactions[Multiplayer.username] = Faction.OfPlayer.loadID;

            SetupLocalClient();

            Find.MainTabsRoot.EscapeCurrentTab(false);

            Multiplayer.session.AddMsg("If you are having any issues with the mod and would like some help resolving them, then please reach out to us on our Discord server:", false);
            Multiplayer.session.AddMsg(new ChatMsg_Url("https://discord.gg/S4bxXpv"), false);

            if (hadSimulation)
            {
                StartServerThread();
            }
            else
            {
                Multiplayer.WorldComp.TimeSpeed = TimeSpeed.Paused;
                foreach (var map in Find.Maps)
                {
                    map.AsyncTime().TimeSpeed = TimeSpeed.Paused;
                }

                Multiplayer.WorldComp.UpdateTimeSpeed();

                Multiplayer.GameComp.asyncTime       = asyncTime;
                Multiplayer.GameComp.debugMode       = settings.debugMode;
                Multiplayer.GameComp.logDesyncTraces = settings.desyncTraces;

                LongEventHandler.QueueLongEvent(() =>
                {
                    Multiplayer.session.dataSnapshot = SaveLoad.CreateGameDataSnapshot(SaveLoad.SaveAndReload());
                    SaveLoad.SendGameData(Multiplayer.session.dataSnapshot, false);

                    StartServerThread();
                }, "MpSaving", false, null);
            }

            void StartServerThread()
            {
                localServer.running = true;

                Multiplayer.LocalServer.serverThread = new Thread(localServer.Run)
                {
                    Name = "Local server thread"
                };
                Multiplayer.LocalServer.serverThread.Start();

                const string text = "Server started.";

                Messages.Message(text, MessageTypeDefOf.SilentInput, false);
                Log.Message(text);
            }
        }