Ejemplo n.º 1
0
        private static void OnJoinGameButtonClick()
        {
            string[] parts = hostIPAdressInput.text.Split(':');
            string   ip    = parts[0];
            int      port;

            if (parts.Length == 1)
            {
                // Use default port
                port = 8469;
            }
            else if (!int.TryParse(parts[1], out port))
            {
                Log.Info($"Port must be a valid number above 1024");
                return;
            }

            Log.Info($"Connecting to server... {ip}:{port}");

            Object.FindObjectOfType <MultiplayerSession>().Connect(ip, port);

            // TODO: Should display a loader during the connection and only open the game once the player as connected to the server.
            // TODO: We should also wait to receive the actual game seed to make sure that we can load the same map and wait for the InitialGameState packet to update the game world properly.

            multiplayerMenu.gameObject.SetActive(false);
            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(UniverseGen.algoVersion, 1, 64, 1, 1f);
            DSPGame.StartGameSkipPrologue(gameDesc);
        }
Ejemplo n.º 2
0
        private static void OnJoinGameButtonClick()
        {
            string[] parts = hostIPAdressInput.text.Split(':');
            string   ip    = parts[0];
            int      port;

            if (parts.Length == 1)
            {
                // Use default port
                port = 8469;
            }
            else if (!int.TryParse(parts[1], out port))
            {
                Log.Info($"Port must be a valid number above 1024");
                return;
            }

            Log.Info($"Connecting to server... {ip}:{port}");

            Object.FindObjectOfType <MultiplayerSession>().Connect(ip, port);

            // TODO: Should display a loader during the connection and only open the game once the player is connected to the server.
            multiplayerMenu.gameObject.SetActive(false);

            // TODO: For now I'm only starting the same world on all clients by using the same seed. But we will need to change this
            // code to instead share the save game to all clients that join the game to make sure that everyone has the same initial state.
            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(UniverseGen.algoVersion, 1, 64, 1, 1f);
            DSPGame.StartGameSkipPrologue(gameDesc);
        }
Ejemplo n.º 3
0
        public static bool EnterGame_Prefix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsInMultiplayerMenu)
            {
                Multiplayer.Session.IsInLobby = false;

                if (UIVirtualStarmap_Transpiler.customBirthPlanet != -1)
                {
                    Log.Debug((GameMain.data.galaxy.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet) == null) ? "null" : "not null");
                    GameMain.data.galaxy.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet)?.UnloadFactory();
                }

                if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)
                {
                    UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false);

                    GameDesc gameDesc = __instance.gameDesc;
                    DSPGame.StartGameSkipPrologue(gameDesc);
                }
                else
                {
                    Multiplayer.Session.Network.SendPacket(new StartGameMessage());
                }
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public override void ProcessPacket(HandshakeResponse packet, NebulaConnection conn)
        {
            using (BinaryUtils.Reader p = new BinaryUtils.Reader(packet.ModsSettings))
            {
                for (int i = 0; i < packet.ModsSettingsCount; i++)
                {
                    string     guid = p.BinaryReader.ReadString();
                    PluginInfo info = Chainloader.PluginInfos[guid];
                    if (info.Instance is IMultiplayerModWithSettings mod)
                    {
                        mod.Import(p.BinaryReader);
                    }
                }
            }

            // overwrite local setting with host setting, but dont save it as its a temp setting for this session
            Config.Options.SyncSoil = packet.SyncSoil;

            ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false;
            ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, packet.IsNewPlayer);

            Multiplayer.Session.IsInLobby      = false;
            Multiplayer.ShouldReturnToJoinMenu = false;

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            DSPGame.StartGameSkipPrologue(gameDesc);

            InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
        }
Ejemplo n.º 5
0
        // TODO: Remove all this once we change the way we deal with hosting a game.
        // We could it should probably be done from the in game Esc Menu.
        private static void OnHostGameButtonClick()
        {
            string[] parts = hostIPAdressInput.text.Split(':');
            int      port;

            if (parts.Length == 1)
            {
                port = Config.DefaultPort;
            }
            else if (!int.TryParse(parts[1], out port))
            {
                Log.Info($"Port must be a valid number above 1024");
                return;
            }

            multiplayerMenu.gameObject.SetActive(false);

            Log.Info($"Listening server on port {port}");
            var session = NebulaBootstrapper.Instance.CreateMultiplayerHostSession();

            session.StartServer(port);

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(UniverseGen.algoVersion, 1, 64, 1, 1f);
            DSPGame.StartGameSkipPrologue(gameDesc);
        }
Ejemplo n.º 6
0
        public void LeaveGame()
        {
            Disconnect();

            // Go back to the main menu
            if (!UIRoot.instance.backToMainMenu)
            {
                UIRoot.instance.backToMainMenu = true;
                DSPGame.EndGame();
            }
        }
Ejemplo n.º 7
0
        public static void LeaveGame()
        {
            networkProvider.DestroySession();
            SimulatedWorld.Clear();

            if (!UIRoot.instance.backToMainMenu)
            {
                UIRoot.instance.backToMainMenu = true;
                DSPGame.EndGame();
            }
        }
        public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn)
        {
            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            DSPGame.StartGameSkipPrologue(gameDesc);

            LocalPlayer.IsMasterClient = false;
            LocalPlayer.SetPlayerData(packet.LocalPlayerData);

            InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
        }
Ejemplo n.º 9
0
        public static void LeaveGame()
        {
            networkProvider.DestroySession();
            PendingFactories.Clear();
            IsMasterClient = false;
            SimulatedWorld.Clear();

            if (!UIRoot.instance.backToMainMenu)
            {
                UIRoot.instance.backToMainMenu = true;
                DSPGame.EndGame();
            }
        }
Ejemplo n.º 10
0
        public static bool EnterGame_Prefix(UIGalaxySelect __instance)
        {
            if (MainMenuManager.IsInMultiplayerMenu)
            {
                Log.Info($"Listening server on port {Config.DefaultPort}");
                var session = NebulaBootstrapper.Instance.CreateMultiplayerHostSession();
                session.StartServer(Config.DefaultPort);

                GameDesc gameDesc = AccessTools.Field(__instance.GetType(), "gameDesc").GetValue(__instance) as GameDesc;
                DSPGame.StartGameSkipPrologue(gameDesc);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
0
 public static void StartDedicatedServer(string saveName)
 {
     // Mimic UI buttons clicking
     UIMainMenu_Patch.OnMultiplayerButtonClick();
     if (GameSave.SaveExist(saveName))
     {
         // Modified from DoLoadSelectedGame
         Log.Info($"Start dedicated server, loading save : {saveName}");
         DSPGame.StartGame(saveName);
         Log.Info($"Listening server on port {NebulaModel.Config.Options.HostPort}");
         Multiplayer.HostGame(new Server(NebulaModel.Config.Options.HostPort, true));
         if (command_ups != 0)
         {
             FPSController.SetFixUPS(command_ups);
         }
     }
 }
Ejemplo n.º 12
0
        public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn)
        {
            if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length > 1) // if host does not use GS2 we send a null byte
            {
                LocalPlayer.GS2ApplySettings(packet.CompressedGS2Settings);
            }
            else if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length == 1)
            {
                InGamePopup.ShowWarning("Galactic Scale - Server not supported", "The server does not seem to use Galactic Scale. Make sure that your mod configuration matches.", "Close");
                return;
            }

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            DSPGame.StartGameSkipPrologue(gameDesc);

            LocalPlayer.IsMasterClient = false;
            LocalPlayer.SetPlayerData(packet.LocalPlayerData);

            InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
        }
Ejemplo n.º 13
0
        public override void ProcessPacket(StartGameMessage packet, NebulaConnection conn)
        {
            if (IsHost)
            {
                if (Multiplayer.Session.IsGameLoaded && !GameMain.isFullscreenPaused)
                {
                    INebulaPlayer player;
                    using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers))
                    {
                        if (!pendingPlayers.TryGetValue(conn, out player))
                        {
                            conn.Disconnect(DisconnectionReason.InvalidData);
                            Log.Warn("WARNING: Player tried to enter the game without being in the pending list");
                            return;
                        }

                        pendingPlayers.Remove(conn);
                    }

                    // Add the new player to the list
                    using (playerManager.GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers))
                    {
                        syncingPlayers.Add(conn, player);
                    }

                    Multiplayer.Session.World.OnPlayerJoining(player.Data.Username);
                    NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data);

                    // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
                    PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData(), Multiplayer.Session.NumPlayers); // Remove inventory from mecha data
                    using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
                    {
                        foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers)
                        {
                            kvp.Value.SendPacket(pdata);
                        }
                    }

                    //Add current tech bonuses to the connecting player based on the Host's mecha
                    ((MechaData)player.Data.Mecha).TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha);

                    conn.SendPacket(new StartGameMessage(true, (PlayerData)player.Data, Config.Options.SyncSoil));
                }
                else
                {
                    conn.SendPacket(new StartGameMessage(false, null, false));
                }
            }
            else if (packet.IsAllowedToStart)
            {
                // overwrite local setting with host setting, but dont save it as its a temp setting for this session
                Config.Options.SyncSoil = packet.SyncSoil;

                ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false;
                ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, true);

                UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false);
                Multiplayer.Session.IsInLobby      = false;
                Multiplayer.ShouldReturnToJoinMenu = false;

                DSPGame.StartGameSkipPrologue(UIRoot.instance.galaxySelect.gameDesc);

                InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
            }
            else
            {
                InGamePopup.ShowInfo("Please Wait", "The host is not ready to let you in, please wait!", "Okay");
            }
        }