add timeout to ip grab

This commit is contained in:
Elijah R 2024-04-02 23:33:03 -04:00
parent 9aeb024fec
commit 580fe24d32
2 changed files with 30 additions and 5 deletions

View file

@ -176,7 +176,15 @@ public class DiscordCommands : ApplicationCommandModule
foreach (var vm in vms) foreach (var vm in vms)
{ {
if (!vm.cvm.ConnectedToVM || vm.cvm.Users.All(u => u.Username != username)) continue; if (!vm.cvm.ConnectedToVM || vm.cvm.Users.All(u => u.Username != username)) continue;
var ip = await vm.cvm.GetIP(username); string ip;
try
{
ip = await vm.cvm.GetIP(username);
}
catch (TimeoutException ex)
{
continue;
}
var ipinfo = await Program.IPinfo.IPApi.GetDetailsAsync(ip); var ipinfo = await Program.IPinfo.IPApi.GetDetailsAsync(ip);
IPEmbeds.Add(new DiscordEmbedBuilder() IPEmbeds.Add(new DiscordEmbedBuilder()
.WithAuthor(username) .WithAuthor(username)

View file

@ -113,10 +113,19 @@ public class VM
await cvm.Ban(e.Username); await cvm.Ban(e.Username);
break; break;
} }
string ip;
try
{
ip = await cvm.GetIP(username);
}
catch (TimeoutException ex)
{
ip = "unknown";
}
MessageIncident.Invoke(this, new MessageIncident MessageIncident.Invoke(this, new MessageIncident
{ {
FilterDescription = filter.Description, FilterDescription = filter.Description,
IP = await cvm.GetIP(e.Username), IP = ip,
Message = e.Message, Message = e.Message,
Punishment = filter.Punishment, Punishment = filter.Punishment,
Username = e.Username, Username = e.Username,
@ -128,8 +137,16 @@ public class VM
private async Task CheckUsername(User user) private async Task CheckUsername(User user)
{ {
var ip = await cvm.GetIP(user.Username); string ip;
await database.LogIPAsync(Config.Name, user.Username, IPAddress.Parse(ip)); try
{
ip = await cvm.GetIP(username);
await database.LogIPAsync(Config.Name, user.Username, IPAddress.Parse(ip));
}
catch (TimeoutException ex)
{
ip = "unknown";
}
if (user.Rank != Rank.Unregistered) return; if (user.Rank != Rank.Unregistered) return;
foreach (var filter in Program.Filters.Where(f => f.CheckUsername)) foreach (var filter in Program.Filters.Where(f => f.CheckUsername))
{ {
@ -140,7 +157,7 @@ public class VM
UsernameIncident.Invoke(this, new UsernameIncident UsernameIncident.Invoke(this, new UsernameIncident
{ {
FilterDescription = filter.Description, FilterDescription = filter.Description,
IP = await cvm.GetIP(user.Username), IP = ip,
Username = user.Username, Username = user.Username,
VM = Config.Name VM = Config.Name
}); });