Advertisement
Guest User

Untitled

a guest
Sep 29th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2.  
  3. using TS3QueryLib.Core;
  4. using TS3QueryLib.Core.Client;
  5.  
  6. namespace tsbot
  7. {
  8.     class App
  9.     {
  10.         private AsyncTcpDispatcher AsyncQueryDispatcher;
  11.         private TS3QueryLib.Core.Server.QueryRunner AsyncServerQueryRunner;
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             new App().Start();
  16.         }
  17.  
  18.         private void Connect()
  19.         {
  20.             try
  21.             {
  22.                 Log("Creating ASync");
  23.  
  24.                 AsyncQueryDispatcher = new AsyncTcpDispatcher("remote.ip", 13337);
  25.                 AsyncQueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
  26.                 AsyncQueryDispatcher.Connect();
  27.  
  28.                 Log("ASync connected");
  29.             }
  30.             catch (Exception ex)
  31.             {
  32.                 Log("Cannot connect", "fatal", ex.Message);
  33.             }
  34.         }
  35.  
  36.  
  37.         private void QueryDispatcher_ReadyForSendingCommands(object sender, System.EventArgs e)
  38.         {
  39.             Log("Ready for sending");
  40.            
  41.             AsyncServerQueryRunner = new TS3QueryLib.Core.Server.QueryRunner(AsyncQueryDispatcher);
  42.             AsyncServerQueryRunner.RegisterForNotifications(TS3QueryLib.Core.Server.Entities.ServerNotifyRegisterEvent.Server | TS3QueryLib.Core.Server.Entities.ServerNotifyRegisterEvent.Channel);
  43.  
  44.             Log("Logging in async");
  45.             AsyncServerQueryRunner.Login("srv", "pass");
  46.             AsyncServerQueryRunner.SelectVirtualServerById(1);
  47.             Log("Async logged in");
  48.         }
  49.  
  50.         public void Start()
  51.         {
  52.             Connect();
  53.             while (true) ;
  54.         }
  55.  
  56.         public static void Log(String msg, String type = null, String reason = null)
  57.         {
  58.             if(type != null)
  59.             {
  60.                 Console.Write("[" + type.ToUpper() + "] ");
  61.             }
  62.  
  63.             if(reason != null)
  64.             {
  65.                 Console.WriteLine(msg + " Reason: " + reason);
  66.             }
  67.             else
  68.             {
  69.                 Console.WriteLine(msg);
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement