Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Lorenzo Iovino
04f900c389 ok 2017-07-13 14:40:10 +02:00
22 changed files with 1278 additions and 1456 deletions

1182
.idea/workspace.xml generated

File diff suppressed because it is too large Load diff

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,13 @@
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 AuthService 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,6 +1,6 @@
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 constants.Config;
import javafx.util.Pair; import javafx.util.Pair;
@ -11,12 +11,11 @@ import java.io.IOException;
import java.net.*; 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 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. * Created by loke on 23/06/2017.
@ -155,7 +154,7 @@ public class Match {
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,25 +1,17 @@
package com.texttwist.server.components; package com.texttwist.server.models.servers;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.texttwist.client.App;
import com.texttwist.server.models.Match; import com.texttwist.server.models.Match;
import com.texttwist.server.services.SessionsService;
import com.texttwist.server.tasks.*; import com.texttwist.server.tasks.*;
import constants.Config;
import javafx.util.Pair;
import models.Message; import models.Message;
import javax.swing.*; import javax.swing.*;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.concurrent.*; import java.util.concurrent.*;
import static com.texttwist.server.components.GameServer.activeMatches; import static com.texttwist.server.services.MessageService.activeMatches;
/** /**
* Created by loke on 18/06/2017. * Created by loke on 18/06/2017.
@ -32,7 +24,7 @@ public class ThreadProxy implements Callable<Boolean> {
boolean matchNotAvailable =false; boolean matchNotAvailable =false;
ThreadProxy(Message request, SocketChannel socketChannel, ByteBuffer bufferMessage) { public ThreadProxy(Message request, SocketChannel socketChannel, ByteBuffer bufferMessage) {
this.request = request; this.request = request;
this.socketChannel = socketChannel; this.socketChannel = socketChannel;
this.bufferMessage = bufferMessage; this.bufferMessage = bufferMessage;
@ -43,7 +35,7 @@ public class ThreadProxy implements Callable<Boolean> {
public Boolean call() { public Boolean call() {
bufferMessage = ByteBuffer.allocate(1024); bufferMessage = ByteBuffer.allocate(1024);
byte[] byteMessage = null; byte[] byteMessage = null;
if(SessionsManager.getInstance().isValidToken(request.token)){ if(SessionsService.getInstance().isValidToken(request.token)){
switch(request.message){ switch(request.message){
case "START_GAME": case "START_GAME":
Future<Boolean> onlineUsers = threadPool.submit(new CheckOnlineUsers(request.data)); Future<Boolean> onlineUsers = threadPool.submit(new CheckOnlineUsers(request.data));

View file

@ -1,4 +1,4 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import models.User; import models.User;
import java.io.Serializable; import java.io.Serializable;
@ -8,19 +8,19 @@ import java.util.*;
/** /**
* Created by loke on 18/06/2017. * Created by loke on 18/06/2017.
*/ */
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 { private static class Holder {
static final AccountsManager INSTANCE = new AccountsManager(); static final AccountsService INSTANCE = new AccountsService();
} }
public static AccountsManager getInstance() { public static AccountsService getInstance() {
return AccountsManager.Holder.INSTANCE; return AccountsService.Holder.INSTANCE;
} }
private AccountsManager(){ private AccountsService(){
List<Serializable> l = JedisService.get("users"); List<Serializable> l = JedisService.get("users");
for(int i=0; i<l.size(); i++) { for(int i=0; i<l.size(); i++) {
users.add((User) l.get(i)); users.add((User) l.get(i));

View file

@ -1,4 +1,4 @@
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;
@ -15,22 +15,22 @@ import static com.texttwist.server.Server.notificationServer;
/** /**
* Created by loke on 15/06/2017. * Created by loke on 15/06/2017.
*/ */
public class Auth extends UnicastRemoteObject implements IAuth { public class AuthService extends UnicastRemoteObject implements IAuth {
private SecureRandom random = new SecureRandom(); private SecureRandom random = new SecureRandom();
public int serverPort = 9999; public int serverPort = 9999;
public Auth(int serverPort) throws RemoteException{ public AuthService(int serverPort) throws RemoteException{
this.serverPort=serverPort; this.serverPort=serverPort;
Server.logger.write("Auth Service running at "+serverPort+" port..."); Server.logger.write("AuthService Service running at "+serverPort+" port...");
} }
@Override @Override
public Response register(String userName, String password) throws RemoteException { public Response register(String userName, String password) throws RemoteException {
Server.logger.write("Invoked register with username=" + userName + " AND " + " password=" + password); Server.logger.write("Invoked register with username=" + userName + " AND " + " password=" + password);
if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) { if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
if(AccountsManager.getInstance().register(userName, password)){ if(AccountsService.getInstance().register(userName, password)){
Server.logger.write("Registration successfull"); Server.logger.write("Registration successfull");
return new Response("Registration successfull", 200, null); return new Response("Registration successfull", 200, null);
} else { } else {
@ -45,11 +45,11 @@ public class Auth extends UnicastRemoteObject implements IAuth {
public Response login(String userName, String password) throws RemoteException { public Response login(String userName, String password) throws RemoteException {
Server.logger.write("Invoked login with username=" + userName + " AND " + " password=" + password); Server.logger.write("Invoked login with username=" + userName + " AND " + " password=" + password);
if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) { if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
if(AccountsManager.getInstance().exists(userName) && AccountsManager.getInstance().checkPassword(userName, password)) { if(AccountsService.getInstance().exists(userName) && AccountsService.getInstance().checkPassword(userName, password)) {
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
String token = nextSessionId(); String token = nextSessionId();
data.put("token", token); data.put("token", token);
SessionsManager.getInstance().add(userName,token); SessionsService.getInstance().add(userName,token);
Server.logger.write("Login successfull"); Server.logger.write("Login successfull");
return new Response("Login successfull", 200, data); return new Response("Login successfull", 200, data);
} }
@ -64,14 +64,14 @@ public class Auth extends UnicastRemoteObject implements IAuth {
notificationServer.unregisterForCallback(stub); notificationServer.unregisterForCallback(stub);
if ((userName != null && !userName.isEmpty()) && (token != null && !token.isEmpty())) { if ((userName != null && !userName.isEmpty()) && (token != null && !token.isEmpty())) {
boolean res = SessionsManager.getInstance().remove(userName); boolean res = SessionsService.getInstance().remove(userName);
if(res) { if(res) {
Server.logger.write("Logout successfull"); Server.logger.write("Logout successfull");
} }
} }
SessionsManager.getInstance().remove(userName); SessionsService.getInstance().remove(userName);
Server.logger.write("Logout successfull (but something gone wrong)"); Server.logger.write("Logout successfull (but something gone wrong)");
return new Response("Logout successfull (but something gone wrong)", 200, null); return new Response("Logout successfull (but something gone wrong)", 200, null);
} }

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;

View file

@ -1,13 +1,12 @@
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.models.Dictionary; import com.texttwist.server.models.Dictionary;
import com.texttwist.server.models.Match; import com.texttwist.server.models.Match;
import com.texttwist.server.models.servers.ThreadProxy;
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.net.*;
import java.io.IOException; import java.io.IOException;
@ -23,7 +22,7 @@ import java.util.concurrent.Executors;
import static java.nio.channels.SelectionKey.OP_ACCEPT; import static java.nio.channels.SelectionKey.OP_ACCEPT;
import static java.nio.channels.SelectionKey.OP_READ; import static java.nio.channels.SelectionKey.OP_READ;
public class GameServer implements Runnable{ public class MessageService implements Runnable{
private int serverPort; private int serverPort;
private ThreadProxy proxy; private ThreadProxy proxy;
@ -39,11 +38,10 @@ public class GameServer implements Runnable{
ByteBuffer bufferMessages = ByteBuffer.allocate(1024); ByteBuffer bufferMessages = ByteBuffer.allocate(1024);
public static List<Match> activeMatches = Collections.synchronizedList(new ArrayList<>()); public static List<Match> activeMatches = Collections.synchronizedList(new ArrayList<>());
public static Integer multicastID = 4000; public static Integer multicastID = 30000;
public GameServer(int port){ public MessageService(int port){
this.serverPort = port; this.serverPort = port;
} }
@ -61,7 +59,7 @@ public class GameServer implements Runnable{
datagramChannel = DatagramChannel.open(); datagramChannel = DatagramChannel.open();
datagramChannel.configureBlocking(true); datagramChannel.configureBlocking(true);
datagramChannel.connect(address); datagramChannel.connect(address);
Server.logger.write("GameService Service is running at "+this.serverPort+" port..."); Server.logger.write("MessageService Service is running at "+this.serverPort+" port...");
wordsReceiver = new ReceiveWords(datagramChannel, bufferWords, bufferMessages, client); wordsReceiver = new ReceiveWords(datagramChannel, bufferWords, bufferMessages, client);
threadPool.submit(wordsReceiver); threadPool.submit(wordsReceiver);
@ -101,7 +99,7 @@ public class GameServer implements Runnable{
String line = new String(bufferMessages.array(), bufferMessages.position(), bufferMessages.remaining()); String line = new String(bufferMessages.array(), bufferMessages.position(), bufferMessages.remaining());
System.out.println(line); System.out.println(line);
if (line.startsWith("MESSAGE")) { if (line.startsWith("MESSAGE")) {
SessionsManager.getInstance().printAll(); SessionsService.getInstance().printAll();
Message msg = Message.toMessage(line); Message msg = Message.toMessage(line);
proxy = new ThreadProxy(msg, client, bufferMessages); proxy = new ThreadProxy(msg, client, bufferMessages);
threadPool.submit(proxy); threadPool.submit(proxy);

View file

@ -1,4 +1,4 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import interfaces.INotificationClient; import interfaces.INotificationClient;
import interfaces.INotificationServer; import interfaces.INotificationServer;
@ -13,10 +13,10 @@ import java.util.List;
/** /**
* Created by loke on 19/06/2017. * Created by loke on 19/06/2017.
*/ */
public class NotificationServer implements INotificationServer { public class NotificationService implements INotificationServer {
private List<INotificationClient> clients; private List<INotificationClient> clients;
public NotificationServer() throws RemoteException { public NotificationService() throws RemoteException {
super(); super();
clients = new ArrayList<>(); clients = new ArrayList<>();
} }

View file

@ -1,5 +1,4 @@
package com.texttwist.server.components; package com.texttwist.server.services;
import interfaces.INotificationClient;
import models.Session; import models.Session;
import models.User; import models.User;
@ -11,18 +10,18 @@ import java.util.List;
/** /**
* Created by loke on 17/06/2017. * Created by loke on 17/06/2017.
*/ */
public class SessionsManager { public class SessionsService {
private List<Session> sessions = Collections.synchronizedList(new ArrayList<Session>()); private List<Session> sessions = Collections.synchronizedList(new ArrayList<Session>());
private static class Holder { private static class Holder {
static final SessionsManager INSTANCE = new SessionsManager(); static final SessionsService INSTANCE = new SessionsService();
} }
public static SessionsManager getInstance() { public static SessionsService getInstance() {
return Holder.INSTANCE; return Holder.INSTANCE;
} }
private SessionsManager(){} private SessionsService(){}
public boolean add(String userName, String token) { public boolean add(String userName, String token) {
remove(userName); remove(userName);

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 javax.swing.*; import javax.swing.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -18,7 +18,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,13 +1,11 @@
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;
/** /**
@ -21,16 +19,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,24 +1,12 @@
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. * Created by loke on 27/06/2017.
*/ */
@ -52,7 +40,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()) {

View file

@ -1,12 +1,8 @@
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;
/** /**
@ -23,7 +19,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,7 +5,7 @@ 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. * Created by loke on 23/06/2017.

View file

@ -1,17 +1,9 @@
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 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. * Created by loke on 27/06/2017.
*/ */

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;
@ -53,7 +53,7 @@ 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.findMatchByPlayer(msg.sender);
threadPool.submit(new ComputeScore(msg.sender, msg.data, match)); threadPool.submit(new ComputeScore(msg.sender, msg.data, match));

View file

@ -1,15 +1,8 @@
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;
/** /**

View file

@ -1296,3 +1296,51 @@ 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 14:22:29 CEST 2017 - Server starting ...
LOGGER (Server): Thu Jul 13 14:22:30 CEST 2017 - Auth Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:22:30 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:22:30 CEST 2017 - Server started
LOGGER (Server): Thu Jul 13 14:22:35 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:22:35 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:22:39 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:22:39 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:22:46 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:22:46 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:22:50 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:22:50 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:23:30 CEST 2017 - Server starting ...
LOGGER (Server): Thu Jul 13 14:23:31 CEST 2017 - Auth Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:23:31 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:23:31 CEST 2017 - Server started
LOGGER (Server): Thu Jul 13 14:23:40 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:23:40 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:23:43 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:23:43 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:23:49 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:23:49 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:23:55 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:23:55 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:28:32 CEST 2017 - Server starting ...
LOGGER (Server): Thu Jul 13 14:28:33 CEST 2017 - Auth Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:28:33 CEST 2017 - GameService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:28:33 CEST 2017 - Server started
LOGGER (Server): Thu Jul 13 14:28:43 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:28:43 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:28:46 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:28:46 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:28:49 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:28:49 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:28:54 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:28:54 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:37:57 CEST 2017 - Services starting ...
LOGGER (Server): Thu Jul 13 14:37:57 CEST 2017 - AuthService Service running at 9999 port...
LOGGER (Server): Thu Jul 13 14:37:57 CEST 2017 - Services started correctly ...
LOGGER (Server): Thu Jul 13 14:37:57 CEST 2017 - MessageService Service is running at 10000 port...
LOGGER (Server): Thu Jul 13 14:38:06 CEST 2017 - Invoked login with username=asd AND password=asd
LOGGER (Server): Thu Jul 13 14:38:06 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:38:09 CEST 2017 - Invoked login with username=a AND password=a
LOGGER (Server): Thu Jul 13 14:38:09 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:38:13 CEST 2017 - Invoked login with username=b AND password=b
LOGGER (Server): Thu Jul 13 14:38:13 CEST 2017 - Login successfull
LOGGER (Server): Thu Jul 13 14:38:17 CEST 2017 - Invoked login with username=dd AND password=dd
LOGGER (Server): Thu Jul 13 14:38:17 CEST 2017 - Login successfull