Commit 63eb0613 authored by Bogdan's avatar Bogdan

Connection Lost Panels work properly now...at least for the RMI server.

parent 6bda3207
......@@ -159,7 +159,7 @@ public class DummyLocalGameLoop extends Thread{
}
else {
try {
sleep(10);
sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
......
......@@ -15,7 +15,7 @@ import graphics.guiSkeleton.guiPanel.menuPanel.multiPlayer_MenuPanel.MultiPlayer
import graphics.guiSkeleton.guiPanel.menuPanel.multiPlayer_MenuPanel.SeverCreatedPanel;
import graphics.guiSkeleton.inputManagement.MainFrameKeyListener;
import graphics.ingame_input_listener.InputConfiguration;
import ingame_programming.IGPpanel;
//import ingame_programming.IGPpanel;
import javax.swing.*;
......@@ -48,7 +48,7 @@ public class GraphicsMaster extends GraphicsMasterAbstraction {
mapGUIStatesToGUIPanel.put(GUIStates.SINGLEPLAYER_MENU, new SinglePlayer_MenuPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.MULTIPLAYER_MENU, new MultiPlayer_MenuPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.INPUT_CONFIG_PANEL, new ConfigurationPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.IGP_PANEL, new IGPpanel(this));
// mapGUIStatesToGUIPanel.put(GUIStates.IGP_PANEL, new IGPpanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.LOUNGE, new LoungePanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.MULTIPLAYER_GAME_CREATION, new MultiPlayer_GameCreationPanel(this));
......
......@@ -12,6 +12,9 @@ import network.outer_shell.server.RPCServer;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
/**
* Created by bogdanbear on 04/01/2016.
......@@ -38,11 +41,17 @@ public class ServerAddressPanel extends MenuPanel{
private ActionListener confirmButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String address=addressTextField.getText();
RPCClient.setIp(address);
//it should start RPC calls
DummyLocalGameLoop.getInstance().setShouldRPC(true);
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MULTIPLAYER_MENU);
try {
String address = addressTextField.getText();
RPCClient.setIp(address);
//it should start RPC calls
DummyLocalGameLoop.getInstance().setShouldRPC(true);
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MULTIPLAYER_MENU);
RPCClient.connect();
}
catch (RemoteException |MalformedURLException |NotBoundException e1) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.LOST_CONNECTION);
}
}
};
......
......@@ -16,6 +16,9 @@ import network.outer_shell.RPCClient;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
/**
......@@ -46,37 +49,47 @@ public class MultiPlayer_MenuPanel extends MenuPanel {
private ActionListener hostNewGameButton_ActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Lounge lounge=RPCClient.createLounge("test");
if (lounge!=null) {
//there have been no errors in lounge creation
RPCClient.joinLounge(lounge.getLoungeID());
GameStarter.startGameMultiplayerPlayer(RPCClient.getIp(),lounge.getPort());
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.PLEASE_WAIT);
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
try{
Lounge lounge=RPCClient.createLounge("test");
if (lounge!=null) {
//there have been no errors in lounge creation
RPCClient.joinLounge(lounge.getLoungeID());
GameStarter.startGameMultiplayerPlayer(RPCClient.getIp(),lounge.getPort());
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.PLEASE_WAIT);
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
}
}
catch (RemoteException |MalformedURLException |NotBoundException e1) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.LOST_CONNECTION);
}
}
};
private ActionListener refreshGameButton_ActionListener=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPanel listPanel=new JPanel();
ArrayList<Lounge> lounges = RPCClient.getLoungeList();
if (lounges!=null) {
for (Lounge lounge : lounges) {
JPanel loungePanel = PickLoungeSubPanelFactory.createPickLoungeSubPanel(lounge.getName() + " " + (lounge.MAX_PLAYERS - lounge.numberFreeSpots()) + "/" + lounge.MAX_PLAYERS, lounge,LoungeList_SubPanel.getGraphicsMaster());
listPanel.add(loungePanel);
try {
JPanel listPanel = new JPanel();
ArrayList<Lounge> lounges = RPCClient.getLoungeList();
if (lounges != null) {
for (Lounge lounge : lounges) {
JPanel loungePanel = PickLoungeSubPanelFactory.createPickLoungeSubPanel(lounge.getName() + " " + (lounge.MAX_PLAYERS - lounge.numberFreeSpots()) + "/" + lounge.MAX_PLAYERS, lounge, LoungeList_SubPanel.getGraphicsMaster());
listPanel.add(loungePanel);
}
BoxLayout boxLayout = new BoxLayout(listPanel, BoxLayout.Y_AXIS);
listPanel.setLayout(boxLayout);
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(listPanel);
add(scrollPane);
}
BoxLayout boxLayout = new BoxLayout(listPanel, BoxLayout.Y_AXIS);
listPanel.setLayout(boxLayout);
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(listPanel);
add(scrollPane);
LoungeList_SubPanel.getUniqueInstance().removeAll();
LoungeList_SubPanel.getUniqueInstance().add(listPanel);
LoungeList_SubPanel.getUniqueInstance().revalidate();
LoungeList_SubPanel.getUniqueInstance().repaint();
}
catch (RemoteException |MalformedURLException |NotBoundException e1) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.LOST_CONNECTION);
}
LoungeList_SubPanel.getUniqueInstance().removeAll();
LoungeList_SubPanel.getUniqueInstance().add(listPanel);
LoungeList_SubPanel.getUniqueInstance().revalidate();
LoungeList_SubPanel.getUniqueInstance().repaint();
}
};
......
......@@ -12,6 +12,9 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
/**
* Created by bogdanbear on 04/01/2016.
......@@ -41,17 +44,20 @@ public class PickLoungeSubPanelFactory {
}
@Override
public void actionPerformed(ActionEvent e) {
try {
if (RPCClient.joinLounge(lounge.getLoungeID()))
{
graphicsMaster.changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.PLEASE_WAIT);
Logging.getInstance().getLogger().info("PickLoungeSubPanel in the PickLoungeSubPanelFactory: server gives green light. Initiate join...");
GameStarter.startGameMultiplayerPlayer(RPCClient.getIp(),lounge.getPort());
graphicsMaster.changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
graphicsMaster.changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
}
else{
Logging.getInstance().getLogger().warning("PickLoungeSubPanel in the PickLoungeSubPanelFactory: join failed");
}
} catch (RemoteException|MalformedURLException|NotBoundException e1) {
graphicsMaster.changeGUIStateTo(GraphicsMaster.GUIStates.LOST_CONNECTION);
}
}
}
......
......@@ -69,14 +69,16 @@ public class ClientInputThread extends Thread {
if (serverside==false) {
EndEvent endEvent = new EndEvent();
parent.addIncomingEvent(endEvent);
//parent.setBroken(true);
//we are allowed to do the following on the client side
parent.setBroken(true);
}
} catch (EOFException e2){
//this is here because of the client thread, see above
LOGGER.info("A socket has been closed on the other end, corresponding thread is useless and ends its life");
EndEvent endEvent=new EndEvent();
parent.addIncomingEvent(endEvent);
//parent.setBroken(true);
if (!serverside)
parent.setBroken(true);
} catch(ClassNotFoundException e1){
//this is needed in order to correctly transmit objects through the network - both server and client must contain class definitions
LOGGER.warning("Problem with package inclusions");
......
......@@ -26,35 +26,23 @@ public class RPCClient {
* @param loungeName
* @return a Lounge object which contains all the parameters that define a lounge
*/
public static Lounge createLounge(String loungeName)
{
public static Lounge createLounge(String loungeName) throws RemoteException, MalformedURLException, NotBoundException {
long id=0;
try {
RegisterInterface registrar = (RegisterInterface) Naming.lookup("//" + ip + ":" + port + "/Registrar");
Lounge resultLounge=registrar.createLounge(loungeName);
resultLounge.addPlayer();
return resultLounge;
} catch (NotBoundException |MalformedURLException |RemoteException e) {
e.printStackTrace();
}
return null;
RegisterInterface registrar = (RegisterInterface) Naming.lookup("//" + ip + ":" + port + "/Registrar");
Lounge resultLounge=registrar.createLounge(loungeName);
resultLounge.addPlayer();
return resultLounge;
}
/**
* this method has been used for testing to check that connections are made correctly
*/
public static void connect()
{
LOGGER.info("RPCClient: Start test");
try {
registrar = (RegisterInterface) Naming.lookup("//"+ip+":"+port+"/Registrar");
LOGGER.info("RPCClient: Lookup finished, begin testing");
registrar.test();
LOGGER.info("RPCClient: Success");
} catch (Exception e) {
LOGGER.warning("RPCClient: Client exception: " + e);
}
public static void connect() throws RemoteException, NotBoundException, MalformedURLException {
LOGGER.info("RPCClient: Start test to //"+ip+" "+port);
registrar = (RegisterInterface) Naming.lookup("//"+ip+":"+port+"/Registrar");
LOGGER.info("RPCClient: Lookup finished, begin testing");
registrar.test();
LOGGER.info("RPCClient: Success");
}
/**
......@@ -63,34 +51,21 @@ public class RPCClient {
* @return a boolean representing whether the operation has been accepted by the server and we are allowed to join
* the game or not
*/
public static boolean joinLounge(long id)
{
try {
RegisterInterface registrar=(RegisterInterface) Naming.lookup("//"+ip+":"+port+"/Registrar");
boolean lever=registrar.joinLounge(id);
return lever;
} catch (NotBoundException|MalformedURLException|RemoteException e) {
e.printStackTrace();
}
return false;
public static boolean joinLounge(long id) throws RemoteException, MalformedURLException, NotBoundException {
RegisterInterface registrar=(RegisterInterface) Naming.lookup("//"+ip+":"+port+"/Registrar");
boolean lever=registrar.joinLounge(id);
return lever;
}
/**
* method used to grab the lounge list from the server, will be used by the gui to display available rooms
* @return an arraylist of all the lounges which are waiting for new players
*/
public static ArrayList<Lounge> getLoungeList()
{
try {
registrar = (RegisterInterface) Naming.lookup("//"+ip+":"+port+"/Registrar");
ArrayList<Lounge> allLounges=registrar.getWaiting();
//LoungeList=allLounges;
return allLounges;
} catch (Exception e) {
LOGGER.warning("RPCClient: Client exception: " + e);
}
return null;
public static ArrayList<Lounge> getLoungeList() throws RemoteException, NotBoundException, MalformedURLException {
registrar = (RegisterInterface) Naming.lookup("//"+ip+":"+port+"/Registrar");
ArrayList<Lounge> allLounges=registrar.getWaiting();
//LoungeList=allLounges;
return allLounges;
}
public static String getIp() { return ip; }
......
......@@ -60,7 +60,6 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
@Override
public synchronized void test() throws RemoteException {
Logging.getInstance().getLogger().info("A client has invoked the test method");
//test signals that there is a client connected, therefore we will create a robot in case the server is empty
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment