diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ecbec17e76d989acb2837c078e78aa147773205b..242aacae057ccdd35a3523c08fc5dd06d895b79d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,22 @@ <component name="ChangeListManager"> <list default="true" id="688d774d-cfc7-4b0d-b00c-5ca931aba600" name="Default Changelist" comment=""> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain$1.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen$1.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/Client.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/Client.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate$1.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate$Action.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate$Action.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/GUI/ApplicationMain.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/ApplicationMain.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/GUI/StartScreen.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/StartScreen.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/client/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/Client.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/client/ClientUpdate.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/ClientUpdate.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/remote/IClientController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/remote/IClientController.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/remote/IClientUpdate.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/remote/IClientUpdate.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/server/ClientController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/server/ClientController.java" afterDir="false" /> </list> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> @@ -47,7 +62,7 @@ <property name="UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH" value="280" /> <property name="WebServerToolWindowFactoryState" value="false" /> <property name="aspect.path.notification.shown" value="true" /> - <property name="last_opened_file_path" value="$PROJECT_DIR$/out/production/comp90015-dsass2-infinitymonkeys-remaster" /> + <property name="last_opened_file_path" value="$PROJECT_DIR$/../MaxCode/comp90015-dsass2-infinitymonkeys-remaster-mpriymak" /> <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> <property name="nodejs_npm_path_reset_for_default_project" value="true" /> <property name="project.structure.last.edited" value="Project" /> @@ -66,7 +81,7 @@ </list> </option> </component> - <component name="RunManager" selected="Application.Client 3"> + <component name="RunManager" selected="Application.Client2"> <configuration name="Client 3" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="client.Client" /> <module name="infinitymonkeys" /> @@ -120,7 +135,7 @@ <workItem from="1571654347656" duration="27259000" /> <workItem from="1571783604151" duration="19947000" /> <workItem from="1571812296671" duration="25759000" /> - <workItem from="1571879738075" duration="3774000" /> + <workItem from="1571879738075" duration="12110000" /> </task> <task id="LOCAL-00001" summary="Changed the join method to send over a reference of the ClientUpdate Interface"> <created>1571646862883</created> @@ -165,21 +180,6 @@ <component name="XDebuggerManager"> <breakpoint-manager> <breakpoints> - <line-breakpoint enabled="true" type="java-line"> - <url>file://$PROJECT_DIR$/src/GUI/StartScreen.java</url> - <line>38</line> - <option name="timeStamp" value="7" /> - </line-breakpoint> - <line-breakpoint enabled="true" type="java-line"> - <url>file://$PROJECT_DIR$/src/GUI/StartScreen.java</url> - <line>33</line> - <option name="timeStamp" value="8" /> - </line-breakpoint> - <line-breakpoint enabled="true" type="java-line"> - <url>file://$PROJECT_DIR$/src/GUI/StartScreen.java</url> - <line>85</line> - <option name="timeStamp" value="9" /> - </line-breakpoint> <line-breakpoint enabled="true" type="java-line"> <url>file://$PROJECT_DIR$/src/client/Client.java</url> <line>47</line> @@ -192,12 +192,7 @@ </line-breakpoint> <line-breakpoint enabled="true" type="java-line"> <url>file://$PROJECT_DIR$/src/GUI/StartScreen.java</url> - <line>40</line> - <option name="timeStamp" value="12" /> - </line-breakpoint> - <line-breakpoint enabled="true" type="java-line"> - <url>file://$PROJECT_DIR$/src/GUI/StartScreen.java</url> - <line>62</line> + <line>59</line> <option name="timeStamp" value="13" /> </line-breakpoint> </breakpoints> diff --git a/out/production/infinitymonkeys/GUI/ApplicationMain$1.class b/out/production/infinitymonkeys/GUI/ApplicationMain$1.class index 7daf4ebca183d7e6b8e4d39d2c016bd7d6e98c54..b1b7ffb50fadd02566fe4a67e2f639737ee986eb 100644 Binary files a/out/production/infinitymonkeys/GUI/ApplicationMain$1.class and b/out/production/infinitymonkeys/GUI/ApplicationMain$1.class differ diff --git a/out/production/infinitymonkeys/GUI/ApplicationMain.class b/out/production/infinitymonkeys/GUI/ApplicationMain.class index f574ba2a0ddbc65b154bb66511c1bda548cbe2d1..b7c68a450c8b41db7a5ea3ee16997af0e61b8b6a 100644 Binary files a/out/production/infinitymonkeys/GUI/ApplicationMain.class and b/out/production/infinitymonkeys/GUI/ApplicationMain.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen$1.class b/out/production/infinitymonkeys/GUI/StartScreen$1.class index f0ec3f4e26dd97aeef8b7b8b07905b0ca5fef5a5..0e33ae80ec6d5ad317fe34d7a81de97737a9c7ec 100644 Binary files a/out/production/infinitymonkeys/GUI/StartScreen$1.class and b/out/production/infinitymonkeys/GUI/StartScreen$1.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen$2.class b/out/production/infinitymonkeys/GUI/StartScreen$2.class new file mode 100644 index 0000000000000000000000000000000000000000..99249c7c0c083b5b04dcfe1b9535dc0a2207753e Binary files /dev/null and b/out/production/infinitymonkeys/GUI/StartScreen$2.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen.class b/out/production/infinitymonkeys/GUI/StartScreen.class index 1d786d989283babc6b573dafa0a7e900807ee030..6226aebe17cfba88b63cd0d2961a3cb076cc4561 100644 Binary files a/out/production/infinitymonkeys/GUI/StartScreen.class and b/out/production/infinitymonkeys/GUI/StartScreen.class differ diff --git a/out/production/infinitymonkeys/client/Client.class b/out/production/infinitymonkeys/client/Client.class index 7fea52fe06f8c6079c81f2fc781b3f2678e09aa6..3af763b9e570a46a5dd0509c235b098a294c9582 100644 Binary files a/out/production/infinitymonkeys/client/Client.class and b/out/production/infinitymonkeys/client/Client.class differ diff --git a/out/production/infinitymonkeys/client/ClientUpdate$1.class b/out/production/infinitymonkeys/client/ClientUpdate$1.class index 1b1e4c50ab7b86ddfde6170006a51b4f94794531..e1872428e89b4af9c22e38f5a2aaf1a8f3fb5bd3 100644 Binary files a/out/production/infinitymonkeys/client/ClientUpdate$1.class and b/out/production/infinitymonkeys/client/ClientUpdate$1.class differ diff --git a/out/production/infinitymonkeys/client/ClientUpdate.class b/out/production/infinitymonkeys/client/ClientUpdate.class index 11926f3376c5f6523f889328cbc88369ea2c2a5a..2901f95ac1e068187f468f14edf6ba575cb7dd31 100644 Binary files a/out/production/infinitymonkeys/client/ClientUpdate.class and b/out/production/infinitymonkeys/client/ClientUpdate.class differ diff --git a/out/production/infinitymonkeys/remote/IClientController$Action.class b/out/production/infinitymonkeys/remote/IClientController$Action.class index 035ddf1381adff501a6e806d89ed427882488ad0..b4c2cef704873af62401e4a1eb634a818a4d812d 100644 Binary files a/out/production/infinitymonkeys/remote/IClientController$Action.class and b/out/production/infinitymonkeys/remote/IClientController$Action.class differ diff --git a/out/production/infinitymonkeys/remote/IClientController.class b/out/production/infinitymonkeys/remote/IClientController.class index d438a291276cb8f60071c2bb1916a305991156c4..c3a87022f98ebf44dd8f90e2565327e5e9452c87 100644 Binary files a/out/production/infinitymonkeys/remote/IClientController.class and b/out/production/infinitymonkeys/remote/IClientController.class differ diff --git a/out/production/infinitymonkeys/remote/IClientUpdate$Action.class b/out/production/infinitymonkeys/remote/IClientUpdate$Action.class index 92cdbe3fe1704265461317700f5d956ea36eb145..dd382481d4ab540e1f2e62b16ff37ddabd2cb284 100644 Binary files a/out/production/infinitymonkeys/remote/IClientUpdate$Action.class and b/out/production/infinitymonkeys/remote/IClientUpdate$Action.class differ diff --git a/out/production/infinitymonkeys/remote/IClientUpdate.class b/out/production/infinitymonkeys/remote/IClientUpdate.class index cf1adf4c123b7ac99404efbeece8fb67c6d819de..7d8923621a39f42b6628c674a2a110f8b54dd03d 100644 Binary files a/out/production/infinitymonkeys/remote/IClientUpdate.class and b/out/production/infinitymonkeys/remote/IClientUpdate.class differ diff --git a/out/production/infinitymonkeys/server/ClientController.class b/out/production/infinitymonkeys/server/ClientController.class index 11839990a93f1c085e7afdc6628bb834a5e92355..2315795d340fb1296adc56bf6a7e5860ba62bebf 100644 Binary files a/out/production/infinitymonkeys/server/ClientController.class and b/out/production/infinitymonkeys/server/ClientController.class differ diff --git a/src/GUI/ApplicationMain.java b/src/GUI/ApplicationMain.java index 58707caf79c7cfe859da6f8e558f479e5585184b..7aec01f2fa8f9a57563a1ce43c946c33b8a52223 100644 --- a/src/GUI/ApplicationMain.java +++ b/src/GUI/ApplicationMain.java @@ -108,8 +108,10 @@ public class ApplicationMain extends JPanel { if (client.getUserName().equals(client.getClientController().getAdmin())) { int terminateAppAnswer = showManagerQuitMessage(); + // If the manager terminates the application if (terminateAppAnswer == 0) { - + client.getClientController().kickAll(client.getUserName()); + exitApplication(); } else if (terminateAppAnswer == 1) { int answer = showNextManagerMessage(); @@ -159,6 +161,7 @@ public class ApplicationMain extends JPanel { } public void exitApplication(){ + System.out.println("I am in exit application"); frame.setVisible(false); frame.dispose(); client.setVisibleStartScreen(); diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 8d44b481540bb10a147d5212060d78bd2a08a64c..8b09ec33810041f2efc6da4477713c1d61c21d46 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -3,8 +3,7 @@ package GUI; import client.Client; import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.event.*; public class StartScreen { @@ -13,6 +12,9 @@ public class StartScreen { private JTextField textField1; private JButton joinButton; private JTextField textField2; + private boolean kickedOut; + private boolean appTerminated; + JFrame frame; private Client client; @@ -22,11 +24,6 @@ public class StartScreen { this.client = client; } -// public static void main(String[] args) { -// new StartScreen().go(); -// } - - ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) @@ -75,6 +72,8 @@ public class StartScreen { }; + + public static void showErrorMessage(String message) { JOptionPane.showMessageDialog(null, @@ -89,9 +88,41 @@ public class StartScreen { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); + + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent e) { + if (isAppTerminated()){ + showKickAllMessage(); + setAppTerminated(false); + } + } + }); } public void setVisible(){ frame.setVisible(true); } + + public void setKickedOut(boolean kickedOut) { + this.kickedOut = kickedOut; + } + + public void setAppTerminated(boolean appTerminated) { + this.appTerminated = appTerminated; + } + + public boolean isKickedOut() { + return kickedOut; + } + + public boolean isAppTerminated() { + return appTerminated; + } + + public void showKickAllMessage() { + JOptionPane.showMessageDialog(null, + "The manager terminated the application", "Application terminated", + JOptionPane.ERROR_MESSAGE); + } } diff --git a/src/client/Client.java b/src/client/Client.java index 1f7b2856a6397c432b08042292ad611db1a8d63b..a3b23c6b153ee5a0cc1f0fb4d65936b65b80e846 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -83,6 +83,10 @@ public class Client public IDrawingController getDrawingController() { return drawingController; } + public StartScreen getStartScreen() { + return startScreen; + } + public Client(String username) throws RemoteException { diff --git a/src/client/ClientUpdate.java b/src/client/ClientUpdate.java index 32d91daea88adc39a789f14979f989eeb5d62bc8..89c77fe7f7360b989e4c34a376a4d82fc88ae7b1 100644 --- a/src/client/ClientUpdate.java +++ b/src/client/ClientUpdate.java @@ -84,8 +84,7 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate, } @Override - public int notifyManagerActions(String toClient, Action action) throws RemoteException { - int outcome = 0; + public void notifyManagerActions(String toClient, Action action) throws RemoteException { switch (action) { case KICKOUT: client.getChatScreen().getChatDisplayBox().append(toClient + " has been kicked out by the manager.\n"); @@ -93,9 +92,9 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate, case ASSIGNADMIN: client.getChatScreen().getChatDisplayBox().append(toClient + " is the new manager.\n"); break; - case MANAGERQUIT: - outcome = client.getApplicationMain().showManagerQuitMessage(); + case KICKALL: + client.getStartScreen().setAppTerminated(true); + client.getApplicationMain().exitApplication(); } - return outcome; } } diff --git a/src/remote/IClientController.java b/src/remote/IClientController.java index 349297d37ca18e26184c87e1d7754b5299718340..27fc06bfdc0cd939c9fbf59af87cbbf18938a376 100644 --- a/src/remote/IClientController.java +++ b/src/remote/IClientController.java @@ -5,7 +5,7 @@ import java.rmi.RemoteException; public interface IClientController extends Remote { - enum Action {KICKOUT, ASSIGNADMIN}; + enum Action {KICKOUT, ASSIGNADMIN, KICKALL}; boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException; @@ -17,5 +17,7 @@ public interface IClientController extends Remote boolean broadcastManagerMessage(String toClient, Action action) throws RemoteException; + void kickAll(String manager) throws RemoteException; + String getAdmin() throws RemoteException; } diff --git a/src/remote/IClientUpdate.java b/src/remote/IClientUpdate.java index 853ce0908a0d46bc152d93f548b9458f4d4010b5..3788bd2810f5cf17dd822be3dc4a45f2b308ca4e 100644 --- a/src/remote/IClientUpdate.java +++ b/src/remote/IClientUpdate.java @@ -6,10 +6,10 @@ import java.rmi.RemoteException; public interface IClientUpdate extends Remote, Serializable { - enum Action {KICKOUT, ASSIGNADMIN, MANAGERQUIT}; + enum Action {KICKOUT, ASSIGNADMIN, KICKALL}; boolean updateUserList(String[] users) throws RemoteException; void terminateChat() throws RemoteException; - int notifyManagerActions(String toClient, Action action) throws RemoteException; + void notifyManagerActions(String toClient, Action action) throws RemoteException; void setVisibility() throws RemoteException; } diff --git a/src/server/ClientController.java b/src/server/ClientController.java index 2ebfe48fcd540f0b201beecc1050253624d2e17f..392e6a725cdc381253ee5c1e4463c287c0c9ef7b 100644 --- a/src/server/ClientController.java +++ b/src/server/ClientController.java @@ -201,20 +201,22 @@ public class ClientController extends UnicastRemoteObject implements IClientCont return true; } - public void kickAllUsers (String manager) { + @Override + public void kickAll (String manager) throws RemoteException { int adminIndex = getUserIndex(manager); IClientUpdate client; + String toClient; if ( server.users.get(adminIndex).isAdmin() ) { - for( User u : server.users ) { client = u.getIClientUpdate(); - client.notifyManagerActions(toClient, remote.IClientUpdate.Action.ASSIGNADMIN); - client.setVisibility(); + toClient = u.getUserName(); + client.notifyManagerActions(toClient, remote.IClientUpdate.Action.KICKALL); } + server.users.clear(); } else { System.out.println("You are not the manager");