Added initial version

This commit is contained in:
Ceikry
2021-03-07 20:37:32 -06:00
commit b452bd670c
13290 changed files with 1178433 additions and 0 deletions
@@ -0,0 +1,96 @@
package ms.world.info;
/**
* The country flags.
* @author Emperor
*
*/
public enum CountryFlag {
/**
* Belgium
*/
BELGIUM(22),
/**
* Canada.
*/
CANADA(38),
/**
* The united kingdom.
*/
UNITED_KINGDOM(77),
/**
* Netherlands
*/
NETHERLANDS(161),
/**
* Sweden
*/
SWEDEN(191),
/**
* Finland
*/
FINLAND(69),
/**
* Australia.
*/
AUSTRALIA(16),
/**
* America (USA)
*/
UNITED_STATES_OF_AMERICA(225),
/**
* Norway
*/
NORWAY(162),
/**
* Ireland
*/
IRELAND(101),
/**
* DENMARK
*/
DENMARK(58),
/**
* Brazil
*/
BRAZIL(31),
/**
* Mexico
*/
MEXICO(152),
;
/**
* The flag id.
*/
private final int id;
/**
* Constructs a new {@code CountryFlag} {@code Object}.
* @param id The flag id.
*/
private CountryFlag(int id) {
this.id = id;
}
/**
* @return the id
*/
public int getId() {
return id;
}
}
@@ -0,0 +1,144 @@
package ms.world.info;
/**
* Holds the response codes during the attempt to login.
* @author Emperor
*/
public enum Response {
/**
* An unexpected server response occurred.
*/
UNEXPECTED_RESPONSE(0),
/**
* Could not display advertisement video, logging in in x seconds.
*/
COULD_NOT_DISPLAY_AD(1),
/**
* A successful login.
*/
SUCCESSFUL(2),
/**
* Invalid username or password has been entered.
*/
INVALID_CREDENTIALS(3),
/**
* This account is banned.
*/
ACCOUNT_DISABLED(4),
/**
* This account is already logged in.
*/
ALREADY_ONLINE(5),
/**
* We have updated and client needs to be reloaded.
*/
UPDATED(6),
/**
* The world is full.
*/
FULL_WORLD(7),
/**
* Login server is offline.
*/
LOGIN_SERVER_OFFLINE(8),
/**
* The login limit has been exceeded.
*/
LOGIN_LIMIT_EXCEEDED(9),
/**
* The session key was invalid.
*/
BAD_SESSION_ID(10),
/**
* The password is too weak, and should be improved.
*/
WEAK_PASSWORD(11),
/**
* When trying to connect to a members world while being f2p.
*/
MEMBERS_WORLD(12),
/**
* Could not login.
*/
COULD_NOT_LOGIN(13),
/**
* The server is currently updating.
*/
UPDATING(14),
/**
* Too many incorrect login attempts from your address.
*/
TOO_MANY_INCORRECT_LOGINS(16),
/**
* When logging on a free world while standing in members area.
*/
STANDING_IN_MEMBER(17),
/**
* This account is locked as it might have been stolen.
*/
LOCKED(18),
/**
* Closed beta going on.
*/
CLOSED_BETA(19),
/**
* The login server connected to is invalid.
*/
INVALID_LOGIN_SERVER(20),
/**
* Moving from another world...
*/
MOVING_WORLD(21),
/**
* When the player's saved file exists, but is unable to be loaded.
*/
ERROR_LOADING_PROFILE(24),
/**
* This computer address is disabled as it was used to break our rules.
*/
BANNED(26);
/**
* The buffer.
*/
private final int opcode;
/**
* Constructs a new {@code Response} {@code Object}.
* @param opcode The login response opcode.
*/
Response(int opcode) {
this.opcode = opcode;
}
/**
* Gets the opcode.
* @return The opcode.
*/
public int opcode() {
return opcode;
}
}
@@ -0,0 +1,222 @@
package ms.world.info;
import java.nio.ByteBuffer;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import ms.system.util.ByteBufferUtils;
/**
* The unique info of a player.
* @author Vexia
*
*/
public class UIDInfo {
/**
* The ip address.
*/
private String ip;
/**
* The computer name.
*/
private String compName;
/**
* The mac-address.
*/
private String mac;
/**
* The motherboard serial of the user.
*/
private String serial;
/**
* Constructs a new {@code UIDInfo} {@code Object}
*/
public UIDInfo() {
/*
* empty.
*/
}
/**
* Constructs a new {@code UIDInfo} {@code Object}
* @param ip the ip.
* @param compName the computer name.
* @param mac the mac.
* @param serial the serial.
*/
public UIDInfo(String ip, String compName, String mac, String serial) {
this.ip = ip;
this.compName = compName;
this.mac = mac;
this.serial = serial;
}
/**
* Parses the data from a prepared statement.
* @param set The result set
* @throws SQLException The exception if thrown.
*/
public void parse(ResultSet set) throws SQLException {
setIp(parseFormat(set.getString("ip")));
setCompName(parseFormat(set.getString("computerName")));
setMac(parseFormat(set.getString("mac")));
setSerial(parseFormat(set.getString("serial")));
}
/**
* Saves the UID data on the buffer.
* @param buffer The buffer.
*/
public void save(ByteBuffer buffer) {
save(buffer, ip, 1);
save(buffer, compName, 2);
save(buffer, mac, 3);
save(buffer, serial, 4);
buffer.put((byte) 0);
}
/**
* Parses the UID data from the buffer.
* @param buffer The buffer.
*/
public void parse(ByteBuffer buffer) {
int opcode;
while ((opcode = buffer.get()) != 0) {
switch (opcode) {
case 1:
ip = ByteBufferUtils.getString(buffer);
break;
case 2:
compName = ByteBufferUtils.getString(buffer);
break;
case 3:
mac = ByteBufferUtils.getString(buffer);
break;
case 4:
serial = ByteBufferUtils.getString(buffer);
break;
}
}
}
/**
* Parses a string with a certain format.
* @param string the string.
* @return the string.
*/
private String parseFormat(String string) {
if (string == null || string == "") {
return null;
}
StringTokenizer token = new StringTokenizer(string, "|");
String s = "";
int t = token.countTokens();
for (int i = 0; i < t; i++) {
s = token.nextToken();
}
return s;
}
/**
* Saves a string value to the buffer.
* @param buffer the buffer.
* @param value the value.
* @param opcode the opcode.
*/
private void save(ByteBuffer buffer, String value, int opcode) {
if (value == null) {
return;
}
ByteBufferUtils.putString(value, buffer.put((byte) opcode));
}
/**
* Converts a to string in format mode for an admin or mod.
* @param admin the admin.
* @return the string.
*/
public String toString(boolean admin) {
String format = toString();
if (!admin) {//formats for non-admins
String[] tokens = format.split("serial=");
format = format.replace("serial=", "uid=").replace(tokens[tokens.length - 1], "*****");
}
return format;
}
/**
* Gets the compName.
* @return the compName
*/
public String getCompName() {
return compName;
}
/**
* Gets the ip.
* @return the ip
*/
public String getIp() {
return ip;
}
/**
* Gets the mac.
* @return the mac
*/
public String getMac() {
return mac;
}
/**
* Gets the serial.
* @return the serial
*/
public String getSerial() {
return serial;
}
/**
* Sets the ip.
* @param ip the ip to set.
*/
public void setIp(String ip) {
this.ip = ip;
}
/**
* Sets the compName.
* @param compName the compName to set.
*/
public void setCompName(String compName) {
this.compName = compName;
}
/**
* Sets the mac.
* @param mac the mac to set.
*/
public void setMac(String mac) {
this.mac = mac;
}
/**
* Sets the serial.
* @param serial the serial to set.
*/
public void setSerial(String serial) {
this.serial = serial;
}
@Override
public String toString() {
return "[ip=" + ip + ", compName=" + compName + ", mac=" + mac + ", serial=" + serial + "]";
}
}
@@ -0,0 +1,163 @@
package ms.world.info;
/**
* Holds the info of a world server.
* @author Emperor
*
*/
public final class WorldInfo {
/**
* The world id.
*/
private final int worldId;
/**
* The IP-address.
*/
private final String address;
/**
* The revision of the world.
*/
private final int revision;
/**
* The country this world is located in.
*/
private final CountryFlag country;
/**
* The world activity.
*/
private final String activity;
/**
* If the world is members only.
*/
private final boolean members;
/**
* If the world is a PvP world.
*/
private final boolean pvp;
/**
* If the world is a quick chat only world.
*/
private final boolean quickChat;
/**
* If the world has lootshare option enabled.
*/
private final boolean lootshare;
/**
* Constructs a new {@code WorldInfo} {@code Object}.
* @param id The world id.
* @param address The address.
* @param country The country flag.
* @param members If the world is members only.
*/
public WorldInfo(int id, String address, int revision, CountryFlag country, String activity, boolean members, boolean pvp, boolean quickChat, boolean lootshare) {
this.worldId = id;
this.address = address;
this.revision = revision;
this.country = country;
this.activity = activity;
this.members = members;
this.pvp = pvp;
this.quickChat = quickChat;
this.lootshare = lootshare;
}
/**
* Gets the settings hash.
* @return The settings hash.
*/
public int getSettings() {
int settings = 0;
if (members) {
settings |= 0x1;
}
if (quickChat) {
settings |= 0x2;
}
if (pvp) {
settings |= 0x4;
}
if (lootshare) {
settings |= 0x8;
}
return settings;
}
/**
* @return the worldId
*/
public int getWorldId() {
return worldId;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @return the country
*/
public CountryFlag getCountry() {
return country;
}
/**
* Gets the members value.
* @return The members.
*/
public boolean isMembers() {
return members;
}
/**
* Gets the activity value.
* @return The activity.
*/
public String getActivity() {
return activity;
}
/**
* Gets the pvp value.
* @return The pvp.
*/
public boolean isPvp() {
return pvp;
}
/**
* Gets the quickChat value.
* @return The quickChat.
*/
public boolean isQuickChat() {
return quickChat;
}
/**
* Gets the lootshare value.
* @return The lootshare.
*/
public boolean isLootshare() {
return lootshare;
}
/**
* Gets the revision.
* @return the revision.
*/
public int getRevision() {
return revision;
}
}