* 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();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
registerCustomBlockBaker(new ScreenBaker(), WebDisplays.INSTANCE.blockScreen);
|
||||
|
||||
mcef = MCEFApi.getAPI();
|
||||
if(mcef != null)
|
||||
mcef.registerScheme("wd", WDScheme.class, true, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityScreen.class, new ScreenRenderer());
|
||||
mcef = MCEFApi.getAPI();
|
||||
jsDispatcher = new JSQueryDispatcher(this);
|
||||
minePadRenderer = new MinePadRenderer();
|
||||
laserPointerRenderer = new LaserPointerRenderer();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import net.montoyo.wd.WebDisplays;
|
|||
import net.montoyo.wd.miniserv.Constants;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.miniserv.client.ClientTaskGetFile;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -47,7 +48,9 @@ public class WDScheme implements IScheme {
|
|||
|
||||
@Override
|
||||
public void getResponseHeaders(ISchemeResponseHeaders resp) {
|
||||
Log.info("Waiting for response...");
|
||||
int status = task.waitForResponse();
|
||||
Log.info("Got response %d", status);
|
||||
|
||||
if(status == 0) {
|
||||
//OK
|
||||
|
|
|
|||
|
|
@ -93,12 +93,9 @@ public abstract class AbstractClient {
|
|||
public void readyWrite() throws Throwable {
|
||||
if(sendBuffer.remaining() > 0 || fillSendBuffer()) {
|
||||
int sent = socket.write(sendBuffer);
|
||||
Log.info("Sent %d bytes", sent);
|
||||
|
||||
if(sent < 0) {
|
||||
Log.error("Error when sending data");
|
||||
if(sent < 0)
|
||||
onWriteError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +128,7 @@ public abstract class AbstractClient {
|
|||
synchronized(sendQueue) {
|
||||
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);
|
||||
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_INTERNAL_ERROR = 3;
|
||||
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) {
|
||||
//Read packet size
|
||||
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;
|
||||
pos = 0;
|
||||
|
||||
if(packetSize < 5 || packetSize > 65536) {
|
||||
Log.warning("Got invalid packet from client of size %d, things won't go well...", packetSize);
|
||||
if(packetSize < 5 || packetSize > 70000) {
|
||||
Log.warning("Got invalid packet of size %d, things won't go well...", packetSize);
|
||||
return true; //Abort packet reading
|
||||
}
|
||||
|
||||
packetSize -= 4;
|
||||
packetData = new byte[packetSize];
|
||||
Log.info("Awaiting packet of size %d", packetSize);
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ret = readByteArray(packetData, buf);
|
||||
Log.info("Read %d out of %d, ok = %s", pos, packetData.length, ret ? "true" : "false");
|
||||
return ret;
|
||||
return readByteArray(packetData, buf);
|
||||
}
|
||||
|
||||
private boolean readByteArray(byte[] dst, ByteBuffer src) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import net.montoyo.wd.miniserv.OutgoingPacket;
|
|||
import net.montoyo.wd.miniserv.PacketID;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
|
|
@ -67,6 +68,9 @@ public class ClientTaskGetFile extends ClientTask {
|
|||
response = status;
|
||||
hasResponse = true;
|
||||
gotResponse.signal();
|
||||
|
||||
if(response != 0)
|
||||
client.nextTask();
|
||||
}
|
||||
|
||||
responseLock.unlock();
|
||||
|
|
@ -77,9 +81,16 @@ public class ClientTaskGetFile extends ClientTask {
|
|||
|
||||
public int waitForResponse() {
|
||||
responseLock.lock();
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
while(!hasResponse) {
|
||||
if(System.currentTimeMillis() - t > 10000) {
|
||||
responseLock.unlock();
|
||||
return Constants.GETF_STATUS_TIMED_OUT;
|
||||
}
|
||||
|
||||
try {
|
||||
gotResponse.await();
|
||||
gotResponse.await(100, TimeUnit.MILLISECONDS);
|
||||
} catch(InterruptedException ex) {}
|
||||
}
|
||||
|
||||
|
|
@ -106,9 +117,18 @@ public class ClientTaskGetFile extends ClientTask {
|
|||
|
||||
public byte[] waitForData() {
|
||||
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 {
|
||||
dataChanged.await();
|
||||
dataChanged.await(100, TimeUnit.MILLISECONDS);
|
||||
} catch(InterruptedException ex) {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
|||
|
||||
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 long size;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
|||
|
||||
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 isAuthenticated;
|
||||
|
|
@ -225,6 +225,7 @@ public class ServerClient extends AbstractClient {
|
|||
|
||||
try {
|
||||
rep.setOnFinishAction(new SendFileCallback(fle));
|
||||
rep.writeByte(0);
|
||||
sendingFile = true;
|
||||
} catch(FileNotFoundException ex) {
|
||||
rep.writeByte(Constants.GETF_STATUS_NOT_FOUND);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user