public override void ProcessPacket(LobbyResponse 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);
                    }
                }
            }
            ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false;
            Multiplayer.Session.NumPlayers = packet.NumPlayers;
            Multiplayer.Session.IsInLobby  = true;
            DiscordManager.UpdateRichPresence(partyId: packet.DiscordPartyId);

            UIRoot.instance.galaxySelect._Open();
            UIRoot.instance.uiMainMenu._Close();

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.GalaxyAlgo, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            gameDesc.savedThemeIds = packet.SavedThemeIds;

            UIRoot.instance.galaxySelect.gameDesc = gameDesc;
            UIRoot.instance.galaxySelect.SetStarmapGalaxy();
        }
示例#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);
        }
示例#3
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);
        }
示例#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);
        }
示例#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);
        }
        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);
        }
        public override void ProcessPacket(LobbyUpdateValues packet, NebulaConnection conn)
        {
            if (IsHost)
            {
                return;
            }

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.GalaxyAlgo, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);

            UIRoot.instance.galaxySelect.gameDesc = gameDesc;
            UIRoot.instance.galaxySelect.SetStarmapGalaxy();
        }
示例#8
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);
        }
示例#9
0
            public static void exportSeed(int seed)
            {
                UnityEngine.Debug.Log("exportSeed:" + seed);
                // set up memoryStream to write output to
                memoryStream = new MemoryStream();
                streamWriter = new StreamWriter((Stream)memoryStream);
                string path = seedExporterDir + "seed_" + seed + ".json";

                // create new galaxy
                GameDesc gameDesc = new GameDesc();

                gameDesc.SetForNewGame(UniverseGen.algoVersion, seed, 64, 1, 1f);
                GalaxyData galaxy = UniverseGen.CreateGalaxy(gameDesc);

                // dump to json
                streamWriter.Write("{\"meta\":{" +
                                   "\"gameVersion\":\"" + GameConfig.gameVersion.ToFullString() + "\"" +
                                   ",\"toolVersion\":\"0.0.1.0\"" +
                                   ",\"seed\":" + seed +
                                   ",\"starCount\":" + galaxy.starCount +
                                   ",\"birthPlanetId\":" + galaxy.birthPlanetId +
                                   ",\"birthStarId\":" + galaxy.birthStarId +
                                   ",\"habitableCount\":" + galaxy.habitableCount +
                                   "},");         // opens main dict
                streamWriter.Write("\"star\":{"); // open star dict
                for (int i = 0; i < galaxy.stars.Length; i++)
                {
                    if (i > 0)
                    {
                        streamWriter.Write(",");
                    }
                    var star = galaxy.stars[i];
                    streamWriter.Write("\"" + star.name + "\":{" +
                                       "\"seed\":" + star.seed +
                                       ",\"index\":" + star.index +
                                       ",\"id\":" + star.id +
                                       ",\"name\":\"" + star.name + "\"" +
                                       ",\"position\":{\"x\":" + star.position.x + ",\"y\":" + star.position.y + ",\"z\":" + star.position.z + "}" +
                                       ",\"uPosition\":{\"x\":" + star.uPosition.x + ",\"y\":" + star.uPosition.y + ",\"z\":" + star.uPosition.z + "}" +
                                       ",\"mass\":" + star.mass +
                                       ",\"lifetime\":" + star.lifetime +
                                       ",\"age\":" + star.age +
                                       ",\"type\":" + (int)star.type +
                                       ",\"temperature\":" + star.temperature +
                                       ",\"spectr\":" + (int)star.spectr +
                                       ",\"classFactor\":" + star.classFactor +
                                       ",\"color\":" + star.color +
                                       ",\"luminosity\":" + star.luminosity +
                                       ",\"radius\":" + star.radius +
                                       ",\"acdiskRadius\":" + star.acdiskRadius +
                                       ",\"habitableRadius\":" + star.habitableRadius +
                                       ",\"lightBalanceRadius\":" + star.lightBalanceRadius +
                                       ",\"dysonRadius\":" + star.dysonRadius +
                                       ",\"orbitScaler\":" + star.orbitScaler +
                                       ",\"asterBelt1OrbitIndex\":" + star.asterBelt1OrbitIndex +
                                       ",\"asterBelt2OrbitIndex\":" + star.asterBelt2OrbitIndex +
                                       ",\"asterBelt1Radius\":" + star.asterBelt1Radius +
                                       ",\"asterBelt2Radius\":" + star.asterBelt2Radius +
                                       ",\"planetCount\":" + star.planetCount +
                                       ",\"level\":" + star.level +
                                       ",\"resourceCoef\":" + star.resourceCoef +
                                       ",\"planet\":{"
                                       ); // initial data, open planet[]
                    firstPlanet = true;
                    for (int j = 0; j < star.planets.Length; j++)
                    {
                        exportStar(star.planets[j]);
                    }
                    streamWriter.Write("}}"); // close planet[] and star dicts
                }
                streamWriter.Write("}");      // close star[] dict

                streamWriter.Write("}");      // closes main dict
                // free the galaxy
                galaxy.Free();

                // close the stream, after flushing it.
                streamWriter.Flush();
                if (memoryStream != null && memoryStream.Length > 0)
                {
                    UnityEngine.Debug.Log("DSP_SeedExporter: dumping to: " + path);
                    using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        memoryStream.WriteTo(fileStream);
                        fileStream.Flush();
                        fileStream.Close();
                        streamWriter.Close();
                        memoryStream.Close();
                        memoryStream = null;
                    }
                }
            }
        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()); // 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;

                GameDesc gameDesc = UIRoot.instance.galaxySelect.gameDesc;
                gameDesc.SetForNewGame(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, 1, gameDesc.resourceMultiplier);
                DSPGame.StartGameSkipPrologue(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");
            }
        }