diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 278d60b..5686506 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,11 +5,23 @@
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
@@ -28,31 +40,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -60,21 +52,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -83,55 +137,24 @@
-
-
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -147,9 +170,6 @@
- Sys
- Syst
- System
System.
s
system.
@@ -171,8 +191,14 @@
TTInpu
TTInputB
TTInput
- TTInputF
controller
+ toke
+ TTInputF
+ n
+ new
+ new Jso
+ new Json
+ new JsonO
adduser
@@ -187,10 +213,6 @@
@@ -248,10 +274,9 @@
DEFINITION_ORDER
-
-
-
-
+
+
+
@@ -550,19 +575,15 @@
-
+
-
-
-
-
-
-
+
+
@@ -571,8 +592,12 @@
-
-
+
+
+
+
+
+
@@ -587,7 +612,7 @@
-
+
@@ -1002,8 +1027,8 @@
-
-
+
+
@@ -1030,33 +1055,33 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -1064,7 +1089,7 @@
-
+
@@ -1081,7 +1106,7 @@
-
+
@@ -1090,52 +1115,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1152,14 +1131,6 @@
-
-
-
-
-
-
-
-
@@ -1194,16 +1165,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1212,16 +1173,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1262,16 +1213,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1317,56 +1258,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1398,18 +1289,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1418,18 +1297,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1438,22 +1305,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1486,10 +1337,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1504,52 +1381,190 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Client/src/com/texttwist/client/App.java b/Client/src/com/texttwist/client/App.java
index c3910d9..9de057e 100644
--- a/Client/src/com/texttwist/client/App.java
+++ b/Client/src/com/texttwist/client/App.java
@@ -2,6 +2,7 @@ package com.texttwist.client;
import com.texttwist.client.pages.AuthService;
import com.texttwist.client.pages.Home;
+import com.texttwist.client.pages.MatchService;
import com.texttwist.client.pages.SessionService;
import javax.swing.*;
@@ -14,6 +15,7 @@ public class App extends JFrame {
public static AuthService authService;
public static SessionService sessionService;
+ public static MatchService matchService;
public App(){
setPreferredSize( new Dimension( 640, 480 ));
@@ -25,6 +27,7 @@ public class App extends JFrame {
//Init services
authService = new AuthService();
sessionService = new SessionService();
+ matchService = new MatchService();
Home home = new Home(this);
}
diff --git a/Client/src/com/texttwist/client/constants/Config.java b/Client/src/com/texttwist/client/constants/Config.java
index ad6db60..46e0623 100644
--- a/Client/src/com/texttwist/client/constants/Config.java
+++ b/Client/src/com/texttwist/client/constants/Config.java
@@ -5,11 +5,19 @@ package com.texttwist.client.constants;
*/
public class Config {
- private static String RMIServerURI = "localhost";
- private static Integer RMIServerPort = 9999;
+ private static String AuthServerURI = "localhost";
+ private static Integer AuthServerPort = 9999;
+
+ public static String GameServerURI = "localhost";
+ public static Integer GameServerPort = 10000;
- public static String getRMIServerAddress(){
- return "rmi://".concat(RMIServerURI).concat(":").concat(RMIServerPort.toString());
+ public static String getAuthServerURI(){
+ return "rmi://".concat(AuthServerURI).concat(":").concat(AuthServerPort.toString());
}
+
+ public static String getGameServerURI(){
+ return "tcp://".concat(GameServerURI).concat(":").concat(GameServerPort.toString());
+ }
+
}
diff --git a/Client/src/com/texttwist/client/pages/AuthService.java b/Client/src/com/texttwist/client/pages/AuthService.java
index 7fb25ab..aaf10d0 100644
--- a/Client/src/com/texttwist/client/pages/AuthService.java
+++ b/Client/src/com/texttwist/client/pages/AuthService.java
@@ -1,5 +1,6 @@
package com.texttwist.client.pages;
+import com.texttwist.client.App;
import com.texttwist.client.constants.Config;
import interfaces.IAuth;
import models.Response;
@@ -14,7 +15,7 @@ import java.rmi.RemoteException;
*/
public class AuthService {
- protected String baseUrl = Config.getRMIServerAddress().concat("/auth");
+ protected String baseUrl = Config.getAuthServerURI().concat("/auth");
public AuthService(){
}
@@ -29,8 +30,8 @@ public class AuthService {
return auth.register(userName, password);
}
- public Response logout(String userName, String token) throws RemoteException, NotBoundException, MalformedURLException {
+ public Response logout(String userName) throws RemoteException, NotBoundException, MalformedURLException {
IAuth auth = (IAuth) Naming.lookup(baseUrl);
- return auth.logout(userName, token);
+ return auth.logout(userName, App.sessionService.account.token);
}
}
diff --git a/Client/src/com/texttwist/client/pages/MatchService.java b/Client/src/com/texttwist/client/pages/MatchService.java
new file mode 100644
index 0000000..ebd1bc5
--- /dev/null
+++ b/Client/src/com/texttwist/client/pages/MatchService.java
@@ -0,0 +1,53 @@
+package com.texttwist.client.pages;
+
+import com.texttwist.client.App;
+import com.texttwist.client.constants.Config;
+import interfaces.IAuth;
+import models.Message;
+import models.Response;
+import org.json.simple.JsonObject;
+
+import javax.swing.*;
+import java.io.*;
+import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+
+/**
+ * Created by loke on 18/06/2017.
+ */
+public class MatchService {
+
+ public MatchService(){
+ }
+
+ public Response play(DefaultListModel userNames) throws IOException {
+
+
+ InetSocketAddress socketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort);
+ SocketChannel clientSocket = SocketChannel.open(socketAddress);
+
+
+ Message message = new Message("START_GAME", App.sessionService.account.token, userNames);
+
+ byte[] byteMessage = new String(message.toString()).getBytes();
+ ByteBuffer buffer = ByteBuffer.wrap(byteMessage);
+
+ clientSocket.write(buffer);
+
+
+ //Risposta dal server
+ /*JsonObject data = new JsonObject();
+ data.put("obj", out);
+ data.put("unavailableUsers", out);*/
+ clientSocket.close();
+
+ Response res = new Response("Player unavailable!",400, new JsonObject());
+ return res;
+ }
+}
diff --git a/Client/src/com/texttwist/client/pages/MatchSetup.java b/Client/src/com/texttwist/client/pages/MatchSetup.java
index 4507aaa..0624400 100644
--- a/Client/src/com/texttwist/client/pages/MatchSetup.java
+++ b/Client/src/com/texttwist/client/pages/MatchSetup.java
@@ -90,7 +90,7 @@ public class MatchSetup extends Page{
new Callable() {
@Override
public Object call() throws Exception {
- return new MatchSetup(Page.window);
+ return null;
}
},null);
}
diff --git a/Client/src/com/texttwist/client/pages/MatchSetupController.java b/Client/src/com/texttwist/client/pages/MatchSetupController.java
index 7f6e265..ca83749 100644
--- a/Client/src/com/texttwist/client/pages/MatchSetupController.java
+++ b/Client/src/com/texttwist/client/pages/MatchSetupController.java
@@ -4,6 +4,7 @@ import com.texttwist.client.App;
import models.Response;
import javax.swing.*;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
@@ -15,13 +16,11 @@ public class MatchSetupController {
public MatchSetupController(){}
public Response play(DefaultListModel userNames) throws RemoteException, NotBoundException, MalformedURLException {
-
- System.out.print(userNames.toString());
- /* Response res = App.authService.login(userName,password);
- if (res.code == 200){
- App.sessionService.create(userName, res.data.get("token").toString());
- }*/
+ try {
+ return App.matchService.play(userNames);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return null;
}
-
}
diff --git a/Client/src/com/texttwist/client/pages/Menu.java b/Client/src/com/texttwist/client/pages/Menu.java
index 1d97d90..b2a7760 100644
--- a/Client/src/com/texttwist/client/pages/Menu.java
+++ b/Client/src/com/texttwist/client/pages/Menu.java
@@ -92,7 +92,7 @@ public class Menu extends Page{
new Callable