コード例 #1
0
 /// <summary>
 /// Returns local client
 /// </summary>
 public TS3Models.Client GetWhoami()
 {
     if (IsConnected())
     {
         ts3Connection.WriteLine("whoami");
         TS3Models.Result result = TS3Helper.ParseResult(ReadAll(), false);
         return(new TS3Models.Client()
         {
             Result = result,
             Channel = new TS3Models.Channel()
             {
                 CId = Convert.ToInt32(result.GetFirstResult("cid"))
             },
             ClId = Convert.ToInt32(result.GetFirstResult("clid"))
         });
     }
     return(null);
 }
コード例 #2
0
 /// <summary>
 /// Selects the client tab
 /// </summary>
 public TS3Models.Result Use(int?schandlerid = null)
 {
     if (IsConnected())
     {
         string query = "use";
         if (schandlerid != null)
         {
             query += string.Format(" schandlerid={0}", schandlerid);
         }
         ts3Connection.WriteLine(query);
         TS3Models.Result result = TS3Helper.ParseResult(ReadAll(), false);
         if (result != null && result.ErrorId == 0)
         {
             CurrentHandlerId = Convert.ToInt32(result.GetFirstResult("schandlerid"));
         }
         return(result);
     }
     return(null);
 }
コード例 #3
0
        internal bool Connect(string hostname = "localhost", int port = 25639)
        {
            if (!IsConnected())
            {
                try
                {
                    tcpClient = new TcpClient(hostname, port);
                    if (!IsConnected())
                    {
                        throw new Exception("Could not connect.");
                    }
                }
                catch
                {
                    return(false);
                }

                networkStream = tcpClient.GetStream();
                streamReader  = new StreamReader(networkStream);
                streamWriter  = new StreamWriter(networkStream)
                {
                    NewLine = "\n"
                };

                // Ignore welcome message
                streamReader.ReadLine();
                streamReader.ReadLine();
                streamReader.ReadLine();
                streamReader.ReadLine();

                StartResponseLoop();
                TS3Models.Result result = TS3Helper.ParseResult(ReadAll(), false);
                if (result != null && result.ErrorId == 0)
                {
                    ts3Client.CurrentHandlerId = Convert.ToInt32(result.GetFirstResult("schandlerid"));
                }
                return(true);
            }
            return(false);
        }
コード例 #4
0
        private void ParseNotification(TS3Models.Notifications notification, TS3Models.Result result)
        {
            switch (notification)
            {
                #region Client
            case TS3Models.Notifications.notifytextmessage:
                if (OnTextMessage != null)
                {
                    OnTextMessage(new TS3Models.TextMessage()
                    {
                        Result     = result,
                        TargetMode = (TS3Models.TextMessageTargetMode)Convert.ToInt32(result.GetFirstResult("targetmode")),
                        Msg        = result.GetFirstResult("msg"),
                        Target     = Convert.ToInt32(result.GetFirstResult("target")),
                        Invoker    = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        }
                    });
                }
                break;

            case TS3Models.Notifications.notifyclientpoke:
                if (OnClientPoke != null)
                {
                    OnClientPoke(new TS3Models.ClientPoke()
                    {
                        Result  = result,
                        Msg     = result.GetFirstResult("msg"),
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        }
                    });
                }
                break;

            case TS3Models.Notifications.notifycliententerview:
                if (OnClientEnterView != null)
                {
                    OnClientEnterView(new TS3Models.ClientEnterView()
                    {
                        Result = result,
                        CfId   = Convert.ToInt32(result.GetFirstResult("cfid")),
                        CtId   = Convert.ToInt32(result.GetFirstResult("ctid")),
                        Reason = (TS3Models.ReasonIdentifier)Convert.ToInt32(result.GetFirstResult("reasonid")),
                        Client = new TS3Models.Client().FillWithResult(result)
                    });
                }
                break;

            case TS3Models.Notifications.notifyclientleftview:
                if (OnClientLeftView != null)
                {
                    OnClientLeftView(new TS3Models.ClientLeftView()
                    {
                        Result  = result,
                        CfId    = Convert.ToInt32(result.GetFirstResult("cfid")),
                        CtId    = Convert.ToInt32(result.GetFirstResult("ctid")),
                        Reason  = (TS3Models.ReasonIdentifier)Convert.ToInt32(result.GetFirstResult("reasonid")),
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        ReasonMsg = result.GetFirstResult("reasonmsg"),
                        BanTime   = Convert.ToInt32(result.GetFirstResult("bantime")),
                        ClId      = Convert.ToInt32(result.GetFirstResult("clid"))
                    });
                }
                break;

            case TS3Models.Notifications.notifyclientmoved:
                if (OnClientMoved != null)
                {
                    List <TS3Models.Client> clients = new List <TS3Models.Client>();
                    foreach (Dictionary <string, string> list in result.ResultsList)
                    {
                        string id = result.GetResultByList(list, "clid");
                        if (!string.IsNullOrEmpty(id))
                        {
                            clients.Add(new TS3Models.Client()
                            {
                                ClId = Convert.ToInt32(id)
                            });
                        }
                    }

                    OnClientMoved(new TS3Models.ClientMoved()
                    {
                        Result  = result,
                        Channel = new TS3Models.Channel()
                        {
                            CId = Convert.ToInt32(result.GetFirstResult("ctid"))
                        },
                        Reason  = (TS3Models.ReasonIdentifier)Convert.ToInt32(result.GetFirstResult("reasonid")),
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        Clients = clients
                    });
                }
                break;

                #endregion
                #region Channel
            case TS3Models.Notifications.notifychannelmoved:
                if (OnChannelMoved != null)
                {
                    OnChannelMoved(new TS3Models.ChannelMoved()
                    {
                        Result  = result,
                        Reason  = (TS3Models.ReasonIdentifier)Convert.ToInt32(result.GetFirstResult("reasonid")),
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        Channel = new TS3Models.Channel().FillWithResult(result)
                    });
                }
                break;

            case TS3Models.Notifications.notifychanneledited:
                if (OnChannelEdited != null)
                {
                    OnChannelEdited(new TS3Models.ChannelEdited()
                    {
                        Result  = result,
                        Reason  = (TS3Models.ReasonIdentifier)Convert.ToInt32(result.GetFirstResult("reasonid")),
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        Channel = new TS3Models.Channel().FillWithResult(result)
                    });
                }
                break;

            case TS3Models.Notifications.notifychannelcreated:
                if (OnChannelCreated != null)
                {
                    OnChannelCreated(new TS3Models.ChannelCreated()
                    {
                        Result  = result,
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        Channel = new TS3Models.Channel().FillWithResult(result)
                    });
                }
                break;

            case TS3Models.Notifications.notifychanneldeleted:
                if (OnChannelDeleted != null)
                {
                    OnChannelDeleted(new TS3Models.ChannelDeleted()
                    {
                        Result  = result,
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        Channel = new TS3Models.Channel().FillWithResult(result)
                    });
                }
                break;

                #endregion
                #region Server
            case TS3Models.Notifications.notifyserveredited:
                if (OnServerEdited != null)
                {
                    OnServerEdited(new TS3Models.ServerEdited()
                    {
                        Result  = result,
                        Reason  = (TS3Models.ReasonIdentifier)Convert.ToInt32(result.GetFirstResult("reasonid")),
                        Invoker = new TS3Models.Client()
                        {
                            ClId                   = Convert.ToInt32(result.GetFirstResult("invokerid")),
                            ClientNickname         = result.GetFirstResult("invokername"),
                            ClientUniqueIdentifier = result.GetFirstResult("invokeruid"),
                        },
                        VirtualServer = new TS3Models.VirtualServer().FillWithResult(result)
                    });
                }
                break;

            case TS3Models.Notifications.notifyservergrouplist:
                if (OnServerGroupList != null)
                {
                    List <TS3Models.ServerGroup> serverGroups = new List <TS3Models.ServerGroup>();
                    foreach (Dictionary <string, string> res in result.ResultsList)
                    {
                        serverGroups.Add(new TS3Models.ServerGroup().FillWithResult(result, res));
                    }
                    OnServerGroupList(serverGroups);
                }
                break;
                #endregion
            }
        }