Commit 21f8461f authored by Adam Gausmann's avatar Adam Gausmann

Add additional fields to Users for further identity verification.

parent c82abda7
package ninja.nonemu.samurai.connection;
import java.io.IOException;
import ninja.nonemu.irc.ChatRecipient;
import ninja.nonemu.irc.ChatSender;
import ninja.nonemu.samurai.command.CommandSender;
public interface User extends ChatSender, ChatRecipient, CommandSender {
String getName();
default String getName() {
return getNickname();
}
ninja.nonemu.irc.User moreInfo() throws IOException;
String getId();
String getNickname();
String getUsername();
String getHostname();
}
package ninja.nonemu.samurai.connection;
import java.io.IOException;
import ninja.nonemu.samurai.BotImpl;
public class UserImpl implements User {
private final BotImpl bot;
private final String name;
private final String id;
private final String nickname;
private final String username;
private final String hostname;
public UserImpl(BotImpl bot, String name) {
public UserImpl(BotImpl bot, String id) {
this.bot = bot;
this.name = name;
this.id = id;
nickname = nickFromId(id);
username = userFromId(id);
hostname = hostFromId(id);
}
/**
......@@ -20,7 +26,7 @@ public class UserImpl implements User {
*/
@Override
public boolean isOperator() {
return bot.getCommandSystem().isOperator(name);
return bot.getCommandSystem().isOperator(id);
}
/**
......@@ -30,7 +36,7 @@ public class UserImpl implements User {
*/
@Override
public boolean isWhitelisted() {
return bot.getCommandSystem().isWhitelisted(name);
return bot.getCommandSystem().isWhitelisted(id);
}
/**
......@@ -40,22 +46,32 @@ public class UserImpl implements User {
*/
@Override
public boolean isBlacklisted() {
return bot.getCommandSystem().isBlacklisted(name);
return bot.getCommandSystem().isBlacklisted(id);
}
@Override
public String getId() {
return id;
}
@Override
public String getNickname() {
return nickname;
}
@Override
public String getName() {
return name;
public String getUsername() {
return username;
}
@Override
public ninja.nonemu.irc.User moreInfo() throws IOException {
return bot.getConnectionManager().getConnection().getUser(name);
public String getHostname() {
return hostname;
}
@Override
public void sendChat(String message) {
bot.getConnectionManager().sendChat(name, message);
bot.getConnectionManager().sendChat(nickname, message);
}
@Override
......@@ -65,16 +81,35 @@ public class UserImpl implements User {
User user = (User) o;
return name.equals(user.getName());
return id.equalsIgnoreCase(user.getId()); // TODO Generify the check to allow for non-specified parameters.
}
@Override
public int hashCode() {
return name.hashCode();
return id.toLowerCase().hashCode();
}
@Override
public String toString() {
return name;
public static String nickFromId(String id) {
if (id.contains("!")) {
return id.substring(0, id.indexOf("!"));
}
return id;
}
public static String userFromId(String id) {
if (id.contains("!")) {
if (id.contains("@")) {
return id.substring(id.indexOf("!") + 1, id.indexOf("@"));
}
return id.substring(id.indexOf("!") + 1);
}
return null;
}
public static String hostFromId(String id) {
if (id.contains("@")) {
return id.substring(id.indexOf("@") + 1);
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment