From 9b2689fcbc713e12ae55e57b92c93007aae25ff7 Mon Sep 17 00:00:00 2001 From: Treeku Date: Fri, 5 Sep 2014 06:48:05 +0100 Subject: [PATCH 1/9] Fixed syntax errors. --- src/resources/objects/creature/CreatureObject.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index bf0aa1e8..10f8c52a 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -1351,7 +1351,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void sendSystemMessage(String message, OutOfBand outOfBand, byte displayType) { - notifySelf((new ChatSystemMessage(message, outOfBand, displayType)).serialize())}; + notifySelf((new ChatSystemMessage(message, outOfBand, displayType)).serialize()}; } public void playMusic(String sndFile) { @@ -1371,7 +1371,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void playMusic(String sndFile, long targetId, int repetitions, boolean flag) { - notifySelf(new PlayMusicMessage(sndFile, targetId, 1, false)); + notifySelf((new PlayMusicMessage(sndFile, targetId, 1, false)).serialize()); } public TangibleObject getInventory() { From 6d7b1c7a9f9150b9615ba18b157586365df505fb Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 13:48:20 +0200 Subject: [PATCH 2/9] Refactored AuctionQueryHeadersMessage --- .../AuctionQueryHeadersMessage.java | 93 +++++-------------- 1 file changed, 22 insertions(+), 71 deletions(-) diff --git a/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java index b92f96c3..9247f215 100644 --- a/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java +++ b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java @@ -21,8 +21,8 @@ ******************************************************************************/ package protocol.swg.auctionManagerClientListener; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; @@ -35,6 +35,7 @@ public class AuctionQueryHeadersMessage extends SWGMessage { private int screen; private int category; private int itemTypeCRC; + private byte unk; private String searchString; private int unkInt; private int minPrice; @@ -47,28 +48,26 @@ public class AuctionQueryHeadersMessage extends SWGMessage { @Override public void deserialize(IoBuffer data) { data.skip(6); - setRange(data.getInt()); - setCounter(data.getInt()); - setScreen(data.getInt()); - setCategory(data.getInt()); - setItemTypeCRC(data.getInt()); - data.get(); // unk + this.range = data.getInt(); + this.counter = data.getInt(); + this.screen = data.getInt(); + this.category = data.getInt(); + this.itemTypeCRC = data.getInt(); + this.unk = data.get(); int size = data.getInt(); - try { - setSearchString(new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), "UTF-16LE")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + + this.searchString = new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), StandardCharsets.UTF_16LE); + data.position(data.position() + size * 2); - setUnkInt(data.getInt()); - setMinPrice(data.getInt()); - setMaxPrice(data.getInt()); - setIncludeEntranceFee(data.get()); + this.unkInt = data.getInt(); + this.minPrice = data.getInt(); + this.maxPrice = data.getInt(); + this.includeEntranceFee = data.get(); // Ziggy - boolean? data.skip(5); // unk - setVendorId(data.getLong()); - setVendorFlag(data.get()); - setOffset(data.getShort()); + this.vendorId = data.getLong(); + this.vendorFlag = data.get(); + this.offset = data.getShort(); } @@ -82,104 +81,56 @@ public class AuctionQueryHeadersMessage extends SWGMessage { return range; } - public void setRange(int range) { - this.range = range; - } - public int getCounter() { return counter; } - - public void setCounter(int counter) { - this.counter = counter; - } - + public int getScreen() { return screen; } - public void setScreen(int screen) { - this.screen = screen; - } - public int getCategory() { return category; } - - public void setCategory(int category) { - this.category = category; - } - + public int getItemTypeCRC() { return itemTypeCRC; } - public void setItemTypeCRC(int itemTypeCRC) { - this.itemTypeCRC = itemTypeCRC; - } - public String getSearchString() { return searchString; } - public void setSearchString(String searchString) { - this.searchString = searchString; - } - public int getUnkInt() { return unkInt; } - public void setUnkInt(int unkInt) { - this.unkInt = unkInt; - } - public int getMinPrice() { return minPrice; } - public void setMinPrice(int minPrice) { - this.minPrice = minPrice; - } - public int getMaxPrice() { return maxPrice; } - public void setMaxPrice(int maxPrice) { - this.maxPrice = maxPrice; - } - public byte getIncludeEntranceFee() { return includeEntranceFee; } - public void setIncludeEntranceFee(byte includeEntranceFee) { - this.includeEntranceFee = includeEntranceFee; - } - public long getVendorId() { return vendorId; } - public void setVendorId(long vendorId) { - this.vendorId = vendorId; - } - public byte getVendorFlag() { return vendorFlag; } - public void setVendorFlag(byte vendorFlag) { - this.vendorFlag = vendorFlag; - } - public short getOffset() { return offset; } - public void setOffset(short offset) { - this.offset = offset; + public byte getUnk() { + return unk; } } From a2430681b9e35611914588c60a714e7d5bc54532 Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 14:22:56 +0200 Subject: [PATCH 3/9] Fixed syntax error in CreatureObject --- src/resources/objects/creature/CreatureObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 10f8c52a..32521beb 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -1351,7 +1351,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void sendSystemMessage(String message, OutOfBand outOfBand, byte displayType) { - notifySelf((new ChatSystemMessage(message, outOfBand, displayType)).serialize()}; + notifySelf((new ChatSystemMessage(message, outOfBand, displayType)).serialize()); } public void playMusic(String sndFile) { From 909684ceb49bfa5e4fa045af8f2dfeb3b53ca789 Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 14:36:54 +0200 Subject: [PATCH 4/9] Refactored CreateImmediateAuctionMessage --- .../CreateImmediateAuctionMessage.java | 55 +++++-------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java index 0546f41e..bf638873 100644 --- a/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java +++ b/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java @@ -21,8 +21,8 @@ ******************************************************************************/ package protocol.swg.auctionManagerClientListener; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; @@ -35,23 +35,21 @@ public class CreateImmediateAuctionMessage extends SWGMessage { private int price; private int duration; private String description; - private byte premium; + private boolean isPremium; @Override public void deserialize(IoBuffer data) { data.skip(6); - setObjectId(data.getLong()); - setVendorId(data.getLong()); - setPrice(data.getInt()); - setDuration(data.getInt()); // in minutes + this.objectId = data.getLong(); + this.vendorId = data.getLong(); + this.price = data.getInt(); + this.duration = data.getInt(); + int size = data.getInt(); - try { - setDescription(new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), "UTF-16LE")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + + this.description = new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), StandardCharsets.UTF_16LE); data.position(data.position() + size * 2); - setPremium(data.get()); + this.isPremium = (data.get() == 0 ? false : true); } @Override @@ -64,50 +62,27 @@ public class CreateImmediateAuctionMessage extends SWGMessage { return objectId; } - public void setObjectId(long objectId) { - this.objectId = objectId; - } - public long getVendorId() { return vendorId; } - public void setVendorId(long vendorId) { - this.vendorId = vendorId; - } - public int getPrice() { return price; } - public void setPrice(int price) { - this.price = price; - } - +/* + * @return Duration in minutes + */ public int getDuration() { return duration; } - public void setDuration(int duration) { - this.duration = duration; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - - public boolean getPremium() { - if(premium == 1) - return true; - return false; - } - - public void setPremium(byte premium) { - this.premium = premium; + public boolean isPremium() { + return isPremium; } } From 7517486bc94691cebe20b88bae5534974c1aee57 Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 14:46:22 +0200 Subject: [PATCH 5/9] Refactored CreateAuctionMessage --- .../CreateAuctionMessage.java | 53 +++++-------------- .../chat/ChatInstantMessageToCharacter.java | 1 - 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java index 33a57339..72e19e7c 100644 --- a/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java +++ b/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java @@ -21,8 +21,8 @@ ******************************************************************************/ package protocol.swg.auctionManagerClientListener; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; @@ -35,24 +35,21 @@ public class CreateAuctionMessage extends SWGMessage { private int price; private int duration; private String description; - private byte premium; + private boolean isPremium; @Override public void deserialize(IoBuffer data) { data.skip(6); - setObjectId(data.getLong()); + this.objectId = data.getLong(); int size = data.getInt(); - try { - setDescription(new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), "UTF-16LE")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - data.position(data.position() + size * 2); + this.description = new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), StandardCharsets.UTF_16LE); - setVendorId(data.getLong()); - setPrice(data.getInt()); - setDuration(data.getInt()); // in minutes - setPremium(data.get()); + data.position(data.position() + size * 2); + + this.vendorId = data.getLong(); + this.price = data.getInt(); + this.duration = data.getInt(); // in minutes + this.isPremium = (data.get() == 0 ? false : true); } @Override @@ -65,50 +62,24 @@ public class CreateAuctionMessage extends SWGMessage { return objectId; } - public void setObjectId(long objectId) { - this.objectId = objectId; - } - public long getVendorId() { return vendorId; } - public void setVendorId(long vendorId) { - this.vendorId = vendorId; - } - public int getPrice() { return price; } - public void setPrice(int price) { - this.price = price; - } - public int getDuration() { return duration; } - public void setDuration(int duration) { - this.duration = duration; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - - public boolean getPremium() { - if(premium == 1) - return true; - return false; - } - - public void setPremium(byte premium) { - this.premium = premium; + public boolean isPremium() { + return isPremium; } } diff --git a/src/protocol/swg/chat/ChatInstantMessageToCharacter.java b/src/protocol/swg/chat/ChatInstantMessageToCharacter.java index c4e746f3..3547220a 100644 --- a/src/protocol/swg/chat/ChatInstantMessageToCharacter.java +++ b/src/protocol/swg/chat/ChatInstantMessageToCharacter.java @@ -21,7 +21,6 @@ ******************************************************************************/ package protocol.swg.chat; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; From 0a6a88a1f5c6018ec24aa3d47fe84c8fc3f75a94 Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 15:35:07 +0200 Subject: [PATCH 6/9] Fixed method name issue in BazaarService The method getPremium() was replaced with isPremium() here: https://github.com/ProjectSWGCore/NGECore2/commit/7517486bc94691cebe20b88bae5534974c1aee57 --- src/services/bazaar/BazaarService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/bazaar/BazaarService.java b/src/services/bazaar/BazaarService.java index 0613155e..52ca9588 100644 --- a/src/services/bazaar/BazaarService.java +++ b/src/services/bazaar/BazaarService.java @@ -331,7 +331,7 @@ public class BazaarService implements INetworkDispatch { if(vendor == null || item == null || item instanceof CreatureObject || item instanceof BuildingObject) return; - addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), true, createAuction.getPremium()); + addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), true, createAuction.isPremium()); }); @@ -359,7 +359,7 @@ public class BazaarService implements INetworkDispatch { if(vendor == null || item == null || item instanceof CreatureObject || item instanceof BuildingObject) return; - addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), false, createAuction.getPremium()); + addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), false, createAuction.isPremium()); }); From 359972cf2acd8b47c801b799a06c6c7b9fc5b696 Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 15:53:02 +0200 Subject: [PATCH 7/9] Fixed an issue where the ITV window would behave like a ticket window --- scripts/radial/terminal/travel_terminal.py | 2 +- .../radial/terminal/travel_terminal_itv.py | 2 +- .../swg/EnterTicketPurchaseModeMessage.java | 44 +++++-------------- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/scripts/radial/terminal/travel_terminal.py b/scripts/radial/terminal/travel_terminal.py index a579af12..de72aa58 100644 --- a/scripts/radial/terminal/travel_terminal.py +++ b/scripts/radial/terminal/travel_terminal.py @@ -13,7 +13,7 @@ def handleSelection(core, owner, target, option): if owner.getCombatFlag() == 1: owner.sendSystemMessage('You can\'t use that while in combat.', 0) return - tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), owner) + tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), False) owner.getClient().getSession().write(tpm.serialize()) return return diff --git a/scripts/radial/terminal/travel_terminal_itv.py b/scripts/radial/terminal/travel_terminal_itv.py index b9356f38..47955905 100644 --- a/scripts/radial/terminal/travel_terminal_itv.py +++ b/scripts/radial/terminal/travel_terminal_itv.py @@ -14,7 +14,7 @@ def handleSelection(core, owner, target, option): if owner.getCombatFlag() == 1: owner.sendSystemMessage('You can\'t use that while in combat.', 0) return - tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), owner, True) + tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), True) owner.getClient().getSession().write(tpm.serialize()) return return diff --git a/src/protocol/swg/EnterTicketPurchaseModeMessage.java b/src/protocol/swg/EnterTicketPurchaseModeMessage.java index 0287c55c..3080d43e 100644 --- a/src/protocol/swg/EnterTicketPurchaseModeMessage.java +++ b/src/protocol/swg/EnterTicketPurchaseModeMessage.java @@ -23,32 +23,21 @@ package protocol.swg; import java.nio.ByteOrder; -import main.NGECore; - import org.apache.mina.core.buffer.IoBuffer; -import services.travel.TravelPoint; -import engine.resources.objects.SWGObject; +import resources.common.Opcodes; +import engine.resources.common.StringUtilities; -@SuppressWarnings("unused") public class EnterTicketPurchaseModeMessage extends SWGMessage { private String planetName; - private String cityName; - private SWGObject player; - private boolean isItv = false; + private String nearestPointName; + private boolean isInstant = false; - public EnterTicketPurchaseModeMessage(String planetName, String cityName, SWGObject player, boolean isItv) { + public EnterTicketPurchaseModeMessage(String planetName, String nearestPointName, boolean isInstant) { this.planetName = planetName; - this.cityName = cityName; - this.player = player; - this.isItv = true; - } - - public EnterTicketPurchaseModeMessage(String planetName, String cityName, SWGObject player) { - this.planetName = planetName; - this.cityName = cityName; - this.player = player; + this.nearestPointName = nearestPointName; + this.isInstant = isInstant; } @Override @@ -58,22 +47,13 @@ public class EnterTicketPurchaseModeMessage extends SWGMessage { @Override public IoBuffer serialize() { - final NGECore core = NGECore.getInstance(); - - TravelPoint nearestPoint = null; - if (!isItv) nearestPoint = core.travelService.getNearestTravelPoint(player); - else nearestPoint = core.travelService.getNearestTravelPoint(player, 5120); - - IoBuffer result = IoBuffer.allocate(11 + planetName.length() + nearestPoint.getName().length()).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer result = IoBuffer.allocate(11 + planetName.length() + nearestPointName.length()).order(ByteOrder.LITTLE_ENDIAN); result.putShort((short) 3); - result.putInt(0x904DAE1A); - - result.put(getAsciiString(planetName)); - result.put(getAsciiString(nearestPoint.getName())); - - - result.put((byte) 0); + result.putInt(Opcodes.EnterTicketPurchaseModeMessage); + result.put(StringUtilities.getAsciiString(planetName)); + result.put(StringUtilities.getAsciiString(nearestPointName)); + result.put(isInstant ? (byte) 1 : (byte) 0); return result.flip(); } From 9821d92a71b305c287f15366525877f7eb91866a Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 15:54:45 +0200 Subject: [PATCH 8/9] Added EnterTicketPurchaseModeMessage to Opcodes table https://github.com/ProjectSWGCore/NGECore2/commit/359972cf2acd8b47c801b799a06c6c7b9fc5b696 won't work without this commit. --- src/resources/common/Opcodes.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/resources/common/Opcodes.java b/src/resources/common/Opcodes.java index 245aa8a6..666ccb0a 100644 --- a/src/resources/common/Opcodes.java +++ b/src/resources/common/Opcodes.java @@ -100,5 +100,7 @@ public class Opcodes { public static final int CreateCharacterSuccess = 0x1DB575CC; public static final int PlayerMoneyResponse = 0x367E737E; public static final int CmdStartScene = 0x3AE6DFAE; + public static final int IncubatorStartMessage = CRC.StringtoCRC("IncubatorStartMessage"); + public static final int EnterTicketPurchaseModeMessage = 0x904DAE1A; } From fcdd7d418483c3825306d0f58b4a81284bc9ac48 Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Fri, 5 Sep 2014 16:05:02 +0200 Subject: [PATCH 9/9] Changed CommandEnqueue to use StandardCharsets --- .../CommandEnqueue.java | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/protocol/swg/objectControllerObjects/CommandEnqueue.java b/src/protocol/swg/objectControllerObjects/CommandEnqueue.java index bb1705a4..5e4278ca 100644 --- a/src/protocol/swg/objectControllerObjects/CommandEnqueue.java +++ b/src/protocol/swg/objectControllerObjects/CommandEnqueue.java @@ -21,13 +21,11 @@ ******************************************************************************/ package protocol.swg.objectControllerObjects; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; -@SuppressWarnings("unused") - public class CommandEnqueue extends ObjControllerObject { public static final int SOCIAL_INTERNAL = 0x32CF1BEE; @@ -48,7 +46,7 @@ public class CommandEnqueue extends ObjControllerObject { public static final int FLO = 0x3B159B76; public static final int BANDFLOURISH = 0xF4C60EC3; public static final int BANDFLO = 0xDD3FB008; - + private int actionCounter; private int commandCRC; private long targetId; @@ -56,31 +54,22 @@ public class CommandEnqueue extends ObjControllerObject { private final int commandObjectIndex = 20; private long objectId; private String commandArguments; - + public CommandEnqueue() { } - public CommandEnqueue(int actionCounter, ObjControllerObject commandObject) { - this.actionCounter = actionCounter; - this.commandObject = commandObject; - } - + public void deserialize(IoBuffer buffer) { - objectId = buffer.getLong(); - buffer.getInt(); - actionCounter = buffer.getInt(); + int size; + + this.objectId = buffer.getLong(); + buffer.getInt(); // Ziggy - related to commandObjectIndex? + this.actionCounter = buffer.getInt(); + this.commandCRC = buffer.getInt(); + this.targetId = buffer.getLong(); + size = buffer.getInt(); - commandCRC = buffer.getInt(); - targetId = buffer.getLong(); - int size = buffer.getInt(); - try { - commandArguments = new String(ByteBuffer.allocate(size * 2).put(buffer.array(), buffer.position(), size * 2).array(), "UTF-16LE"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - //commandArguments = getNextUnicodeString(buffer); - //commandObject = getCommandObject(commandCRC); + commandArguments = new String(ByteBuffer.allocate(size * 2).put(buffer.array(), buffer.position(), size * 2).array(), StandardCharsets.UTF_16LE); } public IoBuffer serialize() {