diff --git a/.idea/artifacts/Client_jar.xml b/.idea/artifacts/Client_jar.xml
new file mode 100644
index 0000000..bca276c
--- /dev/null
+++ b/.idea/artifacts/Client_jar.xml
@@ -0,0 +1,10 @@
+
+
+ $PROJECT_DIR$/out/artifacts/Client_jar
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/artifacts/Server_jar.xml b/.idea/artifacts/Server_jar.xml
new file mode 100644
index 0000000..a0b38e8
--- /dev/null
+++ b/.idea/artifacts/Server_jar.xml
@@ -0,0 +1,14 @@
+
+
+ $PROJECT_DIR$/out/artifacts/Server_jar
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 007f860..68853c4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,27 +2,27 @@
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
+
+
+
@@ -44,74 +44,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -119,11 +56,71 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -131,25 +128,11 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -166,36 +149,36 @@
- MA
- MATCH
- MATCH_N
- MATCH_NO
- MATCH_NOT
- f
- fGAME
- fGAME_
- fGAME_S
- fGAME_STA
- fGAME_ST
- G
- GAMES
- GAME
- GAME_ST
- GAME_STA
- GAME_STAR
- c
- client
- clientMulti
- newMa
- newMat
- newMatch
- ne
- newma
- newm
- addto
- R
- Response
messagedis
+ d
+ dict
+ multicas
+ multicastI
+ multicastId
+ multic
+ multicast
+ multicastID
+ us
+ users
+ users"
+ "users"
+ m
+ matchT
+ matchTi
+ matchTime
+ matchTimeo
+ matchTimeou
+ matchTimeout
+ A
+ AP
+ APP not
+ APP no
+ APP n
+ APP
+ APP
+ APP:
+ APP: A
+ APP:
C:\Users\loke\TextTwist\out\production
@@ -334,28 +317,20 @@
@@ -440,88 +423,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -545,146 +446,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -801,6 +562,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -823,6 +602,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -929,12 +734,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -945,12 +832,8 @@
-
-
-
-
-
-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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Client/src/META-INF/MANIFEST.MF b/Client/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4b258d3
--- /dev/null
+++ b/Client/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.texttwist.client.Main
+
diff --git a/Server/src/META-INF/MANIFEST.MF b/Server/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..d385c6d
--- /dev/null
+++ b/Server/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.texttwist.server.Main
+
diff --git a/Server/src/com/texttwist/server/Server.java b/Server/src/com/texttwist/server/Server.java
index 3a72788..217d89f 100644
--- a/Server/src/com/texttwist/server/Server.java
+++ b/Server/src/com/texttwist/server/Server.java
@@ -1,5 +1,6 @@
package com.texttwist.server;
+import com.texttwist.server.models.Dictionary;
import com.texttwist.server.services.AuthService;
import com.texttwist.server.services.MessageService;
import com.texttwist.server.services.NotificationService;
@@ -27,6 +28,9 @@ public class Server {
public static JedisPool jedisPool;
public static Logger logger;
public static AuthService auth;
+ private String dictionaryPath = "./Server/resources/dictionary";
+ public static Dictionary dict;
+ public static Integer multicastId = Config.NotificationServiceStubPort;
public Server() throws IOException {
logger = new Logger(new File("./notificationServer.log"), "Server", true);
@@ -36,6 +40,9 @@ public class Server {
startMessageService();
startWordsReceiverService();
startNotificationService();
+
+ dict = new Dictionary(dictionaryPath);
+
Server.logger.write("Services started correctly ...");
}
diff --git a/Server/src/com/texttwist/server/models/Match.java b/Server/src/com/texttwist/server/models/Match.java
index 1573d60..d995914 100644
--- a/Server/src/com/texttwist/server/models/Match.java
+++ b/Server/src/com/texttwist/server/models/Match.java
@@ -1,5 +1,6 @@
package com.texttwist.server.models;
+import com.texttwist.server.Server;
import com.texttwist.server.services.MessageService;
import com.texttwist.server.tasks.TimeoutMatch;
import javafx.util.Pair;
@@ -139,7 +140,7 @@ public class Match {
}
private int generateMulticastId(){
- return MessageService.multicastId++;
+ return Server.multicastId++;
}
public void setLetters(DefaultListModel letters){
diff --git a/Server/src/com/texttwist/server/services/MessageService.java b/Server/src/com/texttwist/server/services/MessageService.java
index 965092b..8ca4576 100644
--- a/Server/src/com/texttwist/server/services/MessageService.java
+++ b/Server/src/com/texttwist/server/services/MessageService.java
@@ -1,7 +1,7 @@
package com.texttwist.server.services;
import com.texttwist.server.Server;
-import com.texttwist.server.dispatchers.MessageDispatcher;
+import com.texttwist.server.tasks.MessageDispatcher;
import com.texttwist.server.models.Dictionary;
import constants.Config;
import models.Message;
@@ -24,14 +24,9 @@ public class MessageService implements Runnable{
private Selector selector = null;
private ExecutorService dispatcherPool = Executors.newCachedThreadPool();
- private String dictionaryPath = "./Server/resources/dictionary";
- public static Dictionary dict;
-
- public static Integer multicastId = Config.NotificationServiceStubPort;
public MessageService()
{
- dict = new Dictionary(dictionaryPath);
try {
selector = Selector.open();
@@ -39,7 +34,7 @@ public class MessageService implements Runnable{
serverSocketChannel.configureBlocking(false);
serverSocketChannel.socket().bind(new InetSocketAddress(Config.MessageServicePort));
serverSocketChannel.register(selector, OP_ACCEPT);
- Server.logger.write("GameService Service is running at "+Config.MessageServicePort +" port...");
+ Server.logger.write("Message Service is running at "+Config.MessageServicePort +" port...");
} catch (IOException e) {
e.printStackTrace();
diff --git a/Server/src/com/texttwist/server/tasks/ComputeScore.java b/Server/src/com/texttwist/server/tasks/ComputeScore.java
index 790282a..acda1f0 100644
--- a/Server/src/com/texttwist/server/tasks/ComputeScore.java
+++ b/Server/src/com/texttwist/server/tasks/ComputeScore.java
@@ -26,6 +26,8 @@ public class ComputeScore implements Callable {
@Override
public Integer call() throws Exception {
+
+ //Compute the score depending on the size of the words
Integer score = 0;
for (int i = 0; i < words.size(); i++) {
if (isValid(words.get(i), match.letters)) {
@@ -41,7 +43,7 @@ public class ComputeScore implements Callable {
if(match.allPlayersSendedHisScore()) {
match.matchTimeout = false;
match.setUndefinedScorePlayersToZero();
- new SendScores(match).call();
+ new SendFinalScores(match).call();
}
return score;
}
diff --git a/Server/src/com/texttwist/server/tasks/GenerateLetters.java b/Server/src/com/texttwist/server/tasks/GenerateLetters.java
index 71f3e26..56bb216 100644
--- a/Server/src/com/texttwist/server/tasks/GenerateLetters.java
+++ b/Server/src/com/texttwist/server/tasks/GenerateLetters.java
@@ -1,6 +1,7 @@
package com.texttwist.server.tasks;
-import com.texttwist.server.services.MessageService;
+import com.texttwist.server.Server;
+
import javax.swing.*;
import java.util.concurrent.Callable;
@@ -14,7 +15,7 @@ public class GenerateLetters implements Callable> {
public DefaultListModel call() throws Exception {
DefaultListModel l = new DefaultListModel<>();
- String word = MessageService.dict.getRandomWord(6, 7);
+ String word = Server.dict.getRandomWord(6, 7);
for (int i = 0;i < word.length(); i++){
l.addElement(String.valueOf(word.charAt(i)));
}
diff --git a/Server/src/com/texttwist/server/dispatchers/MessageDispatcher.java b/Server/src/com/texttwist/server/tasks/MessageDispatcher.java
similarity index 96%
rename from Server/src/com/texttwist/server/dispatchers/MessageDispatcher.java
rename to Server/src/com/texttwist/server/tasks/MessageDispatcher.java
index a0f0526..e177729 100644
--- a/Server/src/com/texttwist/server/dispatchers/MessageDispatcher.java
+++ b/Server/src/com/texttwist/server/tasks/MessageDispatcher.java
@@ -1,4 +1,4 @@
-package com.texttwist.server.dispatchers;
+package com.texttwist.server.tasks;
import com.texttwist.server.Server;
import com.texttwist.server.models.Sessions;
@@ -72,13 +72,13 @@ public class MessageDispatcher implements Callable {
Boolean joinTimeoutRes = joinTimeout.get();
//If joinTimeoutRes==true timeout happen, need to notify to all waiting clients
if(joinTimeoutRes){
- Future sendMessageJoinTimeout = threadPool.submit(
+ Future sendMessageToAllPlayers = threadPool.submit(
new SendMessageToAllPlayers(match,
new Message("JOIN_TIMEOUT", "", "", new DefaultListModel<>()), socketChannel));
- Boolean sendMessageJoinTimeoutRes = sendMessageJoinTimeout.get();
- if(!sendMessageJoinTimeoutRes){
+ Boolean sendMessageToAllPlayersRes = sendMessageToAllPlayers.get();
+ if(!sendMessageToAllPlayersRes){
Match.activeMatches.remove(Match.findMatchIndex(Match.activeMatches, match.matchCreator));
- return sendMessageJoinTimeoutRes;
+ return sendMessageToAllPlayersRes;
}
} else {
//All done, all player joined
diff --git a/Server/src/com/texttwist/server/tasks/SendScores.java b/Server/src/com/texttwist/server/tasks/SendFinalScores.java
similarity index 89%
rename from Server/src/com/texttwist/server/tasks/SendScores.java
rename to Server/src/com/texttwist/server/tasks/SendFinalScores.java
index 41acc1b..074cc57 100644
--- a/Server/src/com/texttwist/server/tasks/SendScores.java
+++ b/Server/src/com/texttwist/server/tasks/SendFinalScores.java
@@ -12,13 +12,13 @@ import java.util.concurrent.Callable;
/**
* Author: Lorenzo Iovino on 13/07/2017.
- * Description: Task: Send Scores
+ * Description: Task: Send Final Scores
*/
-public class SendScores implements Callable {
+public class SendFinalScores implements Callable {
private Match match;
- public SendScores(Match match){
+ public SendFinalScores(Match match){
this.match = match;
}
diff --git a/Server/src/com/texttwist/server/tasks/TimeoutMatch.java b/Server/src/com/texttwist/server/tasks/TimeoutMatch.java
index fd175e2..de23a61 100644
--- a/Server/src/com/texttwist/server/tasks/TimeoutMatch.java
+++ b/Server/src/com/texttwist/server/tasks/TimeoutMatch.java
@@ -23,7 +23,7 @@ public class TimeoutMatch implements Callable {
if(match.matchTimeout) {
match.setUndefinedScorePlayersToZero();
- new SendScores(match).call();
+ new SendFinalScores(match).call();
return true;
}
return false;
diff --git a/Server/src/com/texttwist/server/tasks/TokenInvalid.java b/Server/src/com/texttwist/server/tasks/TokenInvalid.java
index 5ae0617..4014232 100644
--- a/Server/src/com/texttwist/server/tasks/TokenInvalid.java
+++ b/Server/src/com/texttwist/server/tasks/TokenInvalid.java
@@ -12,7 +12,7 @@ import java.util.concurrent.Callable;
* Author: Lorenzo Iovino on 11/07/2017.
* Description: Task: Token Invalid
*/
-public class TokenInvalid implements Callable {
+public class TokenInvalid implements Callable {
private String sender;
private ByteBuffer buffer;
private SocketChannel channel;
@@ -24,14 +24,14 @@ public class TokenInvalid implements Callable {
}
@Override
- public Boolean call()throws Exception {
+ public Void call()throws Exception {
Server.logger.write("TOKEN INVALID: TOKEN USED BY "+ sender+ " IS NOT VALID");
Message msg = new Message("TOKEN_NOT_VALID", "", null, new DefaultListModel<>());
buffer.clear();
byte[] byteMessage = msg.toString().getBytes();
buffer = ByteBuffer.wrap(byteMessage);
channel.write(buffer);
- return false;
+ return null;
}
}
\ No newline at end of file