Exemple #1
0
 /// <summary>Builds a use query for you.</summary>
 /// <param name="virtualId">The virtual server Id to use.</param>
 public static TeamspeakQuery buildUseVIdQuery(Int32 virtualId)
 {
     TeamspeakQuery tsUse = new TeamspeakQuery("use");
     tsUse.addParameter("sid", virtualId.ToString());
     return tsUse;
 }
Exemple #2
0
        /// <summary>Attempts to create a channel for the specified team.</summary>
        public void createTeamChannel(String Name, Int32 TeamId)
        {
            // Setup the general portions of the query.
            TeamspeakQuery channelCreateQuery = new TeamspeakQuery("channelcreate");
            channelCreateQuery.addParameter("channel_name", Name);
            channelCreateQuery.addParameter("channel_flag_permanent", "1");
            channelCreateQuery.addParameter("cpid", mStagingChannel.tsId.Value.ToString());
            channelCreateQuery.addParameter( "channel_codec_quality", "10");
            debugWrite(dbgChannels, "[Channels] Attempting to create ^bTeam^n Channel: {0}.", Name);

            // Determine if we should set a password.
            if (chnPassword != String.Empty)
            {
                channelCreateQuery.addParameter("channel_password", chnPassword);
                debugWrite(dbgChannels, "[Channels] Using Password ({0}).", chnPassword);
            }

            // Determine where the channel should be sorted.
            for (int i = TeamId - 1; i >= 0; i--)
                if (mTeamChannels.ContainsKey(i) && mTeamChannels[i].medPId == mStagingChannel.tsId)
                {
                    channelCreateQuery.addParameter("channel_order", mTeamChannels[i].tsId.ToString());
                    debugWrite(dbgChannels, "[Channels] Order After {0}.", mTeamChannels[i].tsName);
                    break;
                }
                else if (i == 0)
                {
                    channelCreateQuery.addParameter("channel_order", "0");
                    debugWrite(dbgChannels, "[Channels] Order After Top.");
                    break;
                }

            // Create the channel.
            sendTeamspeakQuery(channelCreateQuery);
            if (!performResponseHandling(Queries.CreateTeamChannelQuery))
                return;

            // Get the channel's info.
            Int32 channelId = Int32.Parse(mTsResponse.Sections[0].Groups[0]["cid"]);
            sendTeamspeakQuery(TeamspeakQuery.buildChannelInfoQuery(channelId));
            if (!performResponseHandling(Queries.CreateTeamChannelInfo))
                return;

            // Set the channel.
            TeamspeakChannel teamChannel = new TeamspeakChannel(mTsResponse.Sections[0].Groups[0]);
            teamChannel.tsId = channelId;

            // Add the channel to global channels list.
            mTeamChannels.Remove(TeamId);
            mSquadChannels.Remove(TeamId);
            mTeamChannels.Add(TeamId, teamChannel);
            mSquadChannels.Add(TeamId, new Dictionary<Int32, TeamspeakChannel>());
            debugWrite(dbgChannels, "[Channels] Created ^bTeam^n Channel: {0} ({1}).", teamChannel.tsName, teamChannel.tsId);
        }
Exemple #3
0
 /// <summary>Builds a login query for you.</summary>
 /// <param name="username">The username to use.</param>
 /// <param name="password">The password to use.</param>
 public static TeamspeakQuery buildLoginQuery(String username, String password)
 {
     TeamspeakQuery tsLogin = new TeamspeakQuery("login");
     tsLogin.addParameter("client_login_name", username);
     tsLogin.addParameter("client_login_password", password);
     return tsLogin;
 }
Exemple #4
0
 /// <summary>Builds a use query for you.</summary>
 /// <param name="port">The port of the virtual server to use.</param>
 public static TeamspeakQuery buildUsePortQuery(Int32 port)
 {
     TeamspeakQuery tsUse = new TeamspeakQuery("use");
     tsUse.addParameter("port", port.ToString());
     return tsUse;
 }
Exemple #5
0
 /// <summary>Builds a clientinfo query for you.</summary>
 /// <param name="clientId">The client id to use.</param>
 public static TeamspeakQuery buildClientInfoQuery(Int32 clientId)
 {
     TeamspeakQuery tsClientInfo = new TeamspeakQuery("clientinfo");
     tsClientInfo.addParameter("clid", clientId.ToString());
     return tsClientInfo;
 }
Exemple #6
0
 /// <summary>Builds a clientmove query for you.</summary>
 /// <param name="clientId">The client id to use.</param>
 /// <param name="channelId">The channel id to use.</param>
 public static TeamspeakQuery buildClientMoveQuery(Int32 clientId, Int32 channelId)
 {
     TeamspeakQuery tsClientMove = new TeamspeakQuery("clientmove");
     tsClientMove.addParameter("clid", clientId.ToString());
     tsClientMove.addParameter("cid", channelId.ToString());
     return tsClientMove;
 }
Exemple #7
0
 /// <summary>Builds a channelinfo query for you.</summary>
 /// <param name="channelId">The channel id to use.</param>
 public static TeamspeakQuery buildChannelInfoQuery(Int32 channelId)
 {
     TeamspeakQuery tsChannelInfo = new TeamspeakQuery("channelinfo");
     tsChannelInfo.addParameter("cid", channelId.ToString());
     return tsChannelInfo;
 }
Exemple #8
0
 /// <summary>Builds a clientfind query for you.</summary>
 /// <param name="clientName">The client name to use.</param>
 public static TeamspeakQuery buildClientFindQuery(String clientName)
 {
     TeamspeakQuery tsClientFind = new TeamspeakQuery("clientfind");
     tsClientFind.addParameter("pattern", clientName);
     return tsClientFind;
 }
Exemple #9
0
 /// <summary>Builds a channelfind query for you.</summary>
 /// <param name="channelName">The channel name to use.</param>
 public static TeamspeakQuery buildChannelFindQuery(String channelName)
 {
     TeamspeakQuery tsChannelFind = new TeamspeakQuery("channelfind");
     tsChannelFind.addParameter("pattern", channelName);
     return tsChannelFind;
 }
Exemple #10
0
 /// <summary>Builds a clientupdate query that changes the server query's nickname.</summary>
 /// <param name="newNickname">The nickname to change to.</param>
 public static TeamspeakQuery buildChangeNicknameQuery(String newNickname)
 {
     TeamspeakQuery tsClientUpdate = new TeamspeakQuery("clientupdate");
     tsClientUpdate.addParameter("client_nickname", newNickname);
     return tsClientUpdate;
 }
Exemple #11
0
            /// <summary>Sends a query and blocks until a response is received.</summary>
            /// <returns>The response from the server.</returns>
            public TeamspeakResponse send(TeamspeakQuery query)
            {
                // Error Check.
                if (!Socket.Connected) return TSR_SEND_ERR_1;
                if (query == null) return TSR_SEND_ERR_2;

                String rBuffer = null;
                Byte[] sBuffer = null;

                // Send the query.
                try
                {
                    rBuffer = query.rawQuery();
                    sBuffer = Encoding.Default.GetBytes(rBuffer);
                    Socket.Send(sBuffer, rBuffer.Length, SocketFlags.None);
                }
                catch (Exception) { close(); return TSR_SEND_ERR_3; }
                OnDataSent(rBuffer);

                // Receive the response.
                rBuffer = String.Empty;
                sBuffer = new Byte[65536];
                DateTime start = DateTime.Now;
                while (!rBuffer.Contains("error id=") || !rBuffer.EndsWith("\n\r"))
                    try
                    {
                        Int32 size = Socket.Receive(sBuffer, sBuffer.Length, SocketFlags.None);
                        rBuffer += Encoding.Default.GetString(sBuffer, 0, size);
                        if ((DateTime.Now - start).TotalMilliseconds > 5500) break;
                    }
                    catch (Exception) { close(); return TSR_SEND_ERR_4; }
                OnDataReceived(rBuffer);

                // Send back the response.
                return new TeamspeakResponse(rBuffer);
            }
Exemple #12
0
 /// <summary>Sends a query to the teamspeak server (delayed if necessary) and sets the response.</summary>
 public void sendTeamspeakQuery(TeamspeakQuery query)
 {
     if (synDelayQueries)
     {
         TimeSpan delay = TimeSpan.FromMilliseconds(synDelayQueriesAmount);
         TimeSpan delta = DateTime.Now - mTsPrevSendTime;
         if (delta <= delay) Thread.Sleep(delay - delta);
     }
     mTsResponse = mTsConnection.send(query);
     mTsPrevSendTime = DateTime.Now;
 }
Exemple #13
0
        /// <summary>Attempts to remove each squad channel if it is empty.</summary>
        public void removeChannels()
        {
            // Dictionaries of channels to remove.
            Dictionary<Int32, TeamspeakChannel> teamChannels = new Dictionary<Int32, TeamspeakChannel>();
            Dictionary<Int32, Dictionary<Int32, TeamspeakChannel>> squadChannels = new Dictionary<Int32, Dictionary<Int32, TeamspeakChannel>>();
            debugWrite(dbgChannels, "[Channels] Attempting to remove empty channels.");

            // Build a list of clients in the server.
            List<TeamspeakClient> clientInfo = new List<TeamspeakClient>();
            // Request all the clients basic information.  Bail out if the query was bad.
            sendTeamspeakQuery(TeamspeakQuery.buildClientListQuery());
            if (!performResponseHandling(Queries.RemoveChannelsList))
                return;
            // Build list of clients.
            foreach (TeamspeakResponseSection sec in mTsResponse.Sections)
                foreach (TeamspeakResponseGroup grp in sec.Groups)
                    clientInfo.Add(new TeamspeakClient(grp));

            // Get rid of squad channels that are empty.
            foreach (Int32 teamId in mSquadChannels.Keys)
                foreach (Int32 squadId in mSquadChannels[teamId].Keys)
                {
                    // Check if there are users in the channel.
                    Boolean inChannel = false;
                    foreach (TeamspeakClient tsClient in clientInfo)
                        if (inChannel = mSquadChannels[teamId][squadId].tsId == tsClient.medChannelId)
                            break;
                    // Add the channel to the list of channels to remove.
                    if (!inChannel)
                    {
                        if (!squadChannels.ContainsKey(teamId))
                            squadChannels.Add(teamId, new Dictionary<Int32, TeamspeakChannel>());
                        squadChannels[teamId].Add(squadId, mSquadChannels[teamId][squadId]);
                    }
                }

            // Get rid of team channels that are empty.
            //   This only applies to children of the staging channel.
            foreach (Int32 teamId in mTeamChannels.Keys)
                if (mTeamChannels[teamId].medPId == mStagingChannel.tsId)
                {
                    // Check if there are users in the channel.
                    Boolean inChannel = false;
                    foreach (TeamspeakClient tsClient in clientInfo)
                        if (inChannel = mTeamChannels[teamId].tsId == tsClient.medChannelId)
                            break;
                    // Add the channel to the list of channels to remove.
                    if (!inChannel)
                        teamChannels.Add(teamId, mTeamChannels[teamId]);
                }

            // Remove squad channels that we marked as empty.
            foreach (Int32 teamId in squadChannels.Keys)
                foreach (Int32 squadId in squadChannels[teamId].Keys)
                {
                    TeamspeakQuery deleteChannel = new TeamspeakQuery("channeldelete");
                    deleteChannel.addParameter("cid", mSquadChannels[teamId][squadId].tsId.ToString());
                    deleteChannel.addParameter("force", "1");
                    sendTeamspeakQuery(deleteChannel);
                    if (!performResponseHandling(Queries.RemoveChannelsSquadQuery)) return;
                    if (mTsResponse.Id != "0") continue;
                    debugWrite(dbgChannels, "[Channels] Removed ^bSquad^n Channel: {0} ({1}).", mSquadChannels[teamId][squadId].tsName, mSquadChannels[teamId][squadId].tsId);
                    mSquadChannels[teamId].Remove(squadId);
                }

            // Remove team channels we marked as empty.
            //   Double check to make sure all sub-channels are empty.
            foreach (Int32 teamId in teamChannels.Keys)
                if (!mSquadChannels.ContainsKey(teamId) || mSquadChannels[teamId].Count == 0)
                {
                    TeamspeakQuery deleteChannel = new TeamspeakQuery("channeldelete");
                    deleteChannel.addParameter("cid", mTeamChannels[teamId].tsId.ToString());
                    deleteChannel.addParameter("force", "1");
                    sendTeamspeakQuery(deleteChannel);
                    if (!performResponseHandling(Queries.RemoveChannelsTeamQuery)) return;
                    if (mTsResponse.Id != "0") continue;
                    debugWrite(dbgChannels, "[Channels] Removed ^bTeam^n Channel: {0} ({1}).", mTeamChannels[teamId].tsName, mTeamChannels[teamId].tsId);
                    mTeamChannels.Remove(teamId);
                    mSquadChannels.Remove(teamId);
                }

            // Debug print.
            debugWrite(dbgChannels, "[Channels] Done removing empty channels.");
        }