コード例 #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
         }
     }
 }