Ejemplo n.º 1
0
 public FileOutputTarget(string path)
 {
     file = new StreamWriter (path, true);
     thread = new ProgramThread ("LogF", OutputThread);
     thread.IsBackground = false;
     thread.Start ();
 }
        public static void Start(string dbPath)
        {
            LoginDatabase = new PropertiesFile(dbPath);
            LoginDatabase.Load();

            if (String.IsNullOrEmpty(_nonce))
            {
                var nonceFile = Path.Combine(Globals.DataPath, "rcon.nonce");

                if (File.Exists(nonceFile))
                    _nonce = File.ReadAllText(nonceFile);

                if (String.IsNullOrEmpty(_nonce))
                {
                    ProgramLog.Admin.Log("The rcon nonce value has not been set, one is being generated...");
                    var rand = new Random(Main.rand.Next(Int32.MinValue, Int32.MaxValue));
                    var length = rand.Next(12, 32);
                    var sb = new StringBuilder(length);

                    while (sb.Length != length)
                    {
                        System.Threading.Thread.Sleep(rand.Next(0, 200));

                        var chr = (char)(byte)rand.Next(0x20, 0x7E);
                        sb.Append(chr);
                    }
                    _nonce = sb.ToString();
                    File.WriteAllText(nonceFile, _nonce);
                    ProgramLog.Admin.Log("Saved nonce to {0}", nonceFile);
                }
            }

            if (LoginDatabase.Count == 0)
            {
                var bytes = new byte[8];
                (new Random((int)DateTime.Now.Ticks)).NextBytes(bytes);

                string password = String.Format("{0:x2}{1:x2}-{2:x2}{3:x2}-{4:x2}{5:x2}-{6:x2}{7:x2}",
                    bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]);
                string login = "******";
                ProgramLog.Admin.Log("The rcon login database was empty, a new user \"{1}\" has been created with password: {0}", password, login);

                LoginDatabase.SetValue(login, Hash(login, password));
            }

            LoginDatabase.Save();

            var bind = _bindAddress;
            var split = bind.Split(':');
            IPAddress addr;
            ushort port;

            if (split.Length != 2 || !IPAddress.TryParse(split[0], out addr) || !ushort.TryParse(split[1], out port) || port < 1)
            {
                ProgramLog.Error.Log("{0} is not a valid bind address, remote console disabled.", bind);
                return;
            }

            listener = new TcpListener(addr, port);

            try
            {
                listener.Start();
            }
            catch (Exception)
            {
                ProgramLog.Error.Log("Failed to bind to address {0}, remote console disabled.", bind);
                //ProgramLog.Log (exception, "Failed to bind to address 127.0.0.1:" + 7776);
                return;
            }

            thread = new ProgramThread("RCon", RConLoop);
            thread.Start();
        }
Ejemplo n.º 3
0
 public InteractiveLogTarget(string name, TextWriter writer)
 {
     this.writer = writer;
     thread = new ProgramThread (name, OutputThread);
     thread.Start ();
 }