32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
|
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)) {
|
|||
|
ctx.User.Send(new LegacyCommandResponse(LCR.COMMAND_NOT_ALLOWED, true, "/ip"));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
string ipUserStr = ctx.Args.FirstOrDefault();
|
|||
|
ChatUser ipUser;
|
|||
|
|
|||
|
lock(ctx.Chat.UsersAccess)
|
|||
|
if(string.IsNullOrWhiteSpace(ipUserStr) || (ipUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(ipUserStr))) == null) {
|
|||
|
ctx.User.Send(new LegacyCommandResponse(LCR.USER_NOT_FOUND, true, ipUserStr ?? "User"));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
foreach(IPAddress ip in ipUser.RemoteAddresses.Distinct().ToArray())
|
|||
|
ctx.User.Send(new LegacyCommandResponse(LCR.IP_ADDRESS, false, ipUser.Username, ip));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|