public async Task StartCheckAsync(CommandContext ctx, [Description("Registered name.")] string name) { if (string.IsNullOrWhiteSpace(name)) { throw new InvalidCommandUsageException("Name/IP missing."); } if (SwatSpaceCheckService.IsListening(ctx.Channel)) { throw new CommandFailedException("Already checking space in this channel!"); } if (string.IsNullOrWhiteSpace(name)) { throw new InvalidCommandUsageException("Name missing."); } name = name.ToLowerInvariant(); DatabaseSwatServer server; using (DatabaseContext db = this.Database.CreateContext()) server = db.SwatServers.FirstOrDefault(s => s.Name == name); if (server is null) { throw new CommandFailedException("Server with given name is not registered."); } SwatSpaceCheckService.AddListener(server, ctx.Channel); await this.InformAsync(ctx, $"Starting space listening on {server.IP}:{server.JoinPort}... Use command {Formatter.Bold("swat stopcheck")} to stop the check.", important : false); }
public Task StopCheckAsync(CommandContext ctx) { if (!SwatSpaceCheckService.IsListening(ctx.Channel)) { throw new CommandFailedException("No checks were started in this channel."); } SwatSpaceCheckService.RemoveListener(ctx.Channel); return(this.InformAsync(ctx, "Checking stopped.", important: false)); }
public async Task StartCheckAsync(CommandContext ctx, [Description("IP.")] CustomIPFormat ip, [Description("Query port")] int queryport = 10481) { if (queryport <= 0 || queryport > 65535) { throw new InvalidCommandUsageException("Port range invalid (must be in range [1, 65535])!"); } if (SwatSpaceCheckService.IsListening(ctx.Channel)) { throw new CommandFailedException("Already checking space in this channel!"); } var server = SwatServer.FromIP(ip.Content, queryport); SwatSpaceCheckService.AddListener(server, ctx.Channel); await this.InformAsync(ctx, $"Starting space listening on {server.Ip}:{server.JoinPort}... Use command {Formatter.Bold("swat stopcheck")} to stop the check.", important : false); }