コード例 #1
0
ファイル: Server.cs プロジェクト: dretax/SquadRconTool
        public Server()
        {
            bool success = LoadSettings();

            if (!success)
            {
                Logger.Log("Config failure, shutting down...");
                Thread.Sleep(1000);
                return;
            }

            GenerateSelfSignedCertificate();

            SquadServerLoader.LoadServers();
            PermissionLoader.LoadPermissions();
            ValidateServers();

            IPAddress listenip = IPAddress.Any;

            if (ListenIPAddress.ToLower() != "any")
            {
                if (!IPAddress.TryParse(ListenIPAddress, out listenip))
                {
                    Logger.Log("Failed to convert listen ip to an actual IP Address. Listening on all.");
                }
            }

            // Remove insecure protocols (SSL3, TLS 1.0, TLS 1.1)
            ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
            ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
            ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11;
            // Add TLS 1.2, and 1.3
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls13;

            TCPServer = new TcpListener(listenip, ListenPort);
            TCPServer.Start();
            Logger.Log("[TCPServer] Listening for incoming connections. IP: " + listenip + " Port: " + ListenPort);
            Thread t = new Thread(ListenForIncomingConnections);

            t.IsBackground = true;
            t.Start();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            Logger.Init();
            Logger.Log("Squad Rcon Bridge Server Created by " + Author + " v" + Version);
            Logger.Log("Respository Link: " + Github);
            Logger.Log("More Contact: " + WebSite + " " + Discord);
            Logger.Log("Initializing TCP...");
            _srv = new Server();

            while (_isrunning)
            {
                string input = Console.ReadLine();
                switch (input)
                {
                case "quit":
                    _srv.StopConnections();
                    _isrunning = false;
                    Logger.Log("Shutting down TCP Server.");
                    break;

                case "reloadperms":
                    PermissionLoader.LoadPermissions();
                    Logger.Log("Permissions reloaded.");
                    break;

                case "adduser":
                    Console.WriteLine("Please enter a username");
                    string username = Console.ReadLine();
                    Console.WriteLine("Please enter a password. I suggest generating one.");
                    string password = Console.ReadLine();
                    Console.WriteLine("Username: "******"Password: "******"Add user? (Y / N) Default permissions will be applied.");
                    string ok = Console.ReadLine();
                    if (ok != null && ok.ToLower() == "y")
                    {
                        PermissionLoader.AddUser(username, password);
                        Console.WriteLine(username + " added. Edit permissions in the ini file, and reload.");
                    }
                    break;

                case "changepassword":
                    break;

                case "removeuser":
                    break;

                case "cleartokens":
                    TokenHandler.ClearTokens();
                    Logger.Log("Tokens cleared!");
                    break;

                case "help":
                    break;

                default:
                    Logger.Log("Unknown command. Type 'help' to display all of the commands.");
                    break;
                }
            }
            Logger.Log("Press something to exit...");
            Console.ReadKey();
        }