Local forwarding fixes, remote building

This commit is contained in:
Anuken
2018-06-09 01:12:49 -04:00
parent 690571eec0
commit bc7b584001
6 changed files with 88 additions and 28 deletions

View File

@@ -107,31 +107,17 @@ public class RemoteReadGenerator {
}
}
//execute the relevant method before the forward
//if it throws a ValidateException, the method won't be forwarded
readBlock.addStatement("$N." + entry.element.getSimpleName() + "(" + varResult.toString() + ")", ((TypeElement) entry.element.getEnclosingElement()).getQualifiedName().toString());
//begin lambda control flow
readBlock.beginControlFlow("com.badlogic.gdx.Gdx.app.postRunnable(() -> ");
//call forwarded method before the method, so if it throws a ValidateException, the method won't be forwarded
if(entry.forward && entry.where.isServer){
//try block to catch validate exception
readBlock.beginControlFlow("try");
//call forwarded method, don't forward on the client reader
if(entry.forward && entry.where.isServer && needsPlayer){
//call forwarded method
readBlock.addStatement(packageName + "." + entry.className + "." + entry.element.getSimpleName() +
"__forward(player.clientid" + (varResult.length() == 0 ? "" : ", ") + varResult.toString() + ")");
//when a ValidateException is caught, print the error and return
readBlock.nextControlFlow("catch (io.anuke.mindustry.net.ValidateException e)");
readBlock.addStatement("e.printStackTrace()");
readBlock.addStatement("return");
readBlock.endControlFlow();
}
//execute the relevant method
readBlock.addStatement("$N." + entry.element.getSimpleName() + "(" + varResult.toString() + ")", ((TypeElement) entry.element.getEnclosingElement()).getQualifiedName().toString());
//end lambda
readBlock.endControlFlow(")");
}
//end control flow if necessary

View File

@@ -65,9 +65,14 @@ public class RemoteWriteGenerator {
//create builder
MethodSpec.Builder method = MethodSpec.methodBuilder(elem.getSimpleName().toString() + (forwarded ? "__forward" : "")) //add except suffix when forwarding
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.SYNCHRONIZED)
.addModifiers(Modifier.STATIC, Modifier.SYNCHRONIZED)
.returns(void.class);
//forwarded methods aren't intended for use, and are not public
if(!forwarded){
method.addModifiers(Modifier.PUBLIC);
}
//validate client methods to make sure
if(methodEntry.where.isClient){
if(elem.getParameters().isEmpty()){
@@ -173,7 +178,11 @@ public class RemoteWriteGenerator {
String sendString;
if(forwarded){ //forward packet
sendString = "sendExcept(exceptSenderID, ";
if(!methodEntry.local.isClient){ //if the client doesn't get it called locally, forward it back after validation
sendString = "send(";
}else {
sendString = "sendExcept(exceptSenderID, ";
}
}else if(toAll){ //send to all players / to server
sendString = "send(";
}else{ //send to specific client from server