private void StoreSingleChannel(int ChannelId, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel) { //var channel = ServerQueryConnection.QueryRunner.GetChannelInfo((uint)ChannelId); var channel = ChannelInfo; Models.StoredChannels storedChannel = new Models.StoredChannels(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); storedChannel.Parse(ChannelId, channel); using (var db = new CoreContext()) { // Store the channel db.StoredChannels.Add(storedChannel); // Store the channel group assignments var channelGroupClients = ServerQueryConnection.QueryRunner.GetChannelGroupClientList((uint?)ChannelId, null, null).ToList(); foreach (var channelGroupClient in channelGroupClients) { var storeChannel = new Models.StoredChannelGroupClients(Subscriber.SubscriberId, Subscriber.SubscriberUniqueId, channelGroupClient); db.StoredChannelGroupClients.Add(storeChannel); } // Successfully stored the channel, now we can delete it from the server var response = ServerQueryConnection.QueryRunner.DeleteChannel((uint)ChannelId); do { if (response.IsErroneous) { if (response.ErrorMessage == "channel not empty") { var usersInChannel = ServerQueryConnection.QueryRunner.GetClientList(false).Where(client => client.ChannelId == ChannelId); foreach (var user in usersInChannel) { var kickResponse = ServerQueryConnection.QueryRunner.KickClient(user.ClientId, TS3QueryLib.Core.CommandHandling.KickReason.Channel, "Channel is being stored away."); if (kickResponse.IsErroneous) { throw new Exception(kickResponse.ResponseText + " (" + kickResponse.ErrorMessage + ")"); } response = ServerQueryConnection.QueryRunner.DeleteChannel((uint)ChannelId); } } else { throw new Exception(response.ResponseText + " (" + response.ErrorMessage + ")"); } } } while (response.IsErroneous == true); db.SaveChanges(); } }
public SSessionBase SendDeferred(ChannelInfoResponse value) => SendDeferred(SCCategory.Channel, SCChannel.Info, (SPacketWriter writer) => { writer.Write(value.Location); writer.Write((byte)value.Values.Count()); foreach (ChannelInfoResponse.Entity channel in value.Values) { writer.Write(channel.Id); writer.WriteChannelLoadStatus(channel.Status); } });
public SSessionBase SendAsync(ChannelInfoResponse value) => SendAsync(ClientOpcode.ChannelInfo, (PacketWriter writer) => { writer.Write(value.Location); writer.Write((byte)value.Values.Count()); foreach (ChannelInfoResponse.Entity channel in value.Values) { writer.Write(channel.Id); writer.WriteChannelLoadStatus(channel.Status); } });
private void ScanRooms() { sql.NonQuery("DELETE FROM rooms WHERE server_id = " + serverinfo.id + ";"); ListResponse <ChannelListEntry> list = queryRunner.GetChannelList(true); string sql_text = "INSERT INTO rooms VALUES "; foreach (ChannelListEntry entry in list) { //Leave this commented out for now as we might need to store temporary rooms also //if (entry.IsPermanent == true || entry.IsSemiPermanent == true) //{ sql_text += "("; sql_text += serverinfo.id + ","; sql_text += entry.ChannelIconId + ","; sql_text += entry.ChannelId + ","; sql_text += entry.Codec + ","; sql_text += entry.CodecQuality + ","; sql_text += Convert.ToInt32(entry.IsDefaultChannel) + ","; sql_text += Convert.ToInt32(entry.IsPasswordProtected) + ","; sql_text += Convert.ToInt32(entry.IsPermanent) + ","; sql_text += Convert.ToInt32(entry.IsSemiPermanent) + ","; sql_text += Convert.ToInt32(entry.IsSpacer) + ","; sql_text += entry.MaxClients + ","; sql_text += entry.MaxFamilyClients + ","; sql_text += "'" + entry.Name + "',"; sql_text += entry.NeededTalkPower + ","; sql_text += entry.Order + ","; sql_text += entry.ParentChannelId + ","; //sql_text += entry.SpacerInfo + ","; sql_text += "'" + entry.Topic + "',"; ChannelInfoResponse channel = queryRunner.GetChannelInfo(entry.ChannelId); sql_text += "'" + channel.Description + "',"; sql_text += entry.TotalClients + "),"; //} } sql_text = sql_text.TrimEnd(','); sql.NonQuery(sql_text); }
public void Store(QueryRunner QueryRunner, List <ChannelListEntry> ChannelList, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel, Action <int, ChannelInfoResponse, ChannelListEntry> StoreMethod) { this.QueryRunner = QueryRunner; this.Parse(ChannelInfo, Channel); for (int i = 0; i < ChannelList.Count; i++) { if (ChannelList[i].ParentChannelId == Channel.ChannelId) { var SubChannelInfo = QueryRunner.GetChannelInfo(ChannelList[i].ChannelId); SubChannels.Add(new ChannelWithSubChannelsPackager(this.SubscriberId, this.SubscriberUniqueId, QueryRunner, ChannelList, SubChannelInfo, ChannelList[i], StoreMethod)); } } StoreMethod.Invoke((int)this.ChannelId, ChannelInfo, Channel); }
public ChannelWithSubChannelsPackager(int SubscriberId, string SubscriberUniqueId, QueryRunner QueryRunner, List <ChannelListEntry> ChannelList, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel, Action <int, ChannelInfoResponse, ChannelListEntry> StoreMethod) : base(SubscriberId, SubscriberUniqueId) { Store(QueryRunner, ChannelList, ChannelInfo, Channel, StoreMethod); }
public void Parse(int ChannelId, ChannelInfoResponse info, bool overWriteExisting = false) { this.ChannelId = ChannelId; if (overWriteExisting || ForcedSilence == null) { ForcedSilence = info.ForcedSilence; } if (overWriteExisting || IsDefaultChannel == null) { IsDefaultChannel = info.IsDefaultChannel; } if (overWriteExisting || IsMaxClientsUnlimited == null) { IsMaxClientsUnlimited = info.IsMaxClientsUnlimited; } if (overWriteExisting || IsMaxFamilyClientsInherited == null) { IsMaxFamilyClientsInherited = info.IsMaxFamilyClientsInherited; } if (overWriteExisting || IsMaxFamilyClientsUnlimited == null) { IsMaxFamilyClientsUnlimited = info.IsMaxFamilyClientsUnlimited; } if (overWriteExisting || IsPasswordProtected == null) { IsPasswordProtected = info.IsPasswordProtected; } if (overWriteExisting || IsPermanent == null) { IsPermanent = info.IsPermanent; } if (overWriteExisting || IsSemiPermanent == null) { IsSemiPermanent = info.IsSemiPermanent; } if (overWriteExisting || IsUnencrypted == null) { IsUnencrypted = info.IsUnencrypted; } if (overWriteExisting || CodecQuality == null) { CodecQuality = info.CodecQuality; } if (overWriteExisting || MaxClients == null) { MaxClients = info.MaxClients; } if (overWriteExisting || MaxFamilyClients == null) { MaxFamilyClients = info.MaxFamilyClients; } if (overWriteExisting || SecondsEmpty == null) { SecondsEmpty = info.SecondsEmpty; } if (overWriteExisting || Description == null) { Description = info.Description; } if (overWriteExisting || FilePath == null) { FilePath = info.FilePath; } if (overWriteExisting || Name == null) { Name = info.Name; } if (overWriteExisting || PasswordHash == null) { PasswordHash = info.PasswordHash; } if (overWriteExisting || PhoneticName == null) { PhoneticName = info.PhoneticName; } if (overWriteExisting || SecuritySalt == null) { SecuritySalt = info.SecuritySalt; } if (overWriteExisting || Topic == null) { Topic = info.Topic; } if (overWriteExisting || DeleteDelay == null) { DeleteDelay = (int?)info.DeleteDelay; } if ((overWriteExisting || IconId == null) && info.IconId != 0) { IconId = (int?)info.IconId; } if (overWriteExisting || LatencyFactor == null) { LatencyFactor = (int?)info.LatencyFactor; } if (overWriteExisting || NeededTalkPower == null) { NeededTalkPower = (int?)info.NeededTalkPower; } if (overWriteExisting || Order == null) { Order = (int?)info.Order; } if (overWriteExisting || ParentChannelId == null) { ParentChannelId = (int?)info.ParentChannelId; } if (overWriteExisting || Codec == null) { Codec = (short?)info.Codec; } }
private void TidyChannels(int eventChannelId, int eventClientId = -1) { Console.WriteLine("(Thread: " + System.Threading.Thread.CurrentThread.ManagedThreadId + ") " + DateTime.Now + " - TidyChannels: Entering wait queue"); slimtest.Wait(); ChannelInfoResponse _target_channel = queryRunner.GetChannelInfo((uint)eventChannelId); ChannelInfoResponse _parent_channel = queryRunner.GetChannelInfo(_target_channel.ParentChannelId); bool privateChannel = false; slimtest.Release(); Console.WriteLine("(Thread: " + System.Threading.Thread.CurrentThread.ManagedThreadId + ") TidyChannels: Leaving wait queue"); AutoChannelNameType channelNameType = AutoChannelNameType.Numeric; int empty_channel_treshhold = 2; //bool private_channel = false; int parent_channel_id = 0; try { ChannelSettings settings = new ChannelSettings(_parent_channel.Topic); settings.SetActiveSetting("autochannel"); if (settings.ContainsParam("private")) { if (settings.GetParam("private") == "yes") { privateChannel = true; } } if (settings.ContainsParam("empty_channels")) { try { if (Convert.ToInt32(settings.GetParam("empty_channels")) > 0) { empty_channel_treshhold = Convert.ToInt32(settings.GetParam("empty_channels")); } } catch (Exception) { //Value wasn't numeric } } if (settings.ContainsParam("naming_type")) { if (settings.GetParam("naming_type") == "alphabetic") { channelNameType = AutoChannelNameType.Alphabetic; } else if (settings.GetParam("naming_type") == "numeric") { channelNameType = AutoChannelNameType.Numeric; } } VerifyHostPresent(eventChannelId, eventClientId, privateChannel); parent_channel_id = (int)_target_channel.ParentChannelId; } catch (Exception) { //Channel not eligible for tidying return; } //Now we check if the user left any other channel in the auto-section that can now be deleted ListResponse <ChannelListEntry> channels = queryRunner.GetChannelList(false, true, false, false, false); List <ChannelListEntry> empty_channels = new List <ChannelListEntry>(); List <ChannelListEntry> relevant_channels = new List <ChannelListEntry>(); bool channelEmpty = true; //Go through all the channels foreach (ChannelListEntry channel in channels) { channelEmpty = true; //Only match the ones with the same parentid. if (channel.ParentChannelId == parent_channel_id) { foreach (ClientListEntry client in queryRunner.GetClientList()) { if (client.ChannelId == channel.ChannelId) { //There is already someone in the channel. channelEmpty = false; break; } } //If channel is empty, add to list of empty channels for later iteration if (channelEmpty) { empty_channels.Add(channel); //Also remove the password from the empty channel if (channel.IsPasswordProtected == true) { ChannelModification mod = new ChannelModification(); mod.Password = ""; queryRunner.EditChannel(channel.ChannelId, mod); } ListResponse <ChannelGroupClient> channelgroupclientlist = queryRunner.GetChannelGroupClientList(channel.ChannelId, null, 10); foreach (ChannelGroupClient cgclient in channelgroupclientlist) { queryRunner.SetClientChannelGroup(8, channel.ChannelId, cgclient.ClientDatabaseId); } } relevant_channels.Add(channel); } } //Check for excessive amount of empty rooms, delete if necessary if (empty_channels.Count > empty_channel_treshhold) { ChannelListEntry[] sorted_empty_channels = SortChannels_GetArray(empty_channels); for (int i = sorted_empty_channels.Length - 1; i > empty_channel_treshhold - 1; i--) { SimpleResponse resp = queryRunner.DeleteChannel(sorted_empty_channels[i].ChannelId); } } else if (empty_channels.Count < empty_channel_treshhold) { int channels_created = 0; //HostInfoResponse hostinfo = queryRunner.GetHostInfo(); //ClientInfoResponse clientinfo = queryRunner.GetClientInfo(1); do { if (channels_created > 1) { //If more than 2 channels have been created already, we add some delay to make sure not to trigger the flood protection too easily Thread.Sleep(300); } //There are no empty channels left so we need to create a new one. //First we get the lowest available index for a room name. ChannelModification newroom = LowestAvailableRoomName((uint)parent_channel_id, channelNameType); if (newroom.ChannelOrder == null) { newroom.ChannelOrder = SortChannels_FindOrder(relevant_channels, newroom); } string test; //Then we create the channel try { channels_created++; test = queryRunner.CreateChannel(newroom).GetDumpString(); } catch (FormatException) { //Not sure why we're getting an exception. The code is working the way it should. } }while (empty_channels.Count + channels_created < empty_channel_treshhold); //SortChannels(parent_channel_id); } else { //There's still 1 empty channel after user joined the area. We dont have to do anything. } }