mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-04 15:27:30 +07:00
Removed old server code and replaced Account with a different implementation
This commit is contained in:
18
core/src/com/riiablo/net/Account.java
Normal file
18
core/src/com/riiablo/net/Account.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.riiablo.net;
|
||||
|
||||
import com.riiablo.net.packet.bnls.LoginResponse;
|
||||
|
||||
public class Account {
|
||||
public String username;
|
||||
|
||||
public Account() {}
|
||||
|
||||
public Account(LoginResponse loginResponse) {
|
||||
username = loginResponse.username();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return username;
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ import com.riiablo.net.packet.mcp.ListGames;
|
||||
import com.riiablo.net.packet.mcp.MCP;
|
||||
import com.riiablo.net.packet.mcp.MCPData;
|
||||
import com.riiablo.net.packet.mcp.Result;
|
||||
import com.riiablo.server.Account;
|
||||
import com.riiablo.net.Account;
|
||||
import com.riiablo.util.EventUtils;
|
||||
import com.riiablo.widget.Label;
|
||||
import com.riiablo.widget.TextArea;
|
||||
|
@ -30,7 +30,7 @@ import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.net.packet.bnls.BNLS;
|
||||
import com.riiablo.net.packet.bnls.BNLSData;
|
||||
import com.riiablo.net.packet.bnls.LoginResponse;
|
||||
import com.riiablo.server.Account;
|
||||
import com.riiablo.net.Account;
|
||||
import com.riiablo.widget.AnimationWrapper;
|
||||
import com.riiablo.widget.Label;
|
||||
import com.riiablo.widget.TextButton;
|
||||
@ -118,7 +118,6 @@ public class LoginScreen extends ScreenAdapter {
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Actor actor = event.getListenerActor();
|
||||
if (actor == btnLogIn) {
|
||||
|
||||
Socket socket = null;
|
||||
try {
|
||||
socket = Gdx.net.newClientSocket(Net.Protocol.TCP, Riiablo.client.getRealm(), 6110, null);
|
||||
@ -256,7 +255,7 @@ public class LoginScreen extends ScreenAdapter {
|
||||
case BNLSData.LoginResponse:
|
||||
Gdx.app.debug(TAG, "Login successful!");
|
||||
LoginResponse response = (LoginResponse) packet.data(new LoginResponse());
|
||||
final Account account = Account.builder().setAccount(response.username()).build();
|
||||
final Account account = new Account(response);
|
||||
Gdx.app.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -21,7 +21,7 @@ import com.riiablo.codec.DC6;
|
||||
import com.riiablo.codec.StringTBL;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.server.Account;
|
||||
import com.riiablo.net.Account;
|
||||
import com.riiablo.widget.CharacterSelectButton;
|
||||
import com.riiablo.widget.TextButton;
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
public class Account {
|
||||
|
||||
private String account;
|
||||
private String password;
|
||||
|
||||
private Account() {}
|
||||
|
||||
private Account(Builder builder) {
|
||||
account = builder.account;
|
||||
password = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public String account;
|
||||
public String hash;
|
||||
|
||||
public Builder setAccount(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Account build() {
|
||||
return new Account(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
|
||||
public class Connect {
|
||||
|
||||
public int id;
|
||||
public String name;
|
||||
public int classId;
|
||||
public byte[] composites;
|
||||
public byte[] colors;
|
||||
|
||||
private Connect() {}
|
||||
|
||||
public Connect(String name, int classId, byte[] composites, byte[] colors) {
|
||||
this.name = name;
|
||||
this.classId = classId;
|
||||
this.composites = composites;
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public Connect(Entity player) {
|
||||
// Player.D2SStats stats = (Player.D2SStats) player.stats;
|
||||
// this.name = stats.d2s.header.name;
|
||||
// this.classId = stats.d2s.header.charClass;
|
||||
// this.composites = stats.d2s.header.composites;
|
||||
// this.colors = stats.d2s.header.colors;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
public class ConnectResponse {
|
||||
|
||||
public int id;
|
||||
|
||||
private ConnectResponse() {}
|
||||
|
||||
public ConnectResponse(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
public class Disconnect {
|
||||
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
private Disconnect() {}
|
||||
|
||||
public Disconnect(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
import com.riiablo.Riiablo;
|
||||
|
||||
public class Event {
|
||||
|
||||
public int id;
|
||||
public String[] args;
|
||||
|
||||
private Event() {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Riiablo.string.format(id, (Object[]) args);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
public class Message {
|
||||
|
||||
public String name;
|
||||
public String text;
|
||||
|
||||
private Message() {}
|
||||
|
||||
public Message(String name, String text) {
|
||||
this.name = name;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ": " + text;
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
|
||||
public class MoveTo {
|
||||
|
||||
public int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public float angle;
|
||||
|
||||
private MoveTo() {}
|
||||
|
||||
public MoveTo(GridPoint2 origin, float angle) {
|
||||
x = origin.x;
|
||||
y = origin.y;
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
|
||||
public class Packet {
|
||||
|
||||
private static final Json JSON = new Json();
|
||||
|
||||
public int type;
|
||||
public int version;
|
||||
public JsonValue data;
|
||||
|
||||
Packet(int type, int version, JsonValue data) {
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public <T> T readValue(Class<T> type) {
|
||||
return JSON.readValue(type, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJson(this);
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonReader;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
|
||||
public class Packets {
|
||||
|
||||
private static final Json JSON = new Json();
|
||||
|
||||
private Packets() {}
|
||||
|
||||
public static final int MESSAGE = 1;
|
||||
public static final int CONNECT = 2;
|
||||
public static final int DISCONNECT = 3;
|
||||
public static final int MOVETO = 4;
|
||||
public static final int CONNECT_RESPONSE = 5;
|
||||
|
||||
private static final ObjectIntMap<Class> MAP;
|
||||
static {
|
||||
MAP = new ObjectIntMap<>();
|
||||
MAP.put(Message.class, 1);
|
||||
MAP.put(Connect.class, 2);
|
||||
MAP.put(Disconnect.class, 3);
|
||||
MAP.put(MoveTo.class, 4);
|
||||
MAP.put(ConnectResponse.class, 5);
|
||||
}
|
||||
|
||||
public static <T> T parse(Class<T> type, String json) {
|
||||
return parse(json).readValue(type);
|
||||
}
|
||||
|
||||
public static Packet parse(String json) {
|
||||
// TODO: Replace with indexes when well-formed later on
|
||||
JsonValue value = new JsonReader().parse(json);
|
||||
int type = value.getInt("type", 0);
|
||||
int version = value.getInt("version", 0);
|
||||
JsonValue data = value.get("data");
|
||||
return new Packet(type, version, data);
|
||||
}
|
||||
|
||||
public static int getType(String json) {
|
||||
return new JsonReader().parse(json).getInt("type", 0);
|
||||
}
|
||||
|
||||
public static String build(Object instance) {
|
||||
int type = MAP.get(instance.getClass(), 0);
|
||||
if (type == 0) return null;
|
||||
//JsonValue data = new JsonReader().parse(JSON.toJson(instance));
|
||||
EncodedJsonPacket obj = new EncodedJsonPacket(type, 0, instance);
|
||||
return JSON.toJson(obj);
|
||||
}
|
||||
|
||||
private static class EncodedJsonPacket {
|
||||
int type;
|
||||
int version;
|
||||
Object data;
|
||||
|
||||
EncodedJsonPacket() {}
|
||||
EncodedJsonPacket(int type, int version, Object data) {
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
public class Session {
|
||||
|
||||
public String name;
|
||||
public String password;
|
||||
public String desc;
|
||||
public String host;
|
||||
public int port;
|
||||
|
||||
private Session() {}
|
||||
|
||||
public Session(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Session(Builder builder) {
|
||||
name = builder.name;
|
||||
password = builder.password;
|
||||
desc = builder.desc;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public String name;
|
||||
public String password;
|
||||
public String desc;
|
||||
|
||||
public Session build() {
|
||||
return new Session(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.riiablo.server;
|
||||
|
||||
public class SessionError {
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
private SessionError() {}
|
||||
|
||||
public SessionError(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return code + " " + message;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user