Tested & fixed a few pieces, still WIP.
This commit is contained in:
parent
3d9df11058
commit
c191024041
Binary file not shown.
36180
javascript/classes.js
36180
javascript/classes.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -347,7 +347,6 @@ window.initializeLANClient = (() => {
|
||||||
}
|
}
|
||||||
if(this.peerConnection != null) {
|
if(this.peerConnection != null) {
|
||||||
this.peerConnection.close();
|
this.peerConnection.close();
|
||||||
this.peerConnection = null;
|
|
||||||
}
|
}
|
||||||
this.peerConnection = new RTCPeerConnection({ iceServers: this.ICEServers, optional: [ { DtlsSrtpKeyAgreement: true } ] });
|
this.peerConnection = new RTCPeerConnection({ iceServers: this.ICEServers, optional: [ { DtlsSrtpKeyAgreement: true } ] });
|
||||||
this.readyState = READYSTATE_CONNECTING;
|
this.readyState = READYSTATE_CONNECTING;
|
||||||
|
@ -398,15 +397,14 @@ window.initializeLANClient = (() => {
|
||||||
|
|
||||||
signalRemoteConnect() {
|
signalRemoteConnect() {
|
||||||
const self = this;
|
const self = this;
|
||||||
if(self.readyState === READYSTATE_CONNECTED || self.readyState === READYSTATE_CONNECTING) {
|
|
||||||
signalRemoteDisconnect();
|
|
||||||
}
|
|
||||||
this.peerConnection.addEventListener("icecandidate", (evt) => {
|
this.peerConnection.addEventListener("icecandidate", (evt) => {
|
||||||
if(evt.candidate) {
|
if(evt.candidate) {
|
||||||
self.iceCandidateHandler(JSON.stringify({ sdpMLineIndex: evt.candidate.sdpMLineIndex, candidate: evt.candidate.candidate }));
|
self.iceCandidateHandler(JSON.stringify({ sdpMLineIndex: evt.candidate.sdpMLineIndex, candidate: evt.candidate.candidate }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
this.peerConnection.addEventListener("datachannel", (evt) => {
|
this.peerConnection.addEventListener("datachannel", (evt) => {
|
||||||
self.channel = evt.channel;
|
self.channel = evt.channel;
|
||||||
self.remoteDataChannelHandler(self.channel);
|
self.remoteDataChannelHandler(self.channel);
|
||||||
|
@ -414,6 +412,17 @@ window.initializeLANClient = (() => {
|
||||||
self.remotePacketHandler(evt.data);
|
self.remotePacketHandler(evt.data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.channel = this.peerConnection.createDataChannel("lan");
|
||||||
|
|
||||||
|
this.channel.addEventListener("open", (evt) => {
|
||||||
|
self.remoteDataChannelHandler(self.channel);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.channel.addEventListener("message", (evt) => {
|
||||||
|
self.remotePacketHandler(evt.data);
|
||||||
|
});
|
||||||
|
|
||||||
this.peerConnection.createOffer((desc) => {
|
this.peerConnection.createOffer((desc) => {
|
||||||
const selfDesc = desc;
|
const selfDesc = desc;
|
||||||
|
@ -443,11 +452,23 @@ window.initializeLANClient = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
signalRemoteDescription(descJSON) {
|
signalRemoteDescription(descJSON) {
|
||||||
this.peerConnection.setRemoteDescription(descJSON);
|
try {
|
||||||
|
this.peerConnection.setRemoteDescription(JSON.parse(descJSON));
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.readyState = READYSTATE_FAILED;
|
||||||
|
this.signalRemoteDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signalRemoteICECandidate(candidate) {
|
signalRemoteICECandidate(candidate) {
|
||||||
this.peerConnection.addICECandidate(candidate);
|
try {
|
||||||
|
this.peerConnection.addIceCandidate(JSON.parse(candidate));
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.readyState = READYSTATE_FAILED;
|
||||||
|
this.signalRemoteDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signalRemoteDisconnect() {
|
signalRemoteDisconnect() {
|
||||||
|
@ -455,7 +476,9 @@ window.initializeLANClient = (() => {
|
||||||
this.dataChannel.close();
|
this.dataChannel.close();
|
||||||
this.dataChannel = null;
|
this.dataChannel = null;
|
||||||
}
|
}
|
||||||
this.peerConnection.close();
|
if(this.peerConnection != null) {
|
||||||
|
this.peerConnection.close();
|
||||||
|
}
|
||||||
this.remoteDisconnectHandler();
|
this.remoteDisconnectHandler();
|
||||||
this.readyState = READYSTATE_DISCONNECTED;
|
this.readyState = READYSTATE_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
@ -497,15 +520,25 @@ window.initializeLANServer = (() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
this.dataChannel = this.peerConnection.createDataChannel("lan");
|
this.dataChannel = this.peerConnection.createDataChannel("lan");
|
||||||
|
|
||||||
this.dataChannel.addEventListener("open", (evt) => {
|
this.dataChannel.addEventListener("open", (evt) => {
|
||||||
self.client.remoteClientDataChannelHandler(self.peerId, this.dataChannel);
|
self.client.remoteClientDataChannelHandler(self.peerId, self.dataChannel);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.dataChannel.addEventListener("message", (evt) => {
|
this.dataChannel.addEventListener("message", (evt) => {
|
||||||
self.client.remoteClientPacketHandler(self.peerId, evt.data);
|
self.client.remoteClientPacketHandler(self.peerId, evt.data);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.peerConnection.addEventListener("datachannel", (evt) => {
|
||||||
|
self.dataChannel = evt.channel;
|
||||||
|
self.client.remoteClientDataChannelHandler(self.peerId, self.dataChannel);
|
||||||
|
self.dataChannel.addEventListener("message", (evt) => {
|
||||||
|
self.client.remoteClientPacketHandler(self.peerId, evt.data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.peerConnection.addEventListener("connectionstatechange", (evt) => {
|
this.peerConnection.addEventListener("connectionstatechange", (evt) => {
|
||||||
if(evt.connectionState === 'disconnected') {
|
if(evt.connectionState === 'disconnected') {
|
||||||
|
|
|
@ -47,21 +47,21 @@ public class EaglerSPClient {
|
||||||
|
|
||||||
public boolean handle(IPacket packet) throws IOException {
|
public boolean handle(IPacket packet) throws IOException {
|
||||||
if(packet instanceof IPacket03ICECandidate) {
|
if(packet instanceof IPacket03ICECandidate) {
|
||||||
if(LoginState.assertEquals(this, LoginState.INIT)) {
|
if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) {
|
||||||
state = LoginState.SENT_ICE_CANDIDATE;
|
state = LoginState.SENT_ICE_CANDIDATE;
|
||||||
server.handleClientICECandidate(this, (IPacket03ICECandidate)packet);
|
server.handleClientICECandidate(this, (IPacket03ICECandidate)packet);
|
||||||
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x03: ICECandidate", (String) socket.getAttachment());
|
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x03: ICECandidate", (String) socket.getAttachment());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}else if(packet instanceof IPacket04Description) {
|
}else if(packet instanceof IPacket04Description) {
|
||||||
if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) {
|
if(LoginState.assertEquals(this, LoginState.INIT)) {
|
||||||
state = LoginState.SENT_DESCRIPTION;
|
state = LoginState.SENT_DESCRIPTION;
|
||||||
server.handleClientDescription(this, (IPacket04Description)packet);
|
server.handleClientDescription(this, (IPacket04Description)packet);
|
||||||
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x04: Description", (String) socket.getAttachment());
|
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x04: Description", (String) socket.getAttachment());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}else if(packet instanceof IPacket05ClientSuccess) {
|
}else if(packet instanceof IPacket05ClientSuccess) {
|
||||||
if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) {
|
if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) {
|
||||||
state = LoginState.FINISHED;
|
state = LoginState.FINISHED;
|
||||||
server.handleClientSuccess(this, (IPacket05ClientSuccess)packet);
|
server.handleClientSuccess(this, (IPacket05ClientSuccess)packet);
|
||||||
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientSuccess", (String) socket.getAttachment());
|
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientSuccess", (String) socket.getAttachment());
|
||||||
|
@ -69,7 +69,7 @@ public class EaglerSPClient {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}else if(packet instanceof IPacket06ClientFailure) {
|
}else if(packet instanceof IPacket06ClientFailure) {
|
||||||
if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) {
|
if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) {
|
||||||
state = LoginState.FINISHED;
|
state = LoginState.FINISHED;
|
||||||
server.handleClientFailure(this, (IPacket06ClientFailure)packet);
|
server.handleClientFailure(this, (IPacket06ClientFailure)packet);
|
||||||
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientFailure", (String) socket.getAttachment());
|
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientFailure", (String) socket.getAttachment());
|
||||||
|
@ -96,7 +96,7 @@ public class EaglerSPClient {
|
||||||
public void disconnect(int code, String reason) {
|
public void disconnect(int code, String reason) {
|
||||||
IPacket pkt = new IPacketFEDisconnectClient(id, code, reason);
|
IPacket pkt = new IPacketFEDisconnectClient(id, code, reason);
|
||||||
if(!serverNotifiedOfClose) {
|
if(!serverNotifiedOfClose) {
|
||||||
server.send(pkt);
|
if (code != IPacketFEDisconnectClient.TYPE_FINISHED_SUCCESS) server.send(pkt);
|
||||||
serverNotifiedOfClose = true;
|
serverNotifiedOfClose = true;
|
||||||
}
|
}
|
||||||
if(this.socket.isOpen()) {
|
if(this.socket.isOpen()) {
|
||||||
|
|
|
@ -368,7 +368,7 @@ public class EaglerSPRelay extends WebSocketServer {
|
||||||
cl = clientConnections.get(arg0);
|
cl = clientConnections.get(arg0);
|
||||||
}
|
}
|
||||||
if(cl != null) {
|
if(cl != null) {
|
||||||
if(cl.handle(pkt)) {
|
if(!cl.handle(pkt)) {
|
||||||
logger.debug("[{}]: Client sent invalid packet: {}", (String) arg0.getAttachment(), pkt.getClass().getSimpleName());
|
logger.debug("[{}]: Client sent invalid packet: {}", (String) arg0.getAttachment(), pkt.getClass().getSimpleName());
|
||||||
arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_INVALID_PACKET,
|
arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_INVALID_PACKET,
|
||||||
"Invalid Packet Recieved")));
|
"Invalid Packet Recieved")));
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class EaglerSPRelayConfigRelayList {
|
||||||
}else if(isTURNHead) {
|
}else if(isTURNHead) {
|
||||||
addType = RelayType.TURN;
|
addType = RelayType.TURN;
|
||||||
}else if(line.startsWith("url")) {
|
}else if(line.startsWith("url")) {
|
||||||
int spidx = line.indexOf('=');
|
int spidx = line.indexOf('=') + 1;
|
||||||
if(spidx < 3) {
|
if(spidx < 3) {
|
||||||
EaglerSPRelay.logger.error("Error: Invalid line in {}: ", line);
|
EaglerSPRelay.logger.error("Error: Invalid line in {}: ", line);
|
||||||
}else {
|
}else {
|
||||||
|
@ -96,7 +96,7 @@ public class EaglerSPRelayConfigRelayList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(line.startsWith("username")) {
|
}else if(line.startsWith("username")) {
|
||||||
int spidx = line.indexOf('=');
|
int spidx = line.indexOf('=') + 1;
|
||||||
if(spidx < 8) {
|
if(spidx < 8) {
|
||||||
EaglerSPRelay.logger.error("Error: Invalid line in {}: ", line);
|
EaglerSPRelay.logger.error("Error: Invalid line in {}: ", line);
|
||||||
}else {
|
}else {
|
||||||
|
@ -108,7 +108,7 @@ public class EaglerSPRelayConfigRelayList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(line.startsWith("password")) {
|
}else if(line.startsWith("password")) {
|
||||||
int spidx = line.indexOf('=');
|
int spidx = line.indexOf('=') + 1;
|
||||||
if(spidx < 8) {
|
if(spidx < 8) {
|
||||||
EaglerSPRelay.logger.error("Error: Invalid line in {}: ", line);
|
EaglerSPRelay.logger.error("Error: Invalid line in {}: ", line);
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -32,18 +32,18 @@ public class GuiScreenAddRelay extends GuiScreen {
|
||||||
StringTranslate var1 = StringTranslate.getInstance();
|
StringTranslate var1 = StringTranslate.getInstance();
|
||||||
EaglerAdapter.enableRepeatEvents(true);
|
EaglerAdapter.enableRepeatEvents(true);
|
||||||
this.buttonList.clear();
|
this.buttonList.clear();
|
||||||
|
this.parentGui.addNewName = IntegratedServer.relayManager.makeNewRelayName();
|
||||||
|
this.parentGui.addNewAddr = "";
|
||||||
|
this.parentGui.addNewPrimary = IntegratedServer.relayManager.count() == 0;
|
||||||
int sslOff = EaglerAdapter.isSSLPage() ? 36 : 0;
|
int sslOff = EaglerAdapter.isSSLPage() ? 36 : 0;
|
||||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12 + sslOff, var1.translateKey("addRelay.add")));
|
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12 + sslOff, var1.translateKey("addRelay.add")));
|
||||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12 + sslOff, var1.translateKey("gui.cancel")));
|
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12 + sslOff, var1.translateKey("gui.cancel")));
|
||||||
this.buttonList.add(new GuiButton(2, this.width / 2 - 100, 142, var1.translateKey("addRelay.primary") + ": " + var1.translateKey("gui.no")));
|
this.buttonList.add(new GuiButton(2, this.width / 2 - 100, 142, var1.translateKey("addRelay.primary") + ": " + (this.parentGui.addNewPrimary ? var1.translateKey("gui.yes") : var1.translateKey("gui.no"))));
|
||||||
this.serverName = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 106, 200, 20);
|
this.serverName = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 106, 200, 20);
|
||||||
this.serverAddress = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 66, 200, 20);
|
this.serverAddress = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 66, 200, 20);
|
||||||
this.serverAddress.setMaxStringLength(128);
|
this.serverAddress.setMaxStringLength(128);
|
||||||
this.serverAddress.setFocused(true);
|
this.serverAddress.setFocused(true);
|
||||||
((GuiButton) this.buttonList.get(0)).enabled = this.serverAddress.getText().length() > 0 && this.serverAddress.getText().split(":").length > 0 && this.serverName.getText().length() > 0;
|
((GuiButton) this.buttonList.get(0)).enabled = this.serverAddress.getText().length() > 0 && this.serverAddress.getText().split(":").length > 0 && this.serverName.getText().length() > 0;
|
||||||
this.parentGui.addNewName = IntegratedServer.relayManager.makeNewRelayName();
|
|
||||||
this.parentGui.addNewAddr = "";
|
|
||||||
this.parentGui.addNewPrimary = IntegratedServer.relayManager.count() == 0;
|
|
||||||
this.serverName.setText(this.parentGui.addNewName);
|
this.serverName.setText(this.parentGui.addNewName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ public class GuiScreenChangeRelayTimeout extends GuiScreen {
|
||||||
StringTranslate ts = StringTranslate.getInstance();
|
StringTranslate ts = StringTranslate.getInstance();
|
||||||
title = ts.translateKey("networkSettings.relayTimeoutTitle");
|
title = ts.translateKey("networkSettings.relayTimeoutTitle");
|
||||||
buttonList.clear();
|
buttonList.clear();
|
||||||
buttonList.add(new GuiButton(0, width / 2 - 100, height / 3 + 55, ts.translateKey("gui.cancel")));
|
buttonList.add(new GuiButton(0, width / 2 - 100, height / 3 + 55, ts.translateKey("gui.done")));
|
||||||
buttonList.add(new GuiButton(1, width / 2 - 100, height / 3 + 85, ts.translateKey("gui.done")));
|
buttonList.add(new GuiButton(1, width / 2 - 100, height / 3 + 85, ts.translateKey("gui.cancel")));
|
||||||
slider = new GuiSlider2(0, width / 2 - 100, height / 3 + 10, 200, 20, (mc.gameSettings.relayTimeout - 1) / 14.0f, 1.0f) {
|
slider = new GuiSlider2(0, width / 2 - 100, height / 3 + 10, 200, 20, (mc.gameSettings.relayTimeout - 1) / 14.0f, 1.0f) {
|
||||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||||
if(super.mousePressed(par1Minecraft, par2, par3)) {
|
if(super.mousePressed(par1Minecraft, par2, par3)) {
|
||||||
|
@ -41,11 +41,11 @@ public class GuiScreenChangeRelayTimeout extends GuiScreen {
|
||||||
|
|
||||||
public void actionPerformed(GuiButton btn) {
|
public void actionPerformed(GuiButton btn) {
|
||||||
if(btn.id == 0) {
|
if(btn.id == 0) {
|
||||||
mc.displayGuiScreen(parent);
|
|
||||||
}else if(btn.id == 1) {
|
|
||||||
mc.gameSettings.relayTimeout = (int)((slider.sliderValue * 14.0f) + 1.0f);
|
mc.gameSettings.relayTimeout = (int)((slider.sliderValue * 14.0f) + 1.0f);
|
||||||
mc.gameSettings.saveOptions();
|
mc.gameSettings.saveOptions();
|
||||||
mc.displayGuiScreen(parent);
|
mc.displayGuiScreen(parent);
|
||||||
|
}else if(btn.id == 1) {
|
||||||
|
mc.displayGuiScreen(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class IntegratedServerLAN {
|
||||||
Thread.sleep(50l);
|
Thread.sleep(50l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - millis > 1000l);
|
}while(System.currentTimeMillis() - millis < 1000l);
|
||||||
System.out.println("Relay [" + sock.getURI() + "] relay provide ICE servers timeout");
|
System.out.println("Relay [" + sock.getURI() + "] relay provide ICE servers timeout");
|
||||||
closeLAN();
|
closeLAN();
|
||||||
return null;
|
return null;
|
||||||
|
@ -80,6 +80,7 @@ public class IntegratedServerLAN {
|
||||||
lanRelaySocket = null;
|
lanRelaySocket = null;
|
||||||
currentCode = null;
|
currentCode = null;
|
||||||
}
|
}
|
||||||
|
EaglerAdapter.serverLANCloseServer();
|
||||||
cleanupLAN();
|
cleanupLAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +101,7 @@ public class IntegratedServerLAN {
|
||||||
public static void updateLANServer() {
|
public static void updateLANServer() {
|
||||||
if(lanRelaySocket != null) {
|
if(lanRelaySocket != null) {
|
||||||
IPacket pkt;
|
IPacket pkt;
|
||||||
while((pkt = lanRelaySocket.nextPacket()) != null) {
|
while((pkt = lanRelaySocket.readPacket()) != null) {
|
||||||
if(pkt instanceof IPacket02NewClient) {
|
if(pkt instanceof IPacket02NewClient) {
|
||||||
IPacket02NewClient ipkt = (IPacket02NewClient) pkt;
|
IPacket02NewClient ipkt = (IPacket02NewClient) pkt;
|
||||||
if(clients.containsKey(ipkt.clientId)) {
|
if(clients.containsKey(ipkt.clientId)) {
|
||||||
|
@ -180,10 +181,11 @@ public class IntegratedServerLAN {
|
||||||
|
|
||||||
protected LANClient(String clientId) {
|
protected LANClient(String clientId) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
|
EaglerAdapter.serverLANCreatePeer(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleICECandidates(String candidates) {
|
protected void handleICECandidates(String candidates) {
|
||||||
if(state == PRE) {
|
if(state == SENT_DESCRIPTION) {
|
||||||
EaglerAdapter.serverLANPeerICECandidates(clientId, candidates);
|
EaglerAdapter.serverLANPeerICECandidates(clientId, candidates);
|
||||||
long millis = System.currentTimeMillis();
|
long millis = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
|
@ -205,7 +207,7 @@ public class IntegratedServerLAN {
|
||||||
Thread.sleep(20l);
|
Thread.sleep(20l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - millis > 3000l);
|
}while(System.currentTimeMillis() - millis < 3000l);
|
||||||
System.err.println("Getting server ICE candidates for '" + clientId + "' timed out!");
|
System.err.println("Getting server ICE candidates for '" + clientId + "' timed out!");
|
||||||
disconnect();
|
disconnect();
|
||||||
}else {
|
}else {
|
||||||
|
@ -214,7 +216,7 @@ public class IntegratedServerLAN {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDescription(String description) {
|
protected void handleDescription(String description) {
|
||||||
if(state == SENT_ICE_CANDIDATE) {
|
if(state == PRE) {
|
||||||
EaglerAdapter.serverLANPeerDescription(clientId, description);
|
EaglerAdapter.serverLANPeerDescription(clientId, description);
|
||||||
long millis = System.currentTimeMillis();
|
long millis = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
|
@ -236,7 +238,7 @@ public class IntegratedServerLAN {
|
||||||
Thread.sleep(20l);
|
Thread.sleep(20l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - millis > 3000l);
|
}while(System.currentTimeMillis() - millis < 3000l);
|
||||||
System.err.println("Getting server description for '" + clientId + "' timed out!");
|
System.err.println("Getting server description for '" + clientId + "' timed out!");
|
||||||
disconnect();
|
disconnect();
|
||||||
}else {
|
}else {
|
||||||
|
@ -245,7 +247,7 @@ public class IntegratedServerLAN {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleSuccess() {
|
protected void handleSuccess() {
|
||||||
if(state == SENT_DESCRIPTION) {
|
if(state == SENT_ICE_CANDIDATE) {
|
||||||
long millis = System.currentTimeMillis();
|
long millis = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
LANPeerEvent evt;
|
LANPeerEvent evt;
|
||||||
|
@ -254,6 +256,9 @@ public class IntegratedServerLAN {
|
||||||
EaglerAdapter.enableChannel("NET|" + clientId);
|
EaglerAdapter.enableChannel("NET|" + clientId);
|
||||||
state = CONNECTED;
|
state = CONNECTED;
|
||||||
return;
|
return;
|
||||||
|
}else if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
|
||||||
|
// ignore
|
||||||
|
return;
|
||||||
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
|
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
|
||||||
System.err.println("LAN client '" + clientId + "' disconnected while waiting for connection");
|
System.err.println("LAN client '" + clientId + "' disconnected while waiting for connection");
|
||||||
}else {
|
}else {
|
||||||
|
@ -266,7 +271,7 @@ public class IntegratedServerLAN {
|
||||||
Thread.sleep(20l);
|
Thread.sleep(20l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - millis > 3000l);
|
}while(System.currentTimeMillis() - millis < 3000l);
|
||||||
System.err.println("Getting server description for '" + clientId + "' timed out!");
|
System.err.println("Getting server description for '" + clientId + "' timed out!");
|
||||||
disconnect();
|
disconnect();
|
||||||
}else {
|
}else {
|
||||||
|
@ -275,7 +280,7 @@ public class IntegratedServerLAN {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleFailure() {
|
protected void handleFailure() {
|
||||||
if(state == SENT_DESCRIPTION) {
|
if(state == SENT_ICE_CANDIDATE) {
|
||||||
System.err.println("Client '" + clientId + "' failed to connect");
|
System.err.println("Client '" + clientId + "' failed to connect");
|
||||||
disconnect();
|
disconnect();
|
||||||
}else {
|
}else {
|
||||||
|
@ -312,7 +317,10 @@ public class IntegratedServerLAN {
|
||||||
EaglerAdapter.disableChannel("NET|" + clientId);
|
EaglerAdapter.disableChannel("NET|" + clientId);
|
||||||
}
|
}
|
||||||
state = CLOSED;
|
state = CLOSED;
|
||||||
lanRelaySocket.writePacket(new IPacketFEDisconnectClient(clientId, IPacketFEDisconnectClient.TYPE_SERVER_DISCONNECT, "Connection Closed"));
|
if (lanRelaySocket != null) {
|
||||||
|
lanRelaySocket.writePacket(new IPacketFEDisconnectClient(clientId, IPacketFEDisconnectClient.TYPE_SERVER_DISCONNECT, "Connection Closed"));
|
||||||
|
}
|
||||||
|
EaglerAdapter.serverLANDisconnectPeer(clientId);
|
||||||
dead = true;
|
dead = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,29 +76,29 @@ public class LANClientNetworkManager implements INetworkManager {
|
||||||
|
|
||||||
// process
|
// process
|
||||||
EaglerAdapter.clientLANSetICEServersAndConnect(servers.toArray(new String[servers.size()]));
|
EaglerAdapter.clientLANSetICEServersAndConnect(servers.toArray(new String[servers.size()]));
|
||||||
|
|
||||||
// await result
|
// await result
|
||||||
long lm = System.currentTimeMillis();
|
long lm = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
String c = EaglerAdapter.clientLANAwaitICECandidate();
|
String c = EaglerAdapter.clientLANAwaitDescription();
|
||||||
if(c != null) {
|
if(c != null) {
|
||||||
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] client sent ICE candidate");
|
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] client sent description");
|
||||||
|
|
||||||
// 'this.iceCandidateHandler' was called, send result:
|
// 'this.descriptionHandler' was called, send result:
|
||||||
sock.writePacket(new IPacket03ICECandidate("", c));
|
sock.writePacket(new IPacket04Description("", c));
|
||||||
|
|
||||||
connectState = SENT_ICE_CANDIDATE;
|
connectState = SENT_DESCRIPTION;
|
||||||
continue mainLoop;
|
continue mainLoop;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20l);
|
Thread.sleep(20l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - lm > 3000l);
|
}while(System.currentTimeMillis() - lm < 3000l);
|
||||||
|
|
||||||
// no ice candidates were sent
|
// no description was sent
|
||||||
sock.close();
|
sock.close();
|
||||||
System.err.println("Relay [" + displayRelay + "|" + displayCode + "] client provide ICE candidate timeout");
|
System.err.println("Relay [" + displayRelay + "|" + displayCode + "] client provide description timeout");
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
|
@ -121,25 +121,25 @@ public class LANClientNetworkManager implements INetworkManager {
|
||||||
// await result
|
// await result
|
||||||
long lm = System.currentTimeMillis();
|
long lm = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
String c = EaglerAdapter.clientLANAwaitDescription();
|
if(EaglerAdapter.clientLANAwaitChannel()) {
|
||||||
if(c != null) {
|
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] client opened data channel");
|
||||||
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] client sent description");
|
|
||||||
|
// 'this.remoteDataChannelHandler' was called, success
|
||||||
// 'this.descriptionHandler' was called, send result:
|
sock.writePacket(new IPacket05ClientSuccess(ipkt.peerId));
|
||||||
sock.writePacket(new IPacket04Description("", c));
|
sock.close();
|
||||||
|
return new LANClientNetworkManager(displayCode, displayRelay);
|
||||||
connectState = SENT_DESCRIPTION;
|
|
||||||
continue mainLoop;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20l);
|
Thread.sleep(20l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - lm > 3000l);
|
}while(System.currentTimeMillis() - lm < 3000l);
|
||||||
|
|
||||||
// no description was sent
|
// no channel was opened
|
||||||
|
sock.writePacket(new IPacket06ClientFailure());
|
||||||
sock.close();
|
sock.close();
|
||||||
System.err.println("Relay [" + displayRelay + "|" + displayCode + "] client provide description timeout");
|
System.err.println("Relay [" + displayRelay + "|" + displayCode + "] client open data channel timeout");
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
|
@ -152,36 +152,35 @@ public class LANClientNetworkManager implements INetworkManager {
|
||||||
if(connectState == SENT_DESCRIPTION) {
|
if(connectState == SENT_DESCRIPTION) {
|
||||||
|
|
||||||
// %%%%%% Process IPacket04Description %%%%%%
|
// %%%%%% Process IPacket04Description %%%%%%
|
||||||
|
|
||||||
IPacket03ICECandidate ipkt = (IPacket03ICECandidate) pkt;
|
IPacket04Description ipkt = (IPacket04Description) pkt;
|
||||||
|
|
||||||
// process
|
// process
|
||||||
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] recieved server description");
|
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] recieved server description");
|
||||||
EaglerAdapter.clientLANSetDescription(ipkt.candidate);
|
EaglerAdapter.clientLANSetDescription(ipkt.description);
|
||||||
|
|
||||||
// await result
|
// await result
|
||||||
long lm = System.currentTimeMillis();
|
long lm = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
if(EaglerAdapter.clientLANAwaitChannel()) {
|
String c = EaglerAdapter.clientLANAwaitICECandidate();
|
||||||
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] client opened data channel");
|
if(c != null) {
|
||||||
|
System.out.println("Relay [" + displayRelay + "|" + displayCode + "] client sent ICE candidate");
|
||||||
// 'this.remoteDataChannelHandler' was called, success
|
|
||||||
sock.writePacket(new IPacket05ClientSuccess());
|
// 'this.iceCandidateHandler' was called, send result:
|
||||||
sock.close();
|
sock.writePacket(new IPacket03ICECandidate("", c));
|
||||||
return new LANClientNetworkManager(displayCode, displayRelay);
|
|
||||||
|
connectState = SENT_ICE_CANDIDATE;
|
||||||
|
continue mainLoop;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20l);
|
Thread.sleep(20l);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}while(System.currentTimeMillis() - lm > 3000l);
|
}while(System.currentTimeMillis() - lm < 3000l);
|
||||||
|
|
||||||
// no channel was opened
|
// no ice candidates were sent
|
||||||
sock.writePacket(new IPacket06ClientFailure());
|
|
||||||
sock.close();
|
sock.close();
|
||||||
System.err.println("Relay [" + displayRelay + "|" + displayCode + "] client open data channel timeout");
|
System.err.println("Relay [" + displayRelay + "|" + displayCode + "] client provide ICE candidate timeout");
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class GuiIngameMenu extends GuiScreen {
|
||||||
|
|
||||||
private GuiVoiceMenu voiceMenu;
|
private GuiVoiceMenu voiceMenu;
|
||||||
|
|
||||||
|
private GuiButton lanButton;
|
||||||
|
|
||||||
public GuiIngameMenu() {
|
public GuiIngameMenu() {
|
||||||
voiceMenu = new GuiVoiceMenu(this);
|
voiceMenu = new GuiVoiceMenu(this);
|
||||||
}
|
}
|
||||||
|
@ -32,9 +34,8 @@ public class GuiIngameMenu extends GuiScreen {
|
||||||
|
|
||||||
this.buttonList.add(new GuiButton(4, this.width / 2 - 100, this.height / 4 + 24 + var1, StatCollector.translateToLocal("menu.returnToGame")));
|
this.buttonList.add(new GuiButton(4, this.width / 2 - 100, this.height / 4 + 24 + var1, StatCollector.translateToLocal("menu.returnToGame")));
|
||||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + var1, 98, 20, StatCollector.translateToLocal("menu.options")));
|
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + var1, 98, 20, StatCollector.translateToLocal("menu.options")));
|
||||||
GuiButton var3;
|
this.buttonList.add(lanButton = new GuiButton(7, this.width / 2 + 2, this.height / 4 + 96 + var1, 98, 20, StatCollector.translateToLocal(IntegratedServerLAN.isHostingLAN() ? "menu.closeLan" : "menu.shareToLan")));
|
||||||
this.buttonList.add(var3 = new GuiButton(7, this.width / 2 + 2, this.height / 4 + 96 + var1, 98, 20, StatCollector.translateToLocal(IntegratedServerLAN.isHostingLAN() ? "menu.closeLan" : "menu.shareToLan")));
|
lanButton.enabled = mc.isSingleplayer();
|
||||||
var3.enabled = mc.isSingleplayer();
|
|
||||||
this.buttonList.add(new GuiButton(8, 3, 3, 120, 20, StatCollector.translateToLocal("menu.skinCapeSettings")));
|
this.buttonList.add(new GuiButton(8, 3, 3, 120, 20, StatCollector.translateToLocal("menu.skinCapeSettings")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +72,7 @@ public class GuiIngameMenu extends GuiScreen {
|
||||||
IntegratedServerLAN.closeLAN();
|
IntegratedServerLAN.closeLAN();
|
||||||
IntegratedServer.configureLAN(this.mc.theWorld.getWorldInfo().getGameType(), false);
|
IntegratedServer.configureLAN(this.mc.theWorld.getWorldInfo().getGameType(), false);
|
||||||
this.mc.thePlayer.sendChatToPlayer(StatCollector.translateToLocal("lanServer.closed"));
|
this.mc.thePlayer.sendChatToPlayer(StatCollector.translateToLocal("lanServer.closed"));
|
||||||
this.mc.displayGuiScreen((GuiScreen) null);
|
this.lanButton.displayString = StatCollector.translateToLocal("menu.shareToLan");
|
||||||
this.mc.setIngameFocus();
|
|
||||||
this.mc.sndManager.resumeAllSounds();
|
|
||||||
} else {
|
} else {
|
||||||
if(IntegratedServer.relayManager.count() == 0) {
|
if(IntegratedServer.relayManager.count() == 0) {
|
||||||
this.mc.displayGuiScreen(new GuiScreenNoRelays(this, "noRelay.title"));
|
this.mc.displayGuiScreen(new GuiScreenNoRelays(this, "noRelay.title"));
|
||||||
|
|
|
@ -22,11 +22,11 @@ public class GuiShareToLan extends GuiScreen {
|
||||||
private String gameMode = "survival";
|
private String gameMode = "survival";
|
||||||
|
|
||||||
/** True if 'Allow Cheats' is currently enabled */
|
/** True if 'Allow Cheats' is currently enabled */
|
||||||
private boolean allowCommands;
|
private boolean allowCommands = false;
|
||||||
|
|
||||||
private final GuiNetworkSettingsButton relaysButton;
|
private final GuiNetworkSettingsButton relaysButton;
|
||||||
|
|
||||||
private boolean hiddenToggle;
|
private boolean hiddenToggle = false;
|
||||||
|
|
||||||
private GuiTextField codeTextField;
|
private GuiTextField codeTextField;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public class GuiShareToLan extends GuiScreen {
|
||||||
} else if (par1GuiButton.id == 103) {
|
} else if (par1GuiButton.id == 103) {
|
||||||
this.allowCommands = !this.allowCommands;
|
this.allowCommands = !this.allowCommands;
|
||||||
this.func_74088_g();
|
this.func_74088_g();
|
||||||
} else if (par1GuiButton.id == 104) {
|
} else if (par1GuiButton.id == 105) {
|
||||||
this.hiddenToggle = !this.hiddenToggle;
|
this.hiddenToggle = !this.hiddenToggle;
|
||||||
this.func_74088_g();
|
this.func_74088_g();
|
||||||
} else if (par1GuiButton.id == 101) {
|
} else if (par1GuiButton.id == 101) {
|
||||||
|
|
|
@ -3719,7 +3719,23 @@ public class EaglerAdapterImpl2 {
|
||||||
return rtcLANClient.LANClientSupported();
|
return rtcLANClient.LANClientSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void clientLANSetServer(String relay, String peerId) {
|
public static final int clientLANReadyState() {
|
||||||
|
return rtcLANClient.getReadyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void clientLANCloseConnection() {
|
||||||
|
rtcLANClient.signalRemoteDisconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void clientLANSendPacket(byte[] pkt) {
|
||||||
|
rtcLANClient.sendPacketToServer(convertToArrayBuffer(pkt));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final byte[] clientLANReadPacket() {
|
||||||
|
return clientLANPacketBuffer.size() > 0 ? clientLANPacketBuffer.remove(0) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void clientLANSetICEServersAndConnect(String[] servers) {
|
||||||
if(!clientLANinit) {
|
if(!clientLANinit) {
|
||||||
clientLANinit = true;
|
clientLANinit = true;
|
||||||
rtcLANClient.setDescriptionHandler(new EaglercraftLANClient.DescriptionHandler() {
|
rtcLANClient.setDescriptionHandler(new EaglercraftLANClient.DescriptionHandler() {
|
||||||
|
@ -3758,27 +3774,11 @@ public class EaglerAdapterImpl2 {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// todo: java-side: register with relay and set server
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int clientLANReadyState() {
|
|
||||||
return rtcLANClient.getReadyState();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void clientLANCloseConnection() {
|
|
||||||
rtcLANClient.signalRemoteDisconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void clientLANSendPacket(byte[] pkt) {
|
|
||||||
rtcLANClient.sendPacketToServer(convertToArrayBuffer(pkt));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final byte[] clientLANReadPacket() {
|
|
||||||
return clientLANPacketBuffer.size() > 0 ? clientLANPacketBuffer.remove(0) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void clientLANSetICEServersAndConnect(String[] servers) {
|
|
||||||
rtcLANClient.setICEServers(servers);
|
rtcLANClient.setICEServers(servers);
|
||||||
|
if(clientLANReadyState() == rtcLANClient.READYSTATE_CONNECTED || clientLANReadyState() == rtcLANClient.READYSTATE_CONNECTING) {
|
||||||
|
rtcLANClient.signalRemoteDisconnect();
|
||||||
|
}
|
||||||
|
rtcLANClient.initializeClient();
|
||||||
rtcLANClient.signalRemoteConnect();
|
rtcLANClient.signalRemoteConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3850,14 +3850,14 @@ public class EaglerAdapterImpl2 {
|
||||||
serverLANinit = true;
|
serverLANinit = true;
|
||||||
rtcLANServer.setDescriptionHandler(new EaglercraftLANServer.DescriptionHandler() {
|
rtcLANServer.setDescriptionHandler(new EaglercraftLANServer.DescriptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void call(String peerId, String candidate) {
|
public void call(String peerId, String description) {
|
||||||
serverLANEventBuffer.add(new LANPeerEvent.LANPeerDisconnectEvent(peerId));
|
serverLANEventBuffer.add(new LANPeerEvent.LANPeerDescriptionEvent(peerId, description));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rtcLANServer.setICECandidateHandler(new EaglercraftLANServer.ICECandidateHandler() {
|
rtcLANServer.setICECandidateHandler(new EaglercraftLANServer.ICECandidateHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void call(String peerId, String candidate) {
|
public void call(String peerId, String candidate) {
|
||||||
serverLANEventBuffer.add(new LANPeerEvent.LANPeerDisconnectEvent(peerId));
|
serverLANEventBuffer.add(new LANPeerEvent.LANPeerICECandidateEvent(peerId, candidate));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rtcLANServer.setRemoteClientDataChannelHandler(new EaglercraftLANServer.ClientSignalHandler() {
|
rtcLANServer.setRemoteClientDataChannelHandler(new EaglercraftLANServer.ClientSignalHandler() {
|
||||||
|
@ -3892,7 +3892,6 @@ public class EaglerAdapterImpl2 {
|
||||||
|
|
||||||
public static final void serverLANCloseServer() {
|
public static final void serverLANCloseServer() {
|
||||||
rtcLANServer.signalRemoteDisconnect("");
|
rtcLANServer.signalRemoteDisconnect("");
|
||||||
// todo: java-side: disconnect from relay server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final LANPeerEvent serverLANGetEvent() {
|
public static final LANPeerEvent serverLANGetEvent() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user