up
This commit is contained in:
parent
ee230f911c
commit
697d96b322
14 changed files with 562 additions and 609 deletions
10
.idea/artifacts/Client_jar.xml
generated
Normal file
10
.idea/artifacts/Client_jar.xml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<component name="ArtifactManager">
|
||||||
|
<artifact type="jar" name="Client:jar">
|
||||||
|
<output-path>$PROJECT_DIR$/out/artifacts/Client_jar</output-path>
|
||||||
|
<root id="archive" name="Client.jar">
|
||||||
|
<element id="module-output" name="Client" />
|
||||||
|
<element id="module-output" name="Commons" />
|
||||||
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/cliftonlabs/json-simple/2.1.2/json-simple-2.1.2.jar" path-in-jar="/" />
|
||||||
|
</root>
|
||||||
|
</artifact>
|
||||||
|
</component>
|
||||||
14
.idea/artifacts/Server_jar.xml
generated
Normal file
14
.idea/artifacts/Server_jar.xml
generated
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<component name="ArtifactManager">
|
||||||
|
<artifact type="jar" name="Server:jar">
|
||||||
|
<output-path>$PROJECT_DIR$/out/artifacts/Server_jar</output-path>
|
||||||
|
<root id="archive" name="Server.jar">
|
||||||
|
<element id="module-output" name="Server" />
|
||||||
|
<element id="module-output" name="Commons" />
|
||||||
|
<element id="module-output" name="Client" />
|
||||||
|
<element id="library" level="application" name="jedis-2.1.0-sources" />
|
||||||
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0.jar" path-in-jar="/" />
|
||||||
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar" path-in-jar="/" />
|
||||||
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/cliftonlabs/json-simple/2.1.2/json-simple-2.1.2.jar" path-in-jar="/" />
|
||||||
|
</root>
|
||||||
|
</artifact>
|
||||||
|
</component>
|
||||||
1089
.idea/workspace.xml
generated
1089
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load diff
3
Client/src/META-INF/MANIFEST.MF
Normal file
3
Client/src/META-INF/MANIFEST.MF
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: com.texttwist.client.Main
|
||||||
|
|
||||||
3
Server/src/META-INF/MANIFEST.MF
Normal file
3
Server/src/META-INF/MANIFEST.MF
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: com.texttwist.server.Main
|
||||||
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.texttwist.server;
|
package com.texttwist.server;
|
||||||
|
|
||||||
|
import com.texttwist.server.models.Dictionary;
|
||||||
import com.texttwist.server.services.AuthService;
|
import com.texttwist.server.services.AuthService;
|
||||||
import com.texttwist.server.services.MessageService;
|
import com.texttwist.server.services.MessageService;
|
||||||
import com.texttwist.server.services.NotificationService;
|
import com.texttwist.server.services.NotificationService;
|
||||||
|
|
@ -27,6 +28,9 @@ public class Server {
|
||||||
public static JedisPool jedisPool;
|
public static JedisPool jedisPool;
|
||||||
public static Logger logger;
|
public static Logger logger;
|
||||||
public static AuthService auth;
|
public static AuthService auth;
|
||||||
|
private String dictionaryPath = "./Server/resources/dictionary";
|
||||||
|
public static Dictionary dict;
|
||||||
|
public static Integer multicastId = Config.NotificationServiceStubPort;
|
||||||
|
|
||||||
public Server() throws IOException {
|
public Server() throws IOException {
|
||||||
logger = new Logger(new File("./notificationServer.log"), "Server", true);
|
logger = new Logger(new File("./notificationServer.log"), "Server", true);
|
||||||
|
|
@ -36,6 +40,9 @@ public class Server {
|
||||||
startMessageService();
|
startMessageService();
|
||||||
startWordsReceiverService();
|
startWordsReceiverService();
|
||||||
startNotificationService();
|
startNotificationService();
|
||||||
|
|
||||||
|
dict = new Dictionary(dictionaryPath);
|
||||||
|
|
||||||
Server.logger.write("Services started correctly ...");
|
Server.logger.write("Services started correctly ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.texttwist.server.models;
|
package com.texttwist.server.models;
|
||||||
|
|
||||||
|
import com.texttwist.server.Server;
|
||||||
import com.texttwist.server.services.MessageService;
|
import com.texttwist.server.services.MessageService;
|
||||||
import com.texttwist.server.tasks.TimeoutMatch;
|
import com.texttwist.server.tasks.TimeoutMatch;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
|
@ -139,7 +140,7 @@ public class Match {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int generateMulticastId(){
|
private int generateMulticastId(){
|
||||||
return MessageService.multicastId++;
|
return Server.multicastId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLetters(DefaultListModel<String> letters){
|
public void setLetters(DefaultListModel<String> letters){
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.texttwist.server.services;
|
package com.texttwist.server.services;
|
||||||
|
|
||||||
import com.texttwist.server.Server;
|
import com.texttwist.server.Server;
|
||||||
import com.texttwist.server.dispatchers.MessageDispatcher;
|
import com.texttwist.server.tasks.MessageDispatcher;
|
||||||
import com.texttwist.server.models.Dictionary;
|
import com.texttwist.server.models.Dictionary;
|
||||||
import constants.Config;
|
import constants.Config;
|
||||||
import models.Message;
|
import models.Message;
|
||||||
|
|
@ -24,14 +24,9 @@ public class MessageService implements Runnable{
|
||||||
|
|
||||||
private Selector selector = null;
|
private Selector selector = null;
|
||||||
private ExecutorService dispatcherPool = Executors.newCachedThreadPool();
|
private ExecutorService dispatcherPool = Executors.newCachedThreadPool();
|
||||||
private String dictionaryPath = "./Server/resources/dictionary";
|
|
||||||
public static Dictionary dict;
|
|
||||||
|
|
||||||
public static Integer multicastId = Config.NotificationServiceStubPort;
|
|
||||||
|
|
||||||
public MessageService()
|
public MessageService()
|
||||||
{
|
{
|
||||||
dict = new Dictionary(dictionaryPath);
|
|
||||||
try {
|
try {
|
||||||
selector = Selector.open();
|
selector = Selector.open();
|
||||||
|
|
||||||
|
|
@ -39,7 +34,7 @@ public class MessageService implements Runnable{
|
||||||
serverSocketChannel.configureBlocking(false);
|
serverSocketChannel.configureBlocking(false);
|
||||||
serverSocketChannel.socket().bind(new InetSocketAddress(Config.MessageServicePort));
|
serverSocketChannel.socket().bind(new InetSocketAddress(Config.MessageServicePort));
|
||||||
serverSocketChannel.register(selector, OP_ACCEPT);
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ public class ComputeScore implements Callable<Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer call() throws Exception {
|
public Integer call() throws Exception {
|
||||||
|
|
||||||
|
//Compute the score depending on the size of the words
|
||||||
Integer score = 0;
|
Integer score = 0;
|
||||||
for (int i = 0; i < words.size(); i++) {
|
for (int i = 0; i < words.size(); i++) {
|
||||||
if (isValid(words.get(i), match.letters)) {
|
if (isValid(words.get(i), match.letters)) {
|
||||||
|
|
@ -41,7 +43,7 @@ public class ComputeScore implements Callable<Integer> {
|
||||||
if(match.allPlayersSendedHisScore()) {
|
if(match.allPlayersSendedHisScore()) {
|
||||||
match.matchTimeout = false;
|
match.matchTimeout = false;
|
||||||
match.setUndefinedScorePlayersToZero();
|
match.setUndefinedScorePlayersToZero();
|
||||||
new SendScores(match).call();
|
new SendFinalScores(match).call();
|
||||||
}
|
}
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.texttwist.server.tasks;
|
package com.texttwist.server.tasks;
|
||||||
|
|
||||||
import com.texttwist.server.services.MessageService;
|
import com.texttwist.server.Server;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ public class GenerateLetters implements Callable<DefaultListModel<String>> {
|
||||||
public DefaultListModel<String> call() throws Exception {
|
public DefaultListModel<String> call() throws Exception {
|
||||||
DefaultListModel<String> l = new DefaultListModel<>();
|
DefaultListModel<String> 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++){
|
for (int i = 0;i < word.length(); i++){
|
||||||
l.addElement(String.valueOf(word.charAt(i)));
|
l.addElement(String.valueOf(word.charAt(i)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.texttwist.server.dispatchers;
|
package com.texttwist.server.tasks;
|
||||||
|
|
||||||
import com.texttwist.server.Server;
|
import com.texttwist.server.Server;
|
||||||
import com.texttwist.server.models.Sessions;
|
import com.texttwist.server.models.Sessions;
|
||||||
|
|
@ -72,13 +72,13 @@ public class MessageDispatcher implements Callable<Boolean> {
|
||||||
Boolean joinTimeoutRes = joinTimeout.get();
|
Boolean joinTimeoutRes = joinTimeout.get();
|
||||||
//If joinTimeoutRes==true timeout happen, need to notify to all waiting clients
|
//If joinTimeoutRes==true timeout happen, need to notify to all waiting clients
|
||||||
if(joinTimeoutRes){
|
if(joinTimeoutRes){
|
||||||
Future<Boolean> sendMessageJoinTimeout = threadPool.submit(
|
Future<Boolean> sendMessageToAllPlayers = threadPool.submit(
|
||||||
new SendMessageToAllPlayers(match,
|
new SendMessageToAllPlayers(match,
|
||||||
new Message("JOIN_TIMEOUT", "", "", new DefaultListModel<>()), socketChannel));
|
new Message("JOIN_TIMEOUT", "", "", new DefaultListModel<>()), socketChannel));
|
||||||
Boolean sendMessageJoinTimeoutRes = sendMessageJoinTimeout.get();
|
Boolean sendMessageToAllPlayersRes = sendMessageToAllPlayers.get();
|
||||||
if(!sendMessageJoinTimeoutRes){
|
if(!sendMessageToAllPlayersRes){
|
||||||
Match.activeMatches.remove(Match.findMatchIndex(Match.activeMatches, match.matchCreator));
|
Match.activeMatches.remove(Match.findMatchIndex(Match.activeMatches, match.matchCreator));
|
||||||
return sendMessageJoinTimeoutRes;
|
return sendMessageToAllPlayersRes;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//All done, all player joined
|
//All done, all player joined
|
||||||
|
|
@ -12,13 +12,13 @@ import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author: Lorenzo Iovino on 13/07/2017.
|
* Author: Lorenzo Iovino on 13/07/2017.
|
||||||
* Description: Task: Send Scores
|
* Description: Task: Send Final Scores
|
||||||
*/
|
*/
|
||||||
public class SendScores implements Callable<Void> {
|
public class SendFinalScores implements Callable<Void> {
|
||||||
|
|
||||||
private Match match;
|
private Match match;
|
||||||
|
|
||||||
public SendScores(Match match){
|
public SendFinalScores(Match match){
|
||||||
this.match = match;
|
this.match = match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ public class TimeoutMatch implements Callable<Boolean> {
|
||||||
|
|
||||||
if(match.matchTimeout) {
|
if(match.matchTimeout) {
|
||||||
match.setUndefinedScorePlayersToZero();
|
match.setUndefinedScorePlayersToZero();
|
||||||
new SendScores(match).call();
|
new SendFinalScores(match).call();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import java.util.concurrent.Callable;
|
||||||
* Author: Lorenzo Iovino on 11/07/2017.
|
* Author: Lorenzo Iovino on 11/07/2017.
|
||||||
* Description: Task: Token Invalid
|
* Description: Task: Token Invalid
|
||||||
*/
|
*/
|
||||||
public class TokenInvalid implements Callable<Boolean> {
|
public class TokenInvalid implements Callable<Void> {
|
||||||
private String sender;
|
private String sender;
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
private SocketChannel channel;
|
private SocketChannel channel;
|
||||||
|
|
@ -24,14 +24,14 @@ public class TokenInvalid implements Callable<Boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean call()throws Exception {
|
public Void call()throws Exception {
|
||||||
Server.logger.write("TOKEN INVALID: TOKEN USED BY "+ sender+ " IS NOT VALID");
|
Server.logger.write("TOKEN INVALID: TOKEN USED BY "+ sender+ " IS NOT VALID");
|
||||||
Message msg = new Message("TOKEN_NOT_VALID", "", null, new DefaultListModel<>());
|
Message msg = new Message("TOKEN_NOT_VALID", "", null, new DefaultListModel<>());
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
byte[] byteMessage = msg.toString().getBytes();
|
byte[] byteMessage = msg.toString().getBytes();
|
||||||
buffer = ByteBuffer.wrap(byteMessage);
|
buffer = ByteBuffer.wrap(byteMessage);
|
||||||
channel.write(buffer);
|
channel.write(buffer);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue