From ab307b0a9791ac083ac00986f4db03e3b3ade684 Mon Sep 17 00:00:00 2001 From: Lorenzo Iovino Date: Fri, 14 Jul 2017 00:46:37 +0200 Subject: [PATCH] UPPPP FINISH --- .idea/workspace.xml | 1083 ++++++++++------- .../client/services/GameService.java | 3 +- .../client/tasks/WaitForPlayers.java | 4 + Commons/src/constants/Config.java | 6 +- .../src/interfaces/INotificationServer.java | 2 +- Server/src/com/texttwist/server/Server.java | 4 +- .../server/proxies/MessageDispatcher.java | 2 +- .../server/services/AuthService.java | 8 +- .../server/services/JedisService.java | 6 + .../server/services/NotificationService.java | 5 +- .../server/services/ReceiveWordsService.java | 12 +- .../server/services/SessionsService.java | 2 - .../server/tasks/CheckOnlineUsers.java | 3 +- .../server/tasks/ComputeHighscores.java | 4 +- .../texttwist/server/tasks/ComputeScore.java | 39 +- .../server/tasks/GenerateLetters.java | 10 +- .../com/texttwist/server/tasks/JoinMatch.java | 30 +- .../texttwist/server/tasks/JoinTimeout.java | 10 +- .../texttwist/server/tasks/MatchTimeout.java | 3 +- .../server/tasks/SendInvitations.java | 5 +- .../server/tasks/SendMessageToAllPlayers.java | 11 +- .../texttwist/server/tasks/SendScores.java | 27 +- .../texttwist/server/tasks/TokenInvalid.java | 2 +- notificationServer.log | 102 ++ 24 files changed, 857 insertions(+), 526 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index db72c2d..1456423 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,22 +7,28 @@ - - - - - + + + - + + - + + + + + + + + @@ -45,65 +51,34 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -112,35 +87,76 @@ - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -152,36 +168,36 @@ - invio h - invio - multic - datagramChannel - invio g - C - Config - Config. - Config.W - Config.Wor - Config.Word - Config.Words - Config.WordsR - Config.WordsRe - Config.WordsRec - Config.WordsRece - remo - login unsu - s - client - add - print - printall - Syst - System - System. - System.o - System.ou - thread - System.out + wait fo + wait + wait us + wait u + waiting f + waiting for + gameIsSt + waitingF + waitingforU + waitingfor + waitingfo + waitingf + waiting + waiting for + is + i + gam + gameIs + gameIsS + iswa + ga + gameIS + gameISS + n + new inv + new invi + w + wait + waiting + gameISSt C:\Users\loke\TextTwist\out\production @@ -320,15 +336,8 @@ @@ -671,6 +687,222 @@ - @@ -1225,12 +1457,12 @@ - + - + @@ -1264,86 +1496,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1370,14 +1522,6 @@ - - - - - - - - @@ -1392,140 +1536,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1558,28 +1568,173 @@ - + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + @@ -1588,7 +1743,7 @@ - + @@ -1596,80 +1751,74 @@ - + - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1682,16 +1831,110 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Client/src/com/texttwist/client/services/GameService.java b/Client/src/com/texttwist/client/services/GameService.java index 5b3634e..e80e7b9 100644 --- a/Client/src/com/texttwist/client/services/GameService.java +++ b/Client/src/com/texttwist/client/services/GameService.java @@ -27,6 +27,7 @@ public class GameService { public DefaultListModel> globalRanks = new DefaultListModel<>(); public DefaultListModel> ranks = new DefaultListModel<>(); private Boolean gameIsStarted = false; + public Boolean isWaiting = false; private void addToPendingList(String username) throws IOException { pendingList.addElement(username); @@ -44,7 +45,7 @@ public class GameService { e.printStackTrace(); } - if(!App.gameService.gameIsStarted) { + if(!App.gameService.gameIsStarted && !App.gameService.isWaiting) { //Show invite popup new TTDialog("success", "New invite from: " + userName + "!", new Callable() { diff --git a/Client/src/com/texttwist/client/tasks/WaitForPlayers.java b/Client/src/com/texttwist/client/tasks/WaitForPlayers.java index cdc096a..8799eac 100644 --- a/Client/src/com/texttwist/client/tasks/WaitForPlayers.java +++ b/Client/src/com/texttwist/client/tasks/WaitForPlayers.java @@ -28,6 +28,7 @@ public class WaitForPlayers extends SwingWorker { @Override public Void doInBackground() { try { + App.gameService.isWaiting = true; ByteBuffer buffer = ByteBuffer.allocate(1024); TTDialog loading = new TTDialog("alert", "Waiting for users joins",null,null); buffer.flip(); @@ -42,6 +43,7 @@ public class WaitForPlayers extends SwingWorker { Message msg = Message.toMessage(line); if (msg.message.equals("JOIN_TIMEOUT")) { loading.dispose(); + App.gameService.isWaiting = false; joinTimeout = true; new TTDialog("alert", "TIMEOUT!", @@ -58,6 +60,7 @@ public class WaitForPlayers extends SwingWorker { if (msg.message.equals("MATCH_NOT_AVAILABLE")) { loading.dispose(); joinTimeout = true; + App.gameService.isWaiting = false; new TTDialog("alert", "THE GAME IS NOT MORE AVAILABLE!", new Callable() { @@ -72,6 +75,7 @@ public class WaitForPlayers extends SwingWorker { if (msg.message.equals("GAME_STARTED")) { loading.dispose(); + App.gameService.isWaiting = false; if(msg.data !=null ) { DefaultListModel data = msg.data; diff --git a/Commons/src/constants/Config.java b/Commons/src/constants/Config.java index 1496241..c337269 100644 --- a/Commons/src/constants/Config.java +++ b/Commons/src/constants/Config.java @@ -23,9 +23,9 @@ public class Config { public static String RedisServerURI = "localhost"; - public static int gameTimeout = 10; //2 minuti in sec - public static int joinMatchTimeout = 5000; //7 minuti in millisec - public static int sendWordsTimeout = 3000; //5 minuti in millisec + public static int gameTimeout = 120; //2 minuti in sec + public static int joinMatchTimeout = 7*1000*60; //7 minuti in millisec + public static int sendWordsTimeout = 5*1000*60; //5 minuti in millisec public static String getAuthServerURI(){ return "rmi://".concat(AuthServerURI).concat(":").concat(AuthServerPort.toString()); diff --git a/Commons/src/interfaces/INotificationServer.java b/Commons/src/interfaces/INotificationServer.java index 2c72c23..f7cad3c 100644 --- a/Commons/src/interfaces/INotificationServer.java +++ b/Commons/src/interfaces/INotificationServer.java @@ -9,5 +9,5 @@ import java.rmi.RemoteException; */ public interface INotificationServer extends Remote { void registerForCallback (INotificationClient ClientInterface) throws RemoteException; - void unregisterForCallback (INotificationClient ClientInterface) throws RemoteException; + void unregisterForCallback (INotificationClient ClientInterface) throws RemoteException; } diff --git a/Server/src/com/texttwist/server/Server.java b/Server/src/com/texttwist/server/Server.java index f57822b..aebc817 100644 --- a/Server/src/com/texttwist/server/Server.java +++ b/Server/src/com/texttwist/server/Server.java @@ -42,8 +42,8 @@ public class Server { private void startAuthService(){ //Starting Auth service based on RMI try { - auth = new AuthService(Config.AuthServerPort); - Registry authRegistry = LocateRegistry.createRegistry(auth.serverPort); + auth = new AuthService(); + Registry authRegistry = LocateRegistry.createRegistry(Config.AuthServerPort); authRegistry.bind("auth", auth); } catch (RemoteException e) { Server.logger.write("SERVER: RMI authentication service error (Remote exception)"); diff --git a/Server/src/com/texttwist/server/proxies/MessageDispatcher.java b/Server/src/com/texttwist/server/proxies/MessageDispatcher.java index 2f0c217..1adeb92 100644 --- a/Server/src/com/texttwist/server/proxies/MessageDispatcher.java +++ b/Server/src/com/texttwist/server/proxies/MessageDispatcher.java @@ -13,7 +13,7 @@ import java.util.concurrent.*; /** * Author: Lorenzo Iovino on 18/06/2017. - * Description: Proxy Dispatcher + * Description: Message Dispatcher * */ public class MessageDispatcher implements Callable { private final ExecutorService threadPool = Executors.newCachedThreadPool(); diff --git a/Server/src/com/texttwist/server/services/AuthService.java b/Server/src/com/texttwist/server/services/AuthService.java index 675b10c..85e07a0 100644 --- a/Server/src/com/texttwist/server/services/AuthService.java +++ b/Server/src/com/texttwist/server/services/AuthService.java @@ -1,6 +1,7 @@ package com.texttwist.server.services; import com.texttwist.server.Server; +import constants.Config; import interfaces.IAuth; import interfaces.INotificationClient; import models.Response; @@ -19,12 +20,9 @@ import static com.texttwist.server.Server.notificationServer; public class AuthService extends UnicastRemoteObject implements IAuth { private SecureRandom random = new SecureRandom(); - public int serverPort = 9999; - - public AuthService(int serverPort) throws RemoteException{ - this.serverPort=serverPort; - Server.logger.write("AuthService Service running at "+serverPort+" port..."); + public AuthService() throws RemoteException{ + Server.logger.write("AuthService Service running at "+ Config.AuthServerPort+" port..."); } @Override diff --git a/Server/src/com/texttwist/server/services/JedisService.java b/Server/src/com/texttwist/server/services/JedisService.java index 78f519f..134e0ab 100644 --- a/Server/src/com/texttwist/server/services/JedisService.java +++ b/Server/src/com/texttwist/server/services/JedisService.java @@ -1,5 +1,6 @@ package com.texttwist.server.services; +import com.texttwist.server.Server; import models.User; import redis.clients.jedis.Jedis; @@ -16,6 +17,11 @@ import static com.texttwist.server.Server.jedisPool; */ public class JedisService { + + JedisService(){ + Server.logger.write("Jedis Service running on localhost..."); + } + /** Read the object from Base64 string. */ public static Object fromString(String s) throws IOException, ClassNotFoundException { byte [] data = Base64.getDecoder().decode(s); diff --git a/Server/src/com/texttwist/server/services/NotificationService.java b/Server/src/com/texttwist/server/services/NotificationService.java index 7c085e6..863f107 100644 --- a/Server/src/com/texttwist/server/services/NotificationService.java +++ b/Server/src/com/texttwist/server/services/NotificationService.java @@ -1,5 +1,7 @@ package com.texttwist.server.services; +import com.texttwist.server.Server; +import constants.Config; import interfaces.INotificationClient; import interfaces.INotificationServer; @@ -12,13 +14,14 @@ import java.util.List; /** * Author: Lorenzo Iovino on 19/06/2017. - * Description: Jedis Service + * Description: Notification Service */ public class NotificationService implements INotificationServer { private List clients; public NotificationService() throws RemoteException { super(); + Server.logger.write("Notification Service running at "+ Config.NotificationServerPort+" port..."); clients = new ArrayList<>(); } diff --git a/Server/src/com/texttwist/server/services/ReceiveWordsService.java b/Server/src/com/texttwist/server/services/ReceiveWordsService.java index 8078794..bedd48d 100644 --- a/Server/src/com/texttwist/server/services/ReceiveWordsService.java +++ b/Server/src/com/texttwist/server/services/ReceiveWordsService.java @@ -1,34 +1,29 @@ package com.texttwist.server.services; +import com.texttwist.server.Server; import com.texttwist.server.models.Match; import com.texttwist.server.tasks.ComputeScore; -import com.texttwist.server.tasks.TokenInvalid; import constants.Config; import models.Message; - import java.io.IOException; import java.net.*; -import java.nio.ByteBuffer; -import java.nio.channels.DatagramChannel; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * Author: Lorenzo Iovino on 27/06/2017. - * Description: Jedis Service + * Description: Receive Words Service */ public class ReceiveWordsService implements Runnable { private ExecutorService threadPool = Executors.newCachedThreadPool(); public ReceiveWordsService() { - + Server.logger.write("ReceiveWords Service running at "+Config.WordsReceiverServerPort+" port..."); } @Override public void run(){ - - Message msg; DatagramSocket s = null; @@ -40,7 +35,6 @@ public class ReceiveWordsService implements Runnable { DatagramPacket packet; while(true) { - byte[] buf = new byte[1024]; packet = new DatagramPacket(buf, buf.length); diff --git a/Server/src/com/texttwist/server/services/SessionsService.java b/Server/src/com/texttwist/server/services/SessionsService.java index 2f80540..43f6030 100644 --- a/Server/src/com/texttwist/server/services/SessionsService.java +++ b/Server/src/com/texttwist/server/services/SessionsService.java @@ -33,8 +33,6 @@ public class SessionsService { return null; } - public SessionsService(){} - public boolean add(String userName, String token) { remove(userName); return sessions.add(new Session(new User(userName,"",0), token)); diff --git a/Server/src/com/texttwist/server/tasks/CheckOnlineUsers.java b/Server/src/com/texttwist/server/tasks/CheckOnlineUsers.java index 46b66ba..30949aa 100644 --- a/Server/src/com/texttwist/server/tasks/CheckOnlineUsers.java +++ b/Server/src/com/texttwist/server/tasks/CheckOnlineUsers.java @@ -1,13 +1,12 @@ package com.texttwist.server.tasks; import com.texttwist.server.services.SessionsService; - import javax.swing.*; import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 19/06/2017. - * Description: Jedis Service + * Description: Task: Check Online Users */ public class CheckOnlineUsers implements Callable { private final DefaultListModel users; diff --git a/Server/src/com/texttwist/server/tasks/ComputeHighscores.java b/Server/src/com/texttwist/server/tasks/ComputeHighscores.java index 4c143e2..6b8c29d 100644 --- a/Server/src/com/texttwist/server/tasks/ComputeHighscores.java +++ b/Server/src/com/texttwist/server/tasks/ComputeHighscores.java @@ -10,12 +10,10 @@ import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 28/06/2017. - * Description: Jedis Service + * Description: Task: Compute Highscores */ public class ComputeHighscores implements Callable> { - public ComputeHighscores(){} - @Override public DefaultListModel call() throws Exception { DefaultListModel l = new DefaultListModel<>(); diff --git a/Server/src/com/texttwist/server/tasks/ComputeScore.java b/Server/src/com/texttwist/server/tasks/ComputeScore.java index 97113c4..f8bc85e 100644 --- a/Server/src/com/texttwist/server/tasks/ComputeScore.java +++ b/Server/src/com/texttwist/server/tasks/ComputeScore.java @@ -1,23 +1,22 @@ package com.texttwist.server.tasks; + import com.texttwist.server.services.AccountsService; import com.texttwist.server.models.Dictionary; import com.texttwist.server.models.Match; -import javafx.util.Pair; import models.User; - import javax.swing.*; import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 27/06/2017. - * Description: Jedis Service + * Description: Task: Ccmpute Score */ public class ComputeScore implements Callable { private DefaultListModel words; private final String sender; public Match match; - private DefaultListModel wordsValid; + private DefaultListModel wordsValid = new DefaultListModel<>(); public ComputeScore(String sender, DefaultListModel words, Match match){ this.words = words; @@ -27,26 +26,24 @@ public class ComputeScore implements Callable { @Override public Integer call() throws Exception { - wordsValid = new DefaultListModel<>(); - Integer score = 0; - - for (int i = 0; i < words.size(); i++) { - if (isValid(words.get(i), match.letters)) { - score += words.get(i).length(); - wordsValid.addElement(words.get(i)); - } + Integer score = 0; + for (int i = 0; i < words.size(); i++) { + if (isValid(words.get(i), match.letters)) { + score += words.get(i).length(); + wordsValid.addElement(words.get(i)); } - match.setScore(sender, score); + } + match.setScore(sender, score); - User u = AccountsService.getInstance().findUser(sender); - u.addScore(score); + User u = AccountsService.getInstance().findUser(sender); + u.addScore(score); - if(match.allPlayersSendedHisScore()) { - match.matchTimeout = false; - match.setUndefinedScorePlayersToZero(); - new SendScores(match).call(); - } - return score; + if(match.allPlayersSendedHisScore()) { + match.matchTimeout = false; + match.setUndefinedScorePlayersToZero(); + new SendScores(match).call(); + } + return score; } private Boolean isValid(String word, DefaultListModel letters) { diff --git a/Server/src/com/texttwist/server/tasks/GenerateLetters.java b/Server/src/com/texttwist/server/tasks/GenerateLetters.java index a5a5394..71f3e26 100644 --- a/Server/src/com/texttwist/server/tasks/GenerateLetters.java +++ b/Server/src/com/texttwist/server/tasks/GenerateLetters.java @@ -1,24 +1,18 @@ package com.texttwist.server.tasks; import com.texttwist.server.services.MessageService; - import javax.swing.*; import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 25/06/2017. - * Description: Jedis Service + * Description: Task: Generate Letters */ public class GenerateLetters implements Callable> { - - public GenerateLetters(){ - - } - @Override public DefaultListModel call() throws Exception { - DefaultListModel l = new DefaultListModel(); + DefaultListModel l = new DefaultListModel<>(); String word = MessageService.dict.getRandomWord(6, 7); for (int i = 0;i < word.length(); i++){ diff --git a/Server/src/com/texttwist/server/tasks/JoinMatch.java b/Server/src/com/texttwist/server/tasks/JoinMatch.java index d9c7b36..c7cb369 100644 --- a/Server/src/com/texttwist/server/tasks/JoinMatch.java +++ b/Server/src/com/texttwist/server/tasks/JoinMatch.java @@ -8,12 +8,12 @@ import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 23/06/2017. - * Description: Jedis Service + * Description: Task: Join Match */ public class JoinMatch implements Callable { - public final String matchName; - public final String playerName; - public final SocketChannel socketChannel; + private final String matchName; + private final String playerName; + private final SocketChannel socketChannel; public JoinMatch(String playerName, DefaultListModel matchName, SocketChannel socketChannel) { this.playerName = playerName; @@ -24,19 +24,19 @@ public class JoinMatch implements Callable { @Override public Boolean call() throws Exception { final Match thisMatch = Match.findMatch(Match.activeMatches, this.matchName); - if (thisMatch != null) { - for (int j = 0; j < thisMatch.playersStatus.size(); j++) { - String name = thisMatch.playersStatus.get(j).getKey(); - if (name.equals(playerName)) { - thisMatch.playersStatus.remove(j); - thisMatch.playersStatus.add(new Pair<>(name, 1)); - thisMatch.playersSocket.remove(j); - thisMatch.playersSocket.add(new Pair<>(name, socketChannel)); - return allJoined(thisMatch); - } + if (thisMatch != null) { + for (int j = 0; j < thisMatch.playersStatus.size(); j++) { + String name = thisMatch.playersStatus.get(j).getKey(); + if (name.equals(playerName)) { + thisMatch.playersStatus.remove(j); + thisMatch.playersStatus.add(new Pair<>(name, 1)); + thisMatch.playersSocket.remove(j); + thisMatch.playersSocket.add(new Pair<>(name, socketChannel)); + return allJoined(thisMatch); } } - return false; + } + return false; } private Boolean allJoined(Match match) { diff --git a/Server/src/com/texttwist/server/tasks/JoinTimeout.java b/Server/src/com/texttwist/server/tasks/JoinTimeout.java index 2f39eff..0178235 100644 --- a/Server/src/com/texttwist/server/tasks/JoinTimeout.java +++ b/Server/src/com/texttwist/server/tasks/JoinTimeout.java @@ -1,9 +1,12 @@ package com.texttwist.server.tasks; import com.texttwist.server.models.Match; +import constants.Config; + import java.util.concurrent.*; /** - * Created by loke on 23/06/2017. + * Author: Lorenzo Iovino on 23/06/2017. + * Description: Task: Join Timeout */ public class JoinTimeout implements Callable { @@ -11,14 +14,13 @@ public class JoinTimeout implements Callable { public JoinTimeout(Match match) { this.match = match; - } @Override public Boolean call() throws Exception { try { - match.joinTimeout=true; - Thread.currentThread().sleep(5000); + match.joinTimeout = true; + Thread.currentThread().sleep(Config.joinMatchTimeout); if(match.joinTimeout) { match.joinTimeout = false; diff --git a/Server/src/com/texttwist/server/tasks/MatchTimeout.java b/Server/src/com/texttwist/server/tasks/MatchTimeout.java index 91755f5..2fd14e2 100644 --- a/Server/src/com/texttwist/server/tasks/MatchTimeout.java +++ b/Server/src/com/texttwist/server/tasks/MatchTimeout.java @@ -2,12 +2,11 @@ package com.texttwist.server.tasks; import com.texttwist.server.models.Match; import constants.Config; - import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 27/06/2017. - * Description: Jedis Service + * Description: Task: Match Timeout */ public class MatchTimeout implements Callable { diff --git a/Server/src/com/texttwist/server/tasks/SendInvitations.java b/Server/src/com/texttwist/server/tasks/SendInvitations.java index 768094e..12dca8c 100644 --- a/Server/src/com/texttwist/server/tasks/SendInvitations.java +++ b/Server/src/com/texttwist/server/tasks/SendInvitations.java @@ -1,13 +1,12 @@ package com.texttwist.server.tasks; import com.texttwist.server.Server; - import javax.swing.*; import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 19/06/2017. - * Description: Jedis Service + * Description: Task: Send Invitations */ public class SendInvitations implements Callable { private DefaultListModel users; @@ -22,11 +21,9 @@ public class SendInvitations implements Callable { public Boolean call() throws Exception { try { Server.notificationServer.sendInvitations(sender, users); - } catch (Exception e) { e.printStackTrace(); } - return true; } } diff --git a/Server/src/com/texttwist/server/tasks/SendMessageToAllPlayers.java b/Server/src/com/texttwist/server/tasks/SendMessageToAllPlayers.java index 96012cc..379be33 100644 --- a/Server/src/com/texttwist/server/tasks/SendMessageToAllPlayers.java +++ b/Server/src/com/texttwist/server/tasks/SendMessageToAllPlayers.java @@ -2,22 +2,21 @@ package com.texttwist.server.tasks; import com.texttwist.server.models.Match; import models.Message; - -import javax.swing.*; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 27/06/2017. - * Description: Jedis Service + * Description: Task: Send Message To All Players */ public class SendMessageToAllPlayers implements Callable { public final Match match; - public final Message message; - public SocketChannel socketChannel; + private final Message message; + private SocketChannel socketChannel; + public SendMessageToAllPlayers(Match match, Message message, SocketChannel socketChannel){ this.match = match; this.message = message; @@ -37,10 +36,8 @@ public class SendMessageToAllPlayers implements Callable { buffer = ByteBuffer.wrap(byteMessage); socketChannel.write(buffer); } - } return false; - } else { return true; } diff --git a/Server/src/com/texttwist/server/tasks/SendScores.java b/Server/src/com/texttwist/server/tasks/SendScores.java index b5383ac..69569ce 100644 --- a/Server/src/com/texttwist/server/tasks/SendScores.java +++ b/Server/src/com/texttwist/server/tasks/SendScores.java @@ -11,7 +11,8 @@ import java.net.MulticastSocket; import java.util.concurrent.Callable; /** - * Created by loke on 13/07/2017. + * Author: Lorenzo Iovino on 13/07/2017. + * Description: Task: Send Scores */ public class SendScores implements Callable { @@ -24,19 +25,17 @@ public class SendScores implements Callable { @Override public Void call() throws Exception { - while (true) { - Message msg = new Message("FINALSCORE", "SERVER", "", match.getMatchPlayersScoreAsStringList()); - MulticastSocket multicastSocket = null; - try { - multicastSocket = new MulticastSocket(match.multicastId); - InetAddress ia = InetAddress.getByName(Config.ScoreMulticastServerURI); - DatagramPacket hi = new DatagramPacket(msg.toString().getBytes(), msg.toString().length(), ia, match.multicastId); - multicastSocket.send(hi); - } catch (IOException e) { - e.printStackTrace(); - } - Match.activeMatches.remove(Match.findMatchIndex(Match.activeMatches, match.matchCreator)); - return null; + Message msg = new Message("FINALSCORE", "SERVER", "", match.getMatchPlayersScoreAsStringList()); + MulticastSocket multicastSocket = null; + try { + multicastSocket = new MulticastSocket(match.multicastId); + InetAddress ia = InetAddress.getByName(Config.ScoreMulticastServerURI); + DatagramPacket hi = new DatagramPacket(msg.toString().getBytes(), msg.toString().length(), ia, match.multicastId); + multicastSocket.send(hi); + } catch (IOException e) { + e.printStackTrace(); } + Match.activeMatches.remove(Match.findMatchIndex(Match.activeMatches, match.matchCreator)); + return null; } } diff --git a/Server/src/com/texttwist/server/tasks/TokenInvalid.java b/Server/src/com/texttwist/server/tasks/TokenInvalid.java index b190c15..5ae0617 100644 --- a/Server/src/com/texttwist/server/tasks/TokenInvalid.java +++ b/Server/src/com/texttwist/server/tasks/TokenInvalid.java @@ -10,7 +10,7 @@ import java.util.concurrent.Callable; /** * Author: Lorenzo Iovino on 11/07/2017. - * Description: Task: Token Invalid Service + * Description: Task: Token Invalid */ public class TokenInvalid implements Callable { private String sender; diff --git a/notificationServer.log b/notificationServer.log index 1892600..078493a 100644 --- a/notificationServer.log +++ b/notificationServer.log @@ -1884,3 +1884,105 @@ LOGGER (Server): Fri Jul 14 00:05:27 CEST 2017 - Invoked login with username=c A LOGGER (Server): Fri Jul 14 00:05:27 CEST 2017 - Login successfull LOGGER (Server): Fri Jul 14 00:05:31 CEST 2017 - Invoked login with username=d AND password=d LOGGER (Server): Fri Jul 14 00:05:31 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:07:15 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:07:15 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:07:15 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:07:15 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:10:48 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:10:48 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:10:48 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:10:48 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:10:48 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:10:48 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:10:59 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:10:59 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:11:02 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:11:02 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:11:25 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:11:25 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:11:28 CEST 2017 - Invoked login with username=d AND password=d +LOGGER (Server): Fri Jul 14 00:11:28 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:13:37 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:13:37 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:13:38 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:13:38 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:13:38 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:13:38 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:13:42 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:13:42 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:13:48 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:13:48 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:14:10 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:14:10 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:14:14 CEST 2017 - Invoked login with username=d AND password=d +LOGGER (Server): Fri Jul 14 00:14:14 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:21:35 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:21:35 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:21:35 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:21:35 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:21:35 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:21:35 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:21:47 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:21:47 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:21:56 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:21:56 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:22:00 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:22:00 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:22:03 CEST 2017 - Invoked login with username=d AND password=d +LOGGER (Server): Fri Jul 14 00:22:03 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:23:15 CEST 2017 - Invoked login with username=e AND password=e +LOGGER (Server): Fri Jul 14 00:23:15 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:23:19 CEST 2017 - Invoked login with username=f AND password=f +LOGGER (Server): Fri Jul 14 00:23:19 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:25:05 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:25:05 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:25:05 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:25:05 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:25:05 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:25:05 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:25:11 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:25:11 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:25:14 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:25:14 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:25:24 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:25:24 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:25:31 CEST 2017 - Invoked login with username=d AND password=d +LOGGER (Server): Fri Jul 14 00:25:31 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:25:59 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:25:59 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:25:59 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:25:59 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:25:59 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:25:59 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:26:03 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:26:03 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:26:06 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:26:06 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:26:15 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:26:15 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:29:01 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:29:01 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:29:01 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:29:01 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:29:01 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:29:01 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:29:05 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:29:05 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:29:08 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:29:08 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:29:12 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:29:12 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:34:04 CEST 2017 - Services starting ... +LOGGER (Server): Fri Jul 14 00:34:04 CEST 2017 - AuthService Service running at 9999 port... +LOGGER (Server): Fri Jul 14 00:34:04 CEST 2017 - GameService Service is running at 10000 port... +LOGGER (Server): Fri Jul 14 00:34:04 CEST 2017 - ReceiveWords Service running at 10001 port... +LOGGER (Server): Fri Jul 14 00:34:04 CEST 2017 - Notification Service running at 20000 port... +LOGGER (Server): Fri Jul 14 00:34:04 CEST 2017 - Services started correctly ... +LOGGER (Server): Fri Jul 14 00:34:11 CEST 2017 - Invoked login with username=a AND password=a +LOGGER (Server): Fri Jul 14 00:34:11 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:34:14 CEST 2017 - Invoked login with username=b AND password=b +LOGGER (Server): Fri Jul 14 00:34:14 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:34:17 CEST 2017 - Invoked login with username=c AND password=c +LOGGER (Server): Fri Jul 14 00:34:17 CEST 2017 - Login successfull +LOGGER (Server): Fri Jul 14 00:39:01 CEST 2017 - Invoked login with username=d AND password=d +LOGGER (Server): Fri Jul 14 00:39:01 CEST 2017 - Login successfull