diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6237e2a..3203e86 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -10,11 +10,12 @@ - - + + + + - @@ -22,17 +23,35 @@ + + + + + - + - + + - - - + + + + + + + + + + + + + + + @@ -44,7 +63,7 @@ - + com.texttwist.client.* @@ -55,11 +74,11 @@ - - + + - - + + @@ -67,11 +86,87 @@ + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -80,96 +175,25 @@ - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -186,36 +210,36 @@ - getWords - ge - getWindow - getWindows - getWindowsP - getWindowsPo - getWindowsPos - getWindowsPosi - A - App.app - App.ap - ap - app - Wai - Waito - Wait - WaitF - WaitFor - WaitForP - WaitForPla - waitForP - waitForPl - waitForPla - w - waitForS - waitForSc - waitForScor - waitForScore - waitFor - rank + multicastSock + multicastSocke + multicastSocket + T + TTC + TTCi + TTCir + TTCirclC + TTCircl + TTCircle + TTCircleC + C + Callab + Callable + Callable< + isPartia + highscoresPa + j + joinT + joinTimeou + jo + joinTim + joinTime + joinTimeo + joinTimeout + joinTimeoutjoin + TI + TIMEOUT + letters + words C:\Users\loke\TextTwist\out\production @@ -354,57 +378,57 @@ @@ -424,10 +448,10 @@ - @@ -935,8 +959,12 @@ - - + + + + + + @@ -946,12 +974,8 @@ - - - - - - + + @@ -1447,47 +1471,47 @@ - + - - + - - - - - - - - - - + + + + + + + + + + + + - - @@ -1498,7 +1522,7 @@ - @@ -1507,142 +1531,160 @@ - - - - - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1655,196 +1697,295 @@ - + - - + + - + - - - - - - - - - - + + - + - - + + - + - - - + + + + + - + - - - - - - - - - - - + + + + + - - - + + + + + - + + + + + + + + + + + - + - + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1853,78 +1994,30 @@ - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/Client/src/com/texttwist/client/App.java b/Client/src/com/texttwist/client/App.java index b9e9398..de9185d 100644 --- a/Client/src/com/texttwist/client/App.java +++ b/Client/src/com/texttwist/client/App.java @@ -3,6 +3,10 @@ package com.texttwist.client; import com.texttwist.client.services.GameService; import com.texttwist.client.services.AuthService; import com.texttwist.client.pages.HomePage; +import com.texttwist.client.services.NotificationClientService; +import constants.Config; +import interfaces.INotificationClient; +import interfaces.INotificationServer; import models.Session; import utilities.Logger; import javax.swing.*; @@ -10,6 +14,16 @@ import java.awt.*; import java.io.File; import java.io.IOException; import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.MulticastSocket; +import java.nio.channels.DatagramChannel; +import java.nio.channels.SocketChannel; +import java.rmi.NotBoundException; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; /** * Author: Lorenzo Iovino on 13/06/2017. @@ -17,12 +31,22 @@ import java.lang.management.ManagementFactory; * Here is possible to declare services globally accessible. */ public class App extends JFrame { + + private static InetSocketAddress clientTCPSocketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort); + public static InetSocketAddress clientUDPSocketAddress = new InetSocketAddress(Config.WordsReceiverServerURI, Config.WordsReceiverServerPort); + private static InetAddress clientMulticastSocketAddress; + public static AuthService authService; public static GameService gameService; public static Logger logger; public static Session session; public static JFrame app; + public static INotificationClient notificationStub; + public static MulticastSocket clientMulticast; + public static SocketChannel clientTCP; + public static DatagramChannel clientUDP; + public App() throws IOException { setPreferredSize( new Dimension( 640, 480 )); setSize(new Dimension(640,480)); @@ -53,6 +77,54 @@ public class App extends JFrame { new HomePage(this); } + public static void registerForNotifications() throws RemoteException, NotBoundException { + + Registry registry = LocateRegistry.getRegistry(Config.NotificationServerStubPort); + INotificationClient callbackObj = new NotificationClientService(); + notificationStub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0); + INotificationServer notificationServer = (INotificationServer) registry.lookup(Config.NotificationServerName); + notificationServer.registerForCallback(notificationStub); + } + + public static void openClientTCPSocket(){ + try { + clientTCP = SocketChannel.open(clientTCPSocketAddress); + clientTCP.configureBlocking(false); + } catch (IOException e) { + logger.write("APP: Can't open client TCP socket!"); + } + } + + public static void openClientMulticastSocket(Integer multicastId){ + try { + App.gameService.setMulticastId(multicastId); + clientMulticastSocketAddress = InetAddress.getByName(Config.ScoreMulticastServerURI); + clientMulticast = new MulticastSocket(gameService.multicastId); + clientMulticast.joinGroup(clientMulticastSocketAddress); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void closeClientMulticastSocket(){ + //Leave group and close multicast socket + try { + App.clientMulticast.leaveGroup(InetAddress.getByName(Config.ScoreMulticastServerURI)); + App.clientMulticast.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void openClientUDPSocket(){ + try { + clientUDP = DatagramChannel.open(); + clientUDP.bind(null); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static Point getWindowsPosition(){ return new Point(app.getX(), app.getY()); } diff --git a/Client/src/com/texttwist/client/controllers/GameController.java b/Client/src/com/texttwist/client/controllers/GameController.java index b70eeb0..f184279 100644 --- a/Client/src/com/texttwist/client/controllers/GameController.java +++ b/Client/src/com/texttwist/client/controllers/GameController.java @@ -3,10 +3,13 @@ package com.texttwist.client.controllers; import com.texttwist.client.App; import com.texttwist.client.pages.GamePage; import com.texttwist.client.tasks.SendWords; -import com.texttwist.client.tasks.StartGame; import com.texttwist.client.tasks.WaitForPlayers; import com.texttwist.client.tasks.WaitForScore; + import javax.swing.*; +import java.util.concurrent.Callable; + +import static com.texttwist.client.App.gameService; /** * Author: Lorenzo Iovino on 27/06/2017. @@ -14,26 +17,42 @@ import javax.swing.*; */ public class GameController { - private GamePage game; - - public GameController(GamePage game){ - this.game = game; - } - - public SwingWorker waitForPlayers(SwingWorker callback) { - return new WaitForPlayers(callback); - } + private GamePage gamePage; private SwingWorker waitForScore(SwingWorker callback){ return new WaitForScore(callback); } - public SwingWorker sendWords(SwingWorker callback){ - return new SendWords(App.gameService.words, waitForScore(callback)); + private SwingWorker sendWords(SwingWorker callback){ + return new SendWords(gameService.words, waitForScore(callback)); } - public SwingWorker startGame() { - return new StartGame(App.gameService.letters, game); + public GameController(GamePage gamePage){ + this.gamePage = gamePage; } + public SwingWorker waitForPlayers(Callable callback) { + return new WaitForPlayers(callback); + } + + public Callable startGame = new Callable() { + @Override + public Void call() throws Exception { + App.gameService.start(); + gamePage.showGameIsReadyAlert(); + return null; + } + }; + + public DefaultListModel getLetters() { + return gameService.getLetters(); + } + + public SwingWorker timeIsOver(SwingWorker callback) { + return sendWords(callback); + } + + public DefaultListModel getWords(){ + return gameService.getWords(); + } } diff --git a/Client/src/com/texttwist/client/controllers/HighscoresController.java b/Client/src/com/texttwist/client/controllers/HighscoresController.java index dc3e12d..275faed 100644 --- a/Client/src/com/texttwist/client/controllers/HighscoresController.java +++ b/Client/src/com/texttwist/client/controllers/HighscoresController.java @@ -1,10 +1,13 @@ package com.texttwist.client.controllers; -import com.texttwist.client.App; import com.texttwist.client.pages.HighscoresPage; import com.texttwist.client.tasks.FetchHighscore; import javafx.util.Pair; import javax.swing.*; +import java.io.ObjectOutput; +import java.util.concurrent.Callable; + +import static com.texttwist.client.App.gameService; /** * Author: Lorenzo Iovino on 27/06/2017. @@ -12,18 +15,12 @@ import javax.swing.*; */ public class HighscoresController { - private HighscoresPage highscoresPage; - - public HighscoresController(HighscoresPage highscoresPage){ - this.highscoresPage = highscoresPage; - } - - public SwingWorker fetchHighscores () { - return new FetchHighscore(highscoresPage); + public SwingWorker fetchHighscores(Callable callback) { + return new FetchHighscore(callback); } public DefaultListModel> getRanks(Boolean isPartialRank) { - return isPartialRank ? App.gameService.ranks : App.gameService.globalRanks; + return isPartialRank ? gameService.ranks : gameService.globalRanks; } } diff --git a/Client/src/com/texttwist/client/controllers/HomeController.java b/Client/src/com/texttwist/client/controllers/HomeController.java index 0c7b67b..2197bbd 100644 --- a/Client/src/com/texttwist/client/controllers/HomeController.java +++ b/Client/src/com/texttwist/client/controllers/HomeController.java @@ -7,6 +7,7 @@ import models.User; import java.net.MalformedURLException; import java.rmi.NotBoundException; import java.rmi.RemoteException; +import static com.texttwist.client.App.authService; /** * Author: Lorenzo Iovino on 20/06/2017. @@ -15,7 +16,7 @@ import java.rmi.RemoteException; public class HomeController { public Response login(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException { - Response res = App.authService.login(userName,password); + Response res = authService.login(userName,password); if (res.code == 200){ App.session = (new Session(new User(userName,password,0), res.data.get("token").toString())); } diff --git a/Client/src/com/texttwist/client/controllers/MatchRequestController.java b/Client/src/com/texttwist/client/controllers/MatchRequestController.java new file mode 100644 index 0000000..f2d797a --- /dev/null +++ b/Client/src/com/texttwist/client/controllers/MatchRequestController.java @@ -0,0 +1,19 @@ +package com.texttwist.client.controllers; + +import com.texttwist.client.App; +import javax.swing.*; + +/** + * Author: Lorenzo Iovino on 13/072017. + * Description: Controller of the Match Request Page + */ +public class MatchRequestController { + + public DefaultListModel getPendingList(){ + return App.gameService.pendingList; + } + + public void joinMatch(String matchName){ + App.gameService.joinMatch(matchName); + } +} diff --git a/Client/src/com/texttwist/client/controllers/MatchSetupController.java b/Client/src/com/texttwist/client/controllers/MatchSetupController.java index d0aee9d..bf47bb0 100644 --- a/Client/src/com/texttwist/client/controllers/MatchSetupController.java +++ b/Client/src/com/texttwist/client/controllers/MatchSetupController.java @@ -1,8 +1,7 @@ package com.texttwist.client.controllers; -import com.texttwist.client.App; import javax.swing.*; -import java.io.IOException; +import static com.texttwist.client.App.gameService; /** * Author: Lorenzo Iovino on 18/06/2017. @@ -10,12 +9,7 @@ import java.io.IOException; */ public class MatchSetupController { - public Object play(DefaultListModel userNames) { - try { - return App.gameService.play(userNames); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + public void play(DefaultListModel userNames) { + gameService.beginMatch(userNames); } } diff --git a/Client/src/com/texttwist/client/controllers/MenuController.java b/Client/src/com/texttwist/client/controllers/MenuController.java index 7eb9a0e..fafca6a 100644 --- a/Client/src/com/texttwist/client/controllers/MenuController.java +++ b/Client/src/com/texttwist/client/controllers/MenuController.java @@ -1,11 +1,13 @@ package com.texttwist.client.controllers; import com.texttwist.client.App; -import interfaces.INotificationClient; import models.Response; +import models.Session; + import java.net.MalformedURLException; import java.rmi.NotBoundException; import java.rmi.RemoteException; +import static com.texttwist.client.App.authService; /** * Author: Lorenzo Iovino on 17/06/2017. @@ -13,10 +15,14 @@ import java.rmi.RemoteException; */ public class MenuController { - public void logout(String userName, INotificationClient stub) throws RemoteException, NotBoundException, MalformedURLException { - Response res = App.authService.logout(userName, stub); + public void logout() throws RemoteException, NotBoundException, MalformedURLException { + Response res = authService.logout(App.session.account.userName, App.notificationStub); if (res.code == 200){ App.session = null; } } + + public Session getSession(){ + return App.session; + } } diff --git a/Client/src/com/texttwist/client/controllers/RegisterController.java b/Client/src/com/texttwist/client/controllers/RegisterController.java index 26cf6ba..6c928a1 100644 --- a/Client/src/com/texttwist/client/controllers/RegisterController.java +++ b/Client/src/com/texttwist/client/controllers/RegisterController.java @@ -1,10 +1,10 @@ package com.texttwist.client.controllers; -import com.texttwist.client.App; import models.Response; import java.net.MalformedURLException; import java.rmi.NotBoundException; import java.rmi.RemoteException; +import static com.texttwist.client.App.authService; /** * Author: Lorenzo Iovino on 17/06/2017. @@ -13,6 +13,6 @@ import java.rmi.RemoteException; public class RegisterController { public Response register(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException { - return App.authService.register(userName,password); + return authService.register(userName,password); } } diff --git a/Client/src/com/texttwist/client/pages/GamePage.java b/Client/src/com/texttwist/client/pages/GamePage.java index d8bda51..cf5afe3 100644 --- a/Client/src/com/texttwist/client/pages/GamePage.java +++ b/Client/src/com/texttwist/client/pages/GamePage.java @@ -1,4 +1,5 @@ package com.texttwist.client.pages; + import com.texttwist.client.controllers.GameController; import constants.Config; import constants.Palette; @@ -8,10 +9,9 @@ import java.awt.*; import java.io.IOException; import java.util.concurrent.*; -import static com.texttwist.client.App.gameService; - /** - * GamePage Page + * Author: Lorenzo Iovino on 27/06/2017. + * Description: Game Page */ public class GamePage extends Page { @@ -19,24 +19,28 @@ public class GamePage extends Page { private GameController gameController; public Timer timer; - /*Spawning points fixed and not modifiable*/ + //All the spawning points private final DefaultListModel letterSpawningPoints = setLetterSpawningPoint(); - - /*Available spawning points*/ + //Available spawning points private DefaultListModel availableLetterSpawningPoint = new DefaultListModel<>(); public GamePage(JFrame window) throws IOException { super(window); gameController = new GameController(this); + + //Reset and set spawning point for letters availableLetterSpawningPoint.clear(); availableLetterSpawningPoint = letterSpawningPoints; - gameController.waitForPlayers(gameController.startGame()).execute(); + + //Wait for players, then when all players joined start the game + gameController.waitForPlayers(gameController.startGame).execute(); + createUIComponents(); window.setVisible(true); } + /*Occupy a random position of the available spawning points, if positions ends (can't happen) use position (0,0)*/ private Point occupyRandomPosition(){ - if(availableLetterSpawningPoint.size() > 1) { int index = ThreadLocalRandom.current().nextInt(0, letterSpawningPoints.size() - 1); Point placeholder = letterSpawningPoints.get(index); @@ -47,18 +51,6 @@ public class GamePage extends Page { return new Point(0,0); } - - private SwingWorker timeIsOver() { - return gameController.sendWords(new SwingWorker() { - @Override - protected Object doInBackground() throws Exception { - new HighscoresPage(window,true); - return null; - } - } - ); - } - private DefaultListModel setLetterSpawningPoint(){ DefaultListModel l = new DefaultListModel<>(); @@ -90,7 +82,7 @@ public class GamePage extends Page { public void showLetters(){ /* Place letters in an available random spawning point */ - DefaultListModel letters = gameService.getLetters(); + DefaultListModel letters = gameController.getLetters(); for(int i = 0; i < letters.size()-1; i++){ new TTLetter( occupyRandomPosition(), @@ -103,6 +95,19 @@ public class GamePage extends Page { window.revalidate(); } + public void showGameIsReadyAlert(){ + //Mostra pannello di conferma che le lettere sono tutte arrivate + new TTDialog("success", "GameService is ready. Press OK to start!", + new Callable() { + @Override + public Object call() throws Exception { + showLetters(); + timer.start(); + return null; + } + }, null); + } + @Override public void createUIComponents() throws IOException { @@ -120,7 +125,7 @@ public class GamePage extends Page { new Point(150, 90), new Dimension(250, 40), "Insert word and Press ENTER!", - gameService.getWords(), + gameController.getWords(), gameContainer ); @@ -129,7 +134,13 @@ public class GamePage extends Page { timer = addTimer( footer, new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40), - timeIsOver(), + gameController.timeIsOver(new SwingWorker() { + @Override + protected Object doInBackground() throws Exception { + new HighscoresPage(window,true); + return null; + } + }), Config.timeoutGame ); } diff --git a/Client/src/com/texttwist/client/pages/HighscoresPage.java b/Client/src/com/texttwist/client/pages/HighscoresPage.java index 1848ebb..6a18566 100644 --- a/Client/src/com/texttwist/client/pages/HighscoresPage.java +++ b/Client/src/com/texttwist/client/pages/HighscoresPage.java @@ -9,7 +9,8 @@ import java.io.IOException; import java.util.concurrent.Callable; /** - * Highscores Page + * Author: Lorenzo Iovino on 22/06/2017. + * Description: Highscores Page */ public class HighscoresPage extends Page{ @@ -18,26 +19,31 @@ public class HighscoresPage extends Page{ public JFrame window; private HighscoresController highscoreController; - public HighscoresPage(JFrame window, Boolean isPartialScore) throws IOException { + HighscoresPage(JFrame window, Boolean isPartialScore) throws IOException { super(window); this.window = window; this.isPartialScore = isPartialScore; - highscoreController = new HighscoresController(this); - highscoreController.fetchHighscores().execute(); + + highscoreController = new HighscoresController(); + highscoreController.fetchHighscores(showHighscoreList).execute(); createUIComponents(); window.setVisible(true); } - public void showHighscoreList(){ - new TTScrollList( - new Point(20, 60), - new Dimension(515, 142), - highscoreController.getRanks(isPartialScore), - highscoreContainer - ); - window.revalidate(); - window.repaint(); - } + public Callable showHighscoreList = new Callable() { + @Override + public Void call() throws Exception { + new TTScrollList( + new Point(20, 60), + new Dimension(515, 142), + highscoreController.getRanks(isPartialScore), + highscoreContainer + ); + window.revalidate(); + window.repaint(); + return null; + } + }; @Override public void createUIComponents() throws IOException { @@ -51,7 +57,7 @@ public class HighscoresPage extends Page{ root ); - TTLabel title = new TTLabel( + new TTLabel( this.isPartialScore ? new Point(150,0) : new Point(200,0), new Dimension(350,50), this.isPartialScore ? "Scores of the match" : "Highscores", diff --git a/Client/src/com/texttwist/client/pages/HomePage.java b/Client/src/com/texttwist/client/pages/HomePage.java index 8011a45..738f11a 100644 --- a/Client/src/com/texttwist/client/pages/HomePage.java +++ b/Client/src/com/texttwist/client/pages/HomePage.java @@ -1,4 +1,5 @@ package com.texttwist.client.pages; + import com.texttwist.client.controllers.HomeController; import constants.Palette; import com.texttwist.client.ui.*; @@ -8,6 +9,10 @@ import javax.swing.*; import java.awt.*; import java.util.concurrent.Callable; +/** + * Author: Lorenzo Iovino on 23/06/2017. + * Description: Home Page + */ public class HomePage extends Page { private HomeController homeController; diff --git a/Client/src/com/texttwist/client/pages/MatchRequestsPage.java b/Client/src/com/texttwist/client/pages/MatchRequestsPage.java index 0aed817..462441d 100644 --- a/Client/src/com/texttwist/client/pages/MatchRequestsPage.java +++ b/Client/src/com/texttwist/client/pages/MatchRequestsPage.java @@ -1,6 +1,6 @@ package com.texttwist.client.pages; -import com.texttwist.client.App; +import com.texttwist.client.controllers.MatchRequestController; import constants.Palette; import com.texttwist.client.ui.*; import javax.swing.*; @@ -11,13 +11,16 @@ import java.io.IOException; import java.util.concurrent.Callable; /** - * MatchRequest Page + * Author: Lorenzo Iovino on 27/06/2017. + * Description: MatchRequest Page */ public class MatchRequestsPage extends Page{ - public TTContainer matchsContainer; + private MatchRequestController matchRequestController; + MatchRequestsPage(JFrame window) throws IOException { super(window); + matchRequestController = new MatchRequestController(); createUIComponents(); window.setVisible(true); } @@ -25,9 +28,9 @@ public class MatchRequestsPage extends Page{ @Override public void createUIComponents() throws IOException { addLogo(root); - matchsContainer = new TTContainer( + TTContainer matchsContainer = new TTContainer( null, - new Dimension(1150,220), + new Dimension(1150, 220), Palette.root_backgroundColor, -1, root @@ -45,7 +48,7 @@ public class MatchRequestsPage extends Page{ TTScrollList pendingMatches = new TTScrollList( new Point(20, 60), new Dimension(520, 142), - App.gameService.pendingList, + matchRequestController.getPendingList(), matchsContainer ); @@ -56,7 +59,7 @@ public class MatchRequestsPage extends Page{ JList thisList = (JList)evt.getSource(); if (evt.getClickCount() == 2) { int index = thisList.locationToIndex(evt.getPoint()); - App.gameService.joinMatch(App.gameService.pendingList.get(index)); + matchRequestController.joinMatch(matchRequestController.getPendingList().get(index)); } } }); diff --git a/Client/src/com/texttwist/client/pages/MatchSetupPage.java b/Client/src/com/texttwist/client/pages/MatchSetupPage.java index c608e95..016dce5 100644 --- a/Client/src/com/texttwist/client/pages/MatchSetupPage.java +++ b/Client/src/com/texttwist/client/pages/MatchSetupPage.java @@ -8,7 +8,8 @@ import java.awt.*; import java.util.concurrent.Callable; /** - * MatchSetup Page + * Author: Lorenzo Iovino on 27/06/2017. + * Description: MatchSetup Page */ public class MatchSetupPage extends Page{ @@ -56,9 +57,10 @@ public class MatchSetupPage extends Page{ "Play!", new Callable() { @Override - public Object call() throws Exception { - //If notificationServer response ok, start play, else error - return matchSetupController.play(searchUserBar.list); + public Void call() throws Exception { + //If notificationServer response ok, start beginMatch, else error + matchSetupController.play(searchUserBar.list); + return null; } } ); diff --git a/Client/src/com/texttwist/client/pages/MenuPage.java b/Client/src/com/texttwist/client/pages/MenuPage.java index 1016b15..964e7c6 100644 --- a/Client/src/com/texttwist/client/pages/MenuPage.java +++ b/Client/src/com/texttwist/client/pages/MenuPage.java @@ -1,26 +1,25 @@ package com.texttwist.client.pages; -import com.texttwist.client.App; + import com.texttwist.client.controllers.MenuController; import constants.Palette; import com.texttwist.client.ui.*; - import javax.swing.*; import java.awt.*; import java.io.IOException; import java.util.concurrent.Callable; /** - * Created by loke on 14/06/2017. + * Author: Lorenzo Iovino on 17/06/2017. + * Description: Menu Page */ public class MenuPage extends Page{ - private TTContainer menuBar; private MenuController menuController; public MenuPage(JFrame window) throws IOException { super(window); - createUIComponents(); menuController = new MenuController(); + createUIComponents(); window.setVisible(true); } @@ -28,24 +27,24 @@ public class MenuPage extends Page{ public void createUIComponents() throws IOException { addLogo(root); - menuBar = new TTContainer( + TTContainer menuBar = new TTContainer( null, - new Dimension(1150,280), + new Dimension(1150, 280), Palette.root_backgroundColor, -1, root ); - TTLabel playerToSendInvite_flavourText = new TTLabel( + new TTLabel( new Point(25,15), new Dimension(350,20), - "Welcome back, " + App.session.account.userName + "!", + "Welcome back, " + menuController.getSession().account.userName + "!", new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24), null, menuBar ); - TTButton newMatch = new TTButton( + new TTButton( new Point(25,70), new Dimension(250,75), "New GameService!", @@ -59,7 +58,7 @@ public class MenuPage extends Page{ menuBar ); - TTButton matchRequests = new TTButton( + new TTButton( new Point(290,70), new Dimension(250,75), "In pending", @@ -73,14 +72,7 @@ public class MenuPage extends Page{ menuBar ); - TTCircleCounter circleCounter = new TTCircleCounter( - new Point(290,70), - new Dimension(25,25), - menuBar.getGraphics(), - menuBar - ); - - TTButton highscores = new TTButton( + new TTButton( new Point(25, 155), new Dimension(250, 75), "Highscores", @@ -93,14 +85,14 @@ public class MenuPage extends Page{ menuBar ); - TTButton logout = new TTButton( + new TTButton( new Point(290, 155), new Dimension(250, 75), "Logout", new Callable() { @Override public Object call() throws Exception { - menuController.logout(App.session.account.userName, App.gameService.notificationStub); + menuController.logout(); return new HomePage(Page.window); } }, diff --git a/Client/src/com/texttwist/client/pages/Page.java b/Client/src/com/texttwist/client/pages/Page.java index 83afbe9..a2ad578 100644 --- a/Client/src/com/texttwist/client/pages/Page.java +++ b/Client/src/com/texttwist/client/pages/Page.java @@ -1,4 +1,5 @@ package com.texttwist.client.pages; + import constants.Palette; import com.texttwist.client.ui.*; import javax.swing.*; @@ -10,7 +11,8 @@ import java.io.IOException; import java.util.concurrent.Callable; /** - * Base Page + * Author: Lorenzo Iovino on 14/06/2017. + * Description: Controller of the Home Page */ public class Page { @@ -38,18 +40,18 @@ public class Page { public void addLogo(TTContainer parent) { TTContainer container = new TTContainer( - null, - new Dimension(1150, 150), - Palette.root_backgroundColor, - -1, - parent); + null, + new Dimension(1150, 150), + Palette.root_backgroundColor, + -1, + parent); try { - TTImage logoImg = new TTImage( - new Point(0, 10), - new Dimension(1150, 150), - new ImageIcon(new File("./Client/resources/images/logo.png").getCanonicalPath()), - container); + new TTImage( + new Point(0, 10), + new Dimension(1150, 150), + new ImageIcon(new File("./Client/resources/images/logo.png").getCanonicalPath()), + container); } catch (IOException e) { e.printStackTrace(); } @@ -78,14 +80,14 @@ public class Page { } public void addNext(TTContainer parent, String caption, Callable clickHandler) { - TTLabelBtn next = new TTLabelBtn( - new Point(500, 0), - new Dimension(150, 50), - caption, - null, - null, - clickHandler, - parent); + new TTLabelBtn( + new Point(500, 0), + new Dimension(150, 50), + caption, + null, + null, + clickHandler, + parent); } public Timer addTimer(TTContainer parent, Font font, SwingWorker timerEndHandler, Integer value) { diff --git a/Client/src/com/texttwist/client/pages/RegisterPage.java b/Client/src/com/texttwist/client/pages/RegisterPage.java index eb76ac7..44f0dbe 100644 --- a/Client/src/com/texttwist/client/pages/RegisterPage.java +++ b/Client/src/com/texttwist/client/pages/RegisterPage.java @@ -4,19 +4,19 @@ import com.texttwist.client.controllers.RegisterController; import constants.Palette; import com.texttwist.client.ui.*; import models.Response; - import javax.swing.*; import java.awt.*; import java.util.concurrent.Callable; /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 16/06/2017. + * Description: Register Page */ public class RegisterPage extends Page { - private TTContainer registerDataContainer; private RegisterController registerController; - public RegisterPage(JFrame window) { + + RegisterPage(JFrame window) { super(window); createUIComponents(); registerController = new RegisterController(); @@ -26,14 +26,14 @@ public class RegisterPage extends Page { @Override public void createUIComponents() { addLogo(root); - registerDataContainer = new TTContainer( + TTContainer registerDataContainer = new TTContainer( null, - new Dimension(1150,220), + new Dimension(1150, 220), Palette.root_backgroundColor, -1, root ); - TTLabel registerText = new TTLabel( + new TTLabel( new Point(70,35), new Dimension(400,40), "Insert your datas and press Register!", @@ -55,7 +55,7 @@ public class RegisterPage extends Page { registerDataContainer ); - TTButton register = new TTButton( + new TTButton( new Point(70,150), new Dimension(430,50), "Register!", @@ -95,6 +95,5 @@ public class RegisterPage extends Page { } } ); - } } diff --git a/Client/src/com/texttwist/client/services/AuthService.java b/Client/src/com/texttwist/client/services/AuthService.java index 5b25e81..7944483 100644 --- a/Client/src/com/texttwist/client/services/AuthService.java +++ b/Client/src/com/texttwist/client/services/AuthService.java @@ -1,4 +1,5 @@ package com.texttwist.client.services; + import com.texttwist.client.App; import constants.Config; import interfaces.IAuth; @@ -8,10 +9,11 @@ import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; /** - * Authentication Service + * Author: Lorenzo Iovino on 17/06/2017. + * Description: Auth Service. + * Provide the interface for authentication */ public class AuthService { @@ -19,11 +21,9 @@ public class AuthService { public Response login(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException { try { - INotificationClient callbackObj = new NotificationClient(); - App.gameService.notificationStub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0); - App.gameService.notificationServer.registerForCallback(App.gameService.notificationStub); + App.registerForNotifications(); } catch (RemoteException e) { - e.printStackTrace(); + App.logger.write("AUTH SERVICE: Can't register for notification"); } IAuth auth = (IAuth) Naming.lookup(baseUrl); return auth.login(userName, password); diff --git a/Client/src/com/texttwist/client/services/GameService.java b/Client/src/com/texttwist/client/services/GameService.java index ab788aa..5b3634e 100644 --- a/Client/src/com/texttwist/client/services/GameService.java +++ b/Client/src/com/texttwist/client/services/GameService.java @@ -6,68 +6,38 @@ import com.texttwist.client.pages.MenuPage; import com.texttwist.client.pages.Page; import com.texttwist.client.tasks.InvitePlayers; import com.texttwist.client.ui.TTDialog; -import constants.Config; -import interfaces.INotificationClient; -import interfaces.INotificationServer; import javafx.util.Pair; import models.Message; - import javax.swing.*; import java.io.*; -import java.net.InetSocketAddress; -import java.net.MulticastSocket; import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; -import java.rmi.NotBoundException; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; import java.util.concurrent.*; /** - * Created by loke on 18/06/2017. + * Author: Lorenzo Iovino on 18/06/2017. + * Description: GameService. + * Provide the interface for the game. */ public class GameService { public Integer multicastId = 0 ; - public DefaultListModel pendingList = new DefaultListModel(); - public DefaultListModel words = new DefaultListModel(); - public DefaultListModel letters = new DefaultListModel(); + public DefaultListModel pendingList = new DefaultListModel<>(); + public DefaultListModel words = new DefaultListModel<>(); + public DefaultListModel letters = new DefaultListModel<>(); public DefaultListModel> globalRanks = new DefaultListModel<>(); public DefaultListModel> ranks = new DefaultListModel<>(); - public INotificationClient notificationStub; - public MulticastSocket multicastSocket; - public SocketChannel clientSocket; - public INotificationServer notificationServer; - public Boolean gameIsStarted = false; + private Boolean gameIsStarted = false; - private ByteBuffer buffer = ByteBuffer.allocate(1024); - - public GameService(){ - - Registry registry = null; - try { - registry = LocateRegistry.getRegistry(Config.NotificationServerStubPort); - notificationServer = (INotificationServer) registry.lookup(Config.NotificationServerName); - - } catch (RemoteException e) { - e.printStackTrace(); - } catch (NotBoundException e) { - e.printStackTrace(); - } - - InetSocketAddress socketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort); - try { - clientSocket = SocketChannel.open(socketAddress); - clientSocket.configureBlocking(false); - } catch (IOException e) { - e.printStackTrace(); - } + private void addToPendingList(String username) throws IOException { + pendingList.addElement(username); } + public GameService(){ + App.openClientTCPSocket(); + } public void newMatch(String userName) { - //Add to pending invitation list + //Add to pending invites list try { this.addToPendingList(userName); } catch (IOException e) { @@ -75,8 +45,8 @@ public class GameService { } if(!App.gameService.gameIsStarted) { - //Show invitation popup - new TTDialog("success", "New invitation from: " + userName + "!", + //Show invite popup + new TTDialog("success", "New invite from: " + userName + "!", new Callable() { @Override public Object call() throws Exception { @@ -93,7 +63,6 @@ public class GameService { } } - public DefaultListModel getLetters(){ return App.gameService.letters; } @@ -107,6 +76,7 @@ public class GameService { } public void joinMatch(String matchName) { + //Clear pending invitation list and join selected match if(!gameIsStarted) { this.pendingList.clear(); @@ -116,8 +86,8 @@ public class GameService { Message message = new Message("JOIN_GAME", App.session.account.userName, App.session.token, matchNames); byte[] byteMessage = message.toString().getBytes(); - buffer = ByteBuffer.wrap(byteMessage); - clientSocket.write(buffer); + ByteBuffer buffer = ByteBuffer.wrap(byteMessage); + App.clientTCP.write(buffer); new GamePage(Page.window); } catch (IOException e) { @@ -126,27 +96,20 @@ public class GameService { } } - public Object play(DefaultListModel userNames) throws IOException { - SwingWorker worker = new InvitePlayers(userNames,clientSocket); - worker.execute(); - return null; + //Start game and wait for other players + public void beginMatch(DefaultListModel userNames) { + new InvitePlayers(userNames).execute(); } - public Void start(){ - App.gameService.gameIsStarted = true; - return null; + public void start(){ + gameIsStarted = true; } - public Void stop(){ - App.gameService.gameIsStarted = false; - return null; + public void stop(){ + gameIsStarted = false; } public void setMulticastId(Integer multicastId){ this.multicastId = multicastId; } - - private void addToPendingList(String username) throws IOException { - pendingList.addElement(username); - } } diff --git a/Client/src/com/texttwist/client/services/NotificationClient.java b/Client/src/com/texttwist/client/services/NotificationClientService.java similarity index 66% rename from Client/src/com/texttwist/client/services/NotificationClient.java rename to Client/src/com/texttwist/client/services/NotificationClientService.java index 0a7090e..542dd8b 100644 --- a/Client/src/com/texttwist/client/services/NotificationClient.java +++ b/Client/src/com/texttwist/client/services/NotificationClientService.java @@ -1,22 +1,18 @@ package com.texttwist.client.services; + import com.texttwist.client.App; import interfaces.INotificationClient; -import models.Response; - import javax.swing.*; import java.rmi.RemoteException; /** - * Created by loke on 15/06/2017. + * Author: Lorenzo Iovino on 15/06/2017. + * Description: Provide the interface for the notifications. */ -public class NotificationClient implements INotificationClient { - - - public NotificationClient() throws RemoteException { - } +public class NotificationClientService implements INotificationClient { @Override - public Response sendInvite(String userName, DefaultListModel users) throws RemoteException { + public void sendInvite(String userName, DefaultListModel users) throws RemoteException { App.logger.write("Invoked invitation with username =" + userName + "|" + users.toString() ); if(App.session != null) { @@ -27,6 +23,5 @@ public class NotificationClient implements INotificationClient { App.logger.write("User " + userName + " is slogged"); } } - return null; } } diff --git a/Client/src/com/texttwist/client/tasks/FetchHighscore.java b/Client/src/com/texttwist/client/tasks/FetchHighscore.java index 43a70a3..f26f9a8 100644 --- a/Client/src/com/texttwist/client/tasks/FetchHighscore.java +++ b/Client/src/com/texttwist/client/tasks/FetchHighscore.java @@ -1,28 +1,24 @@ package com.texttwist.client.tasks; import com.texttwist.client.App; -import com.texttwist.client.pages.HighscoresPage; -import javafx.util.Pair; import models.Message; - import javax.swing.*; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; +import java.util.concurrent.Callable; /** - * Job: FetchHighscore + * Author: Lorenzo Iovino on 20/06/2017. + * Description: Task: FetchHighscore. + * Ask for highscores to server. When received it shows in highscores list */ public class FetchHighscore extends SwingWorker { - private DefaultListModel> globalRanks = new DefaultListModel<>(); - private SocketChannel socketChannel; private ByteBuffer buffer = ByteBuffer.allocate(1024); - HighscoresPage highscoresPage; + private Callable callback; - public FetchHighscore(HighscoresPage highscoresPage){ - this.socketChannel = App.gameService.clientSocket; - this.highscoresPage = highscoresPage; + public FetchHighscore(Callable callback){ + this.callback = callback; } @Override @@ -31,43 +27,38 @@ public class FetchHighscore extends SwingWorker { buffer = ByteBuffer.allocate(1024); byte[] byteMessage = message.toString().getBytes(); buffer = ByteBuffer.wrap(byteMessage); + try { - socketChannel.write(buffer); + App.clientTCP.write(buffer); } catch (IOException e) { - e.printStackTrace(); + App.logger.write("FETCH HIGHSCORES: Can't write on socket"); } try { buffer = ByteBuffer.allocate(1024); - - while (socketChannel.read(buffer) != -1) { - + while (App.clientTCP.read(buffer) != -1) { String line = new String(buffer.array(), buffer.position(), buffer.remaining()); if (line.startsWith("MESSAGE")) { Message msg = Message.toMessage(line); if (msg.message.equals("HIGHSCORES") && msg.data != null) { - for(int i = 0; i< msg.data.size()-1; i++){ - String[] splitted = msg.data.get(i).split(":"); - globalRanks.addElement(new Pair<>(splitted[0],new Integer(splitted[1]))); - } - - return null; - + App.gameService.globalRanks = utilities.Parse.score(msg.data); + break; } } buffer.clear(); - } } catch (IOException e) { - e.printStackTrace(); + App.logger.write("FETCH HIGHSCORES: Can't read from socket"); } return null; } public void done(){ - App.gameService.globalRanks = globalRanks; - this.highscoresPage.showHighscoreList(); + try { + callback.call(); + } catch (Exception e) { + e.printStackTrace(); + } } } - diff --git a/Client/src/com/texttwist/client/tasks/InvitePlayers.java b/Client/src/com/texttwist/client/tasks/InvitePlayers.java index dd61868..d78e7ae 100644 --- a/Client/src/com/texttwist/client/tasks/InvitePlayers.java +++ b/Client/src/com/texttwist/client/tasks/InvitePlayers.java @@ -5,88 +5,78 @@ import com.texttwist.client.pages.GamePage; import com.texttwist.client.pages.Page; import com.texttwist.client.ui.TTDialog; import models.Message; - import javax.swing.*; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; import java.util.concurrent.Callable; /** - * Created by loke on 25/06/2017. + * Author: Lorenzo Iovino on 25/06/2017. + * Description: Task: InvitePlayers + * Sends invite to all players of the match */ -public class InvitePlayers extends SwingWorker { +public class InvitePlayers extends SwingWorker { - ByteBuffer buffer = ByteBuffer.allocate(1024); + private ByteBuffer buffer = ByteBuffer.allocate(1024); + private DefaultListModel userNames; - public DefaultListModel userNames; - public SocketChannel socketChannel; - - public InvitePlayers(DefaultListModel userNames, SocketChannel socketChannel) { - this.socketChannel = socketChannel; + public InvitePlayers(DefaultListModel userNames) { this.userNames = userNames; } + @Override - public Boolean doInBackground() { + public Void doInBackground() { buffer = ByteBuffer.allocate(1024); Message message = new Message("START_GAME", App.session.account.userName, App.session.token, userNames); - byte[] byteMessage = new String(message.toString()).getBytes(); + byte[] byteMessage = message.toString().getBytes(); buffer = ByteBuffer.wrap(byteMessage); try { - socketChannel.write(buffer); + App.clientTCP.write(buffer); } catch (IOException e) { e.printStackTrace(); } try { - while (socketChannel.read(buffer) != -1) { + while (App.clientTCP.read(buffer) != -1) { String line = new String(buffer.array(), buffer.position(), buffer.remaining()); - if (line.startsWith("MESSAGE")) { Message msg = Message.toMessage(line); + if (msg.message.equals("USER_NOT_ONLINE")) { new TTDialog("alert", "Users not online!", - new Callable() { - @Override - public Object call() throws Exception { - buffer.clear(); - return null; - } - }, null); + new Callable() { + @Override + public Void call() throws Exception { + buffer.clear(); + return null; + } + }, null); buffer.clear(); return null; - } if (msg.message.equals("INVITES_ALL_SENDED")) { - // clientSocket.close(); new TTDialog("success", "Invite all sended!", - new Callable() { - @Override - public Object call() throws Exception { - //In attesa dei giocatori - new GamePage(Page.window); - buffer.clear(); - return null; - } - }, null); + new Callable() { + @Override + public Void call() throws Exception { + //In attesa dei giocatori + new GamePage(Page.window); + buffer.clear(); + return null; + } + }, null); buffer.clear(); return null; - } } buffer.clear(); } } catch (IOException e) { - e.printStackTrace(); + App.logger.write("INVITE PLAYERS: Can't read from socket"); } return null; } - - @Override - public void done() { - - } } diff --git a/Client/src/com/texttwist/client/tasks/SendWords.java b/Client/src/com/texttwist/client/tasks/SendWords.java index 12a750d..d84a200 100644 --- a/Client/src/com/texttwist/client/tasks/SendWords.java +++ b/Client/src/com/texttwist/client/tasks/SendWords.java @@ -1,25 +1,21 @@ package com.texttwist.client.tasks; import com.texttwist.client.App; -import constants.Config; -import javafx.util.Pair; import models.Message; - import javax.swing.*; import java.io.IOException; import java.net.*; import java.nio.ByteBuffer; -import java.nio.channels.DatagramChannel; /** - * Created by loke on 29/06/2017. + * Author: Lorenzo Iovino on 29/06/2017. + * Description: Task: SendWords. + * Send words to server and when done it wait for score. */ public class SendWords extends SwingWorker { - DefaultListModel> ranks = new DefaultListModel>(); - - SwingWorker callback; - DefaultListModel words = new DefaultListModel<>(); + private SwingWorker callback; + private DefaultListModel words = new DefaultListModel<>(); public SendWords(DefaultListModel words, SwingWorker callback){ this.callback = callback; @@ -29,28 +25,23 @@ public class SendWords extends SwingWorker { @Override public Void doInBackground() { try { - System.out.println(words); - InetSocketAddress myAddress = new InetSocketAddress(Config.WordsReceiverServerURI, Config.WordsReceiverServerPort); - DatagramChannel datagramChannel = DatagramChannel.open(); - datagramChannel.bind(null); + App.openClientUDPSocket(); + ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.clear(); - System.out.println("SENDER=" + App.session.account.userName); + Message msg = new Message("WORDS", App.session.account.userName, App.session.token, words); String sentence = msg.toString(); buffer.put(sentence.getBytes()); buffer.flip(); - datagramChannel.send(buffer, myAddress); - System.out.println("WORDS INVIATE"); - System.out.println(sentence); + + App.clientUDP.send(buffer, App.clientUDPSocketAddress); return null; } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (SocketException e) { - e.printStackTrace(); + App.logger.write("SEND WORDS: Host address not correct"); } catch (IOException e) { - e.printStackTrace(); + App.logger.write("SEND WORDS: Can't write on socket"); } return null; } @@ -63,5 +54,4 @@ public class SendWords extends SwingWorker { e.printStackTrace(); } } - } diff --git a/Client/src/com/texttwist/client/tasks/StartGame.java b/Client/src/com/texttwist/client/tasks/StartGame.java deleted file mode 100644 index 33bbf7c..0000000 --- a/Client/src/com/texttwist/client/tasks/StartGame.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.texttwist.client.tasks; - -import com.texttwist.client.App; -import com.texttwist.client.pages.GamePage; -import com.texttwist.client.ui.TTDialog; - -import javax.swing.*; -import java.util.concurrent.Callable; - -/** - * Created by loke on 25/06/2017. - */ -public class StartGame extends SwingWorker { - - /*Words inserted from user*/ - private DefaultListModel letters = new DefaultListModel<>(); - private GamePage gamePage; - - public StartGame(DefaultListModel letters, GamePage game){ - this.letters = letters; - this.gamePage = game; - } - - @Override - public Void doInBackground(){ - App.gameService.start(); - //Mostra pannello di conferma che le lettere sono tutte arrivate - new TTDialog("success", "GameService is ready. Press OK to start!", - new Callable() { - @Override - public Object call() throws Exception { - gamePage.showLetters(); - gamePage.timer.start(); - return null; - } - }, null); - return null; - } - - @Override - public void done(){ - } -} diff --git a/Client/src/com/texttwist/client/tasks/WaitForPlayers.java b/Client/src/com/texttwist/client/tasks/WaitForPlayers.java index 6401f22..cdc096a 100644 --- a/Client/src/com/texttwist/client/tasks/WaitForPlayers.java +++ b/Client/src/com/texttwist/client/tasks/WaitForPlayers.java @@ -4,136 +4,99 @@ import com.texttwist.client.App; import com.texttwist.client.pages.MenuPage; import com.texttwist.client.pages.Page; import com.texttwist.client.ui.TTDialog; -import constants.Config; import models.Message; - import javax.swing.*; import java.io.IOException; -import java.net.InetAddress; -import java.net.MulticastSocket; import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; import java.util.concurrent.Callable; /** - * Created by loke on 25/06/2017. + * Author: Lorenzo Iovino on 25/06/2017. + * Description: Task: WaitForPlayers. + * Wait for players joins, when all joined then sends a message of game started to all + * */ -public class WaitForPlayers extends SwingWorker,DefaultListModel> { +public class WaitForPlayers extends SwingWorker { - public SocketChannel socketChannel; - public DefaultListModel words; - public DefaultListModel letters; - boolean joinTimeout = false; - ByteBuffer buffer = ByteBuffer.allocate(1024); - SwingWorker callback; + private boolean joinTimeout = false; + private Callable callback; - public WaitForPlayers(SwingWorker callback) { + public WaitForPlayers(Callable callback) { this.callback = callback; - this.words = words; - this.socketChannel = App.gameService.clientSocket; } @Override - public DefaultListModel doInBackground() { + public Void doInBackground() { try { - buffer = ByteBuffer.allocate(1024); - String line1 = new String(buffer.array(), buffer.position(), buffer.remaining()); + ByteBuffer buffer = ByteBuffer.allocate(1024); TTDialog loading = new TTDialog("alert", "Waiting for users joins",null,null); buffer.flip(); - while (this.socketChannel.read(buffer) != -1) { - + while (App.clientTCP.read(buffer) != -1) { String line = new String(buffer.array(), buffer.position(), buffer.remaining()); - // String line = new String() buffer.clear(); if (line.startsWith("MESSAGE")) { buffer.clear(); - System.out.println("Mi arriva questo dal notificationServer " + line); Message msg = Message.toMessage(line); - System.out.println(msg.message); if (msg.message.equals("JOIN_TIMEOUT")) { loading.dispose(); joinTimeout = true; - System.out.println("JOIN TIMEOUT ENTERED"); new TTDialog("alert", "TIMEOUT!", new Callable() { @Override - public Object call() throws Exception { - //socketChannel.close(); - return new MenuPage(Page.window); - + public Void call() throws Exception { + new MenuPage(Page.window); + return null; } }, null); - return new DefaultListModel(); + return null; } if (msg.message.equals("MATCH_NOT_AVAILABLE")) { loading.dispose(); - System.out.println("MATCH NOT AVAILABLE ENTERED"); - joinTimeout = true; - new TTDialog("alert", "THE GAME IS NOT MORE AVAILABLE!", - new Callable() { - @Override - public Object call() throws Exception { - //socketChannel.close(); - return new MenuPage(Page.window); - } - }, null); - return new DefaultListModel(); + new TTDialog("alert", "THE GAME IS NOT MORE AVAILABLE!", + new Callable() { + @Override + public Void call() throws Exception { + new MenuPage(Page.window); + return null; + } + }, null); + return null; } if (msg.message.equals("GAME_STARTED")) { loading.dispose(); - System.out.println("GAME STARTED ENTERED"); - DefaultListModel data; if(msg.data !=null ) { - data= msg.data; - - Integer multicastId = Integer.valueOf(data.remove(data.size()-2)); - App.gameService.setMulticastId(multicastId); - - App.gameService.multicastSocket = new MulticastSocket(App.gameService.multicastId); - InetAddress ia = InetAddress.getByName(Config.ScoreMulticastServerURI); - App.gameService.multicastSocket.joinGroup(ia); - letters = msg.data; - - - //socketChannel.close(); - return words; - } else { - System.out.println("USCITO CON"); - System.out.println(line); - return new DefaultListModel<>(); + DefaultListModel data = msg.data; + App.openClientMulticastSocket(Integer.valueOf(data.remove(data.size()-2))); + App.gameService.setLetters(msg.data); + break; } - } buffer = ByteBuffer.allocate(1024); - } } } catch (IOException e) { - - e.printStackTrace(); + App.logger.write("WAIT FOR SCORE: Can't receive from socket"); } - return new DefaultListModel(); + return null; } @Override public void done(){ if(!joinTimeout) { try { - App.gameService.setLetters(letters); - this.callback.execute(); + this.callback.call(); } catch (Exception e) { e.printStackTrace(); } - } else { } } } diff --git a/Client/src/com/texttwist/client/tasks/WaitForScore.java b/Client/src/com/texttwist/client/tasks/WaitForScore.java index b7e5c25..d007a4d 100644 --- a/Client/src/com/texttwist/client/tasks/WaitForScore.java +++ b/Client/src/com/texttwist/client/tasks/WaitForScore.java @@ -1,17 +1,16 @@ package com.texttwist.client.tasks; import com.texttwist.client.App; -import constants.Config; import models.Message; import javax.swing.*; import java.io.IOException; import java.net.DatagramPacket; -import java.net.InetAddress; import java.net.UnknownHostException; /** * Author: Lorenzo Iovino on 27/06/2017. - * Description: This job will waits for the score of the match sent by server, at end it will execute a callback + * Description: Task: WaitForScore. + * This task will waits for the score of the match sent by server, at end it will execute a callback * function that show the highscore pages. */ public class WaitForScore extends SwingWorker { @@ -29,15 +28,14 @@ public class WaitForScore extends SwingWorker { while(true) { byte[] buf = new byte[1024]; DatagramPacket receivedDatagram = new DatagramPacket(buf, buf.length); - App.gameService.multicastSocket.receive(receivedDatagram); + App.clientMulticast.receive(receivedDatagram); String s = new String(receivedDatagram.getData()); Message msg = Message.toMessage(s); - //When arrive a message with message=FINALSCORE popolate ranks + //When arrive a message with message=FINALSCORE => popolate ranks if(msg.message.equals("FINALSCORE")){ if(msg.data != null) { - App.gameService.ranks.clear(); App.gameService.ranks = utilities.Parse.score(msg.data); } break; @@ -53,18 +51,12 @@ public class WaitForScore extends SwingWorker { @Override public void done(){ - try { - //Leave group and close multicast socket - App.gameService.multicastSocket.leaveGroup(InetAddress.getByName(Config.ScoreMulticastServerURI)); - App.gameService.multicastSocket.close(); + App.closeClientMulticastSocket(); - //Stop gameService - App.gameService.stop(); + //Stop gameService + App.gameService.stop(); - //Call callback - this.callback.execute(); - } catch (IOException e) { - e.printStackTrace(); - } + //Call callback + this.callback.execute(); } } diff --git a/Client/src/com/texttwist/client/ui/TTButton.java b/Client/src/com/texttwist/client/ui/TTButton.java index 22778b3..c9355ef 100644 --- a/Client/src/com/texttwist/client/ui/TTButton.java +++ b/Client/src/com/texttwist/client/ui/TTButton.java @@ -1,15 +1,16 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.concurrent.Callable; + /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTContainer component */ public class TTButton extends JButton{ diff --git a/Client/src/com/texttwist/client/ui/TTCircleCounter.java b/Client/src/com/texttwist/client/ui/TTCircleCounter.java deleted file mode 100644 index 0b3f891..0000000 --- a/Client/src/com/texttwist/client/ui/TTCircleCounter.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.texttwist.client.ui; - -import javax.swing.*; -import java.awt.*; -import java.awt.geom.Ellipse2D; -import java.util.Random; - -/** - * Created by loke on 14/06/2017. - */ -public class TTCircleCounter extends JComponent{ - - private Point position; - private Dimension dimension; - - public TTCircleCounter(Point position, Dimension dimension, Graphics g, TTContainer parent){ - this.position=position; - this.dimension=dimension; - - Graphics2D g2d = (Graphics2D)g; - Ellipse2D.Double circle = new Ellipse2D.Double(position.x, position.y, dimension.width, dimension.height); - g2d.fill(circle); - g2d.setColor(Color.RED); - - parent.add(this); - } - - public void paintComponent(Graphics g) { - super.paintComponent(g); - Graphics2D g2d = (Graphics2D)g; - Ellipse2D.Double circle = new Ellipse2D.Double(position.x, position.y, dimension.width, dimension.height); - g2d.setColor(Color.RED); - g2d.fill(circle); - } -} diff --git a/Client/src/com/texttwist/client/ui/TTContainer.java b/Client/src/com/texttwist/client/ui/TTContainer.java index 6590bbf..3f968eb 100644 --- a/Client/src/com/texttwist/client/ui/TTContainer.java +++ b/Client/src/com/texttwist/client/ui/TTContainer.java @@ -6,8 +6,10 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; + /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTButton component */ public class TTContainer extends JPanel{ diff --git a/Client/src/com/texttwist/client/ui/TTDialog.java b/Client/src/com/texttwist/client/ui/TTDialog.java index 0d9ec99..415f04f 100644 --- a/Client/src/com/texttwist/client/ui/TTDialog.java +++ b/Client/src/com/texttwist/client/ui/TTDialog.java @@ -2,14 +2,15 @@ package com.texttwist.client.ui; import com.texttwist.client.App; import constants.Palette; - import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import java.util.concurrent.Callable; + /** - * Created by loke on 17/06/2017. + * Author: Lorenzo Iovino on 17/06/2017. + * Description: TTDialog component */ public class TTDialog extends JFrame { @@ -41,17 +42,60 @@ public class TTDialog extends JFrame { } add(root); - TTLabel msg = new TTLabel( - new Point(60,20), - new Dimension(350,50), - message, - new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38), - null, - root); + new TTLabel( + new Point(60,20), + new Dimension(350,50), + message, + new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38), + null, + root); - if(okHandler != null && cancelHandler != null){ - TTButton okBtn = new TTButton( - new Point(60,100), + if(okHandler != null && cancelHandler != null){ + new TTButton( + new Point(60,100), + new Dimension(150,50), + "Ok", + new Callable() { + @Override + public Object call() throws Exception { + okHandler.call(); + dispose(); + return null; + } + }, + root); + new TTButton( + new Point(250,100), + new Dimension(150,50), + "Cancel", + new Callable() { + @Override + public Object call() throws Exception { + cancelHandler.call(); + dispose(); + return null; + } + }, + root); + } else { + if(cancelHandler != null) { + new TTButton( + new Point(150, 100), + new Dimension(150, 50), + "Cancel", + new Callable() { + @Override + public Object call() throws Exception { + cancelHandler.call(); + dispose(); + return null; + } + }, + root); + } + if(okHandler != null) { + new TTButton( + new Point(150,100), new Dimension(150,50), "Ok", new Callable() { @@ -63,51 +107,8 @@ public class TTDialog extends JFrame { } }, root); - TTButton cancelBtn = new TTButton( - new Point(250,100), - new Dimension(150,50), - "Cancel", - new Callable() { - @Override - public Object call() throws Exception { - cancelHandler.call(); - dispose(); - return null; - } - }, - root); - } else { - if(cancelHandler != null) { - TTButton cancelBtn = new TTButton( - new Point(150, 100), - new Dimension(150, 50), - "Cancel", - new Callable() { - @Override - public Object call() throws Exception { - cancelHandler.call(); - dispose(); - return null; - } - }, - root); } - if(okHandler != null) { - TTButton okBtn = new TTButton( - new Point(150,100), - new Dimension(150,50), - "Ok", - new Callable() { - @Override - public Object call() throws Exception { - okHandler.call(); - dispose(); - return null; - } - }, - root); - } - } + } setVisible(true); } @@ -135,5 +136,4 @@ public class TTDialog extends JFrame { g2d.dispose(); } } - } diff --git a/Client/src/com/texttwist/client/ui/TTGameBox.java b/Client/src/com/texttwist/client/ui/TTGameBox.java index c7f2391..b4fb405 100644 --- a/Client/src/com/texttwist/client/ui/TTGameBox.java +++ b/Client/src/com/texttwist/client/ui/TTGameBox.java @@ -1,24 +1,25 @@ package com.texttwist.client.ui; + import constants.Palette; import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.util.concurrent.Callable; /** - * Created by loke on 14/06/2017. + * Author: Lorenzo Iovino on 14/06/2017. + * Description: TTGameBox component */ public class TTGameBox extends TTInputField{ public TTGameBox(Point position, Dimension dimension, - String placeholer, + String placeholder, DefaultListModel list, TTContainer parent){ - super(position, dimension, placeholer, parent); + super(position, dimension, placeholder, parent); setBackground(Palette.scrollPanel_backgroundColor); setFont(Palette.inputBox_font); setBounds(position.x, position.y, dimension.width, dimension.height); @@ -29,16 +30,16 @@ public class TTGameBox extends TTInputField{ addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - super.keyPressed(e); - if(e.getKeyCode() == 10){ - try { - list.addElement(getText()); - setText(""); - } catch (Exception e1) { - e1.printStackTrace(); - } + super.keyPressed(e); + if(e.getKeyCode() == 10){ + try { + list.addElement(getText()); + setText(""); + } catch (Exception e1) { + e1.printStackTrace(); } - //Every time i press a key, execute a search of users + } + //Every time i press a key, execute a search of users } }); diff --git a/Client/src/com/texttwist/client/ui/TTImage.java b/Client/src/com/texttwist/client/ui/TTImage.java index 70e8911..fc53ac2 100644 --- a/Client/src/com/texttwist/client/ui/TTImage.java +++ b/Client/src/com/texttwist/client/ui/TTImage.java @@ -4,8 +4,10 @@ import javax.swing.*; import java.awt.*; import java.io.IOException; + /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTImage component */ public class TTImage extends JLabel{ @@ -16,6 +18,5 @@ public class TTImage extends JLabel{ setIcon(image); parent.add(this); - } } diff --git a/Client/src/com/texttwist/client/ui/TTImageBtn.java b/Client/src/com/texttwist/client/ui/TTImageBtn.java index 967afef..bb3bb0d 100644 --- a/Client/src/com/texttwist/client/ui/TTImageBtn.java +++ b/Client/src/com/texttwist/client/ui/TTImageBtn.java @@ -1,7 +1,6 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; @@ -10,7 +9,8 @@ import java.io.IOException; import java.util.concurrent.Callable; /** - * Created by loke on 14/06/2017. + * Author: Lorenzo Iovino on 14/06/2017. + * Description: TTImageBtn component */ public class TTImageBtn extends TTImage { public TTImageBtn(Point position, Dimension dimension, ImageIcon image, Callable clickHandler, JPanel parent) throws IOException { @@ -19,13 +19,13 @@ public class TTImageBtn extends TTImage { addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { - super.mouseClicked(e); - setForeground(Palette.registerLblBtn_color); - try { - clickHandler.call(); - } catch (Exception e1) { - e1.printStackTrace(); - } + super.mouseClicked(e); + setForeground(Palette.registerLblBtn_color); + try { + clickHandler.call(); + } catch (Exception e1) { + e1.printStackTrace(); + } } }); } diff --git a/Client/src/com/texttwist/client/ui/TTInputBox.java b/Client/src/com/texttwist/client/ui/TTInputBox.java index a13f8b4..87d8d29 100644 --- a/Client/src/com/texttwist/client/ui/TTInputBox.java +++ b/Client/src/com/texttwist/client/ui/TTInputBox.java @@ -3,13 +3,14 @@ package com.texttwist.client.ui; import javax.swing.*; import java.awt.*; + /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTInputBox component */ public class TTInputBox extends JTextField { public String placeholder; - public void setPlaceholder(final String s) { placeholder = s; } @@ -29,6 +30,5 @@ public class TTInputBox extends JTextField { g.setColor(getDisabledTextColor()); g.drawString(placeholder, getInsets().left, pG.getFontMetrics() .getMaxAscent() + getInsets().top); - } - + } } diff --git a/Client/src/com/texttwist/client/ui/TTInputField.java b/Client/src/com/texttwist/client/ui/TTInputField.java index 888745d..8d96fdf 100644 --- a/Client/src/com/texttwist/client/ui/TTInputField.java +++ b/Client/src/com/texttwist/client/ui/TTInputField.java @@ -1,12 +1,12 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTInputField component */ public class TTInputField extends TTInputBox{ @@ -19,10 +19,6 @@ public class TTInputField extends TTInputBox{ setPreferredSize(dimension); setForeground(Palette.fontColor); setPlaceholder(placeholder); - parent.add(this); - } - - } diff --git a/Client/src/com/texttwist/client/ui/TTLabel.java b/Client/src/com/texttwist/client/ui/TTLabel.java index 9f91cf4..5f748db 100644 --- a/Client/src/com/texttwist/client/ui/TTLabel.java +++ b/Client/src/com/texttwist/client/ui/TTLabel.java @@ -1,12 +1,12 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTLabel component */ public class TTLabel extends JLabel{ @@ -30,8 +30,6 @@ public class TTLabel extends JLabel{ } else { setForeground(fontColor); } - parent.add(this); - } } diff --git a/Client/src/com/texttwist/client/ui/TTLabelBtn.java b/Client/src/com/texttwist/client/ui/TTLabelBtn.java index 7ac6ea4..251609e 100644 --- a/Client/src/com/texttwist/client/ui/TTLabelBtn.java +++ b/Client/src/com/texttwist/client/ui/TTLabelBtn.java @@ -1,7 +1,6 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; @@ -9,7 +8,8 @@ import java.awt.event.MouseEvent; import java.util.concurrent.Callable; /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 14/06/2017. + * Description: TTLabelBtn component */ public class TTLabelBtn extends TTLabel{ @@ -23,6 +23,7 @@ public class TTLabelBtn extends TTLabel{ super.mouseClicked(e); setForeground(Palette.registerLblBtn_onmouseclick_color); } + @Override public void mouseReleased(MouseEvent e) { super.mouseClicked(e); @@ -38,7 +39,6 @@ public class TTLabelBtn extends TTLabel{ public void mouseEntered(MouseEvent e) { super.mouseClicked(e); setForeground(Palette.registerLblBtn_onmouseover_color); - } @Override @@ -48,6 +48,5 @@ public class TTLabelBtn extends TTLabel{ } }); - } } diff --git a/Client/src/com/texttwist/client/ui/TTLetter.java b/Client/src/com/texttwist/client/ui/TTLetter.java index 886f1cc..0a6437b 100644 --- a/Client/src/com/texttwist/client/ui/TTLetter.java +++ b/Client/src/com/texttwist/client/ui/TTLetter.java @@ -1,23 +1,22 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; + /** - * Created by loke on 14/06/2017. + * Author: Lorenzo Iovino on 14/06/2017. + * Description: TTLetter component */ public class TTLetter extends TTLabel{ public TTLetter(Point position, String caption, JPanel parent) { super(position, - new Dimension(50,50), - caption, - new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 20), - Palette.fontColor, - parent); + new Dimension(50,50), + caption, + new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 20), + Palette.fontColor, + parent); parent.add(this); - } - } diff --git a/Client/src/com/texttwist/client/ui/TTPasswordField.java b/Client/src/com/texttwist/client/ui/TTPasswordField.java index 1909ccb..436ffd5 100644 --- a/Client/src/com/texttwist/client/ui/TTPasswordField.java +++ b/Client/src/com/texttwist/client/ui/TTPasswordField.java @@ -1,12 +1,13 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; + /** - * Created by loke on 13/06/2017. + * Author: Lorenzo Iovino on 13/06/2017. + * Description: TTPasswordField component */ public class TTPasswordField extends JPasswordField{ @@ -21,8 +22,6 @@ public class TTPasswordField extends JPasswordField{ setPreferredSize(dimension); setForeground(Palette.fontColor); setText(placeholder); - parent.add(this); } - } diff --git a/Client/src/com/texttwist/client/ui/TTScrollList.java b/Client/src/com/texttwist/client/ui/TTScrollList.java index ab8350f..c516f62 100644 --- a/Client/src/com/texttwist/client/ui/TTScrollList.java +++ b/Client/src/com/texttwist/client/ui/TTScrollList.java @@ -1,12 +1,12 @@ package com.texttwist.client.ui; import constants.Palette; - import javax.swing.*; import java.awt.*; /** - * Created by loke on 14/06/2017. + * Author: Lorenzo Iovino on 14/06/2017. + * Description: TTScrollList component */ public class TTScrollList extends JList { diff --git a/Client/src/com/texttwist/client/ui/TTSearchBar.java b/Client/src/com/texttwist/client/ui/TTSearchBar.java index 96a4675..7d2b793 100644 --- a/Client/src/com/texttwist/client/ui/TTSearchBar.java +++ b/Client/src/com/texttwist/client/ui/TTSearchBar.java @@ -1,7 +1,7 @@ package com.texttwist.client.ui; + import com.texttwist.client.App; import constants.Palette; - import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; @@ -12,11 +12,11 @@ import java.util.concurrent.Callable; /** - * Created by loke on 14/06/2017. + * Author: Lorenzo Iovino on 14/06/2017. + * Description: TTSearchBar component */ public class TTSearchBar extends TTContainer{ - private DefaultListModel matchedUsers = new DefaultListModel(); public DefaultListModel list = new DefaultListModel(); private Callable add(TTInputField ctx){ @@ -33,7 +33,6 @@ public class TTSearchBar extends TTContainer{ }; } - public TTSearchBar(Point position, Dimension dimension, String placeholder, @@ -46,76 +45,65 @@ public class TTSearchBar extends TTContainer{ setPreferredSize(dimension); setForeground(Palette.fontColor); - TTLabel playerFinder_flavourText = new TTLabel( - new Point(20,40), - new Dimension(350,50), - "Add player", - new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), - null, - parent); + new TTLabel( + new Point(20,40), + new Dimension(350,50), + "Add player", + new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), + null, + parent); TTInputField usernameField = new TTInputField( - new Point(20,80), - new Dimension(250,45), - placeholder, - parent); + new Point(20,80), + new Dimension(250,45), + placeholder, + parent); - /*TTScrollList userList = new TTScrollList( - new Point(20,120), - new Dimension(250,95), - matchedUsers, - parent - );*/ + new TTButton( + new Point(70,140), + new Dimension(150,50), + "Add!", + add(usernameField), + parent); - TTButton addUser = new TTButton( - new Point(70,140), - new Dimension(150,50), - "Add!", - add(usernameField), - parent); - - - TTLabel playerToSendInvite_flavourText = new TTLabel( - new Point(305,40), - new Dimension(350,50), - "Double-Click on item for remove", - new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), - null, - parent); + new TTLabel( + new Point(305,40), + new Dimension(350,50), + "Double-Click on item for remove", + new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), + null, + parent); TTScrollList playerToSendInvite = new TTScrollList( - new Point(305, 80), - new Dimension(232, 135), - list, - parent); - + new Point(305, 80), + new Dimension(232, 135), + list, + parent); playerToSendInvite.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { - super.mouseClicked(evt); - JList thisList = (JList)evt.getSource(); - if (evt.getClickCount() == 2) { - - // Double-click detected - int index = thisList.locationToIndex(evt.getPoint()); - list.remove(index); - } + super.mouseClicked(evt); + JList thisList = (JList)evt.getSource(); + if (evt.getClickCount() == 2) { + int index = thisList.locationToIndex(evt.getPoint()); + list.remove(index); + } } }); usernameField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - super.keyPressed(e); - if(e.getKeyCode() == 10){ - try { - add(usernameField).call(); - } catch (Exception e1) { - e1.printStackTrace(); - } + super.keyPressed(e); + if(e.getKeyCode() == 10){ + try { + add(usernameField).call(); + } catch (Exception e1) { + e1.printStackTrace(); } } + } }); parent.add(this); diff --git a/Commons/src/interfaces/INotificationClient.java b/Commons/src/interfaces/INotificationClient.java index c8f3902..9e9bfb0 100644 --- a/Commons/src/interfaces/INotificationClient.java +++ b/Commons/src/interfaces/INotificationClient.java @@ -1,7 +1,5 @@ package interfaces; -import models.Response; - import javax.swing.*; import java.rmi.Remote; import java.rmi.RemoteException; @@ -10,6 +8,5 @@ import java.rmi.RemoteException; * Created by loke on 19/06/2017. */ public interface INotificationClient extends Remote{ - - Response sendInvite(String userName, DefaultListModel users) throws RemoteException; + void sendInvite(String userName, DefaultListModel users) throws RemoteException; } diff --git a/notificationServer.log b/notificationServer.log index 3db0984..6d11abd 100644 --- a/notificationServer.log +++ b/notificationServer.log @@ -889,3 +889,223 @@ LOGGER (Server): Wed Jul 12 17:55:22 CEST 2017 - Login successfull LOGGER (Server): Wed Jul 12 17:55:55 CEST 2017 - Invoked logout with username=b AND token=c7gnsjibk6rgfbrkefoqi36ii8 LOGGER (Server): Wed Jul 12 17:55:55 CEST 2017 - Logout successfull LOGGER (Server): Wed Jul 12 17:55:55 CEST 2017 - Logout successfull (but something gone wrong) +LOGGER (Server): Thu Jul 13 00:00:41 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 00:00:41 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 00:00:41 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 00:00:41 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 00:00:47 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 00:00:47 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 00:00:52 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Thu Jul 13 00:00:52 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 00:33:30 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 00:33:30 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 00:33:30 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 00:33:30 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 00:33:34 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 00:33:34 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 00:33:40 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 00:33:40 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 00:48:19 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 00:48:19 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 00:48:19 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 00:48:19 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 00:50:56 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 00:50:56 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 00:50:56 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 00:50:56 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 00:51:28 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 00:51:29 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 00:51:29 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 00:51:29 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 00:52:14 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 00:52:14 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 00:52:15 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 00:52:15 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 00:52:18 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 00:52:18 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 00:52:22 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 00:52:22 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 00:52:42 CEST 2017 - Invoked logout with username=b AND token=f3769fgmn2aq7bp0uvpi8ac905 +LOGGER (Server): Thu Jul 13 00:52:42 CEST 2017 - Logout successfull +LOGGER (Server): Thu Jul 13 00:52:42 CEST 2017 - Logout successfull (but something gone wrong) +LOGGER (Server): Thu Jul 13 00:52:45 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Thu Jul 13 00:52:45 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:12:14 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:12:14 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:12:14 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:12:14 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:12:19 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:12:19 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:13:08 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:13:08 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:13:08 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:13:08 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:13:12 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:13:12 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:13:54 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:13:55 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:13:55 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:13:55 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:13:59 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:13:59 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:14:35 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:14:35 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:14:35 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:14:35 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:14:38 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:14:38 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:15:34 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:15:34 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:15:34 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:15:34 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:15:37 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:15:37 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:16:07 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:16:07 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:16:07 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:16:07 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:16:10 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:16:10 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:16:36 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:16:36 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:16:36 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:16:36 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:16:39 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:16:39 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:16:43 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 01:16:43 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:25:24 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:25:24 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:25:24 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:25:24 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:25:28 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:25:28 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:25:32 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 01:25:32 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:26:08 CEST 2017 - Invoked register with username=ds AND password=ds +LOGGER (Server): Thu Jul 13 01:26:08 CEST 2017 - Registration successfull +LOGGER (Server): Thu Jul 13 01:26:11 CEST 2017 - Invoked login with username=ds AND password=ds +LOGGER (Server): Thu Jul 13 01:26:11 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:29:20 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:29:20 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:29:20 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:29:20 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:29:25 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:29:25 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:29:29 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Thu Jul 13 01:29:29 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:55:40 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:55:40 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:55:40 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:55:40 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:55:43 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:55:43 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:55:48 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Thu Jul 13 01:55:48 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:56:34 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:56:35 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:56:35 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:56:35 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:56:40 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:56:40 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:56:48 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:56:48 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:56:48 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:56:48 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:56:52 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:56:52 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:57:00 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 01:57:00 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:57:41 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:57:41 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:57:41 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:57:41 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:57:44 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:57:44 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 01:59:03 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 01:59:03 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 01:59:03 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 01:59:03 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 01:59:08 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 01:59:08 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:00:01 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:00:01 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:00:01 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:00:01 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:00:05 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:00:05 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:02:34 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:02:35 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:02:35 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:02:35 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:02:38 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:02:38 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:02:44 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:02:44 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:25:21 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:25:21 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:25:21 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:25:21 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:25:27 CEST 2017 - Invoked login with username=a AND password= +LOGGER (Server): Thu Jul 13 02:25:27 CEST 2017 - Login unsuccessfull +LOGGER (Server): Thu Jul 13 02:25:29 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:25:29 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:25:35 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:25:35 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:25:49 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:25:50 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:25:50 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:25:50 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:25:58 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:25:58 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:26:02 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:26:02 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:26:38 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Thu Jul 13 02:26:38 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:26:47 CEST 2017 - Invoked login with username=dd AND password=dd +LOGGER (Server): Thu Jul 13 02:26:47 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:38:42 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:38:42 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:38:43 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:38:43 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:38:46 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:38:46 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:38:51 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:38:51 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:39:55 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:39:55 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:39:55 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:39:55 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:40:01 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:40:01 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:40:11 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:40:11 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:41:22 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:41:22 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:41:22 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:41:22 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:41:27 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:41:27 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:41:32 CEST 2017 - Invoked login with username=b AND password=h +LOGGER (Server): Thu Jul 13 02:41:32 CEST 2017 - Login unsuccessfull +LOGGER (Server): Thu Jul 13 02:41:36 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:41:36 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:42:24 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:42:24 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:42:24 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:42:24 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:42:35 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:42:35 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:42:39 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:42:39 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:46:27 CEST 2017 - Server starting ... +LOGGER (Server): Thu Jul 13 02:46:27 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Thu Jul 13 02:46:27 CEST 2017 - Server started +LOGGER (Server): Thu Jul 13 02:46:27 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Thu Jul 13 02:46:32 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Thu Jul 13 02:46:32 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:46:35 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Thu Jul 13 02:46:35 CEST 2017 - Login successfull +LOGGER (Server): Thu Jul 13 02:47:30 CEST 2017 - Invoked logout with username=a AND token=arlci4cv3ct54q7jh5ddaog8q0 +LOGGER (Server): Thu Jul 13 02:47:30 CEST 2017 - Logout successfull +LOGGER (Server): Thu Jul 13 02:47:30 CEST 2017 - Logout successfull (but something gone wrong)