mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-10 15:58:13 +07:00
Backporting changes from com.riiablo.server.d2gs to com.riiablo.server.d2gs_test
This commit is contained in:
@ -3,6 +3,7 @@ package com.riiablo.server.d2gs_test;
|
|||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -152,7 +153,7 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
|||||||
final ClientData[] clients = this.clients;
|
final ClientData[] clients = this.clients;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
for (id = 0; id < MAX_CLIENTS && !from.equals(clients[id].address); id++);
|
for (id = 0; id < MAX_CLIENTS && !from.equals(clients[id].address); id++) ;
|
||||||
if (id == MAX_CLIENTS) {
|
if (id == MAX_CLIENTS) {
|
||||||
Gdx.app.debug(TAG, " " + "no connection record found for " + from);
|
Gdx.app.debug(TAG, " " + "no connection record found for " + from);
|
||||||
Gdx.app.debug(TAG, " " + "creating connection record for " + from);
|
Gdx.app.debug(TAG, " " + "creating connection record for " + from);
|
||||||
@ -167,7 +168,7 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Gdx.app.debug(TAG, " " + "assigned " + from + " to " + id);
|
Gdx.app.debug(TAG, " " + "assigned " + from + " to " + id);
|
||||||
client = clients[id].connect(from, clientSalt);
|
client = clients[id].connect(ctx.channel(), from, clientSalt);
|
||||||
} else {
|
} else {
|
||||||
Gdx.app.debug(TAG, " " + "found connection record for " + from + " as " + id);
|
Gdx.app.debug(TAG, " " + "found connection record for " + from + " as " + id);
|
||||||
client = clients[id];
|
client = clients[id];
|
||||||
@ -211,10 +212,10 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
|||||||
synchronized (clients) {
|
synchronized (clients) {
|
||||||
int id;
|
int id;
|
||||||
for (id = 0; id < MAX_CLIENTS && !from.equals(clients[id].address); id++) ;
|
for (id = 0; id < MAX_CLIENTS && !from.equals(clients[id].address); id++) ;
|
||||||
Gdx.app.debug(TAG, " " + "found connection record for " + from + " as " + id);
|
|
||||||
if (id == MAX_CLIENTS) {
|
if (id == MAX_CLIENTS) {
|
||||||
Gdx.app.error(TAG, " " + "channel reported inactive, but there isn't any client connecting from it: " + from);
|
Gdx.app.debug(TAG, " " + "client from " + from + " already disconnected");
|
||||||
} else {
|
} else {
|
||||||
|
Gdx.app.debug(TAG, " " + "found connection record for " + from + " as " + id);
|
||||||
Gdx.app.debug(TAG, " " + "disconnecting " + id);
|
Gdx.app.debug(TAG, " " + "disconnecting " + id);
|
||||||
clients[id].disconnect();
|
clients[id].disconnect();
|
||||||
}
|
}
|
||||||
@ -267,11 +268,13 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
|||||||
long serverSalt;
|
long serverSalt;
|
||||||
long xor;
|
long xor;
|
||||||
byte state;
|
byte state;
|
||||||
|
Channel channel;
|
||||||
SocketAddress address;
|
SocketAddress address;
|
||||||
boolean connected;
|
boolean connected;
|
||||||
|
|
||||||
ClientData connect(SocketAddress address, long clientSalt) {
|
ClientData connect(Channel channel, SocketAddress address, long clientSalt) {
|
||||||
assert !connected;
|
assert !connected;
|
||||||
|
this.channel = channel;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.clientSalt = clientSalt;
|
this.clientSalt = clientSalt;
|
||||||
connected = true;
|
connected = true;
|
||||||
@ -281,9 +284,15 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
|||||||
ClientData disconnect() {
|
ClientData disconnect() {
|
||||||
assert connected;
|
assert connected;
|
||||||
connected = false;
|
connected = false;
|
||||||
|
channel = null;
|
||||||
address = null;
|
address = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return connected ? String.format("[%016x: %s]", xor, address) : "[disconnected]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SizePrefixedDecoder extends ByteToMessageDecoder {
|
private static class SizePrefixedDecoder extends ByteToMessageDecoder {
|
||||||
|
@ -70,8 +70,8 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
|
|
||||||
ChannelFuture f = b.connect("localhost", Main.PORT).sync();
|
ChannelFuture f = b.connect("localhost", Main.PORT).sync();
|
||||||
sendConnectionPacket();
|
sendConnectionPacket();
|
||||||
sendConnectionPacket();
|
// sendConnectionPacket();
|
||||||
sendDisconnectPacket();
|
// sendDisconnectPacket();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Gdx.app.error(TAG, t.getMessage(), t);
|
Gdx.app.error(TAG, t.getMessage(), t);
|
||||||
Gdx.app.exit();
|
Gdx.app.exit();
|
||||||
|
Reference in New Issue
Block a user