Exemplo n.º 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;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 11
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.");
        }