From 2969ca846a9488e73e2de8bcf3086d14b26dff62 Mon Sep 17 00:00:00 2001
From: 1004268 <isaac.pedrozaaguirre@student.unimelb.edu.au>
Date: Thu, 24 Oct 2019 14:29:09 +1100
Subject: [PATCH] Admin functions changes

---
 .idea/workspace.xml              | 30 +----------------------
 src/GUI/ApplicationMain.java     | 41 +++++++++++++++++++++++++-------
 src/server/ClientController.java | 21 ++++++++++++++++
 3 files changed, 54 insertions(+), 38 deletions(-)

diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index dee474e..ecbec17 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,37 +2,8 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="688d774d-cfc7-4b0d-b00c-5ca931aba600" name="Default Changelist" comment="">
-      <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
       <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/ChatScreen$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen$1.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$1.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$Mode.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$Mode.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI$1.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI.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/client/DrawingUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/DrawingUpdate.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/remote/IDrawingController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingController.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingUpdate.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController$1.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$/out/production/infinitymonkeys/server/DrawingController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/DrawingController.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/ChatScreen.form" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/ChatScreen.form" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/GUI/ChatScreen.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/ChatScreen.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/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" />
@@ -149,6 +120,7 @@
       <workItem from="1571654347656" duration="27259000" />
       <workItem from="1571783604151" duration="19947000" />
       <workItem from="1571812296671" duration="25759000" />
+      <workItem from="1571879738075" duration="3774000" />
     </task>
     <task id="LOCAL-00001" summary="Changed the join method to send over a reference of the ClientUpdate Interface">
       <created>1571646862883</created>
diff --git a/src/GUI/ApplicationMain.java b/src/GUI/ApplicationMain.java
index 02ba6bc..58707ca 100644
--- a/src/GUI/ApplicationMain.java
+++ b/src/GUI/ApplicationMain.java
@@ -8,6 +8,7 @@ import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.rmi.RemoteException;
 import java.util.ArrayList;
+import java.util.Random;
 
 public class ApplicationMain extends JPanel {
     private Client client;
@@ -25,7 +26,14 @@ public class ApplicationMain extends JPanel {
 
     public int showManagerQuitMessage() {
         int answer = JOptionPane.showConfirmDialog(null,
-                "Before closing the application for everyone, do you want to give manager permissions to another user?",
+                "Do you want to terminate the application for all the users?",
+                "Close the application", JOptionPane.YES_NO_CANCEL_OPTION);
+        return answer;
+    }
+
+    public int showNextManagerMessage() {
+        int answer = JOptionPane.showConfirmDialog(null,
+                "Before leaving, do you want to choose the next manager manually?",
                 "Close the application", JOptionPane.YES_NO_CANCEL_OPTION);
         return answer;
     }
@@ -99,16 +107,31 @@ public class ApplicationMain extends JPanel {
                 try {
                     if (client.getUserName().equals(client.getClientController().getAdmin())) {
 
-                        int answer = showManagerQuitMessage();
-                        if (answer == 0) {
-                            String newManager = showAssignManagerMessage();
-                            client.getClientController().assignAdmin(client.getUserName(), newManager);
-                            client.getClientController().quit(client.getUserName());
-                            exitApplication();
+                        int terminateAppAnswer = showManagerQuitMessage();
+                        if (terminateAppAnswer == 0) {
+
                         }
-                        if (answer == 1) {
-                            exitApplication();
+                        else if (terminateAppAnswer == 1) {
+                            int answer = showNextManagerMessage();
+                            // If the manager wants to assign the next manager manually
+                            if (answer == 0) {
+                                String newManager = showAssignManagerMessage();
+                                client.getClientController().assignAdmin(client.getUserName(), newManager);
+                                client.getClientController().quit(client.getUserName());
+                                exitApplication();
+                            }
+                            // If the manager wants to assign the next manager by random choice
+                            if (answer == 1) {
+                                int numUsers = client.getChatScreen().getKickUserComboBox().getItemCount();
+                                Random random = new Random();
+                                int randomUserIndex = random.nextInt(numUsers);
+                                String newManager = client.getChatScreen().getKickUserComboBox().getItemAt(randomUserIndex).toString();
+                                client.getClientController().assignAdmin(client.getUserName(), newManager);
+                                client.getClientController().quit(client.getUserName());
+                                exitApplication();
+                            }
                         }
+
                     }
                     else {
                         int reply = JOptionPane.showConfirmDialog(null,
diff --git a/src/server/ClientController.java b/src/server/ClientController.java
index 3272d27..2ebfe48 100644
--- a/src/server/ClientController.java
+++ b/src/server/ClientController.java
@@ -200,4 +200,25 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
 
         return true;
     }
+
+    public void kickAllUsers (String manager) {
+
+        int adminIndex = getUserIndex(manager);
+        IClientUpdate client;
+
+        if ( server.users.get(adminIndex).isAdmin() )
+        {
+
+            for( User u : server.users )
+            {
+                client = u.getIClientUpdate();
+                client.notifyManagerActions(toClient, remote.IClientUpdate.Action.ASSIGNADMIN);
+                client.setVisibility();
+            }
+        }
+        else {
+            System.out.println("You are not the manager");
+        }
+
+    }
 }
-- 
GitLab