mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-06 00:08:19 +07:00
Changed port for d2gs within TCP/IP screen and implemented render() within d2gs
This commit is contained in:
@ -272,7 +272,6 @@ public class Engine extends PooledEngine {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Entity createMonster(Map map, Map.Zone zone, DS1 ds1, DS1.Object object, float x, float y) {
|
private Entity createMonster(Map map, Map.Zone zone, DS1 ds1, DS1.Object object, float x, float y) {
|
||||||
String id = Riiablo.files.obj.getType1(ds1.getAct(), object.id);
|
String id = Riiablo.files.obj.getType1(ds1.getAct(), object.id);
|
||||||
MonStats.Entry monstats = Riiablo.files.monstats.get(id);
|
MonStats.Entry monstats = Riiablo.files.monstats.get(id);
|
||||||
|
@ -129,7 +129,7 @@ public class TCPIPScreen extends ScreenAdapter {
|
|||||||
Gdx.input.getTextInput(new Input.TextInputListener() {
|
Gdx.input.getTextInput(new Input.TextInputListener() {
|
||||||
@Override
|
@Override
|
||||||
public void input(String text) {
|
public void input(String text) {
|
||||||
Socket socket = Gdx.net.newClientSocket(Net.Protocol.TCP, text, 6112, new SocketHints());
|
Socket socket = Gdx.net.newClientSocket(Net.Protocol.TCP, text, 6114, new SocketHints());
|
||||||
socket.dispose();
|
socket.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,16 +13,18 @@ import com.badlogic.gdx.utils.BufferUtils;
|
|||||||
import com.riiablo.engine.Engine;
|
import com.riiablo.engine.Engine;
|
||||||
import com.riiablo.net.packet.d2gs.D2GSData;
|
import com.riiablo.net.packet.d2gs.D2GSData;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -41,14 +43,11 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
ByteBuffer buffer;
|
ByteBuffer buffer;
|
||||||
Thread main;
|
Thread main;
|
||||||
AtomicBoolean kill;
|
AtomicBoolean kill;
|
||||||
Thread cli;
|
|
||||||
ThreadGroup clientThreads;
|
ThreadGroup clientThreads;
|
||||||
CopyOnWriteArrayList<Client> CLIENTS = new CopyOnWriteArrayList<>();
|
CopyOnWriteArrayList<Client> CLIENTS = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private static final String[][] REALMS = new String[][] {
|
final BlockingQueue<com.riiablo.net.packet.d2gs.D2GS> packets = new ArrayBlockingQueue<>(32);
|
||||||
{"localhost", "U.S. West"},
|
final Collection<com.riiablo.net.packet.d2gs.D2GS> cache = new ArrayList<>();
|
||||||
{"localhost", "PTR"},
|
|
||||||
};
|
|
||||||
|
|
||||||
D2GS() {}
|
D2GS() {}
|
||||||
|
|
||||||
@ -110,31 +109,6 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
});
|
});
|
||||||
main.setName("D2GS");
|
main.setName("D2GS");
|
||||||
main.start();
|
main.start();
|
||||||
|
|
||||||
cli = new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
|
||||||
while (!kill.get()) {
|
|
||||||
try {
|
|
||||||
if (!reader.ready()) continue;
|
|
||||||
String in = reader.readLine();
|
|
||||||
if (in.equalsIgnoreCase("exit")) {
|
|
||||||
Gdx.app.exit();
|
|
||||||
} else if (in.equalsIgnoreCase("realms")) {
|
|
||||||
Gdx.app.log(TAG, "realms:");
|
|
||||||
for (String[] realms : REALMS) {
|
|
||||||
Gdx.app.log(TAG, " " + realms[0] + " " + realms[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
Gdx.app.log(TAG, t.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cli.setName("CLI");
|
|
||||||
cli.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -147,7 +121,17 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
} catch (Throwable ignored) {}
|
} catch (Throwable ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void process(Socket socket, com.riiablo.net.packet.d2gs.D2GS packet) throws IOException {
|
@Override
|
||||||
|
public void render() {
|
||||||
|
cache.clear();
|
||||||
|
packets.drainTo(cache);
|
||||||
|
for (com.riiablo.net.packet.d2gs.D2GS packet : cache) {
|
||||||
|
Gdx.app.log(TAG, "processing packet from " + packet);
|
||||||
|
process(null, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void process(Socket socket, com.riiablo.net.packet.d2gs.D2GS packet) {
|
||||||
// switch (packet.dataType()) {
|
// switch (packet.dataType()) {
|
||||||
// case BNLSData.QueryRealms:
|
// case BNLSData.QueryRealms:
|
||||||
// QueryRealms(socket);
|
// QueryRealms(socket);
|
||||||
@ -218,7 +202,11 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
|
|
||||||
com.riiablo.net.packet.d2gs.D2GS packet = com.riiablo.net.packet.d2gs.D2GS.getRootAsD2GS(buffer);
|
com.riiablo.net.packet.d2gs.D2GS packet = com.riiablo.net.packet.d2gs.D2GS.getRootAsD2GS(buffer);
|
||||||
Gdx.app.log(TAG, "packet type " + D2GSData.name(packet.dataType()));
|
Gdx.app.log(TAG, "packet type " + D2GSData.name(packet.dataType()));
|
||||||
process(socket, packet);
|
boolean success = packets.offer(packet);
|
||||||
|
if (!success) {
|
||||||
|
Gdx.app.log(TAG, "queue full -- kicking client");
|
||||||
|
kill.set(true);
|
||||||
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Gdx.app.log(TAG, t.getMessage(), t);
|
Gdx.app.log(TAG, t.getMessage(), t);
|
||||||
kill.set(true);
|
kill.set(true);
|
||||||
@ -227,6 +215,7 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
|
|
||||||
Gdx.app.log(TAG, "closing socket...");
|
Gdx.app.log(TAG, "closing socket...");
|
||||||
if (socket != null) socket.dispose();
|
if (socket != null) socket.dispose();
|
||||||
|
CLIENTS.remove(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user