From 2125f07b1e4ebdfc95f0bb46e86ad3562b8debfe Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 15 May 2016 11:51:54 +0200 Subject: [PATCH 1/5] Added biography request responses and setting biography --- scripts/commands/generic/setBiography.js | 6 ++ .../object_controller/BiographyUpdate.java | 76 +++++++++++++++++++ .../object_controller/ObjectController.java | 1 + .../RequestBiographyCmdCallback.java | 59 ++++++++++++++ src/services/commands/CommandService.java | 1 + 5 files changed, 143 insertions(+) create mode 100644 scripts/commands/generic/setBiography.js create mode 100644 src/network/packets/swg/zone/object_controller/BiographyUpdate.java create mode 100644 src/resources/commands/callbacks/RequestBiographyCmdCallback.java diff --git a/scripts/commands/generic/setBiography.js b/scripts/commands/generic/setBiography.js new file mode 100644 index 000000000..03594e03e --- /dev/null +++ b/scripts/commands/generic/setBiography.js @@ -0,0 +1,6 @@ +function executeCommand(galacticManager, player, target, args) { + var BiographyUpdate = Java.type("network.packets.swg.zone.object_controller.BiographyUpdate"); + var objectId = player.getCreatureObject().getObjectId(); + + player.sendPacket(new BiographyUpdate(objectId, objectId, args)); +} diff --git a/src/network/packets/swg/zone/object_controller/BiographyUpdate.java b/src/network/packets/swg/zone/object_controller/BiographyUpdate.java new file mode 100644 index 000000000..9413f521e --- /dev/null +++ b/src/network/packets/swg/zone/object_controller/BiographyUpdate.java @@ -0,0 +1,76 @@ +/*********************************************************************************** +* 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 network.packets.swg.zone.object_controller; + +import java.nio.ByteBuffer; + +public class BiographyUpdate extends ObjectController { + + public static final int CRC = 0x01DB; + + private long targetId; + private String biography; + + public BiographyUpdate(long objectId, long targetId, String biography) { + super(objectId, CRC); + setTargetId(targetId); + setBiography(biography); + } + + public BiographyUpdate(ByteBuffer data) { + super(CRC); + decode(data); + } + + public void decode(ByteBuffer data) { + decodeHeader(data); + targetId = getLong(data); + biography = getUnicode(data); + } + + public ByteBuffer encode() { + ByteBuffer data = ByteBuffer.allocate(HEADER_LENGTH + Long.BYTES + biography.length() * 2); + encodeHeader(data); + addLong(data, targetId); + addUnicode(data, biography); + return data; + } + + public long getTargetId() { return targetId; } + + public void setTargetId(long targetId) { this.targetId = targetId; } + + public String getBiography() { + return biography; + } + + public void setBiography(String biography) { + this.biography = biography; + } + +} diff --git a/src/network/packets/swg/zone/object_controller/ObjectController.java b/src/network/packets/swg/zone/object_controller/ObjectController.java index 41bccc863..5b6865545 100644 --- a/src/network/packets/swg/zone/object_controller/ObjectController.java +++ b/src/network/packets/swg/zone/object_controller/ObjectController.java @@ -101,6 +101,7 @@ public abstract class ObjectController extends SWGPacket { case 0x0134: return new CombatSpam(data); case 0x0146: return new ObjectMenuRequest(data); case 0x01BD: return new ShowFlyText(data); + case 0x01DB: return new BiographyUpdate(data); case 0x044D: return new ChangeRoleIconChoice(data); case 0x04C5: return new IntendedTarget(data); } diff --git a/src/resources/commands/callbacks/RequestBiographyCmdCallback.java b/src/resources/commands/callbacks/RequestBiographyCmdCallback.java new file mode 100644 index 000000000..53ed8108f --- /dev/null +++ b/src/resources/commands/callbacks/RequestBiographyCmdCallback.java @@ -0,0 +1,59 @@ +/*********************************************************************************** +* 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 resources.commands.callbacks; + +import network.packets.swg.zone.object_controller.BiographyUpdate; +import resources.commands.ICmdCallback; +import resources.objects.SWGObject; +import resources.objects.creature.CreatureObject; +import resources.player.Player; +import resources.server_info.Log; +import services.galaxy.GalacticManager; + +/** + * + * @author mads + */ +public class RequestBiographyCmdCallback implements ICmdCallback { + + @Override + public void execute(GalacticManager galacticManager, Player player, SWGObject target, String args) { + CreatureObject creatureObject = player.getCreatureObject(); + if(target != null) { + if(creatureObject.isPlayer()) { + // TODO send BiographyUpdate to Player + player.sendPacket(new BiographyUpdate(creatureObject.getObjectId(), target.getObjectId(), creatureObject.getPlayerObject().getBiography())); + } else { + Log.w("RequestBiographyCmdCallback", "%s tried to request biography of NPC %s", creatureObject, target); + } + } else { + Log.w("RequestBiographyCmdCallback", "%s tried to request biography of a null object", creatureObject); + } + } + +} \ No newline at end of file diff --git a/src/services/commands/CommandService.java b/src/services/commands/CommandService.java index 46d2c22cd..71adee345 100644 --- a/src/services/commands/CommandService.java +++ b/src/services/commands/CommandService.java @@ -312,6 +312,7 @@ public class CommandService extends Service { registerCallback("qatool", QaToolCmdCallback.class); registerCallback("goto", GotoCmdCallback.class); registerCallback("startDance", StartDanceCallback.class); + registerCallback("requestBiography", RequestBiographyCmdCallback.class); } private void clearCommands() { From e2d638c71603afdc9c8b70b4816636b8b0c018c1 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 15 May 2016 14:18:44 +0200 Subject: [PATCH 2/5] Removed a TODO comment in RequestBiographyCmdCallback for a feature that's already implemented --- .../commands/callbacks/RequestBiographyCmdCallback.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/resources/commands/callbacks/RequestBiographyCmdCallback.java b/src/resources/commands/callbacks/RequestBiographyCmdCallback.java index 53ed8108f..938aff0bf 100644 --- a/src/resources/commands/callbacks/RequestBiographyCmdCallback.java +++ b/src/resources/commands/callbacks/RequestBiographyCmdCallback.java @@ -46,7 +46,6 @@ public class RequestBiographyCmdCallback implements ICmdCallback { CreatureObject creatureObject = player.getCreatureObject(); if(target != null) { if(creatureObject.isPlayer()) { - // TODO send BiographyUpdate to Player player.sendPacket(new BiographyUpdate(creatureObject.getObjectId(), target.getObjectId(), creatureObject.getPlayerObject().getBiography())); } else { Log.w("RequestBiographyCmdCallback", "%s tried to request biography of NPC %s", creatureObject, target); From 472d8a460da833e6609886b154183502c4b04605 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 15 May 2016 14:25:18 +0200 Subject: [PATCH 3/5] Fixed an issue where the biography wouldn't be saved once set --- scripts/commands/generic/setBiography.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/commands/generic/setBiography.js b/scripts/commands/generic/setBiography.js index 03594e03e..89ec90968 100644 --- a/scripts/commands/generic/setBiography.js +++ b/scripts/commands/generic/setBiography.js @@ -1,6 +1,8 @@ function executeCommand(galacticManager, player, target, args) { var BiographyUpdate = Java.type("network.packets.swg.zone.object_controller.BiographyUpdate"); - var objectId = player.getCreatureObject().getObjectId(); + var creatureObject = player.getCreatureObject(); + var objectId = creatureObject.getObjectId(); + creatureObject.getPlayerObject().setBiography(args); player.sendPacket(new BiographyUpdate(objectId, objectId, args)); } From 79952582311df76d256a8decfffcaa6605a94776 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 15 May 2016 15:23:50 +0200 Subject: [PATCH 4/5] Added a 1025 character limit for biographies --- scripts/commands/generic/setBiography.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/commands/generic/setBiography.js b/scripts/commands/generic/setBiography.js index 89ec90968..ccffe3a63 100644 --- a/scripts/commands/generic/setBiography.js +++ b/scripts/commands/generic/setBiography.js @@ -1,4 +1,9 @@ function executeCommand(galacticManager, player, target, args) { + + if(args.length() > 1025) { + return; + } + var BiographyUpdate = Java.type("network.packets.swg.zone.object_controller.BiographyUpdate"); var creatureObject = player.getCreatureObject(); var objectId = creatureObject.getObjectId(); From 0780c58db39e16cf6f38ea0911b2deaeef142078 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Mon, 16 May 2016 21:53:10 +0200 Subject: [PATCH 5/5] Fixed incorrect buffer size allocation in BiographyUpdate --- .../packets/swg/zone/object_controller/BiographyUpdate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/packets/swg/zone/object_controller/BiographyUpdate.java b/src/network/packets/swg/zone/object_controller/BiographyUpdate.java index 9413f521e..a9e7cff0c 100644 --- a/src/network/packets/swg/zone/object_controller/BiographyUpdate.java +++ b/src/network/packets/swg/zone/object_controller/BiographyUpdate.java @@ -54,7 +54,7 @@ public class BiographyUpdate extends ObjectController { } public ByteBuffer encode() { - ByteBuffer data = ByteBuffer.allocate(HEADER_LENGTH + Long.BYTES + biography.length() * 2); + ByteBuffer data = ByteBuffer.allocate(HEADER_LENGTH + Long.BYTES + Integer.BYTES + biography.length() * 2); encodeHeader(data); addLong(data, targetId); addUnicode(data, biography);