Beispiel #1
0
        /// <summary>
        /// Parses and handles a "clientlist" response and updates the dictionary of client ID/nicknames
        /// </summary>
        /// <param name="clientList">The client list response</param>
        private void AddClients(string clientList)
        {
            var clientStrings = clientList.Split('|');

            foreach (var clientString in clientStrings)
            {
                if (clientString.Contains(Properties.ClientID) && clientString.Contains(Properties.ClientNickname))
                {
                    uint clientId = DecodeUtility.DecodeUIntProperty(clientString, Properties.ClientID);

                    string clientNickname = DecodeUtility.DecodeStringProperty(clientString, true, Properties.ClientNickname);

                    uint channelId = 0;
                    if (clientString.Contains(Properties.ChannelID) || clientString.Contains(Properties.TargetChannelID))
                    {
                        channelId = DecodeUtility.DecodeUIntProperty(clientString, Properties.ChannelID, Properties.TargetChannelID);
                    }

                    var client = new Client(clientId, clientNickname, channelId);
                    this.clients.AddOrUpdate(clientId, client, (key, oldValue) => client);

                    // If they joined the current channel, raise the client entered channel event
                    if (client.ChannelID == this.CurrentChannelID)
                    {
                        this.localClients.AddOrUpdate(clientId, this.clients[clientId], (key, oldValue) => this.clients[clientId]);
                        this.RaiseClientEnteredChannel(new Data.ClientEventArgs(clientId, this.clients[clientId].Name));
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Handles the ClientUpdated TS notification
 /// </summary>
 /// <param name="notificationString">The notification string</param>
 private void HandleClientUpdated(string notificationString)
 {
     // Someone changed their nickname
     if (notificationString.Contains(Properties.ClientNickname))
     {
         uint clientId = DecodeUtility.DecodeUIntProperty(notificationString, Properties.ClientID);
         if (this.clients.ContainsKey(clientId))
         {
             string clientNickname = DecodeUtility.DecodeStringProperty(notificationString, true, Properties.ClientNickname);
             this.clients[clientId].Name = clientNickname;
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Sends a request for the current server information and raises the server connected event
        /// </summary>
        private void RequestCurrentServerInfo()
        {
            // Determine the current server information
            logger.Info("Requesting current server information");
            string result = this.TsConnection.SendCommand(new Command("servervariable " + Properties.ServerName + " " + Properties.ServerIP));

            if (!string.IsNullOrEmpty(result))
            {
                string serverName    = DecodeUtility.DecodeStringProperty(result, true, Properties.ServerName);
                string serverAddress = DecodeUtility.DecodeStringProperty(result, false, Properties.ServerIP);

                logger.Info("Server Information: name={0} address={1}", serverName, serverAddress);
                this.RaiseNewServerInfo(new NewServerInfoEventArgs(serverName, serverAddress));
            }
        }
Beispiel #4
0
        internal static Channel FromChannelString(string channelString)
        {
            var parts = channelString.Split(' ', '\n', '\r');

            uint id = DecodeUtility.DecodeUIntProperty(channelString, Properties.ChannelID);

            uint parentId = 0;

            if (parts.FirstOrDefault(part => part.StartsWith(Properties.ParentID)) != null ||
                parts.FirstOrDefault(part => part.StartsWith(Properties.ChannelParentID)) != null)
            {
                parentId = DecodeUtility.DecodeUIntProperty(channelString, Properties.ParentID, Properties.ChannelParentID);
            }

            uint order = 0;

            if (parts.FirstOrDefault(part => part.StartsWith(Properties.ChannelOrder)) != null)
            {
                order = DecodeUtility.DecodeUIntProperty(channelString, Properties.ChannelOrder);
            }

            string name = string.Empty;

            if (parts.FirstOrDefault(part => part.StartsWith(Properties.ChannelName)) != null)
            {
                name = DecodeUtility.DecodeStringProperty(channelString, true, Properties.ChannelName);
            }

            uint clientsCount = 0;

            if (parts.FirstOrDefault(part => part.StartsWith(Properties.ChannelClientsCount)) != null)
            {
                clientsCount = DecodeUtility.DecodeUIntProperty(channelString, Properties.ChannelClientsCount);
            }

            bool isSpacer = SpacerInfo.Parse(name) != null;

            Channel channelInfo = new Channel(id, name, isSpacer)
            {
                ParentID     = parentId,
                Order        = order,
                ClientsCount = clientsCount
            };

            return(channelInfo);
        }
Beispiel #5
0
        /// <summary>
        /// Sends a request for the current channel and raises the channel switched event
        /// </summary>
        private void RequestCurrentChannelInfo()
        {
            logger.Info("Requesting current channel information");
            var    command = new Command(string.Format("channelvariable {0}={1} {2} {3}", Properties.ChannelID, this.currentChannelID, Properties.ChannelName, Properties.ChannelDescription));
            string result  = this.TsConnection.SendCommand(command);

            if (!string.IsNullOrEmpty(result))
            {
                // Parse the channel info
                string channelName        = DecodeUtility.DecodeStringProperty(result, true, Properties.ChannelName);
                string channelDescription = DecodeUtility.DecodeStringProperty(result, true, Properties.ChannelDescription);

                logger.Info("Channel Information: name={0} description={1}", channelName, channelDescription);
                this.RaiseClientChannelChanged(new ChannelEventArgs(new Channel(this.currentChannelID, channelName)
                {
                    Description = channelDescription
                }));
            }
        }