* Fixes, wd:// scheme now works
This commit is contained in:
parent
98ae84bf58
commit
4b8acc8801
|
|
@ -118,12 +118,15 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
||||||
mc = Minecraft.getMinecraft();
|
mc = Minecraft.getMinecraft();
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
registerCustomBlockBaker(new ScreenBaker(), WebDisplays.INSTANCE.blockScreen);
|
registerCustomBlockBaker(new ScreenBaker(), WebDisplays.INSTANCE.blockScreen);
|
||||||
|
|
||||||
|
mcef = MCEFApi.getAPI();
|
||||||
|
if(mcef != null)
|
||||||
|
mcef.registerScheme("wd", WDScheme.class, true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityScreen.class, new ScreenRenderer());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityScreen.class, new ScreenRenderer());
|
||||||
mcef = MCEFApi.getAPI();
|
|
||||||
jsDispatcher = new JSQueryDispatcher(this);
|
jsDispatcher = new JSQueryDispatcher(this);
|
||||||
minePadRenderer = new MinePadRenderer();
|
minePadRenderer = new MinePadRenderer();
|
||||||
laserPointerRenderer = new LaserPointerRenderer();
|
laserPointerRenderer = new LaserPointerRenderer();
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import net.montoyo.wd.WebDisplays;
|
||||||
import net.montoyo.wd.miniserv.Constants;
|
import net.montoyo.wd.miniserv.Constants;
|
||||||
import net.montoyo.wd.miniserv.client.Client;
|
import net.montoyo.wd.miniserv.client.Client;
|
||||||
import net.montoyo.wd.miniserv.client.ClientTaskGetFile;
|
import net.montoyo.wd.miniserv.client.ClientTaskGetFile;
|
||||||
|
import net.montoyo.wd.utilities.Log;
|
||||||
import net.montoyo.wd.utilities.Util;
|
import net.montoyo.wd.utilities.Util;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -47,7 +48,9 @@ public class WDScheme implements IScheme {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getResponseHeaders(ISchemeResponseHeaders resp) {
|
public void getResponseHeaders(ISchemeResponseHeaders resp) {
|
||||||
|
Log.info("Waiting for response...");
|
||||||
int status = task.waitForResponse();
|
int status = task.waitForResponse();
|
||||||
|
Log.info("Got response %d", status);
|
||||||
|
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
//OK
|
//OK
|
||||||
|
|
|
||||||
|
|
@ -93,12 +93,9 @@ public abstract class AbstractClient {
|
||||||
public void readyWrite() throws Throwable {
|
public void readyWrite() throws Throwable {
|
||||||
if(sendBuffer.remaining() > 0 || fillSendBuffer()) {
|
if(sendBuffer.remaining() > 0 || fillSendBuffer()) {
|
||||||
int sent = socket.write(sendBuffer);
|
int sent = socket.write(sendBuffer);
|
||||||
Log.info("Sent %d bytes", sent);
|
|
||||||
|
|
||||||
if(sent < 0) {
|
if(sent < 0)
|
||||||
Log.error("Error when sending data");
|
|
||||||
onWriteError();
|
onWriteError();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +128,7 @@ public abstract class AbstractClient {
|
||||||
synchronized(sendQueue) {
|
synchronized(sendQueue) {
|
||||||
sendQueue.offer(pkt);
|
sendQueue.offer(pkt);
|
||||||
|
|
||||||
if((selKey.interestOps() & SelectionKey.OP_WRITE) == 0) {
|
if(selKey.isValid() && (selKey.interestOps() & SelectionKey.OP_WRITE) == 0) {
|
||||||
selKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
|
selKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
|
||||||
selector.wakeup(); //Is this needed?
|
selector.wakeup(); //Is this needed?
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,6 @@ public abstract class Constants {
|
||||||
public static int GETF_STATUS_NOT_FOUND = 2;
|
public static int GETF_STATUS_NOT_FOUND = 2;
|
||||||
public static int GETF_STATUS_INTERNAL_ERROR = 3;
|
public static int GETF_STATUS_INTERNAL_ERROR = 3;
|
||||||
public static int GETF_STATUS_CONNECTION_LOST = 4;
|
public static int GETF_STATUS_CONNECTION_LOST = 4;
|
||||||
|
public static int GETF_STATUS_TIMED_OUT = 5;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,25 +19,22 @@ public final class PacketReader {
|
||||||
if(needSize) {
|
if(needSize) {
|
||||||
//Read packet size
|
//Read packet size
|
||||||
if(readByteArray(sizeArray, buf)) {
|
if(readByteArray(sizeArray, buf)) {
|
||||||
int packetSize = (sizeArray[0] << 24) | (sizeArray[1] << 16) | (sizeArray[2] << 8) | sizeArray[3];
|
int packetSize = ((sizeArray[0] & 0xFF) << 24) | ((sizeArray[1] & 0xFF) << 16) | ((sizeArray[2] & 0xFF) << 8) | (sizeArray[3] & 0xFF);
|
||||||
needSize = false;
|
needSize = false;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
|
||||||
if(packetSize < 5 || packetSize > 65536) {
|
if(packetSize < 5 || packetSize > 70000) {
|
||||||
Log.warning("Got invalid packet from client of size %d, things won't go well...", packetSize);
|
Log.warning("Got invalid packet of size %d, things won't go well...", packetSize);
|
||||||
return true; //Abort packet reading
|
return true; //Abort packet reading
|
||||||
}
|
}
|
||||||
|
|
||||||
packetSize -= 4;
|
packetSize -= 4;
|
||||||
packetData = new byte[packetSize];
|
packetData = new byte[packetSize];
|
||||||
Log.info("Awaiting packet of size %d", packetSize);
|
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ret = readByteArray(packetData, buf);
|
return readByteArray(packetData, buf);
|
||||||
Log.info("Read %d out of %d, ok = %s", pos, packetData.length, ret ? "true" : "false");
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean readByteArray(byte[] dst, ByteBuffer src) {
|
private boolean readByteArray(byte[] dst, ByteBuffer src) {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import net.montoyo.wd.miniserv.OutgoingPacket;
|
||||||
import net.montoyo.wd.miniserv.PacketID;
|
import net.montoyo.wd.miniserv.PacketID;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
|
@ -67,6 +68,9 @@ public class ClientTaskGetFile extends ClientTask {
|
||||||
response = status;
|
response = status;
|
||||||
hasResponse = true;
|
hasResponse = true;
|
||||||
gotResponse.signal();
|
gotResponse.signal();
|
||||||
|
|
||||||
|
if(response != 0)
|
||||||
|
client.nextTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
responseLock.unlock();
|
responseLock.unlock();
|
||||||
|
|
@ -77,9 +81,16 @@ public class ClientTaskGetFile extends ClientTask {
|
||||||
|
|
||||||
public int waitForResponse() {
|
public int waitForResponse() {
|
||||||
responseLock.lock();
|
responseLock.lock();
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
|
||||||
while(!hasResponse) {
|
while(!hasResponse) {
|
||||||
|
if(System.currentTimeMillis() - t > 10000) {
|
||||||
|
responseLock.unlock();
|
||||||
|
return Constants.GETF_STATUS_TIMED_OUT;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gotResponse.await();
|
gotResponse.await(100, TimeUnit.MILLISECONDS);
|
||||||
} catch(InterruptedException ex) {}
|
} catch(InterruptedException ex) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,9 +117,18 @@ public class ClientTaskGetFile extends ClientTask {
|
||||||
|
|
||||||
public byte[] waitForData() {
|
public byte[] waitForData() {
|
||||||
dataLock.lock();
|
dataLock.lock();
|
||||||
while(this.data == null) {
|
long t = System.currentTimeMillis();
|
||||||
|
|
||||||
|
while(data == null) {
|
||||||
|
if(System.currentTimeMillis() - t > 10000) {
|
||||||
|
data = new byte[1];
|
||||||
|
dataLen = -1;
|
||||||
|
dataLock.unlock();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dataChanged.await();
|
dataChanged.await(100, TimeUnit.MILLISECONDS);
|
||||||
} catch(InterruptedException ex) {}
|
} catch(InterruptedException ex) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
public class ClientTaskUploadFile extends ClientTask implements Consumer<OutgoingPacket> {
|
public class ClientTaskUploadFile extends ClientTask implements Consumer<OutgoingPacket> {
|
||||||
|
|
||||||
private static final byte[] UPLOAD_BUFFER = new byte[65536];
|
private static final byte[] UPLOAD_BUFFER = new byte[65535];
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
private final long size;
|
private final long size;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
public class ServerClient extends AbstractClient {
|
public class ServerClient extends AbstractClient {
|
||||||
|
|
||||||
private static final byte[] FILE_UPLOAD_BUFFER = new byte[65536];
|
private static final byte[] FILE_UPLOAD_BUFFER = new byte[65535];
|
||||||
|
|
||||||
private boolean remove;
|
private boolean remove;
|
||||||
private boolean isAuthenticated;
|
private boolean isAuthenticated;
|
||||||
|
|
@ -225,6 +225,7 @@ public class ServerClient extends AbstractClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rep.setOnFinishAction(new SendFileCallback(fle));
|
rep.setOnFinishAction(new SendFileCallback(fle));
|
||||||
|
rep.writeByte(0);
|
||||||
sendingFile = true;
|
sendingFile = true;
|
||||||
} catch(FileNotFoundException ex) {
|
} catch(FileNotFoundException ex) {
|
||||||
rep.writeByte(Constants.GETF_STATUS_NOT_FOUND);
|
rep.writeByte(Constants.GETF_STATUS_NOT_FOUND);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user