sUPER UP
This commit is contained in:
parent
6b915932ae
commit
dc206c0bb0
15 changed files with 1540 additions and 332 deletions
|
|
@ -45,21 +45,6 @@ public class App extends JFrame {
|
|||
Logger logger = new Logger(new File("./client_"+id+".log"), "Client"+id);
|
||||
|
||||
Logger.write("Client starting ...");
|
||||
try {
|
||||
Registry registry = LocateRegistry.getRegistry(Config.NotificationServerStubPort);
|
||||
INotificationServer server = (INotificationServer) registry.lookup(Config.NotificationServerName);
|
||||
|
||||
/* si registra per la callback */
|
||||
System.out.println("Registering for callback");
|
||||
INotificationClient callbackObj = new NotificationClient();
|
||||
INotificationClient stub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0);
|
||||
|
||||
server.registerForCallback(stub);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotBoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Init models
|
||||
game = new Game();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import interfaces.INotificationClient;
|
||||
import models.Response;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
|
@ -12,8 +13,8 @@ import java.rmi.RemoteException;
|
|||
*/
|
||||
public class MenuController {
|
||||
|
||||
public Response logout(String userName) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
Response res = App.authService.logout(userName);
|
||||
public Response logout(String userName, INotificationClient stub) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
Response res = App.authService.logout(userName, stub);
|
||||
if (res.code == 200){
|
||||
App.session = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import com.texttwist.client.App;
|
|||
import com.texttwist.client.pages.GamePage;
|
||||
import com.texttwist.client.pages.MenuPage;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.services.NotificationClient;
|
||||
import com.texttwist.client.tasks.InvitePlayers;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import constants.Config;
|
||||
import interfaces.INotificationClient;
|
||||
import interfaces.INotificationServer;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
|
|
@ -17,6 +20,11 @@ import java.net.InetSocketAddress;
|
|||
import java.net.MulticastSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
|
|
@ -30,12 +38,26 @@ public class Game {
|
|||
public DefaultListModel<String> words = new DefaultListModel<String>();
|
||||
public DefaultListModel<String> letters = new DefaultListModel<String>();
|
||||
public DefaultListModel<Pair<String,Integer>> ranks = new DefaultListModel<>();
|
||||
public INotificationClient stub;
|
||||
public DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<>();
|
||||
public MulticastSocket multicastSocket;
|
||||
public INotificationServer server;
|
||||
|
||||
public SocketChannel clientSocket = null;
|
||||
|
||||
public Game(){
|
||||
|
||||
Registry registry = null;
|
||||
try {
|
||||
registry = LocateRegistry.getRegistry(Config.NotificationServerStubPort);
|
||||
server = (INotificationServer) registry.lookup(Config.NotificationServerName);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotBoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
InetSocketAddress socketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort);
|
||||
try {
|
||||
clientSocket = SocketChannel.open(socketAddress);
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class MenuPage extends Page{
|
|||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
menuController.logout(App.session.account.userName);
|
||||
menuController.logout(App.session.account.userName, App.game.stub);
|
||||
return new HomePage(Page.window);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
package com.texttwist.client.services;
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.models.Game;
|
||||
import constants.Config;
|
||||
import interfaces.IAuth;
|
||||
import interfaces.INotificationClient;
|
||||
import interfaces.INotificationServer;
|
||||
import models.Response;
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
/**
|
||||
* Authentication Service
|
||||
|
|
@ -16,6 +22,17 @@ public class AuthService {
|
|||
private String baseUrl = Config.getAuthServerURI().concat("/auth");
|
||||
|
||||
public Response login(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
try {
|
||||
|
||||
/* si registra per la callback */
|
||||
System.out.println("Registering for callback");
|
||||
INotificationClient callbackObj = new NotificationClient();
|
||||
App.game.stub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0);
|
||||
|
||||
App.game.server.registerForCallback(App.game.stub);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
IAuth auth = (IAuth) Naming.lookup(baseUrl);
|
||||
return auth.login(userName, password);
|
||||
}
|
||||
|
|
@ -25,8 +42,8 @@ public class AuthService {
|
|||
return auth.register(userName, password);
|
||||
}
|
||||
|
||||
public Response logout(String userName) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
public Response logout(String userName, INotificationClient stub) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
IAuth auth = (IAuth) Naming.lookup(baseUrl);
|
||||
return auth.logout(userName, App.session.token);
|
||||
return auth.logout(userName, App.session.token, stub);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,13 @@ public class NotificationClient implements INotificationClient {
|
|||
public Response sendInvite(String userName, DefaultListModel<String> users) throws RemoteException {
|
||||
Logger.write("Invoked invitation with username=" + userName + "|" + users.toString() );
|
||||
|
||||
if(users.contains(App.session.account.userName)){
|
||||
Logger.write(userName+" ti ha sfidato!");
|
||||
App.game.newMatch(userName);
|
||||
if(App.session != null) {
|
||||
if (users.contains(App.session.account.userName)) {
|
||||
Logger.write(userName + " ti ha sfidato!");
|
||||
App.game.newMatch(userName);
|
||||
} else {
|
||||
Logger.write("L'utente è sloggato");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
}
|
||||
}
|
||||
App.game.ranks = ranks;
|
||||
App.game.multicastSocket.leaveGroup(InetAddress.getByName(Config.ScoreMulticastServerURI));
|
||||
App.game.multicastSocket.close();
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -65,6 +63,12 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
@Override
|
||||
public void done(){
|
||||
App.game.ranks = ranks;
|
||||
try {
|
||||
App.game.multicastSocket.leaveGroup(InetAddress.getByName(Config.ScoreMulticastServerURI));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
App.game.multicastSocket.close();
|
||||
|
||||
try {
|
||||
this.callback.execute();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue