Beispiel #1
0
        public void Enable()
        {
            Harmony.PatchAll();
            foreach (var arg in Environment.GetCommandLineArgs())
            {
                const string consoleArg = "-console";

                if (arg.StartsWith(consoleArg))
                {
                    if (ushort.TryParse(arg.Substring(consoleArg.Length), out var consolePort))
                    {
                        ConsolePort = consolePort;
                    }
                }
            }

            ServerConsole.AddLog($"Starting TcpClient on port {ConsolePort}");

            TcpClient = new TcpClient();

            try
            {
                TcpClient.Connect(new IPEndPoint(IPAddress.Loopback, ConsolePort));
            }
            catch
            {
                return;
            }

            SendMessage("LocalAdminPlus Companion connected!");

            var streamReader = new StreamReader(TcpClient.GetStream());

            Task.Run(async() =>
            {
                while (true)
                {
                    if (!streamReader.EndOfStream)
                    {
                        ServerConsole.EnterCommand(streamReader.ReadLine());
                    }

                    await Task.Delay(10);
                }
            });
        }
    private static IEnumerator CheckLog()
    {
        if (PlayerPrefs.GetString("server_accepted", "false") != "true")
        {
            StreamWriter sw = new StreamWriter(string.Concat(new object[]
            {
                "SCPSL_Data/Dedicated/",
                ServerConsole.session,
                "/sl",
                ServerConsole.logID,
                ".mapi"
            }));
            ServerConsole.logID++;
            sw.WriteLine("THE PROJECT OWNERS  (HUBERT MOSZKA & WESLEY VAN VELSEN) RESERVE THE RIGHT TO OVERRIDE ACCESS TO THE REMOTE ADMIN PANEL LOGTYPE-12");
            sw.Close();
            sw = new StreamWriter(string.Concat(new object[]
            {
                "SCPSL_Data/Dedicated/",
                ServerConsole.session,
                "/sl",
                ServerConsole.logID,
                ".mapi"
            }));
            ServerConsole.logID++;
            sw.WriteLine("TYPE 'Yes, I accept' if you agree LOGTYPE-12");
            sw.Close();
            ServerConsole.accepted = false;
            while (!ServerConsole.accepted)
            {
                string[] tasks = Directory.GetFiles("SCPSL_Data/Dedicated/" + ServerConsole.session, "cs*.mapi", SearchOption.TopDirectoryOnly);
                foreach (string task in tasks)
                {
                    string       t       = task.Remove(0, task.IndexOf("cs"));
                    StreamReader sr      = new StreamReader("SCPSL_Data/Dedicated/" + ServerConsole.session + "/" + t);
                    string       content = sr.ReadToEnd();
                    sr.Close();
                    File.Delete("SCPSL_Data/Dedicated/" + ServerConsole.session + "/" + t);
                    if (content.ToUpper().Contains("YES, I ACCEPT"))
                    {
                        PlayerPrefs.SetString("server_accepted", "true");
                        sw = new StreamWriter(string.Concat(new object[]
                        {
                            "SCPSL_Data/Dedicated/",
                            ServerConsole.session,
                            "/sl",
                            ServerConsole.logID,
                            ".mapi"
                        }));
                        ServerConsole.logID++;
                        sw.WriteLine("Cool! Let me just restart the session... LOGTYPE-10");
                        sw.Close();
                        yield return(new WaitForSeconds(5f));

                        ServerConsole.TerminateProcess();
                    }
                    else
                    {
                        ServerConsole.TerminateProcess();
                    }
                }
                yield return(new WaitForSeconds(0.07f));
            }
            yield return(new WaitForSeconds(1f));

            if (ServerConsole.consoleID == null || ServerConsole.consoleID.HasExited)
            {
                ServerConsole.TerminateProcess();
            }
        }
        yield return(new WaitForSeconds(10f));

        for (;;)
        {
            string[] tasks2 = Directory.GetFiles("SCPSL_Data/Dedicated/" + ServerConsole.session, "cs*.mapi", SearchOption.TopDirectoryOnly);
            foreach (string task2 in tasks2)
            {
                string t2        = task2.Remove(0, task2.IndexOf("cs"));
                string toLog     = string.Empty;
                string exception = string.Empty;
                try
                {
                    exception = "Error while reading the file: " + t2;
                    StreamReader streamReader = new StreamReader("SCPSL_Data/Dedicated/" + ServerConsole.session + "/" + t2);
                    string       text         = streamReader.ReadToEnd();
                    if (text.Contains("terminator"))
                    {
                        text = text.Remove(text.LastIndexOf("terminator"));
                    }
                    toLog = ServerConsole.EnterCommand(text);
                    try
                    {
                        exception = "Error while closing the file: " + t2 + " :: " + text;
                    }
                    catch
                    {
                    }
                    streamReader.Close();
                    try
                    {
                        exception = "Error while deleting the file: " + t2 + " :: " + text;
                    }
                    catch
                    {
                    }
                    File.Delete("SCPSL_Data/Dedicated/" + ServerConsole.session + "/" + t2);
                }
                catch
                {
                }
                if (!string.IsNullOrEmpty(toLog))
                {
                    ServerConsole.AddLog(toLog);
                }
                yield return(new WaitForSeconds(0.07f));
            }
            yield return(new WaitForSeconds(1f));

            if (ServerConsole.consoleID == null || ServerConsole.consoleID.HasExited)
            {
                ServerConsole.TerminateProcess();
            }
        }
        yield break;
    }