add commands
This commit is contained in:
parent
9b0d7bcb72
commit
0732d9edff
35 changed files with 366 additions and 95 deletions
|
@ -375,16 +375,33 @@ public class Proxy {
|
||||||
return this.users.get(user.toLowerCase(Locale.US));
|
return this.users.get(user.toLowerCase(Locale.US));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUser(String user, User password) {
|
public void setUser(User usr) {
|
||||||
this.users.put(user.toLowerCase(Locale.US), password);
|
this.users.put(usr.getUsername().toLowerCase(Locale.US), usr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteUser(String user) {
|
||||||
|
user = user.toLowerCase(Locale.US);
|
||||||
|
this.users.remove(user);
|
||||||
|
this.players.remove(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoggedIn(String user, ProxyHandler handler) {
|
public void setLoggedIn(String user, ProxyHandler handler) {
|
||||||
this.players.put(user.toLowerCase(Locale.US), handler);
|
user = user.toLowerCase(Locale.US);
|
||||||
|
User usr = this.users.remove(user);
|
||||||
|
if(usr != null)
|
||||||
|
handler.copyFrom(usr);
|
||||||
|
this.users.put(user, handler);
|
||||||
|
this.players.put(user, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoggedOut(String user) {
|
public void setLoggedOut(String user) {
|
||||||
this.players.remove(user.toLowerCase(Locale.US));
|
user = user.toLowerCase(Locale.US);
|
||||||
|
ProxyHandler handler = this.players.remove(user);
|
||||||
|
if(handler != null) {
|
||||||
|
User usr = new User(handler.getUsername());
|
||||||
|
usr.copyFrom(handler);
|
||||||
|
this.users.put(user, usr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoggedIn(String user) {
|
public boolean isLoggedIn(String user) {
|
||||||
|
@ -404,6 +421,10 @@ public class Proxy {
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
this.register(new CommandHelp());
|
this.register(new CommandHelp());
|
||||||
this.register(new CommandExit());
|
this.register(new CommandExit());
|
||||||
|
this.register(new CommandAdmin());
|
||||||
|
this.register(new CommandRevoke());
|
||||||
|
this.register(new CommandRegister());
|
||||||
|
this.register(new CommandDelete());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Command> getCommands() {
|
public Map<String, Command> getCommands() {
|
||||||
|
@ -414,6 +435,26 @@ public class Proxy {
|
||||||
return this.players.values();
|
return this.players.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getPlayerNames() {
|
||||||
|
List<String> list = Lists.newArrayList();
|
||||||
|
for(ProxyHandler player : this.players.values()) {
|
||||||
|
list.add(player.getUsername());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<User> getUsers() {
|
||||||
|
return this.users.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getUserNames() {
|
||||||
|
List<String> list = Lists.newArrayList();
|
||||||
|
for(User user : this.users.values()) {
|
||||||
|
list.add(user.getUsername());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
}
|
}
|
||||||
|
@ -445,7 +486,16 @@ public class Proxy {
|
||||||
player.sendMessage(Formatter.DARK_RED + "Internal error trying to execute command");
|
player.sendMessage(Formatter.DARK_RED + "Internal error trying to execute command");
|
||||||
Log.error(t, "Could not execute '%s'" + (player != null ? " as %s" : ""), line, player != null ? player.getUsername() : null);
|
Log.error(t, "Could not execute '%s'" + (player != null ? " as %s" : ""), line, player != null ? player.getUsername() : null);
|
||||||
}
|
}
|
||||||
if(player != null)
|
if(player != null) {
|
||||||
|
int redacted = cmd.getRedactedLogArg(argv.length);
|
||||||
|
if(redacted >= 0 && redacted < argv.length) {
|
||||||
|
StringBuilder sb = new StringBuilder("/vproxy " + cmd.getName());
|
||||||
|
for(int z = 0; z < argv.length && z < redacted; z++) {
|
||||||
|
sb.append(' ').append(argv[z]);
|
||||||
|
}
|
||||||
|
line = sb.append(" [<redacted> ...]").toString();
|
||||||
|
}
|
||||||
Log.info("%s executed: %s", player.getUsername(), line);
|
Log.info("%s executed: %s", player.getUsername(), line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,26 @@ public abstract class Command {
|
||||||
public Iterable<String> complete(Proxy proxy, ProxyHandler player, String[] args) {
|
public Iterable<String> complete(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public int getRedactedLogArg(int args) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
protected static void sendMessage(ProxyHandler player, String msg) {
|
protected static void sendMessage(ProxyHandler player, String msg) {
|
||||||
if(player != null)
|
if(player != null)
|
||||||
player.sendMessage(Formatter.DARK_PURPLE + msg);
|
player.sendMessage(msg);
|
||||||
else
|
else
|
||||||
Log.info(msg);
|
Log.info(Formatter.strip(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void sendMessage(ProxyHandler player, String fmt, Object ... args) {
|
protected static void sendMessage(ProxyHandler player, String fmt, Object ... args) {
|
||||||
sendMessage(player, String.format(fmt, args));
|
sendMessage(player, String.format(fmt, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void sendInfo(ProxyHandler player, String msg) {
|
||||||
|
sendMessage(player, Formatter.LIGHT_PURPLE + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void sendInfo(ProxyHandler player, String fmt, Object ... args) {
|
||||||
|
sendInfo(player, String.format(fmt, args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
49
proxy/src/main/java/proxy/command/CommandAdmin.java
Normal file
49
proxy/src/main/java/proxy/command/CommandAdmin.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package proxy.command;
|
||||||
|
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
|
|
||||||
|
import proxy.Proxy;
|
||||||
|
import proxy.network.ProxyHandler;
|
||||||
|
import proxy.util.Formatter;
|
||||||
|
import proxy.util.User;
|
||||||
|
|
||||||
|
public class CommandAdmin extends Command {
|
||||||
|
public String getName() {
|
||||||
|
return "admin";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Makes a user an admin or lists admins";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArgs() {
|
||||||
|
return "[username]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
if(args.length == 0) {
|
||||||
|
int cnt = 0;
|
||||||
|
for(User user : proxy.getUsers()) {
|
||||||
|
if(user.isAdmin()) {
|
||||||
|
sendMessage(player, Formatter.GREEN + user.getUsername());
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendMessage(player, (cnt == 0 ? Formatter.GRAY + "No admins" : Formatter.DARK_GREEN + (cnt == 1 ? "1 admin" : "%d admins")) + " on this proxy", cnt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
User user = proxy.getUser(args[0]);
|
||||||
|
if(user == null)
|
||||||
|
throw new RunException("'%s' is not registered", args[0]);
|
||||||
|
if(user.isAdmin())
|
||||||
|
throw new RunException("%s is already an admin", user.getUsername());
|
||||||
|
user.setAdmin(true);
|
||||||
|
if(user.isOnline())
|
||||||
|
((ProxyHandler)user).sendMessage(Formatter.GOLD + "You were given proxy admin privileges");
|
||||||
|
sendInfo(player, "%s is now an admin", user.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<String> complete(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
return args.length == 1 ? Collections2.filter(proxy.getUserNames(), user -> !proxy.getUser(user).isAdmin()) : null;
|
||||||
|
}
|
||||||
|
}
|
39
proxy/src/main/java/proxy/command/CommandDelete.java
Normal file
39
proxy/src/main/java/proxy/command/CommandDelete.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package proxy.command;
|
||||||
|
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
|
|
||||||
|
import proxy.Proxy;
|
||||||
|
import proxy.network.ProxyHandler;
|
||||||
|
import proxy.util.User;
|
||||||
|
|
||||||
|
public class CommandDelete extends Command {
|
||||||
|
public String getName() {
|
||||||
|
return "delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Deletes a users profile (console only for admins)";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArgs() {
|
||||||
|
return "<username>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
if(args.length < 1)
|
||||||
|
throw new RunException("Please provide a username");
|
||||||
|
User user = proxy.getUser(args[0]);
|
||||||
|
if(user == null)
|
||||||
|
throw new RunException("'%s' is not registered", args[0]);
|
||||||
|
if(player != null && user.isAdmin())
|
||||||
|
throw new RunException("Only the console can delete users with admin status");
|
||||||
|
if(user.isOnline())
|
||||||
|
((ProxyHandler)user).disconnect("Your profile was deleted");
|
||||||
|
proxy.deleteUser(user.getUsername());
|
||||||
|
sendInfo(player, "The profile of %s was deleted", user.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<String> complete(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
return args.length == 1 ? Collections2.filter(proxy.getUserNames(), user -> !proxy.getUser(user).isAdmin()) : null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import proxy.Proxy;
|
import proxy.Proxy;
|
||||||
import proxy.network.ProxyHandler;
|
import proxy.network.ProxyHandler;
|
||||||
|
import proxy.util.Formatter;
|
||||||
|
|
||||||
public class CommandHelp extends Command {
|
public class CommandHelp extends Command {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -20,7 +21,8 @@ public class CommandHelp extends Command {
|
||||||
|
|
||||||
private static String formatCommand(Command cmd, boolean prefix) {
|
private static String formatCommand(Command cmd, boolean prefix) {
|
||||||
String args = cmd.getArgs();
|
String args = cmd.getArgs();
|
||||||
return (prefix ? "/vproxy " : "") + cmd.getName() + (args == null || args.isEmpty() ? "" : " " + args);
|
return (prefix ? Formatter.DARK_GRAY + "/" + Formatter.DARK_GREEN + "vproxy " : "") + Formatter.AQUA + cmd.getName() + (args == null || args.isEmpty() ? "" : Formatter.GREEN + " " + args)
|
||||||
|
+ Formatter.GRAY + " - " + Formatter.YELLOW + cmd.getHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(Proxy proxy, ProxyHandler player, String[] args) {
|
public void run(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
|
52
proxy/src/main/java/proxy/command/CommandRegister.java
Normal file
52
proxy/src/main/java/proxy/command/CommandRegister.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package proxy.command;
|
||||||
|
|
||||||
|
import proxy.Proxy;
|
||||||
|
import proxy.network.ProxyHandler;
|
||||||
|
import proxy.util.Formatter;
|
||||||
|
import proxy.util.User;
|
||||||
|
|
||||||
|
public class CommandRegister extends Command {
|
||||||
|
public String getName() {
|
||||||
|
return "register";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Registers a new user or lists users";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArgs() {
|
||||||
|
return "<username> <password>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRedactedLogArg(int args) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
if(args.length == 0) {
|
||||||
|
int cnt = proxy.getUsers().size();
|
||||||
|
for(User user : proxy.getUsers()) {
|
||||||
|
sendMessage(player, (user.isAdmin() ? Formatter.GOLD : Formatter.GREEN) + user.getUsername());
|
||||||
|
}
|
||||||
|
sendMessage(player, (cnt == 0 ? Formatter.GRAY + "No users" : Formatter.DARK_GREEN + (cnt == 1 ? "1 user" : "%d users")) + " on this proxy", cnt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(args.length < 2)
|
||||||
|
throw new RunException("Please provide a username and a password");
|
||||||
|
if(!Formatter.isValidUser(args[0]))
|
||||||
|
throw new RunException("'%s' is not a valid username", args[0]);
|
||||||
|
else if(args[0].length() < 3)
|
||||||
|
throw new RunException("Username too short, length must be between 3-16 characters");
|
||||||
|
else if(args[0].length() > 16)
|
||||||
|
throw new RunException("Username too long, length must be between 3-16 characters");
|
||||||
|
User user = proxy.getUser(args[0]);
|
||||||
|
if(user != null)
|
||||||
|
throw new RunException("%s is already registered", user.getUsername());
|
||||||
|
if(args[1].isEmpty() || args[1].length() < proxy.getMinimumPasswordLength())
|
||||||
|
throw new RunException("Password too short, length must be between %d-32 characters", proxy.getMinimumPasswordLength());
|
||||||
|
else if(args[1].length() > 32)
|
||||||
|
throw new RunException("Password too long, length must be between %d-32 characters", proxy.getMinimumPasswordLength());
|
||||||
|
proxy.setUser(User.createUser(args[0], args[1]));
|
||||||
|
sendInfo(player, "%s was successfully registered", args[0]);
|
||||||
|
}
|
||||||
|
}
|
36
proxy/src/main/java/proxy/command/CommandRevoke.java
Normal file
36
proxy/src/main/java/proxy/command/CommandRevoke.java
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package proxy.command;
|
||||||
|
|
||||||
|
import proxy.Proxy;
|
||||||
|
import proxy.network.ProxyHandler;
|
||||||
|
import proxy.util.Formatter;
|
||||||
|
import proxy.util.User;
|
||||||
|
|
||||||
|
public class CommandRevoke extends Command {
|
||||||
|
public String getName() {
|
||||||
|
return "revoke";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Removes a users admin status (console only)";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArgs() {
|
||||||
|
return "<username>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Proxy proxy, ProxyHandler player, String[] args) {
|
||||||
|
if(player != null)
|
||||||
|
throw new RunException("Only the console can revoke admin status");
|
||||||
|
if(args.length < 1)
|
||||||
|
throw new RunException("Please provide a username");
|
||||||
|
User user = proxy.getUser(args[0]);
|
||||||
|
if(user == null)
|
||||||
|
throw new RunException("'%s' is not registered", args[0]);
|
||||||
|
if(!user.isAdmin())
|
||||||
|
throw new RunException("%s is not an admin", user.getUsername());
|
||||||
|
user.setAdmin(false);
|
||||||
|
if(user.isOnline())
|
||||||
|
((ProxyHandler)user).sendMessage(Formatter.RED + "Your admin privileges were revoked");
|
||||||
|
sendInfo(player, "%s is no longer an admin", user.getUsername());
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import proxy.packet.L01PacketEncryptionResponse;
|
||||||
import proxy.packet.R00PacketDisconnect;
|
import proxy.packet.R00PacketDisconnect;
|
||||||
import proxy.packet.R02PacketLoginSuccess;
|
import proxy.packet.R02PacketLoginSuccess;
|
||||||
import proxy.packet.R03PacketEnableCompression;
|
import proxy.packet.R03PacketEnableCompression;
|
||||||
|
import proxy.util.Formatter;
|
||||||
import proxy.util.Log;
|
import proxy.util.Log;
|
||||||
|
|
||||||
public class LoginHandler implements Handler {
|
public class LoginHandler implements Handler {
|
||||||
|
@ -22,15 +23,6 @@ public class LoginHandler implements Handler {
|
||||||
private int timer;
|
private int timer;
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
private static boolean isValidUser(String name) {
|
|
||||||
for(int z = 0; z < name.length(); z++) {
|
|
||||||
char ch = name.charAt(z);
|
|
||||||
if((ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && ch != '_')
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginHandler(Proxy proxy, Connection connection) {
|
public LoginHandler(Proxy proxy, Connection connection) {
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
@ -91,7 +83,7 @@ public class LoginHandler implements Handler {
|
||||||
if(this.state != LoginState.INIT)
|
if(this.state != LoginState.INIT)
|
||||||
throw new IllegalStateException("Unexpected hello packet");
|
throw new IllegalStateException("Unexpected hello packet");
|
||||||
this.username = packet.getProfile();
|
this.username = packet.getProfile();
|
||||||
if(this.username.length() < 3 || this.username.length() > 16 || !isValidUser(this.username)) {
|
if(this.username.length() < 3 || this.username.length() > 16 || !Formatter.isValidUser(this.username)) {
|
||||||
this.disconnect("Invalid username");
|
this.disconnect("Invalid username");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import proxy.util.User;
|
||||||
import proxy.util.Stack;
|
import proxy.util.Stack;
|
||||||
import proxy.util.Log;
|
import proxy.util.Log;
|
||||||
|
|
||||||
public class ProxyHandler implements Handler {
|
public class ProxyHandler extends User implements Handler {
|
||||||
public class ProxyLoginHandler implements Handler {
|
public class ProxyLoginHandler implements Handler {
|
||||||
public void handleEncryptionRequest(R01PacketEncryptionRequest packetIn) {
|
public void handleEncryptionRequest(R01PacketEncryptionRequest packetIn) {
|
||||||
ProxyHandler.this.server.closeChannel("Online mode auth request received");
|
ProxyHandler.this.server.closeChannel("Online mode auth request received");
|
||||||
|
@ -59,7 +59,6 @@ public class ProxyHandler implements Handler {
|
||||||
|
|
||||||
private final Proxy proxy;
|
private final Proxy proxy;
|
||||||
private final Connection client;
|
private final Connection client;
|
||||||
private final String username;
|
|
||||||
|
|
||||||
private Connection server;
|
private Connection server;
|
||||||
|
|
||||||
|
@ -73,7 +72,6 @@ public class ProxyHandler implements Handler {
|
||||||
private boolean wasClosed;
|
private boolean wasClosed;
|
||||||
private volatile int signPreloaded;
|
private volatile int signPreloaded;
|
||||||
private String completion;
|
private String completion;
|
||||||
private boolean admin;
|
|
||||||
|
|
||||||
private static boolean isAllowedChar(char ch) {
|
private static boolean isAllowedChar(char ch) {
|
||||||
return ch != 167 && ch >= 32 && ch != 127;
|
return ch != 167 && ch >= 32 && ch != 127;
|
||||||
|
@ -99,9 +97,9 @@ public class ProxyHandler implements Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyHandler(Proxy proxy, Connection client, String username) {
|
public ProxyHandler(Proxy proxy, Connection client, String username) {
|
||||||
|
super(username);
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.username = username;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
@ -173,6 +171,10 @@ public class ProxyHandler implements Handler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOnline() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void connectToServer() {
|
private void connectToServer() {
|
||||||
this.proxy.setLoggedIn(this.username, this);
|
this.proxy.setLoggedIn(this.username, this);
|
||||||
final String host = this.proxy.getForwardHost();
|
final String host = this.proxy.getForwardHost();
|
||||||
|
@ -275,9 +277,8 @@ public class ProxyHandler implements Handler {
|
||||||
Formatter.DARK_RED + "" + this.proxy.getMinimumPasswordLength() + "-32 characters");
|
Formatter.DARK_RED + "" + this.proxy.getMinimumPasswordLength() + "-32 characters");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.proxy.setUser(this.username, User.createUser(this.username, password));
|
this.proxy.setUser(User.createUser(this.username, password));
|
||||||
Log.info("%s registered with password", this.username);
|
Log.info("%s registered with password", this.username);
|
||||||
this.admin = true; //false;
|
|
||||||
this.connectToServer();
|
this.connectToServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,13 +290,16 @@ public class ProxyHandler implements Handler {
|
||||||
this.setSign(Formatter.DARK_RED + "" + Formatter.UNDERLINE + "Wrong password", Formatter.DARK_RED + "Please try again");
|
this.setSign(Formatter.DARK_RED + "" + Formatter.UNDERLINE + "Wrong password", Formatter.DARK_RED + "Please try again");
|
||||||
Log.info("%s failed password attempt %d/%d", this.username, this.passwordAttempts, this.proxy.getMaximumPasswordAttempts());
|
Log.info("%s failed password attempt %d/%d", this.username, this.passwordAttempts, this.proxy.getMaximumPasswordAttempts());
|
||||||
}
|
}
|
||||||
else if(this.proxy.isCheckingCase() && !stored.getName().equals(this.username)) {
|
else if(this.proxy.isCheckingCase() && !stored.getUsername().equals(this.username)) {
|
||||||
this.disconnect("You used the wrong username casing, please use '" + stored.getName() + "' exactly");
|
this.disconnect("You used the wrong username casing, please use '" + stored.getUsername() + "' exactly");
|
||||||
Log.info("%s tried to use a different username casing", this.username);
|
Log.info("%s tried to use a different username casing", this.username);
|
||||||
}
|
}
|
||||||
|
else if(this.proxy.getPlayer(this.username) != null) {
|
||||||
|
this.disconnect("You are already logged in");
|
||||||
|
Log.info("%s was already logged in from another client", this.username);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
Log.info("%s logged in with password", this.username);
|
Log.info("%s logged in with password", this.username);
|
||||||
this.admin = true; //stored.isAdmin();
|
|
||||||
this.connectToServer();
|
this.connectToServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,6 +391,7 @@ public class ProxyHandler implements Handler {
|
||||||
for(ProxyHandler player : this.proxy.getPlayers()) {
|
for(ProxyHandler player : this.proxy.getPlayers()) {
|
||||||
player.sendToClient(new S02PacketChat(msg, (byte)1));
|
player.sendToClient(new S02PacketChat(msg, (byte)1));
|
||||||
}
|
}
|
||||||
|
Log.info(Formatter.strip(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -849,7 +854,7 @@ public class ProxyHandler implements Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleCombatEvent(S42PacketCombatEvent packetIn) {
|
public void handleCombatEvent(S42PacketCombatEvent packetIn) {
|
||||||
this.sendToClient(packetIn);
|
// this.sendToClient(packetIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleServerDifficulty(S41PacketServerDifficulty packetIn) {
|
public void handleServerDifficulty(S41PacketServerDifficulty packetIn) {
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class C02PacketUseEntity implements Packet<ProxyHandler>
|
public class C02PacketUseEntity extends EntityIdPacketServer implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private C02PacketUseEntity.Action action;
|
private C02PacketUseEntity.Action action;
|
||||||
private float hitX;
|
private float hitX;
|
||||||
private float hitY;
|
private float hitY;
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class C0BPacketEntityAction implements Packet<ProxyHandler>
|
public class C0BPacketEntityAction extends EntityIdPacketServer implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityID;
|
|
||||||
private C0BPacketEntityAction.Action action;
|
private C0BPacketEntityAction.Action action;
|
||||||
private int auxData;
|
private int auxData;
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ public class C0BPacketEntityAction implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
this.entityID = buf.readVarIntFromBuffer();
|
this.entityId = buf.readVarIntFromBuffer();
|
||||||
this.action = (C0BPacketEntityAction.Action)buf.readEnumValue(C0BPacketEntityAction.Action.class);
|
this.action = (C0BPacketEntityAction.Action)buf.readEnumValue(C0BPacketEntityAction.Action.class);
|
||||||
this.auxData = buf.readVarIntFromBuffer();
|
this.auxData = buf.readVarIntFromBuffer();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +26,7 @@ public class C0BPacketEntityAction implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.entityID);
|
buf.writeVarIntToBuffer(this.entityId);
|
||||||
buf.writeEnumValue(this.action);
|
buf.writeEnumValue(this.action);
|
||||||
buf.writeVarIntToBuffer(this.auxData);
|
buf.writeVarIntToBuffer(this.auxData);
|
||||||
}
|
}
|
||||||
|
|
10
proxy/src/main/java/proxy/packet/EntityIdPacketClient.java
Normal file
10
proxy/src/main/java/proxy/packet/EntityIdPacketClient.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package proxy.packet;
|
||||||
|
|
||||||
|
public class EntityIdPacketClient {
|
||||||
|
protected int entityId;
|
||||||
|
|
||||||
|
public void replaceEntityId(int real, int spoofed) {
|
||||||
|
if(this.entityId == real)
|
||||||
|
this.entityId = spoofed;
|
||||||
|
}
|
||||||
|
}
|
10
proxy/src/main/java/proxy/packet/EntityIdPacketServer.java
Normal file
10
proxy/src/main/java/proxy/packet/EntityIdPacketServer.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package proxy.packet;
|
||||||
|
|
||||||
|
public class EntityIdPacketServer {
|
||||||
|
protected int entityId;
|
||||||
|
|
||||||
|
public void replaceEntityId(int real, int spoofed) {
|
||||||
|
if(this.entityId == spoofed)
|
||||||
|
this.entityId = real;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S01PacketJoinGame implements Packet<ProxyHandler>
|
public class S01PacketJoinGame extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private boolean hardcoreMode;
|
private boolean hardcoreMode;
|
||||||
private byte gameType;
|
private byte gameType;
|
||||||
private int dimension;
|
private int dimension;
|
||||||
|
|
|
@ -7,9 +7,8 @@ import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
import proxy.util.Stack;
|
import proxy.util.Stack;
|
||||||
|
|
||||||
public class S04PacketEntityEquipment implements Packet<ProxyHandler>
|
public class S04PacketEntityEquipment extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityID;
|
|
||||||
private int equipmentSlot;
|
private int equipmentSlot;
|
||||||
private Stack itemStack;
|
private Stack itemStack;
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ public class S04PacketEntityEquipment implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
this.entityID = buf.readVarIntFromBuffer();
|
this.entityId = buf.readVarIntFromBuffer();
|
||||||
this.equipmentSlot = buf.readShort();
|
this.equipmentSlot = buf.readShort();
|
||||||
this.itemStack = buf.readStack();
|
this.itemStack = buf.readStack();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +27,7 @@ public class S04PacketEntityEquipment implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.entityID);
|
buf.writeVarIntToBuffer(this.entityId);
|
||||||
buf.writeShort(this.equipmentSlot);
|
buf.writeShort(this.equipmentSlot);
|
||||||
buf.writeStack(this.itemStack);
|
buf.writeStack(this.itemStack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,8 @@ import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
import proxy.util.Vec3;
|
import proxy.util.Vec3;
|
||||||
|
|
||||||
public class S0APacketUseBed implements Packet<ProxyHandler>
|
public class S0APacketUseBed extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int playerID;
|
|
||||||
private Vec3 bedPos;
|
private Vec3 bedPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +16,7 @@ public class S0APacketUseBed implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
this.playerID = buf.readVarIntFromBuffer();
|
this.entityId = buf.readVarIntFromBuffer();
|
||||||
this.bedPos = buf.readVector();
|
this.bedPos = buf.readVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ public class S0APacketUseBed implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.playerID);
|
buf.writeVarIntToBuffer(this.entityId);
|
||||||
buf.writeVector(this.bedPos);
|
buf.writeVector(this.bedPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S0BPacketAnimation implements Packet<ProxyHandler>
|
public class S0BPacketAnimation extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private int type;
|
private int type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,9 +9,8 @@ import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
import proxy.util.EntityData;
|
import proxy.util.EntityData;
|
||||||
|
|
||||||
public class S0CPacketSpawnPlayer implements Packet<ProxyHandler>
|
public class S0CPacketSpawnPlayer extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private UUID playerId;
|
private UUID playerId;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
|
|
|
@ -6,10 +6,9 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S0DPacketCollectItem implements Packet<ProxyHandler>
|
public class S0DPacketCollectItem extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int collectedItemEntityId;
|
private int collectedItemEntityId;
|
||||||
private int entityId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the raw packet data from the data stream.
|
* Reads the raw packet data from the data stream.
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S12PacketEntityVelocity implements Packet<ProxyHandler>
|
public class S12PacketEntityVelocity extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityID;
|
|
||||||
private int motionX;
|
private int motionX;
|
||||||
private int motionY;
|
private int motionY;
|
||||||
private int motionZ;
|
private int motionZ;
|
||||||
|
@ -18,7 +17,7 @@ public class S12PacketEntityVelocity implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
this.entityID = buf.readVarIntFromBuffer();
|
this.entityId = buf.readVarIntFromBuffer();
|
||||||
this.motionX = buf.readShort();
|
this.motionX = buf.readShort();
|
||||||
this.motionY = buf.readShort();
|
this.motionY = buf.readShort();
|
||||||
this.motionZ = buf.readShort();
|
this.motionZ = buf.readShort();
|
||||||
|
@ -29,7 +28,7 @@ public class S12PacketEntityVelocity implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.entityID);
|
buf.writeVarIntToBuffer(this.entityId);
|
||||||
buf.writeShort(this.motionX);
|
buf.writeShort(this.motionX);
|
||||||
buf.writeShort(this.motionY);
|
buf.writeShort(this.motionY);
|
||||||
buf.writeShort(this.motionZ);
|
buf.writeShort(this.motionZ);
|
||||||
|
|
|
@ -8,18 +8,25 @@ import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S13PacketDestroyEntities implements Packet<ProxyHandler>
|
public class S13PacketDestroyEntities implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int[] entityIDs;
|
private int[] entityIds;
|
||||||
|
|
||||||
|
public void replaceEntityIds(int real, int spoofed) {
|
||||||
|
for(int z = 0; z < this.entityIds.length; z++) {
|
||||||
|
if(this.entityIds[z] == real)
|
||||||
|
this.entityIds[z] = spoofed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the raw packet data from the data stream.
|
* Reads the raw packet data from the data stream.
|
||||||
*/
|
*/
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
this.entityIDs = new int[buf.readVarIntFromBuffer()];
|
this.entityIds = new int[buf.readVarIntFromBuffer()];
|
||||||
|
|
||||||
for (int i = 0; i < this.entityIDs.length; ++i)
|
for (int i = 0; i < this.entityIds.length; ++i)
|
||||||
{
|
{
|
||||||
this.entityIDs[i] = buf.readVarIntFromBuffer();
|
this.entityIds[i] = buf.readVarIntFromBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +35,11 @@ public class S13PacketDestroyEntities implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.entityIDs.length);
|
buf.writeVarIntToBuffer(this.entityIds.length);
|
||||||
|
|
||||||
for (int i = 0; i < this.entityIDs.length; ++i)
|
for (int i = 0; i < this.entityIds.length; ++i)
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.entityIDs[i]);
|
buf.writeVarIntToBuffer(this.entityIds[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S14PacketEntity implements Packet<ProxyHandler>
|
public class S14PacketEntity extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
protected int entityId;
|
|
||||||
protected byte posX;
|
protected byte posX;
|
||||||
protected byte posY;
|
protected byte posY;
|
||||||
protected byte posZ;
|
protected byte posZ;
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S18PacketEntityTeleport implements Packet<ProxyHandler>
|
public class S18PacketEntityTeleport extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private int posX;
|
private int posX;
|
||||||
private int posY;
|
private int posY;
|
||||||
private int posZ;
|
private int posZ;
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S19PacketEntityHeadLook implements Packet<ProxyHandler>
|
public class S19PacketEntityHeadLook extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private byte yaw;
|
private byte yaw;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S19PacketEntityStatus implements Packet<ProxyHandler>
|
public class S19PacketEntityStatus extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private byte logicOpcode;
|
private byte logicOpcode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,12 +6,17 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S1BPacketEntityAttach implements Packet<ProxyHandler>
|
public class S1BPacketEntityAttach extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int leash;
|
private int leash;
|
||||||
private int entityId;
|
|
||||||
private int vehicleEntityId;
|
private int vehicleEntityId;
|
||||||
|
|
||||||
|
public void replaceEntityId(int real, int spoofed) {
|
||||||
|
super.replaceEntityId(real, spoofed);
|
||||||
|
if(this.vehicleEntityId == real)
|
||||||
|
this.vehicleEntityId = spoofed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the raw packet data from the data stream.
|
* Reads the raw packet data from the data stream.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,9 +8,8 @@ import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
import proxy.util.EntityData;
|
import proxy.util.EntityData;
|
||||||
|
|
||||||
public class S1CPacketEntityMetadata implements Packet<ProxyHandler>
|
public class S1CPacketEntityMetadata extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private List<EntityData> field_149378_b;
|
private List<EntityData> field_149378_b;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S1DPacketEntityEffect implements Packet<ProxyHandler>
|
public class S1DPacketEntityEffect extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private byte effectId;
|
private byte effectId;
|
||||||
private byte amplifier;
|
private byte amplifier;
|
||||||
private int duration;
|
private int duration;
|
||||||
|
|
|
@ -6,9 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S1EPacketRemoveEntityEffect implements Packet<ProxyHandler>
|
public class S1EPacketRemoveEntityEffect extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private int effectId;
|
private int effectId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,9 +11,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S20PacketEntityProperties implements Packet<ProxyHandler>
|
public class S20PacketEntityProperties extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private final List<S20PacketEntityProperties.Snapshot> field_149444_b = Lists.<S20PacketEntityProperties.Snapshot>newArrayList();
|
private final List<S20PacketEntityProperties.Snapshot> field_149444_b = Lists.<S20PacketEntityProperties.Snapshot>newArrayList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,9 +7,8 @@ import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
import proxy.util.Vec3;
|
import proxy.util.Vec3;
|
||||||
|
|
||||||
public class S25PacketBlockBreakAnim implements Packet<ProxyHandler>
|
public class S25PacketBlockBreakAnim extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int breakerId;
|
|
||||||
private Vec3 position;
|
private Vec3 position;
|
||||||
private int progress;
|
private int progress;
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ public class S25PacketBlockBreakAnim implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
this.breakerId = buf.readVarIntFromBuffer();
|
this.entityId = buf.readVarIntFromBuffer();
|
||||||
this.position = buf.readVector();
|
this.position = buf.readVector();
|
||||||
this.progress = buf.readUnsignedByte();
|
this.progress = buf.readUnsignedByte();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +27,7 @@ public class S25PacketBlockBreakAnim implements Packet<ProxyHandler>
|
||||||
*/
|
*/
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException
|
||||||
{
|
{
|
||||||
buf.writeVarIntToBuffer(this.breakerId);
|
buf.writeVarIntToBuffer(this.entityId);
|
||||||
buf.writeVector(this.position);
|
buf.writeVector(this.position);
|
||||||
buf.writeByte(this.progress);
|
buf.writeByte(this.progress);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S43PacketCamera implements Packet<ProxyHandler>
|
public class S43PacketCamera extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the raw packet data from the data stream.
|
* Reads the raw packet data from the data stream.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,9 +7,8 @@ import proxy.network.ProxyHandler;
|
||||||
import proxy.network.Packet;
|
import proxy.network.Packet;
|
||||||
import proxy.network.PacketBuffer;
|
import proxy.network.PacketBuffer;
|
||||||
|
|
||||||
public class S49PacketUpdateEntityNBT implements Packet<ProxyHandler>
|
public class S49PacketUpdateEntityNBT extends EntityIdPacketClient implements Packet<ProxyHandler>
|
||||||
{
|
{
|
||||||
private int entityId;
|
|
||||||
private NbtCompound tagCompound;
|
private NbtCompound tagCompound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -90,6 +90,15 @@ public enum Formatter {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidUser(String name) {
|
||||||
|
for(int z = 0; z < name.length(); z++) {
|
||||||
|
char ch = name.charAt(z);
|
||||||
|
if((ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && ch != '_')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private Formatter(char code) {
|
private Formatter(char code) {
|
||||||
this.value = "\u00a7" + code;
|
this.value = "\u00a7" + code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,22 @@ import java.security.SecureRandom;
|
||||||
public class User {
|
public class User {
|
||||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
private final String username;
|
protected final String username;
|
||||||
private final byte[] hash;
|
|
||||||
private final byte[] salt;
|
|
||||||
|
|
||||||
private boolean admin;
|
private byte[] hash;
|
||||||
|
private byte[] salt;
|
||||||
|
protected boolean admin;
|
||||||
|
|
||||||
public User(String username, byte[] hash, byte[] salt) {
|
public User(String username) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(byte[] hash, byte[] salt) {
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.salt = salt;
|
this.salt = salt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getUsername() {
|
||||||
return this.username;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +39,16 @@ public class User {
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOnline() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyFrom(User user) {
|
||||||
|
this.hash = user.hash;
|
||||||
|
this.salt = user.salt;
|
||||||
|
this.admin = user.admin;
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] hashPassword(String pass, byte[] salt) {
|
private static byte[] hashPassword(String pass, byte[] salt) {
|
||||||
try {
|
try {
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
||||||
|
@ -53,6 +66,8 @@ public class User {
|
||||||
SecureRandom rand = new SecureRandom();
|
SecureRandom rand = new SecureRandom();
|
||||||
byte[] salt = new byte[32];
|
byte[] salt = new byte[32];
|
||||||
rand.nextBytes(salt);
|
rand.nextBytes(salt);
|
||||||
return new User(user, hashPassword(pass, salt), salt);
|
User usr = new User(user);
|
||||||
|
usr.setPassword(hashPassword(pass, salt), salt);
|
||||||
|
return usr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue