Ejemplo n.º 1
0
        private static async void ActivityManager_OnActivityJoin(string secret)
        {
            if (Multiplayer.IsActive)
            {
                Log.Warn("Cannot join lobby from Discord, we are already in a lobby.");
                return;
            }

            if (string.IsNullOrWhiteSpace(secret))
            {
                Log.Warn("Received Discord invite without IP address.");
                return;
            }

            var ipAddresses = secret.FromBase64().Split(';');

            if (ipAddresses.Length != 1 && ipAddresses.Length != 3)
            {
                Log.Warn("Received invalid discord invite.");
                return;
            }

            string ipAddress = string.Empty;

            if (ipAddresses.Length == 1 && ipAddresses[0].Contains("ngrok"))
            {
                ipAddress = ipAddresses[0];
            }

            if (string.IsNullOrWhiteSpace(ipAddress) && await IPUtils.IsIPv6Supported())
            {
                if (ipAddresses.Length > 1)
                {
                    if (IPUtils.IsIPv6(ipAddresses[1]))
                    {
                        ipAddress = $"{ipAddresses[1]}:{ipAddresses[2]}";
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(ipAddress))
            {
                if (IPUtils.IsIPv4(ipAddresses[0]))
                {
                    ipAddress = $"{ipAddresses[0]}:{ipAddresses[2]}";
                }
            }

            if (string.IsNullOrWhiteSpace(ipAddress))
            {
                Log.Warn("Received Discord invite with invalid IP address.");
                return;
            }

            Log.Info("Joining lobby from Discord...");
            UIMainMenu_Patch.OnMultiplayerButtonClick();
            UIMainMenu_Patch.JoinGame($"{ipAddress}");
            DiscordManager.UpdateRichPresence(ip: secret, secretPassthrough: true, updateTimestamp: true);
        }
Ejemplo n.º 2
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);
         }
     }
 }