2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Packet;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
|
|
|
|
public class RemoteAddressCommand : IChatCommand {
|
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("ip")
|
|
|
|
|
|| ctx.NameEquals("whois");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
|
|
|
if(!ctx.User.Can(ChatUserPermissions.SeeIPAddress)) {
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.COMMAND_NOT_ALLOWED, true, "/ip"));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 19:18:55 +00:00
|
|
|
|
string? ipUserStr = ctx.Args.FirstOrDefault();
|
|
|
|
|
ChatUser? ipUser;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2023-02-19 22:27:08 +00:00
|
|
|
|
if(string.IsNullOrWhiteSpace(ipUserStr) || (ipUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(ipUserStr))) == null) {
|
2024-05-10 19:18:55 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.USER_NOT_FOUND, true, ipUserStr ?? string.Empty));
|
2023-02-19 22:27:08 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2023-02-16 22:33:48 +00:00
|
|
|
|
foreach(IPAddress ip in ctx.Chat.GetRemoteAddresses(ipUser))
|
2023-02-22 00:28:53 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.IP_ADDRESS, false, ipUser.UserName, ip));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|