From 9c14a1629d9a37c8ca9209446dfdc61e1a5054d0 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Sun, 18 Jan 2015 15:18:19 -0500 Subject: [PATCH] Added ServerManagementIntent, Updated /server command to broadcast management intents, Added "Unban Player" to Server Management window --- src/intents/ServerManagementIntent.java | 32 ++++++++++ .../commands/callbacks/ServerCmdCallback.java | 63 ++++++++++++++----- src/resources/player/PlayerEvent.java | 4 +- src/resources/sui/SuiListBox.java | 4 ++ src/resources/sui/SuiMessageBox.java | 17 +++++ 5 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 src/intents/ServerManagementIntent.java diff --git a/src/intents/ServerManagementIntent.java b/src/intents/ServerManagementIntent.java new file mode 100644 index 000000000..10607e90f --- /dev/null +++ b/src/intents/ServerManagementIntent.java @@ -0,0 +1,32 @@ +package intents; + +import resources.control.Intent; +import resources.player.Player; + +public class ServerManagementIntent extends Intent { + public static final String TYPE = "PlayerEventIntent"; + + private Player player; + private String target; + private ServerManagementEvent event; + + public ServerManagementIntent(Player p, String target, ServerManagementEvent event) { + super(TYPE); + this.player = p; + this.target = target; + this.event = event; + } + + public Player getPlayer() { return player; } + public String getTarget() { return target; } + public ServerManagementEvent getEvent() { return event; } + + public enum ServerManagementEvent { + LOCK, + UNLOCK, + SHUTDOWN, + KICK, + BAN, + UNBAN + } +} diff --git a/src/resources/commands/callbacks/ServerCmdCallback.java b/src/resources/commands/callbacks/ServerCmdCallback.java index 4d971a27f..0ea5f5176 100644 --- a/src/resources/commands/callbacks/ServerCmdCallback.java +++ b/src/resources/commands/callbacks/ServerCmdCallback.java @@ -1,5 +1,8 @@ package resources.commands.callbacks; +import intents.ServerManagementIntent; +import intents.ServerManagementIntent.ServerManagementEvent; + import java.util.List; import resources.commands.ICmdCallback; @@ -10,6 +13,8 @@ import resources.sui.SuiInputBox; import resources.sui.SuiInputBox.InputBoxType; import resources.sui.SuiListBox; import resources.sui.SuiListBox.ListBoxType; +import resources.sui.SuiMessageBox; +import resources.sui.SuiMessageBox.MessageBoxType; import services.objects.ObjectManager; public class ServerCmdCallback implements ICmdCallback { @@ -18,9 +23,10 @@ public class ServerCmdCallback implements ICmdCallback { public void execute(ObjectManager objManager, Player player, SWGObject target, String args) { SuiListBox listBox = new SuiListBox(player, ListBoxType.OK_CANCEL, "Server Management", "Select the management function you wish to perform from the list."); - listBox.addListItem("Shutdown Server", 0); - listBox.addListItem("Kick Player", 1); - listBox.addListItem("Ban Player", 2); + listBox.addListItem("Kick Player", 0); + listBox.addListItem("Ban Player", 1); + listBox.addListItem("Unban Player", 2); + listBox.addListItem("Shutdown Server", 3); listBox.addItemSelectionCallback(0, new ServerSuiCallback()); @@ -34,27 +40,24 @@ public class ServerCmdCallback implements ICmdCallback { int selection = SuiListBox.getSelectedIndex(returnParams); switch(selection) { - case 0: handleShutdownServer(); break; - case 1: handleKickPlayer(player); break; - case 2: handleBanPlayer(player); break; + case 0: handleKickPlayer(player); break; + case 1: handleBanPlayer(player); break; + case 2: handleUnbanPlayer(player); break; + case 3: handleShutdownServer(player); break; default: break; } } - - private void handleShutdownServer() { - // TODO: initiate server shutdown - } - + private void handleKickPlayer(Player actor) { SuiInputBox window = new SuiInputBox(actor, InputBoxType.OK_CANCEL, "Kick Player", "Enter the name of the player that you wish to KICK from the server."); window.addInputTextCallback(0, new ISuiCallback() { @Override public void handleEvent(Player player, SWGObject actor, int eventType, List returnParams) { - //String name = returnParams.get(0); // input - // TODO: Kick the player that has name entered + String name = returnParams.get(0); // input + new ServerManagementIntent(player, name, ServerManagementEvent.KICK).broadcast(); } - }); + window.display(); } @@ -63,10 +66,38 @@ public class ServerCmdCallback implements ICmdCallback { window.addInputTextCallback(0, new ISuiCallback() { @Override public void handleEvent(Player player, SWGObject actor, int eventType, List returnParams) { - //String name = returnParams.get(0); // input - // TODO: Ban the player that has name entered + String name = returnParams.get(0); // input + new ServerManagementIntent(player, name, ServerManagementEvent.BAN).broadcast(); } }); + + window.display(); + } + + private void handleUnbanPlayer(Player actor) { + SuiInputBox window = new SuiInputBox(actor, InputBoxType.OK_CANCEL, "Unban Player", "Enter the name of the player that you wish to UNBAN from the server."); + window.addInputTextCallback(0, new ISuiCallback() { + + @Override + public void handleEvent(Player player, SWGObject actor, int eventType, List returnParams) { + String name = returnParams.get(0); + new ServerManagementIntent(player, name, ServerManagementEvent.UNBAN).broadcast(); + } + }); + + window.display(); + } + + private void handleShutdownServer(Player actor) { + SuiMessageBox window = new SuiMessageBox(actor, MessageBoxType.YES_NO, "Shutdown Server", "Are you sure you wish to begin the shutdown sequence?"); + window.addOkButtonCallback(0, new ISuiCallback() { + + @Override + public void handleEvent(Player player, SWGObject actor, int eventType, List returnParams) { + new ServerManagementIntent(player, null, ServerManagementEvent.SHUTDOWN).broadcast(); + } + }); + window.display(); } } diff --git a/src/resources/player/PlayerEvent.java b/src/resources/player/PlayerEvent.java index 4b1eac8b0..edf06c393 100644 --- a/src/resources/player/PlayerEvent.java +++ b/src/resources/player/PlayerEvent.java @@ -5,6 +5,6 @@ public enum PlayerEvent { PE_CREATE_CHARACTER, PE_ZONE_IN, PE_LOGGED_OUT, - PE_DISAPPEAR - + PE_DISAPPEAR, + PE_SERVER_KICKED } diff --git a/src/resources/sui/SuiListBox.java b/src/resources/sui/SuiListBox.java index 12fb25a10..cf0ed52cc 100644 --- a/src/resources/sui/SuiListBox.java +++ b/src/resources/sui/SuiListBox.java @@ -43,6 +43,10 @@ public class SuiListBox extends SuiBaseWindow { list.add(item); } + public void addListItem(String name) { + addListItem(name, 0); + } + public void addItemSelectionCallback(int eventId, ISuiCallback callback) { List returnList = new ArrayList(); returnList.add("List.lstList:SelectedRow"); diff --git a/src/resources/sui/SuiMessageBox.java b/src/resources/sui/SuiMessageBox.java index f9689cd01..ce4eaa50e 100644 --- a/src/resources/sui/SuiMessageBox.java +++ b/src/resources/sui/SuiMessageBox.java @@ -1,5 +1,8 @@ package resources.sui; +import java.util.ArrayList; +import java.util.List; + import resources.player.Player; public class SuiMessageBox extends SuiBaseWindow { @@ -32,6 +35,20 @@ public class SuiMessageBox extends SuiBaseWindow { this(owner, MessageBoxType.OK_CANCEL, title, prompt); } + public void addOkCancelButtonsCallback(int okEventId, int cancelEventId, ISuiCallback callback) { + List returnParams = new ArrayList(); + returnParams.add("btnOk:Text"); + returnParams.add("btnCancel:Text"); + addCallback(okEventId, "", Trigger.OK, returnParams, callback); + addCallback(cancelEventId, "", Trigger.CANCEL, returnParams, callback); + } + + public void addOkButtonCallback(int eventId, ISuiCallback callback) { + List returnParams = new ArrayList(); + returnParams.add("btnOk:Text"); + addCallback(eventId, "", Trigger.OK, returnParams, callback); + } + public enum MessageBoxType { OK, OK_CANCEL,