Commit 8f78310b authored by Toussaint Etienne's avatar Toussaint Etienne
Browse files

Merge branch 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project

* 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project:
  Refresh button+Minor code modifications
parents 78f3db92 705e943b
......@@ -19,27 +19,21 @@ import java.util.ArrayList;
public class LoungeList_SubPanel extends JPanel {
//CODE FROM BoxLayout tutorial, ListDialog.java
private JPanel listPanel;
private static final long serialVersionUID = 1L;
private GraphicsMaster graphicsMaster;
private static GraphicsMaster graphicsMaster;
//by design, we use the same panels forever anyway, so a static variable here is not problematic
private static LoungeList_SubPanel uniqueInstance;
public LoungeList_SubPanel(GraphicsMaster graphicsMaster) {
this.graphicsMaster=graphicsMaster;
uniqueInstance=this;
}
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,graphicsMaster);
listPanel.add(loungePanel);
}
BoxLayout boxLayout = new BoxLayout(listPanel, BoxLayout.Y_AXIS);
listPanel.setLayout(boxLayout);
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(listPanel);
add(scrollPane);
}
public static LoungeList_SubPanel getUniqueInstance() {
return uniqueInstance;
}
public static GraphicsMaster getGraphicsMaster() {
return graphicsMaster;
}
}
......@@ -16,6 +16,7 @@ import network.outershell.RPCClient;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
/**
* Created by dupriez on 05/12/15.
......@@ -32,6 +33,7 @@ public class MultiPlayer_MenuPanel extends MenuPanel {
inputLabel.setForeground(GUIColorsAndFonts.fontColor1);
setTitlePanel("MultiPlayer Thessia");
//addToCentralColumn(ButtonMaker.makeButton("Join Lounge", joinLoungeButton_ActionListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("Refresh Lounges List", refreshGameButton_ActionListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("Create a new game", hostNewGameButton_ActionListener),1,1);
addToCentralColumn(inputLabel,1,1);
addToCentralColumn(new LoungeList_SubPanel(getGraphicsMaster()),1,1);
......@@ -53,6 +55,25 @@ public class MultiPlayer_MenuPanel extends MenuPanel {
}
}
};
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);
}
BoxLayout boxLayout = new BoxLayout(listPanel, BoxLayout.Y_AXIS);
listPanel.setLayout(boxLayout);
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(listPanel);
add(scrollPane);
}
}
};
// private ActionListener joinLoungeButton_ActionListener = new ActionListener() {
// @Override
......
......@@ -19,18 +19,14 @@ public class LoungeServer extends Thread {
@Override
public void run()
{
ServerConnection serverConnection=new ServerConnection(lounge.getPort(),0, true,lounge.MAX_PLAYERS);
ServerConnection serverConnection=new ServerConnection(lounge.getPort(),lounge.MAX_PLAYERS,0);
Logging.getInstance().getLogger().info("Server started second phase, initialization done");
ServerLoop dummyServerLoop=new ServerLoop(serverConnection);
dummyServerLoop.start();
notifyOnIt();
}
public synchronized void notifyOnIt()
{
notify();
}
public synchronized void waitOnIt()
{
try {
......
......@@ -4,6 +4,8 @@ import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
/**
* Instance of NetworkConnection for the server.
......@@ -11,7 +13,12 @@ import java.util.ArrayList;
*/
public class ServerConnection extends NetworkConnection{
static ServerSocket serverSocket=null;
/**
* toNotify Object is used to notify a thread that the ServerConnection constructor is ready to accept clients
*/
private Object toNotify;
private boolean stillRunning=true;
private boolean disableLateJoining=true;
/**
* this parameter gives the maximum number of clients allowed to join late
*/
......@@ -19,10 +26,8 @@ public class ServerConnection extends NetworkConnection{
//this blocking deque stores all the events received from the clients, in a consistent order
//TODO uses the two following variable
/*
private BlockingDeque<NetworkObject> incomingEvents=new LinkedBlockingDeque<>();
private boolean disableLateJoining;
*/
//a list of outgoing client threads
private ArrayList<ClientOutputThread> outputThreads=new ArrayList<>();
......@@ -49,6 +54,12 @@ public class ServerConnection extends NetworkConnection{
return maxNumberOfLateClients;
}
/**
* @return the object which will be notifed when the serverconnection becomes ready
*/
public Object getToNotify() {
return toNotify;
}
private class ServerListeningThread extends Thread{
private ServerConnection parent;
......@@ -92,7 +103,9 @@ public class ServerConnection extends NetworkConnection{
* @param PORT port to communicate for the server
* @param numberOfClients
*/
public ServerConnection(int PORT, int numberOfClients, boolean disableLateJoining, int maxNumberOfLateClients){
public ServerConnection(int PORT, int numberOfClients, int maxNumberOfLateClients){
if (numberOfClients>0)
disableLateJoining=false;
this.maxNumberOfLateClients=maxNumberOfLateClients;
try {
serverSocket=new ServerSocket(PORT);
......
......@@ -37,7 +37,7 @@ public class ServerConnectionTest{
}
public void run(){
server = new ServerConnection(PORT,2,true,0);
server = new ServerConnection(PORT,2,0);
notify();
}
......
......@@ -58,7 +58,7 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
@Override
public synchronized Lounge createLounge(String name) throws RemoteException {
LOGGER.info("Somebody called createLounge method");
LOGGER.info("RPCServer: Somebody called createLounge method");
long genID = generateId();
identifiers.add(genID);
int genPort=generatePort();
......@@ -70,6 +70,7 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
loungeServer.start();
loungeServer.waitOnIt();
//after obtaining the genID the host will immediately launch joinGame
return lounge;
}
......
......@@ -12,7 +12,7 @@ import network.innershell.ServerConnection;
public class DummyServer {
public static void main(String[] args)
{
ServerConnection serverConnection=new ServerConnection(8888,2, true,0);
ServerConnection serverConnection=new ServerConnection(8888,2,0);
Logging.getInstance().getLogger().info("Server started second phase, initialization done");
ServerLoop dummyServerLoop=new ServerLoop(serverConnection);
......
......@@ -16,7 +16,7 @@ public class SimpleTestServer {
public static void main(String[] args)
{
//For the constructor, 8888 is the port and 2 is the number of expected clients
ServerConnection serverConnection=new ServerConnection(8888,2,true,0);
ServerConnection serverConnection=new ServerConnection(8888,2,0);
Logger LOGGER = Logging.getInstance().getLogger();
while (true)
{
......
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