RMI callback for manage the invitations
This commit is contained in:
parent
cedaf8f009
commit
c54393c2b9
43 changed files with 2060 additions and 556 deletions
|
|
@ -4,9 +4,21 @@ import com.texttwist.client.pages.AuthService;
|
|||
import com.texttwist.client.pages.Home;
|
||||
import com.texttwist.client.pages.MatchService;
|
||||
import com.texttwist.client.pages.SessionService;
|
||||
import com.texttwist.client.services.ClientNotification;
|
||||
import constants.Config;
|
||||
import interfaces.INotificationClient;
|
||||
import interfaces.INotificationServer;
|
||||
import utilities.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
|
|
@ -17,13 +29,34 @@ public class App extends JFrame {
|
|||
public static SessionService sessionService;
|
||||
public static MatchService matchService;
|
||||
|
||||
public App(){
|
||||
public App() throws IOException {
|
||||
setPreferredSize( new Dimension( 640, 480 ));
|
||||
setSize(new Dimension(640,480));
|
||||
setLocation(100,100);
|
||||
setResizable( false );
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
//Definitions of registry for auth
|
||||
long id = Thread.currentThread().getId();
|
||||
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 ClientNotification();
|
||||
INotificationClient stub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0);
|
||||
|
||||
server.registerForCallback(stub);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotBoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Init services
|
||||
authService = new AuthService();
|
||||
sessionService = new SessionService();
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
package com.texttwist.client.constants;
|
||||
|
||||
/**
|
||||
* Created by loke on 15/06/2017.
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
private static String AuthServerURI = "localhost";
|
||||
private static Integer AuthServerPort = 9999;
|
||||
|
||||
public static String GameServerURI = "localhost";
|
||||
public static Integer GameServerPort = 10000;
|
||||
|
||||
|
||||
public static String getAuthServerURI(){
|
||||
return "rmi://".concat(AuthServerURI).concat(":").concat(AuthServerPort.toString());
|
||||
}
|
||||
|
||||
public static String getGameServerURI(){
|
||||
return "tcp://".concat(GameServerURI).concat(":").concat(GameServerPort.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package com.texttwist.client.constants;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class Palette {
|
||||
public static Color root_backgroundColor = new Color(145,181,88);
|
||||
public static Color inputBox_backgroundColor = new Color(250,250,250); //"#FAFAFA;
|
||||
public static Color button_backgroundColor = new Color(105,130,63); //#69823f
|
||||
public static Font inputBox_font = new Font("DK Trained Monkey", Font.BOLD, 26);
|
||||
public static Font password_font = new Font("Arial Black", Font.BOLD, 26);
|
||||
public static Color fontColor = new Color(95,0,0);
|
||||
public static Color registerLblBtn_color = new Color(95,0,0);
|
||||
public static Color registerLblBtn_onmouseover_color = new Color(95,0,0, 127);
|
||||
public static Color registerLblBtn_onmouseclick_color = new Color(53,66,32);
|
||||
public static Color scrollPanel_backgroundColor = new Color(220,229,207);
|
||||
public static Color dialog_alert = Color.red;
|
||||
public static Color dialog_success = new Color(53,66,32);
|
||||
|
||||
|
||||
public static Font button_font = new Font("DK Trained Monkey", Font.BOLD, 30);
|
||||
|
||||
public Palette() {
|
||||
//TODO fetchare dal server questi dati
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.constants.Config;
|
||||
import constants.Config;
|
||||
import interfaces.IAuth;
|
||||
import models.Response;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.pages.*;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListDataListener;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import models.Response;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.constants.Config;
|
||||
import interfaces.IAuth;
|
||||
import constants.Config;
|
||||
import models.Message;
|
||||
import models.Response;
|
||||
import org.json.simple.JsonObject;
|
||||
|
|
@ -10,13 +9,8 @@ import org.json.simple.JsonObject;
|
|||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
/**
|
||||
* Created by loke on 18/06/2017.
|
||||
|
|
@ -33,7 +27,7 @@ public class MatchService {
|
|||
SocketChannel clientSocket = SocketChannel.open(socketAddress);
|
||||
|
||||
|
||||
Message message = new Message("START_GAME", App.sessionService.account.token, userNames);
|
||||
Message message = new Message("START_GAME", App.sessionService.account.userName, App.sessionService.account.token, userNames);
|
||||
|
||||
byte[] byteMessage = new String(message.toString()).getBytes();
|
||||
ByteBuffer buffer = ByteBuffer.wrap(byteMessage);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import models.Response;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.texttwist.client.services;
|
||||
import com.texttwist.client.App;
|
||||
import interfaces.INotificationClient;
|
||||
import models.Response;
|
||||
import utilities.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
/**
|
||||
* Created by loke on 15/06/2017.
|
||||
*/
|
||||
public class ClientNotification implements INotificationClient {
|
||||
|
||||
|
||||
public ClientNotification() throws RemoteException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response sendInvite(String userName, DefaultListModel<String> users) throws RemoteException {
|
||||
Logger.write("Invoked invitation with username=" + userName + "|" + users.toString() );
|
||||
|
||||
if(users.contains(App.sessionService.account.userName)){
|
||||
Logger.write(userName+" ti ha sfidato!");
|
||||
}
|
||||
//Aggiungi alla lista di inviti
|
||||
/* if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
|
||||
if(AccountsManager.getInstance().register(userName, password)){
|
||||
Logger.write("Registration successfull");
|
||||
return new Response("Registration successfull", 200, null);
|
||||
} else {
|
||||
Logger.write("Registration unsuccessfull");
|
||||
return new Response("Registration unsuccessfull: Username exist!", 400, null);
|
||||
}
|
||||
}*/
|
||||
return new Response("Invitation received!", 200, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.pages.Home;
|
||||
import com.texttwist.client.ui.TTContainer;
|
||||
import com.texttwist.client.ui.TTLabel;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package com.texttwist.client.ui;
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -15,14 +15,12 @@ public class TTScrollList extends JList {
|
|||
setBackground(Palette.scrollPanel_backgroundColor);
|
||||
setFont(Palette.inputBox_font);
|
||||
setBounds(position.x, position.y, dimension.width, dimension.height);
|
||||
// setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollPane.setBounds(position.x, position.y, dimension.width, dimension.height);
|
||||
// scrollPane.setMinimumSize(dimension);
|
||||
scrollPane.setBackground(Palette.scrollPanel_backgroundColor);
|
||||
scrollPane.setViewportView(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.pages.MatchSetup;
|
||||
import com.texttwist.client.App;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -24,7 +24,7 @@ public class TTSearchBar extends TTContainer{
|
|||
@Override
|
||||
public Object call() throws Exception {
|
||||
String username = ctx.getText();
|
||||
if(!username.equals("")) {
|
||||
if(!username.equals("") && !username.equals(App.sessionService.account.userName)) {
|
||||
ctx.setText("");
|
||||
list.addElement(username);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue