public object CreateObject() { object o = FactoryDescription.InvokeDefaultConstruction(_type); if (o is EntityBase) { (o as EntityBase).CreateNew(); if (_ps == null) { throw new ApplicationException("PS IS NULL"); } (o as EntityBase).CreatorPs = _ps; } return(o as EntityBase); }
public object CreateObject(params object[] args) { object o = FactoryDescription.InvokeConstructionWithArgs(_type, args); if (o is EntityBase) { (o as EntityBase).CreateNew(); if (_ps == null) { throw new ApplicationException("PS IS NULL"); } (o as EntityBase).CreatorPs = _ps; } return(o as EntityBase); }
public void createFactory(ulong id) { if (server.config.factories.Any(x => x.id == id)) { HttpContext.Response.StatusCode = 403; return; } var channel = (IChannel)server.client.GetChannel(id); var factory = new FactoryDescription { id = id, name = channel.Name, maxChannels = 5 }; server.config.factories.Add(factory); }
// Checks the state of a factory; if it's currently unused, all the voice channels are removed // Triggered by a factory timer private async Task checkFactory(FactoryDescription factory) { var inUse = false; foreach (var channelId in factory.channels) { var channel = (IVoiceChannel)client.GetChannel(channelId); if (channel == null) { continue; } var users = channel.GetUsersAsync(); if (!await users.AnyAsync(user => user.Count != 0)) { continue; } inUse = true; break; } // If all channels are currently not in use, remove all of them if (!inUse) { factory.timer.Stop(); factory.timer = null; foreach (var voiceChannel in factory.channels .Select(channel => client.GetChannel(channel)) .OfType <SocketVoiceChannel>()) { await voiceChannel.DeleteAsync(); } factory.channels.Clear(); } }