non funziona

This commit is contained in:
Lorenzo Iovino 2017-07-13 14:17:32 +02:00
parent 4760152e90
commit 5117b28e2c
29 changed files with 1707 additions and 1663 deletions

1432
.idea/workspace.xml generated

File diff suppressed because it is too large Load diff

View file

@ -68,7 +68,7 @@ public class App extends JFrame {
logger.write("APP: Font not found!"); logger.write("APP: Font not found!");
} }
/*Services*/ /*services*/
gameService = new GameService(); gameService = new GameService();
authService = new AuthService(); authService = new AuthService();

View file

@ -141,7 +141,7 @@ public class GamePage extends Page {
return null; return null;
} }
}), }),
Config.timeoutGame Config.gameTimeout
); );
} }
} }

View file

@ -18,9 +18,14 @@ public class Config {
public static String ScoreMulticastServerURI = "226.226.226.226"; public static String ScoreMulticastServerURI = "226.226.226.226";
public static Integer NotificationServerPort = 20000; public static Integer NotificationServerPort = 20000;
public static Integer NotificationServerStubPort = 5000; public static Integer NotificationServerStubPort = 30000;
public static String NotificationServerName ="notification"; public static String NotificationServerName ="notification";
public static int timeoutGame = 120;
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 String getAuthServerURI(){ public static String getAuthServerURI(){
return "rmi://".concat(AuthServerURI).concat(":").concat(AuthServerPort.toString()); return "rmi://".concat(AuthServerURI).concat(":").concat(AuthServerPort.toString());

View file

@ -1,13 +1,12 @@
package com.texttwist.server; package com.texttwist.server;
import utilities.Logger;
import java.io.File;
import java.io.IOException; import java.io.IOException;
/**
* Author: Lorenzo Iovino on 14/06/2017.
* Description: Main
*/
public class Main { public class Main {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
Server ttServer = new Server(); new Server();
} }
} }

View file

@ -1,65 +1,78 @@
package com.texttwist.server; package com.texttwist.server;
import com.texttwist.server.components.Auth; import com.texttwist.server.services.AuthService;
import com.texttwist.server.components.GameServer; import com.texttwist.server.services.MessageService;
import com.texttwist.server.components.NotificationServer; import com.texttwist.server.services.NotificationService;
import constants.Config; import constants.Config;
import interfaces.INotificationServer; import interfaces.INotificationServer;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisPoolConfig;
import utilities.Logger; import utilities.Logger;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.rmi.AlreadyBoundException; import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry; import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
/** /**
* Created by loke on 15/06/2017. * Author: Lorenzo Iovino on 15/06/2017.
* Description: Server. Initialize all services.
*/ */
public class Server { public class Server {
public static NotificationServer notificationServer; public static NotificationService notificationServer;
public static JedisPool jedisPool; public static JedisPool jedisPool;
public static Logger logger; public static Logger logger;
public static AuthService auth;
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);
Server.logger.write("Server starting ..."); Server.logger.write("Services starting ...");
startAuthService();
//Start services startJedisService();
startMessageService();
startNotificationService();
Server.logger.write("Services started correctly ...");
}
private void startAuthService(){
//Starting Auth service based on RMI
try { try {
//Definitions of registry for auth auth = new AuthService(Config.AuthServerPort);
Auth auth = new Auth(Config.AuthServerPort);
Registry authRegistry = LocateRegistry.createRegistry(auth.serverPort); Registry authRegistry = LocateRegistry.createRegistry(auth.serverPort);
authRegistry.bind("auth", auth); authRegistry.bind("auth", auth);
} catch (RemoteException e) {
//Connecting to Redis server on localhost Server.logger.write("SERVER: RMI authentication service error (Remote exception)");
jedisPool = new JedisPool(new JedisPoolConfig(), "localhost");
GameServer gameServer = new GameServer(Config.GameServerPort);
new Thread(gameServer).start();
try {
/*registrazione presso il registry */
notificationServer = new NotificationServer();
INotificationServer stub = (INotificationServer) UnicastRemoteObject.exportObject(notificationServer, Config.NotificationServerPort);
LocateRegistry.createRegistry(Config.NotificationServerStubPort);
Registry notificationRegistry = LocateRegistry.getRegistry(Config.NotificationServerStubPort);
notificationRegistry.bind(Config.NotificationServerName, stub);
} catch (Exception e) {
System.out.println("Eccezione" + e);
}
Server.logger.write("Server started");
} catch (AlreadyBoundException e) { } catch (AlreadyBoundException e) {
e.printStackTrace(); Server.logger.write("SERVER: RMI authentication service can't use this port because is busy ");
} }
} }
private void startJedisService(){
//Starting Jedis pool for Redis connection
jedisPool = new JedisPool(new JedisPoolConfig(), Config.RedisServerURI);
}
private void startMessageService(){
//Starting the Message service based on TCP
new Thread(new MessageService(Config.GameServerPort)).start();
}
private void startNotificationService(){
//Starting Notification service based on RMI
try {
notificationServer = new NotificationService();
INotificationServer stub = (INotificationServer) UnicastRemoteObject.exportObject(notificationServer, Config.NotificationServerPort);
LocateRegistry.createRegistry(Config.NotificationServerStubPort);
Registry notificationRegistry = LocateRegistry.getRegistry(Config.NotificationServerStubPort);
notificationRegistry.bind(Config.NotificationServerName, stub);
} catch (RemoteException e) {
Server.logger.write("SERVER: RMI notification service error (Remote exception)");
} catch (AlreadyBoundException e) {
Server.logger.write("SERVER: RMI notification service can't use this port because is busy ");
}
}
} }

View file

@ -1,88 +0,0 @@
package com.texttwist.server.components;
import interfaces.INotificationClient;
import models.Session;
import models.User;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Created by loke on 17/06/2017.
*/
public class SessionsManager {
private List<Session> sessions = Collections.synchronizedList(new ArrayList<Session>());
private static class Holder {
static final SessionsManager INSTANCE = new SessionsManager();
}
public static SessionsManager getInstance() {
return Holder.INSTANCE;
}
private SessionsManager(){}
public boolean add(String userName, String token) {
remove(userName);
return sessions.add(new Session(new User(userName,"",0), token));
}
public void printAll(){
Iterator<Session> i = sessions.iterator();
while (i.hasNext()) {
Session elem = i.next();
System.out.println(elem.account.userName + " | " + elem.token);
}
}
public boolean remove(String userName){
if(exists(userName)) {
Session s = getSession(userName);
if(s != null) {
sessions.remove(s);
return true;
}
}
return false;
}
public Session getSession(String userName) {
Iterator<Session> i = sessions.iterator();
while (i.hasNext()) {
Session elem = i.next();
if (elem.account.userName.equals(userName)) {
return elem;
}
}
return null;
}
public boolean exists(String userName) {
Iterator<Session> i = sessions.iterator();
while (i.hasNext()) {
Session elem = i.next();
if (elem.account.userName.equals(userName)) {
return true;
}
}
return false;
}
public boolean isValidToken(String token) {
Iterator<Session> i = sessions.iterator();
while (i.hasNext()) {
if (i.next().token.equals(token)) {
return true;
}
}
return false;
}
}

View file

@ -1,23 +1,20 @@
package com.texttwist.server.models; package com.texttwist.server.models;
import com.texttwist.server.Server;
import javax.swing.*; import javax.swing.*;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Random; import java.util.Random;
import java.util.stream.Stream;
/** /**
* Created by loke on 26/06/2017. * Author: Lorenzo Iovino on 26/06/2017.
* Description: Dictionary Model. Provides the dictionary and methods for manage it
*/ */
public class Dictionary { public class Dictionary {
static DefaultListModel<String> wordList = new DefaultListModel<>(); private static DefaultListModel<String> wordList = new DefaultListModel<>();
private Random randomGenerator;
public Dictionary(String dictionaryPath) { public Dictionary(String dictionaryPath) {
try (BufferedReader br = new BufferedReader(new FileReader(new File(dictionaryPath)))) { try (BufferedReader br = new BufferedReader(new FileReader(new File(dictionaryPath)))) {
@ -25,15 +22,16 @@ public class Dictionary {
wordList.addElement(line); wordList.addElement(line);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); Server.logger.write("DICTIONARY: Dictionary file not found!");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Server.logger.write("DICTIONARY: Can't read dictionary file!");
} }
} }
//Get a random word in wordsList with minimumWordSize < size < maximumWordSize
public String getRandomWord(int minimumWordSize, int maximumWordSize){ public String getRandomWord(int minimumWordSize, int maximumWordSize){
randomGenerator = new Random(); Random randomGenerator = new Random();
int index = randomGenerator.nextInt(wordList.size()); int index = randomGenerator.nextInt(wordList.size());
String word = wordList.get(index); String word = wordList.get(index);
if(word.length() >= minimumWordSize && word.length() <= maximumWordSize) { if(word.length() >= minimumWordSize && word.length() <= maximumWordSize) {
@ -55,6 +53,7 @@ public class Dictionary {
} }
} }
//Check if a word is contained in dictionary
public static Boolean isContainedInDictionary(String word){ public static Boolean isContainedInDictionary(String word){
if(word.equals("")){ if(word.equals("")){
return true; return true;
@ -66,5 +65,4 @@ public class Dictionary {
} }
return false; return false;
} }
} }

View file

@ -1,40 +1,57 @@
package com.texttwist.server.models; package com.texttwist.server.models;
import com.texttwist.server.components.GameServer; import com.texttwist.server.services.MessageService;
import com.texttwist.server.tasks.MatchTimeout; import com.texttwist.server.tasks.MatchTimeout;
import constants.Config;
import javafx.util.Pair; import javafx.util.Pair;
import models.Message;
import javax.swing.*; import javax.swing.*;
import java.io.IOException;
import java.net.*;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.*; import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import static com.texttwist.server.components.GameServer.activeMatches; import static com.texttwist.server.services.MessageService.activeMatches;
/** /**
* Created by loke on 23/06/2017. * Author: Lorenzo Iovino on 23/06/2017.
* Description: Match Model. Methods for manage the matches and model of single match.
* Single point of concurrent access.
*/ */
public class Match { public class Match {
public final List<Pair<String,Integer>> playersStatus = Collections.synchronizedList(new ArrayList<>()); //Usare Liste!!!!!!!
public final List<Pair<String,SocketChannel>> playersSocket = Collections.synchronizedList(new ArrayList<>());
private boolean started = false;
public final String matchCreator;
public Integer multicastId;
public Future<Boolean> timeout;
public boolean matchTimeout = true;
public boolean joinTimeout =true;
public DefaultListModel<String> letters;
protected ExecutorService threadPool = Executors.newSingleThreadExecutor();
/****GLOBAL AREA OF ALL MATCHES****/
//Players status: A list of pair where elements are <playerName, status>.
// status is 0 if user is not currently in a match, and 1 otherwise
public final List<Pair<String,Integer>> playersStatus = Collections.synchronizedList(new ArrayList<>());
//Players socket: A list of pair where elements are <playerName, socketChannel>.
// socketChannel is the TCP socket associated with client for messages exchange
public final List<Pair<String,SocketChannel>> playersSocket = Collections.synchronizedList(new ArrayList<>());
//Players score: A list of pair where elements are <playerName, score>.
public final List<Pair<String,Integer>> playersScore = Collections.synchronizedList(new ArrayList<>()); public final List<Pair<String,Integer>> playersScore = Collections.synchronizedList(new ArrayList<>());
/****SINGLE INSTANCE OF MATCH****/
//If match is started
private boolean started = false;
//Name of the creator of the match
public final String matchCreator;
//MulticastID associated with this match
public Integer multicastId;
//True if happen timeout, false otherwise
public boolean matchTimeout;
public boolean joinTimeout;
//Letters of the match
public DefaultListModel<String> letters;
protected ExecutorService matchTimeoutThread = Executors.newSingleThreadExecutor();
public Match(String matchCreator, DefaultListModel<String> players){ public Match(String matchCreator, DefaultListModel<String> players){
for (int i =0; i < players.size(); i++){ for (int i =0; i < players.size(); i++){
this.playersStatus.add(new Pair<>(players.get(i), 0)); this.playersStatus.add(new Pair<>(players.get(i), 0));
@ -47,116 +64,90 @@ public class Match {
} }
public Void sendScores(){
while (true) {
System.out.println("SENDING");
Message msg = new Message("FINALSCORE", "SERVER", "", this.getMatchPlayersScoreAsStringList());
MulticastSocket multicastSocket = null;
try {
multicastSocket = new MulticastSocket(this.multicastId);
InetAddress ia = null;
ia = InetAddress.getByName(Config.ScoreMulticastServerURI);
DatagramPacket hi = new DatagramPacket(msg.toString().getBytes(), msg.toString().length(), ia, this.multicastId);
multicastSocket.send(hi);
} catch (IOException e) {
e.printStackTrace();
}
activeMatches.remove(Match.findMatchIndex(activeMatches, this.matchCreator));
}
}
public static Match findMatch(List<Match> matches, String matchName){ public static Match findMatch(List<Match> matches, String matchName){
for (int i = 0; i < matches.size(); i++) { for (Match match : matches) {
if (matches.get(i).matchCreator.equals(matchName)) { if (match.matchCreator.equals(matchName)) {
return matches.get(i); return match;
} }
} }
return null; return null;
} }
public void printAll(){ public void printAll(){
for (int i = 0; i < playersScore.size(); i++) { for (Pair<String, Integer> aPlayersScore : playersScore) {
System.out.println(playersScore.get(i).getKey() + " : " +playersScore.get(i).getValue()); System.out.println(aPlayersScore.getKey() + " : " + aPlayersScore.getValue());
} }
} }
public static int findMatchIndex(List<Match> matches, String matchName){ public static int findMatchIndex(List<Match> matches, String matchName){
for (int i = 0; i < matches.size(); i++) { for (int i = 0; i < matches.size(); i++) {
if (matches.get(i).matchCreator.equals(matchName)) { if (matches.get(i).matchCreator.equals(matchName)) {
return i; return i;
}
} }
return -1; }
return -1;
} }
public boolean isStarted(){ public boolean isStarted(){
return started; return started;
} }
public static Match findMatchByPlayer(String player){ public static Match findMatchByPlayerName(String player){
for (int i = 0; i < activeMatches.size(); i++) { for (Match activeMatch : activeMatches) {
for (int j = 0; j < activeMatches.get(i).playersStatus.size(); j++) { for (int j = 0; j < activeMatch.playersStatus.size(); j++) {
if (activeMatches.get(i).playersStatus.get(j).getKey().equals(player)) { if (activeMatch.playersStatus.get(j).getKey().equals(player)) {
return activeMatches.get(i); return activeMatch;
} }
} }
/* if (matches.get(i).matchCreator.equals(matchName)) {
return i;
}*/
} }
return null; return null;
} }
public void startGame(){ public void startGame(){
this.started=true; this.started = true;
threadPool.submit(new MatchTimeout(this)); matchTimeoutThread.submit(new MatchTimeout(this));
} }
public void setScore(String player, Integer score){ public void setScore(String player, Integer score){
Match m = findMatchByPlayer(player); Match m = findMatchByPlayerName(player);
m.printAll(); if(m!=null) {
for (int i = 0; i < m.playersScore.size(); i++) {
for (int i = 0; i < m.playersScore.size(); i++) { if (m.playersScore.get(i).getKey().equals(player)) {
if (m.playersScore.get(i).getKey().equals(player)) { m.playersScore.set(i, new Pair<>(player, score));
m.playersScore.set(i, new Pair<String, Integer>(player, score)); }
} }
} }
} }
public Boolean allPlayersSendedHisScore(){ public Boolean allPlayersSendedHisScore(){
System.out.println(matchCreator); for (Pair<String, Integer> player : playersScore) {
printAll(); if (player.getValue() == -1) {
for (int i = 0; i < playersScore.size(); i++) { return false;
if (playersScore.get(i).getValue() == -1) {
return false;
}
} }
return true; }
return true;
} }
public void setUndefinedScorePlayersToZero(){ public void setUndefinedScorePlayersToZero(){
for (int i = 0; i < playersScore.size(); i++) { for (int i = 0; i < playersScore.size(); i++) {
if (playersScore.get(i).getValue() == -1) { if (playersScore.get(i).getValue() == -1) {
playersScore.set(i, new Pair<String, Integer>(playersScore.get(i).getKey(), 0)); playersScore.set(i, new Pair<>(playersScore.get(i).getKey(), 0));
}
} }
}
} }
public DefaultListModel<String> getMatchPlayersScoreAsStringList(){ public DefaultListModel<String> getMatchPlayersScoreAsStringList(){
DefaultListModel<String> l = new DefaultListModel<>(); DefaultListModel<String> l = new DefaultListModel<>();
for (int i = 0; i < playersScore.size(); i++) { for (Pair<String, Integer> player : playersScore) {
l.addElement(playersScore.get(i).getKey() + ":" + playersScore.get(i).getValue()); l.addElement(player.getKey() + ":" + player.getValue());
} }
return l; return l;
} }
private int generateMulticastId(){ private int generateMulticastId(){
return GameServer.multicastID++; return MessageService.multicastID++;
} }
public void setLetters(DefaultListModel<String> letters){ public void setLetters(DefaultListModel<String> letters){
this.letters = letters; this.letters = letters;
} }

View file

@ -1,221 +1,214 @@
package com.texttwist.server.components; package com.texttwist.server.servers;
import com.sun.org.apache.xpath.internal.operations.Bool; import com.texttwist.server.services.SessionsService;
import com.texttwist.client.App; import com.texttwist.server.models.Match;
import com.texttwist.server.models.Match; import com.texttwist.server.tasks.*;
import com.texttwist.server.tasks.*; import models.Message;
import constants.Config;
import javafx.util.Pair; import javax.swing.*;
import models.Message; import java.io.IOException;
import java.nio.ByteBuffer;
import javax.swing.*; import java.nio.channels.SocketChannel;
import java.io.IOException; import java.util.concurrent.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket; import static com.texttwist.server.services.MessageService.activeMatches;
import java.net.InetAddress;
import java.net.MulticastSocket; /**
import java.nio.ByteBuffer; * Author: Lorenzo Iovino on 18/06/2017.
import java.nio.channels.DatagramChannel; * Description: Jedis Service
import java.nio.channels.SocketChannel; */
import java.util.concurrent.*; public class ProxyDispatcher implements Callable<Boolean> {
protected final ExecutorService threadPool = Executors.newCachedThreadPool();
import static com.texttwist.server.components.GameServer.activeMatches; private final Message request;
private final SocketChannel socketChannel;
/** private ByteBuffer bufferMessage;
* Created by loke on 18/06/2017. boolean matchNotAvailable =false;
*/
public class ThreadProxy implements Callable<Boolean> {
protected final ExecutorService threadPool = Executors.newCachedThreadPool(); public ProxyDispatcher(Message request, SocketChannel socketChannel, ByteBuffer bufferMessage) {
private final Message request; this.request = request;
private final SocketChannel socketChannel; this.socketChannel = socketChannel;
private ByteBuffer bufferMessage; this.bufferMessage = bufferMessage;
boolean matchNotAvailable =false;
}
ThreadProxy(Message request, SocketChannel socketChannel, ByteBuffer bufferMessage) { @Override
this.request = request; public Boolean call() {
this.socketChannel = socketChannel; bufferMessage = ByteBuffer.allocate(1024);
this.bufferMessage = bufferMessage; byte[] byteMessage = null;
if(SessionsService.getInstance().isValidToken(request.token)){
} switch(request.message){
case "START_GAME":
@Override Future<Boolean> onlineUsers = threadPool.submit(new CheckOnlineUsers(request.data));
public Boolean call() { try {
bufferMessage = ByteBuffer.allocate(1024); Boolean usersOnline = onlineUsers.get();
byte[] byteMessage = null; if(usersOnline){
if(SessionsManager.getInstance().isValidToken(request.token)){ Future<Boolean> sendInvitations = threadPool.submit(new SendInvitations(request.sender, request.data));
switch(request.message){ try {
case "START_GAME": Boolean invitationSended = sendInvitations.get();
Future<Boolean> onlineUsers = threadPool.submit(new CheckOnlineUsers(request.data)); if (invitationSended) {
try {
Boolean usersOnline = onlineUsers.get(); //Crea nuova partita e attendi i giocatori
if(usersOnline){ request.data.addElement(request.sender);
Future<Boolean> sendInvitations = threadPool.submit(new SendInvitations(request.sender, request.data)); final Match match = new Match(request.sender, request.data);
try { match.printAll();
Boolean invitationSended = sendInvitations.get();
if (invitationSended) { activeMatches.add(match);
//Crea nuova partita e attendi i giocatori DefaultListModel<String> matchName = new DefaultListModel<>();
request.data.addElement(request.sender); matchName.addElement(request.sender);
final Match match = new Match(request.sender, request.data);
match.printAll(); Future<Boolean> joinMatch = threadPool.submit(new JoinMatch(request.sender, matchName, socketChannel));
Boolean joinMatchRes = joinMatch.get();
activeMatches.add(match);
if(!joinMatchRes){
DefaultListModel<String> matchName = new DefaultListModel<>(); bufferMessage = ByteBuffer.allocate(1024);
matchName.addElement(request.sender);
//NON FARE NULLA, ASPETTA GLI ALTRI
Future<Boolean> joinMatch = threadPool.submit(new JoinMatch(request.sender, matchName, socketChannel)); Message message = new Message("INVITES_ALL_SENDED", "", "", new DefaultListModel<>());
Boolean joinMatchRes = joinMatch.get(); byteMessage = message.toString().getBytes();
bufferMessage = ByteBuffer.wrap(byteMessage);
if(!joinMatchRes){ socketChannel.write(bufferMessage);
bufferMessage = ByteBuffer.allocate(1024); }
//NON FARE NULLA, ASPETTA GLI ALTRI Future<Boolean> joinTimeout = threadPool.submit(new JoinTimeout(match));
Message message = new Message("INVITES_ALL_SENDED", "", "", new DefaultListModel<>()); joinTimeout.get();
byteMessage = message.toString().getBytes(); if(match.joinTimeout){
bufferMessage = ByteBuffer.wrap(byteMessage); Future<Boolean> sendMessageJoinTimeout = threadPool.submit(
socketChannel.write(bufferMessage); new SendMessageToAllPlayers(match, new Message("JOIN_TIMEOUT", "", "", new DefaultListModel<>()), socketChannel));
} Boolean sendMessageJoinTimeoutRes = sendMessageJoinTimeout.get();
if(!sendMessageJoinTimeoutRes){
Future<Boolean> joinTimeout = threadPool.submit(new JoinTimeout(match)); activeMatches.remove(Match.findMatchIndex(activeMatches, match.matchCreator));
joinTimeout.get(); return sendMessageJoinTimeoutRes;
if(match.joinTimeout){ }
Future<Boolean> sendMessageJoinTimeout = threadPool.submit( } else {
new SendMessageToAllPlayers(match, new Message("JOIN_TIMEOUT", "", "", new DefaultListModel<>()), socketChannel)); System.out.println("TIMEOUT FINITO SENZA EFFETTI");
Boolean sendMessageJoinTimeoutRes = sendMessageJoinTimeout.get(); return true;
if(!sendMessageJoinTimeoutRes){ }
activeMatches.remove(Match.findMatchIndex(activeMatches, match.matchCreator));
return sendMessageJoinTimeoutRes; } else {
} return false;
} else { }
System.out.println("TIMEOUT FINITO SENZA EFFETTI"); } catch (InterruptedException e) {
return true; e.printStackTrace();
} } catch (ExecutionException e) {
e.printStackTrace();
} else { }
return false; } else {
}
} catch (InterruptedException e) { Message message = new Message("USER_NOT_ONLINE", "", "", new DefaultListModel<>());
e.printStackTrace(); byteMessage = new String(message.toString()).getBytes();
} catch (ExecutionException e) { bufferMessage.clear();
e.printStackTrace(); bufferMessage = ByteBuffer.wrap(byteMessage);
} this.socketChannel.write(bufferMessage);
} else { return false;
}
Message message = new Message("USER_NOT_ONLINE", "", "", new DefaultListModel<>()); } catch (InterruptedException e) {
byteMessage = new String(message.toString()).getBytes(); e.printStackTrace();
bufferMessage.clear(); } catch (ExecutionException e) {
bufferMessage = ByteBuffer.wrap(byteMessage); e.printStackTrace();
this.socketChannel.write(bufferMessage); } catch (IOException e) {
return false; e.printStackTrace();
} }
} catch (InterruptedException e) {
e.printStackTrace(); case "FETCH_HIGHSCORES":
} catch (ExecutionException e) { Future<DefaultListModel<String>> computeHighscores = threadPool.submit(new ComputeHighscores());
e.printStackTrace(); try {
} catch (IOException e) { DefaultListModel<String> computeHighscoresRes = computeHighscores.get();
e.printStackTrace(); bufferMessage.clear();
} bufferMessage = ByteBuffer.allocate(1024);
case "FETCH_HIGHSCORES": Message message = new Message("HIGHSCORES", "", "", computeHighscoresRes);
Future<DefaultListModel<String>> computeHighscores = threadPool.submit(new ComputeHighscores()); byteMessage = message.toString().getBytes();
try {
DefaultListModel<String> computeHighscoresRes = computeHighscores.get(); bufferMessage = ByteBuffer.wrap(byteMessage);
bufferMessage.clear(); try {
bufferMessage = ByteBuffer.allocate(1024); String s = new String(bufferMessage.array(), bufferMessage.position(), bufferMessage.remaining());
System.out.println("INVIO HIGHSCORES "+ s);
Message message = new Message("HIGHSCORES", "", "", computeHighscoresRes); socketChannel.write(bufferMessage);
byteMessage = message.toString().getBytes(); } catch (IOException e) {
e.printStackTrace();
bufferMessage = ByteBuffer.wrap(byteMessage); }
try { return false;
String s = new String(bufferMessage.array(), bufferMessage.position(), bufferMessage.remaining()); } catch (InterruptedException e) {
System.out.println("INVIO HIGHSCORES "+ s); e.printStackTrace();
socketChannel.write(bufferMessage); } catch (ExecutionException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace(); }
}
return false; case "JOIN_GAME":
} catch (InterruptedException e) { Future<Boolean> joinMatch = threadPool.submit(new JoinMatch(request.sender, request.data, socketChannel));
e.printStackTrace(); try {
} catch (ExecutionException e) { Match match = Match.findMatch(activeMatches, request.data.get(0));;
e.printStackTrace(); Boolean joinMatchRes = joinMatch.get();
} if(joinMatchRes){
case "JOIN_GAME": if(!match.joinTimeout) {
Future<Boolean> joinMatch = threadPool.submit(new JoinMatch(request.sender, request.data, socketChannel)); Future<DefaultListModel<String>> generateLetters = threadPool.submit(new GenerateLetters());
try { match.setLetters(generateLetters.get());
Match match = Match.findMatch(activeMatches, request.data.get(0));; match.letters.addElement(String.valueOf(match.multicastId));
Boolean joinMatchRes = joinMatch.get();
if(joinMatchRes){ for (int i = 0; i < match.playersSocket.size(); i++) {
SocketChannel socketClient = match.playersSocket.get(i).getValue();
if(!match.joinTimeout) { if (socketClient != null) {
Future<DefaultListModel<String>> generateLetters = threadPool.submit(new GenerateLetters()); bufferMessage.clear();
match.setLetters(generateLetters.get()); bufferMessage = ByteBuffer.allocate(1024);
match.letters.addElement(String.valueOf(match.multicastId));
Message message = new Message("GAME_STARTED", "", "", match.letters);
for (int i = 0; i < match.playersSocket.size(); i++) { match.startGame();
SocketChannel socketClient = match.playersSocket.get(i).getValue();
if (socketClient != null) { System.out.println("TIMEOUT CANCELLEd");
bufferMessage.clear(); byteMessage = message.toString().getBytes();
bufferMessage = ByteBuffer.allocate(1024);
bufferMessage = ByteBuffer.wrap(byteMessage);
Message message = new Message("GAME_STARTED", "", "", match.letters); try {
match.startGame(); String s = new String(bufferMessage.array(), bufferMessage.position(), bufferMessage.remaining());
System.out.println("INVIO GAME_STARTED "+ s);
System.out.println("TIMEOUT CANCELLEd"); socketClient.write(bufferMessage);
byteMessage = message.toString().getBytes(); } catch (IOException e) {
e.printStackTrace();
bufferMessage = ByteBuffer.wrap(byteMessage); }
try { }
String s = new String(bufferMessage.array(), bufferMessage.position(), bufferMessage.remaining());
System.out.println("INVIO GAME_STARTED "+ s); }
socketClient.write(bufferMessage); if (matchNotAvailable) {
} catch (IOException e) { return false;
e.printStackTrace(); }
} }
} } else {
if(match == null){
} bufferMessage = ByteBuffer.allocate(1024);
if (matchNotAvailable) { if (socketChannel != null) {
return false; bufferMessage = ByteBuffer.allocate(1024);
}
} Message msg = new Message("MATCH_NOT_AVAILABLE", "", null, new DefaultListModel<>());
} else { bufferMessage.clear();
if(match == null){ byteMessage = msg.toString().getBytes();
bufferMessage = ByteBuffer.allocate(1024); bufferMessage = ByteBuffer.wrap(byteMessage);
if (socketChannel != null) { socketChannel.write(bufferMessage);
bufferMessage = ByteBuffer.allocate(1024); matchNotAvailable = true;
}
Message msg = new Message("MATCH_NOT_AVAILABLE", "", null, new DefaultListModel<>());
bufferMessage.clear(); }
byteMessage = msg.toString().getBytes(); }
bufferMessage = ByteBuffer.wrap(byteMessage); } catch (InterruptedException e) {
socketChannel.write(bufferMessage); e.printStackTrace();
matchNotAvailable = true; } catch (ExecutionException e) {
} e.printStackTrace();
} catch (IOException e) {
} e.printStackTrace();
} }
} catch (InterruptedException e) {
e.printStackTrace(); default:
} catch (ExecutionException e) {
e.printStackTrace(); break;
} catch (IOException e) { }
e.printStackTrace();
} } else {
threadPool.submit(new TokenInvalid(request.sender, socketChannel, bufferMessage));
default: return false;
}
break;
} return false;
}
} else { }
threadPool.submit(new TokenInvalid(request.sender, socketChannel, bufferMessage));
return false;
}
return false;
}
}

View file

@ -1,79 +1,80 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import models.User; import models.User;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
/** /**
* Created by loke on 18/06/2017. * Author: Lorenzo Iovino on 18/06/2017.
*/ * Description: AccountsService
public class AccountsManager { */
public class AccountsService {
public List<User> users = Collections.synchronizedList(new ArrayList<User>());
public List<User> users = Collections.synchronizedList(new ArrayList<User>());
private static class Holder {
static final AccountsManager INSTANCE = new AccountsManager(); private static class Holder {
} static final AccountsService INSTANCE = new AccountsService();
}
public static AccountsManager getInstance() {
return AccountsManager.Holder.INSTANCE; public static AccountsService getInstance() {
} return AccountsService.Holder.INSTANCE;
}
private AccountsManager(){
List<Serializable> l = JedisService.get("users"); private AccountsService(){
for(int i=0; i<l.size(); i++) { List<Serializable> l = JedisService.get("users");
users.add((User) l.get(i)); for(int i=0; i<l.size(); i++) {
} users.add((User) l.get(i));
} }
}
public boolean register(String userName, String password) {
if(!exists(userName)){ public boolean register(String userName, String password) {
User newUser = new User(userName, password,0); if(!exists(userName)){
Boolean res = users.add(newUser); User newUser = new User(userName, password,0);
JedisService.add("users", newUser); Boolean res = users.add(newUser);
return res; JedisService.add("users", newUser);
} else { return res;
return false; } else {
} return false;
} }
}
public boolean exists(String userName) {
Iterator<User> i = users.iterator(); public boolean exists(String userName) {
while (i.hasNext()) { Iterator<User> i = users.iterator();
if (i.next().userName.equals(userName)) { while (i.hasNext()) {
return true; if (i.next().userName.equals(userName)) {
} return true;
} }
return false; }
return false;
}
}
public boolean checkPassword(String userName, String password) {
Iterator<User> i = users.iterator(); public boolean checkPassword(String userName, String password) {
while (i.hasNext()) { Iterator<User> i = users.iterator();
User account = i.next(); while (i.hasNext()) {
if (account.userName.equals(userName) && account.password.equals(password)) { User account = i.next();
return true; if (account.userName.equals(userName) && account.password.equals(password)) {
} return true;
} }
return false; }
return false;
}
}
public User findUser(String userName){
Iterator<User> i = users.iterator(); public User findUser(String userName){
while (i.hasNext()) { Iterator<User> i = users.iterator();
User u = i.next(); while (i.hasNext()) {
if (u.userName.equals(userName)) { User u = i.next();
return u; if (u.userName.equals(userName)) {
} return u;
} }
return null; }
} return null;
}
public int size(){
return users.size(); public int size(){
} return users.size();
}
}
}

View file

@ -1,83 +1,84 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import com.texttwist.server.Server; import com.texttwist.server.Server;
import interfaces.IAuth; import interfaces.IAuth;
import interfaces.INotificationClient; import interfaces.INotificationClient;
import models.Response; import models.Response;
import org.json.simple.JsonObject; import org.json.simple.JsonObject;
import java.math.BigInteger; import java.math.BigInteger;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
import java.security.SecureRandom; import java.security.SecureRandom;
import static com.texttwist.server.Server.notificationServer; import static com.texttwist.server.Server.notificationServer;
/** /**
* Created by loke on 15/06/2017. * Author: Lorenzo Iovino on 15/06/2017.
*/ * Description: AuthService
public class Auth extends UnicastRemoteObject implements IAuth { */
public class AuthService extends UnicastRemoteObject implements IAuth {
private SecureRandom random = new SecureRandom();
public int serverPort = 9999; private SecureRandom random = new SecureRandom();
public int serverPort = 9999;
public Auth(int serverPort) throws RemoteException{
this.serverPort=serverPort; public AuthService(int serverPort) throws RemoteException{
Server.logger.write("Auth Service running at "+serverPort+" port..."); this.serverPort=serverPort;
} Server.logger.write("AuthService Service running at "+serverPort+" port...");
}
@Override
public Response register(String userName, String password) throws RemoteException { @Override
Server.logger.write("Invoked register with username=" + userName + " AND " + " password=" + password); public Response register(String userName, String password) throws RemoteException {
if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) { Server.logger.write("Invoked register with username=" + userName + " AND " + " password=" + password);
if(AccountsManager.getInstance().register(userName, password)){ if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
Server.logger.write("Registration successfull"); if(AccountsService.getInstance().register(userName, password)){
return new Response("Registration successfull", 200, null); Server.logger.write("Registration successfull");
} else { return new Response("Registration successfull", 200, null);
Server.logger.write("Registration unsuccessfull"); } else {
return new Response("<html><center>Registration unsuccessfull: <br/> Username exist!</center></html>", 400, null); Server.logger.write("Registration unsuccessfull");
} return new Response("<html><center>Registration unsuccessfull: <br/> Username exist!</center></html>", 400, null);
} }
return new Response("<html><center>Registration unsuccessfull! <br/> All fields are mandatories</center></html>", 400, null); }
} return new Response("<html><center>Registration unsuccessfull! <br/> All fields are mandatories</center></html>", 400, null);
}
@Override
public Response login(String userName, String password) throws RemoteException { @Override
Server.logger.write("Invoked login with username=" + userName + " AND " + " password=" + password); public Response login(String userName, String password) throws RemoteException {
if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) { Server.logger.write("Invoked login with username=" + userName + " AND " + " password=" + password);
if(AccountsManager.getInstance().exists(userName) && AccountsManager.getInstance().checkPassword(userName, password)) { if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
JsonObject data = new JsonObject(); if(AccountsService.getInstance().exists(userName) && AccountsService.getInstance().checkPassword(userName, password)) {
String token = nextSessionId(); JsonObject data = new JsonObject();
data.put("token", token); String token = nextSessionId();
SessionsManager.getInstance().add(userName,token); data.put("token", token);
Server.logger.write("Login successfull"); SessionsService.getInstance().add(userName,token);
return new Response("Login successfull", 200, data); Server.logger.write("Login successfull");
} return new Response("Login successfull", 200, data);
} }
Server.logger.write("Login unsuccessfull"); }
return new Response("Login unsuccessfull", 400, null); Server.logger.write("Login unsuccessfull");
} return new Response("Login unsuccessfull", 400, null);
}
@Override
public Response logout(String userName, String token, INotificationClient stub) throws RemoteException { @Override
Server.logger.write("Invoked logout with username=" + userName + " AND " + " token=" + token); public Response logout(String userName, String token, INotificationClient stub) throws RemoteException {
notificationServer.unregisterForCallback(stub); Server.logger.write("Invoked logout with username=" + userName + " AND " + " token=" + token);
notificationServer.unregisterForCallback(stub);
if ((userName != null && !userName.isEmpty()) && (token != null && !token.isEmpty())) {
boolean res = SessionsManager.getInstance().remove(userName); if ((userName != null && !userName.isEmpty()) && (token != null && !token.isEmpty())) {
if(res) { boolean res = SessionsService.getInstance().remove(userName);
Server.logger.write("Logout successfull"); if(res) {
Server.logger.write("Logout successfull");
}
} }
}
SessionsManager.getInstance().remove(userName);
Server.logger.write("Logout successfull (but something gone wrong)"); SessionsService.getInstance().remove(userName);
return new Response("Logout successfull (but something gone wrong)", 200, null); Server.logger.write("Logout successfull (but something gone wrong)");
} return new Response("Logout successfull (but something gone wrong)", 200, null);
}
public String nextSessionId() {
return new BigInteger(130, random).toString(32); public String nextSessionId() {
} return new BigInteger(130, random).toString(32);
}
}
}

View file

@ -1,10 +1,9 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import models.User; import models.User;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import java.io.*; import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
@ -12,7 +11,8 @@ import java.util.List;
import static com.texttwist.server.Server.jedisPool; import static com.texttwist.server.Server.jedisPool;
/** /**
* Created by loke on 11/07/2017. * Author: Lorenzo Iovino on 11/07/2017.
* Description: Jedis Service
*/ */
public class JedisService { public class JedisService {

View file

@ -1,138 +1,141 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import com.texttwist.client.App; import com.texttwist.server.Server;
import com.texttwist.server.Server; import com.texttwist.server.servers.ProxyDispatcher;
import com.texttwist.server.models.Dictionary; import com.texttwist.server.models.Dictionary;
import com.texttwist.server.models.Match; import com.texttwist.server.models.Match;
import com.texttwist.server.tasks.ReceiveWords; import com.texttwist.server.tasks.ReceiveWords;
import constants.Config; import constants.Config;
import models.Message; import models.Message;
import utilities.Logger; import java.net.*;
import java.io.IOException;
import java.net.*; import java.nio.ByteBuffer;
import java.io.IOException; import java.nio.channels.*;
import java.nio.ByteBuffer; import java.util.ArrayList;
import java.nio.channels.*; import java.util.Collections;
import java.util.ArrayList; import java.util.Iterator;
import java.util.Collections; import java.util.List;
import java.util.Iterator; import java.util.concurrent.ExecutorService;
import java.util.List; import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import static java.nio.channels.SelectionKey.OP_ACCEPT;
import static java.nio.channels.SelectionKey.OP_READ;
import static java.nio.channels.SelectionKey.OP_ACCEPT;
import static java.nio.channels.SelectionKey.OP_READ;
/**
public class GameServer implements Runnable{ * Author: Lorenzo Iovino on 17/06/2017.
* Description: Game Server
private int serverPort; */
private ThreadProxy proxy; public class MessageService implements Runnable{
private ReceiveWords wordsReceiver;
private int serverPort;
private DatagramChannel datagramChannel; private ProxyDispatcher proxy;
private Selector selector = null; private ReceiveWords wordsReceiver;
private ExecutorService threadPool = Executors.newCachedThreadPool();
private String dictionaryPath = "./Server/resources/dictionary"; private DatagramChannel datagramChannel;
public static Dictionary dict; private Selector selector = null;
SocketChannel client; private ExecutorService threadPool = Executors.newCachedThreadPool();
ByteBuffer bufferWords = ByteBuffer.allocate(1024); private String dictionaryPath = "./Server/resources/dictionary";
ByteBuffer bufferMessages = ByteBuffer.allocate(1024); public static Dictionary dict;
SocketChannel client;
ByteBuffer bufferWords = ByteBuffer.allocate(1024);
ByteBuffer bufferMessages = ByteBuffer.allocate(1024);
public static List<Match> activeMatches = Collections.synchronizedList(new ArrayList<>());
public static Integer multicastID = 4000;
public GameServer(int port){ public static List<Match> activeMatches = Collections.synchronizedList(new ArrayList<>());
this.serverPort = port; public static Integer multicastID = 4000;
}
public MessageService(int port){
public void run(){ this.serverPort = port;
}
dict = new Dictionary(dictionaryPath);
try { public void run(){
selector = Selector.open();
dict = new Dictionary(dictionaryPath);
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); try {
serverSocketChannel.configureBlocking(false); selector = Selector.open();
serverSocketChannel.socket().bind(new InetSocketAddress(serverPort));
serverSocketChannel.register(selector, OP_ACCEPT); ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
InetSocketAddress address = new InetSocketAddress(Config.WordsReceiverServerURI,Config.WordsReceiverServerPort); serverSocketChannel.configureBlocking(false);
datagramChannel = DatagramChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress(serverPort));
datagramChannel.configureBlocking(true); serverSocketChannel.register(selector, OP_ACCEPT);
datagramChannel.connect(address); InetSocketAddress address = new InetSocketAddress(Config.WordsReceiverServerURI,Config.WordsReceiverServerPort);
Server.logger.write("GameService Service is running at "+this.serverPort+" port..."); datagramChannel = DatagramChannel.open();
datagramChannel.configureBlocking(true);
wordsReceiver = new ReceiveWords(datagramChannel, bufferWords, bufferMessages, client); datagramChannel.connect(address);
threadPool.submit(wordsReceiver); Server.logger.write("GameService Service is running at "+this.serverPort+" port...");
} catch (IOException e) { wordsReceiver = new ReceiveWords(datagramChannel, bufferWords, bufferMessages, client);
e.printStackTrace(); threadPool.submit(wordsReceiver);
}
} catch (IOException e) {
while (true) { e.printStackTrace();
System.out.println("WAITING FOR MSG"); }
try {
selector.select(); while (true) {
} catch (IOException e) { System.out.println("WAITING FOR MSG");
e.printStackTrace(); try {
} selector.select();
} catch (IOException e) {
Iterator<SelectionKey> iter = selector.selectedKeys().iterator(); e.printStackTrace();
while (iter.hasNext()) { }
bufferMessages = ByteBuffer.allocate(1024);
bufferMessages.clear(); Iterator<SelectionKey> iter = selector.selectedKeys().iterator();
client = null; while (iter.hasNext()) {
SelectionKey key = iter.next(); bufferMessages = ByteBuffer.allocate(1024);
iter.remove(); bufferMessages.clear();
client = null;
try { SelectionKey key = iter.next();
switch (key.readyOps()) { iter.remove();
case OP_ACCEPT:
client = ((ServerSocketChannel) key.channel()).accept(); try {
client.configureBlocking(false); switch (key.readyOps()) {
client.register(selector, OP_READ); case OP_ACCEPT:
break; client = ((ServerSocketChannel) key.channel()).accept();
client.configureBlocking(false);
case OP_READ: client.register(selector, OP_READ);
client = (SocketChannel) key.channel(); break;
if (client.read(bufferMessages) != -1) {
bufferMessages.flip(); case OP_READ:
String line = new String(bufferMessages.array(), bufferMessages.position(), bufferMessages.remaining()); client = (SocketChannel) key.channel();
System.out.println(line); if (client.read(bufferMessages) != -1) {
if (line.startsWith("MESSAGE")) { bufferMessages.flip();
SessionsManager.getInstance().printAll(); String line = new String(bufferMessages.array(), bufferMessages.position(), bufferMessages.remaining());
Message msg = Message.toMessage(line); System.out.println(line);
proxy = new ThreadProxy(msg, client, bufferMessages); if (line.startsWith("MESSAGE")) {
threadPool.submit(proxy); SessionsService.getInstance().printAll();
} Message msg = Message.toMessage(line);
proxy = new ProxyDispatcher(msg, client, bufferMessages);
if (line.startsWith("CLOSE")) { threadPool.submit(proxy);
client.close(); }
} else if (line.startsWith("QUIT")) {
for (SelectionKey k : selector.keys()) { if (line.startsWith("CLOSE")) {
k.cancel(); client.close();
k.channel().close(); } else if (line.startsWith("QUIT")) {
} for (SelectionKey k : selector.keys()) {
selector.close(); k.cancel();
return; k.channel().close();
} }
} else { selector.close();
key.cancel(); return;
} }
break; } else {
key.cancel();
default: }
break; break;
}
} catch (IOException e) { default:
try { break;
client.close(); }
} catch (IOException e1) { } catch (IOException e) {
e1.printStackTrace(); try {
} client.close();
} } catch (IOException e1) {
} e1.printStackTrace();
} }
} }
}
}
}
} }

View file

@ -1,62 +1,63 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import interfaces.INotificationClient; import interfaces.INotificationClient;
import interfaces.INotificationServer; import interfaces.INotificationServer;
import javax.swing.*; import javax.swing.*;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* Created by loke on 19/06/2017. * Author: Lorenzo Iovino on 19/06/2017.
*/ * Description: Jedis Service
public class NotificationServer implements INotificationServer { */
public class NotificationService implements INotificationServer {
private List<INotificationClient> clients;
public NotificationServer() throws RemoteException { private List<INotificationClient> clients;
super(); public NotificationService() throws RemoteException {
clients = new ArrayList<>(); super();
} clients = new ArrayList<>();
}
public synchronized void registerForCallback(INotificationClient clientInterface) throws RemoteException {
if(!clients.contains(clientInterface)){ public synchronized void registerForCallback(INotificationClient clientInterface) throws RemoteException {
clients.add(clientInterface); if(!clients.contains(clientInterface)){
System.out.println(clientInterface); clients.add(clientInterface);
System.out.println("New client registered"); System.out.println(clientInterface);
} System.out.println("New client registered");
} }
}
public synchronized void unregisterForCallback(INotificationClient client) throws RemoteException {
if (clients.remove(client)) { public synchronized void unregisterForCallback(INotificationClient client) throws RemoteException {
System.out.println("Client unregistered"); if (clients.remove(client)) {
} else { System.out.println("Client unregistered");
System.out.println("Unable to unregister client"); } else {
} System.out.println("Unable to unregister client");
}
}
}
public synchronized void sendInvitations(String username, DefaultListModel<String> users){
Iterator i = clients.iterator(); public synchronized void sendInvitations(String username, DefaultListModel<String> users){
INotificationClient client = null; Iterator i = clients.iterator();
System.out.println("Starting callbacks"); INotificationClient client = null;
while (i.hasNext()) { System.out.println("Starting callbacks");
client = (INotificationClient) i.next(); while (i.hasNext()) {
try { client = (INotificationClient) i.next();
try {
System.out.println("SENDING INVITE TO "+users);
client.sendInvite(username, users); System.out.println("SENDING INVITE TO "+users);
} catch (RemoteException e) { client.sendInvite(username, users);
System.out.println("Sembra down"); } catch (RemoteException e) {
try { System.out.println("Sembra down");
unregisterForCallback(client); try {
} catch (RemoteException e1) { unregisterForCallback(client);
e1.printStackTrace(); } catch (RemoteException e1) {
} e1.printStackTrace();
} }
} }
}
}
} }
}

View file

@ -0,0 +1,77 @@
package com.texttwist.server.services;
import models.Session;
import models.User;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Author: Lorenzo Iovino on 17/06/2017.
* Description: SessionsService. It is a singleton that provides the model and methods for manage sessions
*/
public class SessionsService {
private List<Session> sessions = Collections.synchronizedList(new ArrayList<Session>());
private static class Holder {
static final SessionsService INSTANCE = new SessionsService();
}
public static SessionsService getInstance() {
return Holder.INSTANCE;
}
private Session getSession(String userName) {
for (Session elem : sessions) {
if (elem.account.userName.equals(userName)) {
return elem;
}
}
return null;
}
public SessionsService(){}
public boolean add(String userName, String token) {
remove(userName);
return sessions.add(new Session(new User(userName,"",0), token));
}
public void printAll(){
for (Session elem : sessions) {
System.out.println(elem.account.userName + " | " + elem.token);
}
}
public boolean remove(String userName){
if(exists(userName)) {
Session s = getSession(userName);
if(s != null) {
sessions.remove(s);
return true;
}
}
return false;
}
public boolean exists(String userName) {
for (Session elem : sessions) {
if (elem.account.userName.equals(userName)) {
return true;
}
}
return false;
}
public boolean isValidToken(String token) {
for (Session session : sessions) {
if (session.token.equals(token)) {
return true;
}
}
return false;
}
}

View file

@ -1,12 +1,13 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.texttwist.server.components.SessionsManager; import com.texttwist.server.services.SessionsService;
import javax.swing.*; import javax.swing.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* Created by loke on 19/06/2017. * Author: Lorenzo Iovino on 19/06/2017.
* Description: Jedis Service
*/ */
public class CheckOnlineUsers implements Callable<Boolean> { public class CheckOnlineUsers implements Callable<Boolean> {
private final DefaultListModel<String> users; private final DefaultListModel<String> users;
@ -18,7 +19,7 @@ public class CheckOnlineUsers implements Callable<Boolean> {
@Override @Override
public Boolean call() throws Exception { public Boolean call() throws Exception {
for(int i = 0; i < users.size(); i++){ for(int i = 0; i < users.size(); i++){
if(!(SessionsManager.getInstance().exists(users.get(i)))){ if(!(SessionsService.getInstance().exists(users.get(i)))){
return false; return false;
} }
} }

View file

@ -1,17 +1,16 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.texttwist.server.components.AccountsManager; import com.texttwist.server.services.AccountsService;
import com.texttwist.server.components.JedisService; import com.texttwist.server.services.JedisService;
import models.User; import models.User;
import javax.swing.*; import javax.swing.*;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* Created by loke on 28/06/2017. * Author: Lorenzo Iovino on 28/06/2017.
* Description: Jedis Service
*/ */
public class ComputeHighscores implements Callable<DefaultListModel<String>> { public class ComputeHighscores implements Callable<DefaultListModel<String>> {
@ -21,16 +20,16 @@ public class ComputeHighscores 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<>();
AccountsManager.getInstance().users.sort(new Comparator<User>() { AccountsService.getInstance().users.sort(new Comparator<User>() {
@Override @Override
public int compare(User o1, User o2) { public int compare(User o1, User o2) {
return o2.score.compareTo(o1.score); return o2.score.compareTo(o1.score);
} }
}); });
JedisService.removeAll("users"); JedisService.removeAll("users");
for(int i =0; i< AccountsManager.getInstance().users.size(); i++){ for(int i = 0; i< AccountsService.getInstance().users.size(); i++){
l.addElement(AccountsManager.getInstance().users.get(i).userName+":"+AccountsManager.getInstance().users.get(i).score); l.addElement(AccountsService.getInstance().users.get(i).userName+":"+ AccountsService.getInstance().users.get(i).score);
JedisService.add("users",AccountsManager.getInstance().users.get(i)); JedisService.add("users", AccountsService.getInstance().users.get(i));
} }
return l; return l;
} }

View file

@ -1,26 +1,15 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.texttwist.client.App; import com.texttwist.server.services.AccountsService;
import com.texttwist.server.components.AccountsManager;
import com.texttwist.server.components.JedisService;
import com.texttwist.server.models.Dictionary; import com.texttwist.server.models.Dictionary;
import com.texttwist.server.models.Match; import com.texttwist.server.models.Match;
import constants.Config;
import models.Message;
import models.User; import models.User;
import redis.clients.jedis.Jedis;
import javax.swing.*; import javax.swing.*;
import java.io.Serializable;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static com.texttwist.server.components.GameServer.activeMatches;
/** /**
* Created by loke on 27/06/2017. * Author: Lorenzo Iovino on 27/06/2017.
* Description: Jedis Service
*/ */
public class ComputeScore implements Callable<Integer> { public class ComputeScore implements Callable<Integer> {
@ -52,7 +41,7 @@ public class ComputeScore implements Callable<Integer> {
match.setScore(sender, score); match.setScore(sender, score);
System.out.println(score); System.out.println(score);
User u = AccountsManager.getInstance().findUser(sender); User u = AccountsService.getInstance().findUser(sender);
u.addScore(score); u.addScore(score);
if(match.allPlayersSendedHisScore()) { if(match.allPlayersSendedHisScore()) {
@ -61,7 +50,7 @@ public class ComputeScore implements Callable<Integer> {
System.out.println("MATCH TIMEOUT CANCELLATO"); System.out.println("MATCH TIMEOUT CANCELLATO");
match.setUndefinedScorePlayersToZero(); match.setUndefinedScorePlayersToZero();
match.sendScores(); new SendScores(match).call();
} }
return score; return score;

View file

@ -1,16 +1,13 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.texttwist.server.components.GameServer; import com.texttwist.server.services.MessageService;
import javax.swing.*; import javax.swing.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* Created by loke on 25/06/2017. * Author: Lorenzo Iovino on 25/06/2017.
* Description: Jedis Service
*/ */
public class GenerateLetters implements Callable<DefaultListModel<String>> { public class GenerateLetters implements Callable<DefaultListModel<String>> {
@ -23,7 +20,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<String>(); DefaultListModel<String> l = new DefaultListModel<String>();
String word = GameServer.dict.getRandomWord(6, 7); String word = MessageService.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)));
} }

View file

@ -5,10 +5,11 @@ import javafx.util.Pair;
import javax.swing.*; import javax.swing.*;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static com.texttwist.server.components.GameServer.activeMatches; import static com.texttwist.server.services.MessageService.activeMatches;
/** /**
* Created by loke on 23/06/2017. * Author: Lorenzo Iovino on 23/06/2017.
* Description: Jedis Service
*/ */
public class JoinMatch implements Callable<Boolean> { public class JoinMatch implements Callable<Boolean> {
public final String matchName; public final String matchName;

View file

@ -17,13 +17,14 @@ public class JoinTimeout implements Callable<Boolean> {
@Override @Override
public Boolean call() throws Exception { public Boolean call() throws Exception {
try { try {
Thread.currentThread().sleep(7*60*1000); Thread.currentThread().sleep(1*60*1000);
System.out.println("TIMEOUTTTT"); System.out.println("TIMEOUTTTT");
if(match.joinTimeout) { if(match.joinTimeout) {
return false; return false;
} }
else { else {
match.joinTimeout=true;
return true; return true;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {

View file

@ -1,19 +1,13 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.texttwist.server.models.Match; import com.texttwist.server.models.Match;
import constants.Config; import constants.Config;
import models.Message;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static com.texttwist.server.components.GameServer.activeMatches;
/** /**
* Created by loke on 27/06/2017. * Author: Lorenzo Iovino on 27/06/2017.
* Description: Jedis Service
*/ */
public class MatchTimeout implements Callable<Boolean> { public class MatchTimeout implements Callable<Boolean> {
@ -26,12 +20,12 @@ public class MatchTimeout implements Callable<Boolean> {
@Override @Override
public Boolean call() throws Exception { public Boolean call() throws Exception {
try { try {
Thread.currentThread().sleep(5*60*1000); //TODO 5*60*1000 Thread.currentThread().sleep(Config.sendWordsTimeout);
match.setUndefinedScorePlayersToZero(); match.setUndefinedScorePlayersToZero();
if(match.matchTimeout) { if(match.matchTimeout) {
System.out.println("SEND BROADCAST BECAUSE TIMEOUT"); System.out.println("SEND BROADCAST BECAUSE TIMEOUT");
match.sendScores(); new SendScores(match).call();
return true; return true;
} }
return false; return false;

View file

@ -1,6 +1,6 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.texttwist.server.components.SessionsManager; import com.texttwist.server.services.SessionsService;
import com.texttwist.server.models.Match; import com.texttwist.server.models.Match;
import constants.Config; import constants.Config;
import models.Message; import models.Message;
@ -14,7 +14,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
/** /**
* Created by loke on 27/06/2017. * Author: Lorenzo Iovino on 27/06/2017.
* Description: Jedis Service
*/ */
public class ReceiveWords implements Callable<Boolean>{ public class ReceiveWords implements Callable<Boolean>{
@ -53,9 +54,9 @@ public class ReceiveWords implements Callable<Boolean>{
System.out.println(rcv); System.out.println(rcv);
if (rcv.startsWith("MESSAGE")) { if (rcv.startsWith("MESSAGE")) {
msg = Message.toMessage(rcv); msg = Message.toMessage(rcv);
if(SessionsManager.getInstance().isValidToken(msg.token)) { if(SessionsService.getInstance().isValidToken(msg.token)) {
System.out.println(msg.sender); System.out.println(msg.sender);
Match match = Match.findMatchByPlayer(msg.sender); Match match = Match.findMatchByPlayerName(msg.sender);
threadPool.submit(new ComputeScore(msg.sender, msg.data, match)); threadPool.submit(new ComputeScore(msg.sender, msg.data, match));
} else { } else {
threadPool.submit(new TokenInvalid(msg.sender, socketChannel, bufferMessages)); threadPool.submit(new TokenInvalid(msg.sender, socketChannel, bufferMessages));

View file

@ -1,19 +1,13 @@
package com.texttwist.server.tasks; package com.texttwist.server.tasks;
import com.texttwist.server.Server; import com.texttwist.server.Server;
import com.texttwist.server.components.NotificationServer;
import com.texttwist.server.components.SessionsManager;
import constants.Config;
import interfaces.INotificationServer;
import javax.swing.*; import javax.swing.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* Created by loke on 19/06/2017. * Author: Lorenzo Iovino on 19/06/2017.
* Description: Jedis Service
*/ */
public class SendInvitations implements Callable<Boolean> { public class SendInvitations implements Callable<Boolean> {
private DefaultListModel<String> users; private DefaultListModel<String> users;

View file

@ -9,7 +9,8 @@ import java.nio.channels.SocketChannel;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* Created by loke on 27/06/2017. * Author: Lorenzo Iovino on 27/06/2017.
* Description: Jedis Service
*/ */
public class SendMessageToAllPlayers implements Callable<Boolean> { public class SendMessageToAllPlayers implements Callable<Boolean> {

View file

@ -0,0 +1,46 @@
package com.texttwist.server.tasks;
import com.texttwist.server.models.Match;
import constants.Config;
import models.Message;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.concurrent.Callable;
import static com.texttwist.server.services.MessageService.activeMatches;
/**
* Created by loke on 13/07/2017.
*/
public class SendScores implements Callable<Void> {
private Match match;
public SendScores(Match match){
this.match = match;
}
@Override
public Void call() throws Exception {
while (true) {
System.out.println("SENDING");
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();
}
activeMatches.remove(Match.findMatchIndex(activeMatches, match.matchCreator));
return null;
}
}
}

View file

@ -5,12 +5,12 @@ import models.Message;
import javax.swing.*; import javax.swing.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.Channel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* Created by loke on 11/07/2017. * Author: Lorenzo Iovino on 11/07/2017.
* Description: Task: Token Invalid Service
*/ */
public class TokenInvalid implements Callable<Boolean> { public class TokenInvalid implements Callable<Boolean> {
private String sender; private String sender;
@ -25,9 +25,8 @@ public class TokenInvalid implements Callable<Boolean> {
@Override @Override
public Boolean call()throws Exception { public Boolean call()throws Exception {
System.out.print("TOKEN NON VALIDO"); Server.logger.write("TOKEN INVALID: TOKEN USED BY "+ sender+ " IS NOT VALID");
buffer = ByteBuffer.allocate(1024); Message msg = new Message("TOKEN_NOT_VALID", "", null, new DefaultListModel<>());
Message msg = new Message("MATCH_NOT_AVAILABLE", "", 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);

View file

@ -1296,3 +1296,162 @@ LOGGER (Server): Thu Jul 13 03:30:57 CEST 2017 - Invoked login with username=asd
LOGGER (Server): Thu Jul 13 03:30:57 CEST 2017 - Login successfull LOGGER (Server): Thu Jul 13 03:30:57 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 03:31:02 CEST 2017 - Invoked login with username=a AND password=a LOGGER (Server): Thu Jul 13 03:31:02 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 03:31:02 CEST 2017 - Login successfull LOGGER (Server): Thu Jul 13 03:31:02 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 12:23:43 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 12:23:44 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 12:23:44 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 12:23:44 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 12:23:48 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 12:23:48 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 12:23:51 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 12:23:51 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 12:57:17 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 12:57:17 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 12:57:17 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 12:57:17 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 12:57:23 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 12:57:23 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 12:57:26 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 12:57:26 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:02:35 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:02:36 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:02:36 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:02:36 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:02:41 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:02:42 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:02:44 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:02:44 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:04:46 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:04:46 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:04:46 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:04:46 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:04:51 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:04:51 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:04:54 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:04:54 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:05:29 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:05:29 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:05:29 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:05:29 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:05:36 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:05:36 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:05:38 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:05:38 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:09:00 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:09:00 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:09:01 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:09:01 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:09:04 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:09:04 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:09:07 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:09:07 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:10:10 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:10:10 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:10:10 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:10:10 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:10:15 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:10:15 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:10:17 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:10:17 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:13:01 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:13:01 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:13:01 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:13:01 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:13:06 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:13:06 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:13:08 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:13:08 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:14:51 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:14:51 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:14:51 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:14:51 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:14:56 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:14:56 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:14:58 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:14:58 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:15:47 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:15:47 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:15:47 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:15:47 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:15:51 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:15:51 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:15:53 CEST 2017 - Invoked logout with username=a AND token=8e462nrn7or1750ik15gsm1ha2
LOGGER (Server): Thu Jul 13 13:15:53 CEST 2017 - Logout successfull
LOGGER (Server): Thu Jul 13 13:15:53 CEST 2017 - Logout successfull (but something gone wrong)
LOGGER (Server): Thu Jul 13 13:15:55 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:15:55 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:16:02 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:16:02 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:19:30 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:19:30 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:19:30 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:19:30 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:19:35 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:19:35 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:19:37 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:19:37 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:53:43 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:53:43 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:53:43 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:53:43 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:53:49 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:53:49 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:53:52 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:53:52 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:59:25 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 13:59:25 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 13:59:25 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 13:59:25 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 13:59:37 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 13:59:37 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:59:41 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 13:59:41 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:59:46 CEST 2017 - Invoked login with username=asd AND password=sad
LOGGER (Server): Thu Jul 13 13:59:46 CEST 2017 - Login unsuccessfull
LOGGER (Server): Thu Jul 13 13:59:50 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 13:59:50 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 13:59:55 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 13:59:55 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:01:58 CEST 2017 - Invoked register with username=ss AND password=ss
LOGGER (Server): Thu Jul 13 14:01:58 CEST 2017 - Registration successfull
LOGGER (Server): Thu Jul 13 14:02:00 CEST 2017 - Invoked login with username=ss AND password=ss
LOGGER (Server): Thu Jul 13 14:02:00 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:02:05 CEST 2017 - Invoked register with username=aa AND password=aa
LOGGER (Server): Thu Jul 13 14:02:05 CEST 2017 - Registration successfull
LOGGER (Server): Thu Jul 13 14:02:08 CEST 2017 - Invoked login with username=aa AND password=aa
LOGGER (Server): Thu Jul 13 14:02:08 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:02:43 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 14:02:44 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:02:44 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 14:02:44 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:03:08 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:03:08 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:03:10 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:03:10 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:03:12 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:03:12 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:03:14 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:03:14 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:10:29 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 14:10:29 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:10:30 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 14:10:30 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:10:34 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:10:34 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:10:40 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:10:40 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:10:45 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:10:45 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:10:49 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:10:49 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:14:11 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 14:14:11 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:14:11 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 14:14:11 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:14:24 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:14:24 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:14:26 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:14:26 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:14:30 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:14:30 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:14:36 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:14:36 CEST 2017 - Login successfull