示例#1
0
文件: Program.cs 项目: Gachl/RustRcon
        static void Main(string[] args)
        {
            // Initialise connection
            Rcon rcon = new Rcon("rust.yourserver.com", 26101, "your rcon passphrase");

            // Single command
            rcon.Send("say \"Thank [color#FF0000]you [color#FFFFFF]for choosing this RCON class.\"");

            // Command with (multipart) reply
            Package command = new Package("banlistex");
            command.RegisterCallback((Package result) => { rcon.Send(String.Format("say \"There are {0} entries on your ban list.\"", result.Response.Split('\n').Length)); }); // Note that result and command are the same object.

            rcon.SendPackage(command);

            // Handle passive traffic (eg. chat, join and quit messages, ...)
            Task passive = new Task(() =>
                {
                    while (true)
                    {
                        Package package = rcon.ReadPackage();
                        if (Regex.IsMatch(package.Response, "^\\[CHAT\\] \\\".*\\\":\\\".*\\\"$"))
                            Console.WriteLine("Chat message received.");
                        else if (Regex.IsMatch(package.Response, "^User Connected: .* \\(\\d+\\)$"))
                            Console.WriteLine("User connected.");
                    }
                });
            passive.Start();
            Task.WaitAll(new Task[] { passive });
        }
示例#2
0
文件: Reader.cs 项目: Gachl/RustRcon
 /// <summary>
 /// Start the reader.
 /// </summary>
 public void Run(Rcon rcon)
 {
     while (Running)
     {
         Int32 size = readSize();
         Int32 id = readId();
         Int32 type = readType();
         string body = readEnd();
         if (id == 1) // Ignore all packages with ID 1 (buffer duplicate)
             continue;
         rcon.UpdatePackage(new Package(id, type, body));
     }
 }
示例#3
0
 /// <summary>
 /// Start the reader.
 /// </summary>
 public void Run(Rcon rcon)
 {
     while (Running)
     {
         Int32  size = readSize();
         Int32  id   = readId();
         Int32  type = readType();
         string body = readEnd();
         if (id == 1) // Ignore all packages with ID 1 (buffer duplicate)
         {
             continue;
         }
         rcon.UpdatePackage(new Package(id, type, body));
     }
 }
示例#4
0
 /// <summary>
 /// Start the reader.
 /// </summary>
 public void Run(Rcon rcon)
 {
     while (Running)
     {
         try
         {
             Int32  size = readSize();
             Int32  id   = readId();
             Int32  type = readType();
             string body = readEnd(size - 8);
             if (id == 1) // Ignore all packages with ID 1 (buffer duplicate)
             {
                 continue;
             }
             rcon.UpdatePackage(new Package(id, type, body));
         }
         catch (IllegalProtocolException e)
         {
             // Ignore
         }
     }
 }