diff --git a/src/intents/player/DeleteCharacterIntent.java b/src/intents/player/DeleteCharacterIntent.java new file mode 100644 index 000000000..fb78bbfd6 --- /dev/null +++ b/src/intents/player/DeleteCharacterIntent.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ +package intents.player; + +import resources.control.Intent; +import resources.objects.creature.CreatureObject; + +public class DeleteCharacterIntent extends Intent { + + public static final String TYPE = "DeleteCharacterIntent"; + + private final CreatureObject creature; + + public DeleteCharacterIntent(CreatureObject creature) { + super(TYPE); + this.creature = creature; + } + + public CreatureObject getCreature() { + return creature; + } + +} diff --git a/src/resources/commands/callbacks/QaToolCmdCallback.java b/src/resources/commands/callbacks/QaToolCmdCallback.java index f42290a6b..821e4f30a 100644 --- a/src/resources/commands/callbacks/QaToolCmdCallback.java +++ b/src/resources/commands/callbacks/QaToolCmdCallback.java @@ -28,8 +28,11 @@ package resources.commands.callbacks; import intents.chat.ChatBroadcastIntent; +import intents.network.CloseConnectionIntent; +import intents.player.DeleteCharacterIntent; import resources.commands.ICmdCallback; import resources.objects.SWGObject; +import resources.objects.creature.CreatureObject; import resources.player.Player; import resources.server_info.Log; import resources.sui.ISuiCallback; @@ -39,9 +42,12 @@ import resources.sui.SuiInputBox; import resources.sui.SuiListBox; import resources.sui.SuiMessageBox; import services.galaxy.GalacticManager; +import services.objects.ObjectManager; import java.util.Map; +import network.packets.soe.Disconnect.DisconnectReason; + /** * Created by Waverunner on 8/19/2015 */ @@ -65,6 +71,9 @@ public class QaToolCmdCallback implements ICmdCallback { else displayItemCreator(player); break; case "help": displayHelp(player); break; + case "force-delete": + forceDelete(galacticManager.getObjectManager(), player, target); + break; default: displayMainWindow(player); break; } } else { @@ -111,6 +120,25 @@ public class QaToolCmdCallback implements ICmdCallback { sendSystemMessage(player, "Object has been created and placed in your inventory"); Log.i("QA", "%s created item from template %s", player, template); } + + private void forceDelete(final ObjectManager objManager, final Player player, final SWGObject target) { + SuiMessageBox inputBox = new SuiMessageBox(SuiButtons.OK_CANCEL, "Force Delete?", "Are you sure you want to delete this object?"); + inputBox.addOkButtonCallback("handleDeleteObject", (caller, actor, event, parameters) -> { + if (target instanceof CreatureObject && ((CreatureObject) target).getPlayerObject() != null) { + Log.i("QA", "[%s] Requested deletion of character: %s", player.getUsername(), target.getName()); + new DeleteCharacterIntent((CreatureObject) target).broadcast(); + Player owner = target.getOwner(); + if (owner != null) + new CloseConnectionIntent(owner.getConnectionId(), owner.getNetworkId(), DisconnectReason.APPLICATION).broadcast(); + return; + } + Log.i("QA", "[%s] Requested deletion of object: %s", player.getUsername(), target); + if (target != null) { + objManager.deleteObject(target.getObjectId()); + } + }); + inputBox.display(player); + } private void displayHelp(Player player) { String prompt = "The following are acceptable arguments that can be used as shortcuts to the various QA tools:\n" + diff --git a/src/services/objects/ObjectManager.java b/src/services/objects/ObjectManager.java index 8e9800cf9..d798444b5 100644 --- a/src/services/objects/ObjectManager.java +++ b/src/services/objects/ObjectManager.java @@ -40,6 +40,7 @@ import intents.object.ObjectCreateIntent; import intents.object.ObjectIdRequestIntent; import intents.object.ObjectIdResponseIntent; import intents.object.ObjectTeleportIntent; +import intents.player.DeleteCharacterIntent; import intents.PlayerEventIntent; import intents.RequestZoneInIntent; import intents.network.GalacticPacketIntent; @@ -106,6 +107,7 @@ public class ObjectManager extends Manager { registerForIntent(ObjectTeleportIntent.TYPE); registerForIntent(ObjectIdRequestIntent.TYPE); registerForIntent(ObjectCreateIntent.TYPE); + registerForIntent(DeleteCharacterIntent.TYPE); objectAwareness.initialize(); loadClientObjects(); maxObjectId = 1000000000; // Gets over all the buildouts/snapshots @@ -297,6 +299,8 @@ public class ObjectManager extends Manager { processObjectIdRequestIntent((ObjectIdRequestIntent) i); } else if (i instanceof ObjectCreateIntent) { processObjectCreateIntent((ObjectCreateIntent) i); + } else if (i instanceof DeleteCharacterIntent) { + deleteObject(((DeleteCharacterIntent) i).getCreature().getObjectId()); } } diff --git a/src/services/player/LoginService.java b/src/services/player/LoginService.java index 1e37d9c28..ad63d82f2 100644 --- a/src/services/player/LoginService.java +++ b/src/services/player/LoginService.java @@ -30,6 +30,7 @@ package services.player; import intents.GalacticIntent; import intents.LoginEventIntent; import intents.LoginEventIntent.LoginEvent; +import intents.player.DeleteCharacterIntent; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -62,6 +63,7 @@ import resources.Galaxy; import resources.Race; import resources.Galaxy.GalaxyStatus; import resources.config.ConfigFile; +import resources.control.Intent; import resources.control.Service; import resources.objects.SWGObject; import resources.objects.creature.CreatureObject; @@ -98,6 +100,7 @@ public class LoginService extends Service { @Override public boolean initialize() { + registerForIntent(DeleteCharacterIntent.TYPE); RelationalDatabase local = getLocalDatabase(); getUser = local.prepareStatement("SELECT * FROM users WHERE username = ?"); getUserInsensitive = local.prepareStatement("SELECT * FROM users WHERE username ilike ?"); @@ -108,6 +111,13 @@ public class LoginService extends Service { return super.initialize(); } + @Override + public void onIntentReceived(Intent i) { + if (i instanceof DeleteCharacterIntent) { + deleteCharacter(((DeleteCharacterIntent) i).getCreature().getObjectId()); + } + } + public void handlePacket(GalacticIntent intent, Player player, Packet p) { if (p instanceof SessionRequest) { player.setConnectionId(((SessionRequest)p).getConnectionID());