diff --git a/Makefile b/Makefile index d411d9c..6739f7e 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,5 @@ all: build build: javac 2>&1 src/*.java -d bin -classpath lib/protobuf-java-2.4.1.jar - +generate: + protoc -I=./ --java_out=./src *.proto \ No newline at end of file diff --git a/src/GLI.java b/src/GLI.java index ca7187a..67ef8ed 100644 --- a/src/GLI.java +++ b/src/GLI.java @@ -2,11 +2,11 @@ import com.google.protobuf.ByteString; -public interface GLI { +public interface GLI { public JOutPiqi.response init(List players); public JOutPiqi.response handle_action(String user_id, String command_name, List args, ByteString state); public JOutPiqi.response handle_user_join(String user_id, ByteString state); - public JOutPiqi.response handle_user_leave(String user_id, ByteString state); - public JOutPiqi.response handle_timer(ByteString identifier, int delta, ByteString state); - public JOutPiqi.response handle_timer_complete(ByteString identifier, int delta, ByteString state); + public JOutPiqi.response handle_user_leave(String user_id, ByteString state); + public JOutPiqi.response handle_timer(String id, int delta, ByteString state); + public JOutPiqi.response handle_timer_complete(String id, int delta, ByteString state); } diff --git a/src/GLIExample.java b/src/GLIExample.java index bb186cb..9b0c384 100644 --- a/src/GLIExample.java +++ b/src/GLIExample.java @@ -27,22 +27,22 @@ public JOutPiqi.response init(List players) { @Override public JOutPiqi.response handle_action(String userId, String commandName, List args, ByteString state) { - System.out.println("handle_action [" + commandName + "] with [" + args + "], state: ["+state.toStringUtf8() + "]"); + System.out.println("handle_action [" + commandName + "] with [" + args + "], state: ["+state.toStringUtf8() + "]"); // service.buy_item_request(userId, 1, 1); return demo().build(); } @Override - public JOutPiqi.response handle_timer(ByteString identifier, int delta, + public JOutPiqi.response handle_timer(String id, int delta, ByteString state) { - System.out.println("handle_timer [" + identifier.toStringUtf8() + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]"); + System.out.println("handle_timer [" + id + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]"); return demo().build(); } @Override - public JOutPiqi.response handle_timer_complete(ByteString identifier, int delta, + public JOutPiqi.response handle_timer_complete(String id, int delta, ByteString state) { - System.out.println("handle_timer_complete [" + identifier.toStringUtf8() + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]"); + System.out.println("handle_timer_complete [" + id + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]"); return demo().build(); } diff --git a/src/GLSProtoServer.java b/src/GLSProtoServer.java index 85fc8c0..6cac6ed 100644 --- a/src/GLSProtoServer.java +++ b/src/GLSProtoServer.java @@ -5,8 +5,8 @@ import java.net.Socket; /** - * Waits for incoming GLSResponseProto obects. When one arrives, recreates it from - * the inputStream and prints out its state + * Waits for incoming GLSResponseProto obects. When one arrives, recreates it from + * the inputStream and prints out its state * @author kevinparkings * */ @@ -27,7 +27,7 @@ public static void main (String [] argv) throws Exception { public void loop(){ socket = new ServerSocket(PORT); - service = new GLIService(this); + service = new GLIService(this); while (true) { @@ -58,10 +58,10 @@ public void loop(){ } write_message(response); - + os.flush(); os.close(); - + sock.close(); } } @@ -71,12 +71,12 @@ public void send_system_request(JSystemPiqi.system_request request) { write_message(JOutPiqi.response.getBuilder().setSystem(request).build()); JInPiqi.request response = read_message(); - if(response.hasSystem()){ - JInPiqi.system_response system_response = packet.getSystem(); - if (!system_response.hasOk()) { - throw new Exception("Received error response: message: " - + system_response.getError().getMessage() + ", code: " - + system_response.getError().getCode() + if(packet.hasSystem()){ + JInPiqi.system_response response = packet.getSystem(); + if (!response.hasOk()) { + throw new Exception("Received error response: message: " + + response.getError().getMessage() + ", code: " + + response.getError().getCode() ); } }else{ @@ -86,7 +86,7 @@ public void send_system_request(JSystemPiqi.system_request request) { } } - public void write_message(Object r){ + public void write_message(Object r){ OutputStream os = sock.getOutputStream(); if (r != null) { @@ -98,17 +98,17 @@ public void write_message(Object r){ } } - public void read_message(){ + public JInPiqi.request read_message(){ System.out.println ("Waiting for connections on port " + PORT); //This waits for an incomming message sock = ss.accept(); - InputStream is = sock.getInputStream(); + InputStream is = sock.getInputStream(); byte[] lb = new byte[4]; int length = 0; //Gets the incoming data and recreates the proto object - + is.read(lb, 0, 4); length = lb[0] << 24 | lb[1] << 16 | lb[2] << 8 | lb[3] << 0;