mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-14 17:57:56 +07:00
More netcode updates
This commit is contained in:
@ -31,7 +31,7 @@ public class CallGenerator{
|
|||||||
.addModifiers(Modifier.PUBLIC);
|
.addModifiers(Modifier.PUBLIC);
|
||||||
|
|
||||||
//temporary data to deserialize later
|
//temporary data to deserialize later
|
||||||
packet.addField(byte[].class, "DATA", Modifier.PRIVATE);
|
packet.addField(FieldSpec.builder(byte[].class, "DATA", Modifier.PRIVATE).initializer("NODATA").build());
|
||||||
|
|
||||||
packet.superclass(tname("mindustry.net.Packet"));
|
packet.superclass(tname("mindustry.net.Packet"));
|
||||||
|
|
||||||
@ -149,11 +149,11 @@ public class CallGenerator{
|
|||||||
|
|
||||||
typespec.addMethod(readbuilder.build());
|
typespec.addMethod(readbuilder.build());
|
||||||
|
|
||||||
MethodSpec.Builder builder = MethodSpec.methodBuilder("check")
|
MethodSpec.Builder builder = MethodSpec.methodBuilder("handled")
|
||||||
.addModifiers(Modifier.PRIVATE);
|
.addModifiers(Modifier.PUBLIC)
|
||||||
|
.addAnnotation(Override.class);
|
||||||
|
|
||||||
//make sure data is present, begin reading it if so
|
//make sure data is present, begin reading it if so
|
||||||
builder.beginControlFlow("if(DATA != null)");
|
|
||||||
builder.addStatement("BAIS.setBytes(DATA)");
|
builder.addStatement("BAIS.setBytes(DATA)");
|
||||||
|
|
||||||
Seq<Svar> params = ent.element.params();
|
Seq<Svar> params = ent.element.params();
|
||||||
@ -202,8 +202,6 @@ public class CallGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.endControlFlow();
|
|
||||||
|
|
||||||
typespec.addMethod(builder.build());
|
typespec.addMethod(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,8 +349,6 @@ public class CallGenerator{
|
|||||||
.addAnnotation(Override.class)
|
.addAnnotation(Override.class)
|
||||||
.returns(void.class);
|
.returns(void.class);
|
||||||
|
|
||||||
builder.addStatement("check()");
|
|
||||||
|
|
||||||
Smethod elem = ent.element;
|
Smethod elem = ent.element;
|
||||||
Seq<Svar> params = elem.params();
|
Seq<Svar> params = elem.params();
|
||||||
|
|
||||||
|
@ -257,6 +257,7 @@ public class Net{
|
|||||||
* Call to handle a packet being received for the client.
|
* Call to handle a packet being received for the client.
|
||||||
*/
|
*/
|
||||||
public void handleClientReceived(Packet object){
|
public void handleClientReceived(Packet object){
|
||||||
|
object.handled();
|
||||||
|
|
||||||
if(object instanceof StreamBegin b){
|
if(object instanceof StreamBegin b){
|
||||||
streams.put(b.id, currentStream = new StreamBuilder(b));
|
streams.put(b.id, currentStream = new StreamBuilder(b));
|
||||||
@ -291,6 +292,8 @@ public class Net{
|
|||||||
* Call to handle a packet being received for the server.
|
* Call to handle a packet being received for the server.
|
||||||
*/
|
*/
|
||||||
public void handleServerReceived(NetConnection connection, Packet object){
|
public void handleServerReceived(NetConnection connection, Packet object){
|
||||||
|
object.handled();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
//handle object normally
|
//handle object normally
|
||||||
if(serverListeners.get(object.getClass()) != null){
|
if(serverListeners.get(object.getClass()) != null){
|
||||||
|
@ -10,6 +10,7 @@ public abstract class Packet{
|
|||||||
//readObject
|
//readObject
|
||||||
//readBuilding
|
//readBuilding
|
||||||
//readUnit (possibly)
|
//readUnit (possibly)
|
||||||
|
protected static final byte[] NODATA = {};
|
||||||
protected static final ReusableByteInStream BAIS = new ReusableByteInStream();
|
protected static final ReusableByteInStream BAIS = new ReusableByteInStream();
|
||||||
protected static final Reads READ = new Reads(new DataInputStream(BAIS));
|
protected static final Reads READ = new Reads(new DataInputStream(BAIS));
|
||||||
|
|
||||||
@ -29,6 +30,8 @@ public abstract class Packet{
|
|||||||
read(read);
|
read(read);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handled(){}
|
||||||
|
|
||||||
public int getPriority(){
|
public int getPriority(){
|
||||||
return priorityNormal;
|
return priorityNormal;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user