From ea8bc533944f8a3efd820ebed476ef947b507d95 Mon Sep 17 00:00:00 2001 From: Light2 Date: Fri, 11 Apr 2014 23:47:03 +0200 Subject: [PATCH] Started work on bazaar --- src/main/NGECore.java | 9 +- .../AcceptAuctionResponseMessage.java | 34 +++ .../AuctionItemDescriptionMessage.java | 38 +++ .../AuctionQueryHeadersMessage.java | 162 ++++++++++++ .../AuctionQueryHeadersResponseMessage.java | 21 ++ .../BidAuctionMessage.java | 51 ++++ .../BidAuctionResponseMessage.java | 45 ++++ .../CancelLiveAuctionMessage.java | 31 +++ .../CancelLiveAuctionResponseMessage.java | 42 +++ .../CommoditiesItemTypeListResponse.java | 30 +++ .../CommoditiesResourceTypeListResponse.java | 47 ++++ .../CreateAuctionMessage.java | 90 +++++++ .../CreateImmediateAuctionMessage.java | 90 +++++++ .../GetAuctionDetails.java | 31 +++ .../GetAuctionDetailsResponse.java | 21 ++ .../IsVendorOwnerMessage.java | 31 +++ .../IsVendorOwnerResponseMessage.java | 42 +++ .../ItemSoldMessage.java | 55 ++++ .../RetrieveAuctionItemMessage.java | 41 +++ .../RetrieveAuctionItemResponseMessage.java | 41 +++ src/resources/common/Opcodes.java | 5 +- src/services/PlayerService.java | 6 +- src/services/bazaar/AuctionItem.java | 243 ++++++++++++++++++ src/services/bazaar/BazaarService.java | 149 +++++++++++ src/services/resources/ResourceService.java | 4 + 25 files changed, 1349 insertions(+), 10 deletions(-) create mode 100644 src/protocol/swg/auctionManagerClientListener/AcceptAuctionResponseMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/AuctionItemDescriptionMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersResponseMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/BidAuctionMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/BidAuctionResponseMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionResponseMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/CommoditiesItemTypeListResponse.java create mode 100644 src/protocol/swg/auctionManagerClientListener/CommoditiesResourceTypeListResponse.java create mode 100644 src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/GetAuctionDetails.java create mode 100644 src/protocol/swg/auctionManagerClientListener/GetAuctionDetailsResponse.java create mode 100644 src/protocol/swg/auctionManagerClientListener/IsVendorOwnerMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/IsVendorOwnerResponseMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/ItemSoldMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemMessage.java create mode 100644 src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemResponseMessage.java create mode 100644 src/services/bazaar/AuctionItem.java create mode 100644 src/services/bazaar/BazaarService.java diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 0762507f..ca13e959 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -70,6 +70,7 @@ import services.SurveyService; import services.TerrainService; import services.WeatherService; import services.ai.AIService; +import services.bazaar.BazaarService; import services.chat.ChatService; import services.collections.CollectionService; import services.combat.CombatService; @@ -170,11 +171,10 @@ public class NGECore { //public MissionService missionService; public InstanceService instanceService; public DevService devService; - public SurveyService surveyService; public ResourceService resourceService; - public ConversationService conversationService; + public BazaarService bazaarService; // Login Server @@ -199,7 +199,7 @@ public class NGECore { private BusConfiguration eventBusConfig = BusConfiguration.Default(1, new ThreadPoolExecutor(1, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue())); private ObjectDatabase buildingODB; - + private ObjectDatabase auctionODB; private ObjectDatabase resourcesODB; private ObjectDatabase resourceRootsODB; private ObjectDatabase resourceHistoryODB; @@ -258,6 +258,7 @@ public class NGECore { resourcesODB = new ObjectDatabase("resources", true, false, true); resourceRootsODB = new ObjectDatabase("resourceroots", true, false, true); resourceHistoryODB = new ObjectDatabase("resourcehistory", true, false, true); + auctionODB = new ObjectDatabase("auction", true, false, true); // Services loginService = new LoginService(this); @@ -286,6 +287,7 @@ public class NGECore { entertainmentService = new EntertainmentService(this); devService = new DevService(this); conversationService = new ConversationService(this); + bazaarService = new BazaarService(this); if (config.keyExists("JYTHONCONSOLE.PORT")) { int jythonPort = config.getInt("JYTHONCONSOLE.PORT"); @@ -338,6 +340,7 @@ public class NGECore { zoneDispatch.addService(buffService); zoneDispatch.addService(entertainmentService); //zoneDispatch.addService(missionService); + zoneDispatch.addService(bazaarService); zoneServer = new MINAServer(zoneDispatch, config.getInt("ZONE.PORT")); zoneServer.start(); diff --git a/src/protocol/swg/auctionManagerClientListener/AcceptAuctionResponseMessage.java b/src/protocol/swg/auctionManagerClientListener/AcceptAuctionResponseMessage.java new file mode 100644 index 00000000..669132ff --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/AcceptAuctionResponseMessage.java @@ -0,0 +1,34 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class AcceptAuctionResponseMessage extends SWGMessage { + + private long itemId; + private int error; + + public AcceptAuctionResponseMessage(long itemId, int error) { + this.itemId = itemId; + this.error = error; + } + + @Override + public void deserialize(IoBuffer data) { + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(18).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 3); + result.putInt(0xC58A446E); + result.putLong(itemId); + result.putInt(error); + return result.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/AuctionItemDescriptionMessage.java b/src/protocol/swg/auctionManagerClientListener/AuctionItemDescriptionMessage.java new file mode 100644 index 00000000..957118e1 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/AuctionItemDescriptionMessage.java @@ -0,0 +1,38 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class AuctionItemDescriptionMessage extends SWGMessage { + + private long itemId; + private String description; + + public AuctionItemDescriptionMessage(long itemId, String description) { + this.itemId = itemId; + this.description = description; + } + + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(26 + (description.length() * 2)).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 2); + result.putInt(0xFE0E644B); + result.putLong(itemId); + result.put(getUnicodeString(description)); + result.putInt(0); + result.putInt(0); + return result.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java new file mode 100644 index 00000000..1436f459 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java @@ -0,0 +1,162 @@ +package protocol.swg.auctionManagerClientListener; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class AuctionQueryHeadersMessage extends SWGMessage { + + private int range; + private int counter; + private int screen; + private int category; + private int itemTypeCRC; + private String searchString; + private int unkInt; + private int minPrice; + private int maxPrice; + private byte includeEntranceFee; + private long vendorId; + private byte vendorFlag; + private short offset; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setRange(data.getInt()); + setCounter(data.getInt()); + setScreen(data.getInt()); + setCategory(data.getInt()); + setItemTypeCRC(data.getInt()); + 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(); + } + data.position(data.position() + size * 2); + setUnkInt(data.getInt()); + setMinPrice(data.getInt()); + setMaxPrice(data.getInt()); + setIncludeEntranceFee(data.get()); + data.skip(5); // unk + setVendorId(data.getLong()); + setVendorFlag(data.get()); + setOffset(data.getShort()); + + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public int getRange() { + 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; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersResponseMessage.java b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersResponseMessage.java new file mode 100644 index 00000000..71eea176 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersResponseMessage.java @@ -0,0 +1,21 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class AuctionQueryHeadersResponseMessage extends SWGMessage { + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/BidAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/BidAuctionMessage.java new file mode 100644 index 00000000..21492348 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/BidAuctionMessage.java @@ -0,0 +1,51 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class BidAuctionMessage extends SWGMessage { + + private long auctionId; + private int myPrice; + private int proxyPrice; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setAuctionId(data.getLong()); + setMyPrice(data.getInt()); + setProxyPrice(data.getInt()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getAuctionId() { + return auctionId; + } + + public void setAuctionId(long auctionId) { + this.auctionId = auctionId; + } + + public int getMyPrice() { + return myPrice; + } + + public void setMyPrice(int myPrice) { + this.myPrice = myPrice; + } + + public int getProxyPrice() { + return proxyPrice; + } + + public void setProxyPrice(int proxyPrice) { + this.proxyPrice = proxyPrice; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/BidAuctionResponseMessage.java b/src/protocol/swg/auctionManagerClientListener/BidAuctionResponseMessage.java new file mode 100644 index 00000000..da1bccc8 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/BidAuctionResponseMessage.java @@ -0,0 +1,45 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class BidAuctionResponseMessage extends SWGMessage { + + private long objectId; + private int status; + + public static final int SUCCESS = 0; + public static final int INVALIDAUCTIONER = 1; + public static final int INVALIDITEM = 2; + public static final int INVALIDPRICE = 4; + public static final int NOTENOUGHCREDITS = 9; + public static final int PURCHASEFAILED = 10; + public static final int PURCHASEREJECTED = 11; + public static final int PRICETOOHIGH = 13; + public static final int PRICEOVERFLOW = 14; + + public BidAuctionResponseMessage(long objectId, int status) { + this.objectId = objectId; + this.status = status; + } + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(18).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 3); + result.putInt(0x8FCBEF4A); + result.putLong(objectId); + result.putInt(status); + return result.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionMessage.java new file mode 100644 index 00000000..64685acf --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionMessage.java @@ -0,0 +1,31 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class CancelLiveAuctionMessage extends SWGMessage { + + private long objectId; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setObjectId(data.getLong()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getObjectId() { + return objectId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionResponseMessage.java b/src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionResponseMessage.java new file mode 100644 index 00000000..8b72042c --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/CancelLiveAuctionResponseMessage.java @@ -0,0 +1,42 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class CancelLiveAuctionResponseMessage extends SWGMessage { + + public static final int SUCCESS = 0; + public static final int NOTALLOWED = 1; + public static final int INVALIDITEM = 2; + public static final int NOTOWNER = 8; + public static final int ALREADYCOMPLETED = 15; + private long itemId; + private int status; + + public CancelLiveAuctionResponseMessage(long itemId, int status) { + this.itemId = itemId; + this.status = status; + } + + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(19).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 4); + result.putInt(0x7DA2246C); + result.putLong(itemId); + result.putInt(status); + result.put((byte) 0); // unk + return result.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/CommoditiesItemTypeListResponse.java b/src/protocol/swg/auctionManagerClientListener/CommoditiesItemTypeListResponse.java new file mode 100644 index 00000000..bb2a915b --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/CommoditiesItemTypeListResponse.java @@ -0,0 +1,30 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import main.NGECore; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class CommoditiesItemTypeListResponse extends SWGMessage { + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + String galaxy = NGECore.getInstance().getGalaxyName(); + IoBuffer result = IoBuffer.allocate(14 + galaxy.length()).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 2); + result.putInt(0xD4E937FC); + result.put(getAsciiString(galaxy + ".0")); + result.putInt(0); + return result.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/CommoditiesResourceTypeListResponse.java b/src/protocol/swg/auctionManagerClientListener/CommoditiesResourceTypeListResponse.java new file mode 100644 index 00000000..c55b4726 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/CommoditiesResourceTypeListResponse.java @@ -0,0 +1,47 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; +import java.util.Vector; + +import main.NGECore; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class CommoditiesResourceTypeListResponse extends SWGMessage { + + private Vector resNames; + + public CommoditiesResourceTypeListResponse(Vector resNames) { + this.resNames = resNames; + } + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + String galaxyName = NGECore.getInstance().getGalaxyName(); + final IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN); + result.setAutoExpand(true); + + result.putShort((short) 2); + result.putInt(0x5EDD19CB); + + result.put(getAsciiString(galaxyName + "." + String.valueOf(resNames.size()))); + result.putInt(479); + result.putLong(0); + + resNames.forEach(s -> result.put(getAsciiString(s))); + + int size = result.position(); + IoBuffer result2 = IoBuffer.allocate(size).put(result.array(), 0, size); + + return result2.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java new file mode 100644 index 00000000..159e911b --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java @@ -0,0 +1,90 @@ +package protocol.swg.auctionManagerClientListener; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class CreateAuctionMessage extends SWGMessage { + + private long objectId; + private long vendorId; + private int price; + private int duration; + private String description; + private byte premium; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setObjectId(data.getLong()); + setVendorId(data.getLong()); + setPrice(data.getInt()); + setDuration(data.getInt()); // in minutes + 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); + setPremium(data.get()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getObjectId() { + 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 byte getPremium() { + return premium; + } + + public void setPremium(byte premium) { + this.premium = premium; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java new file mode 100644 index 00000000..ce961680 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java @@ -0,0 +1,90 @@ +package protocol.swg.auctionManagerClientListener; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class CreateImmediateAuctionMessage extends SWGMessage { + + private long objectId; + private long vendorId; + private int price; + private int duration; + private String description; + private byte premium; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setObjectId(data.getLong()); + setVendorId(data.getLong()); + setPrice(data.getInt()); + setDuration(data.getInt()); // in minutes + 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); + setPremium(data.get()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getObjectId() { + 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 byte getPremium() { + return premium; + } + + public void setPremium(byte premium) { + this.premium = premium; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/GetAuctionDetails.java b/src/protocol/swg/auctionManagerClientListener/GetAuctionDetails.java new file mode 100644 index 00000000..127d3450 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/GetAuctionDetails.java @@ -0,0 +1,31 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class GetAuctionDetails extends SWGMessage { + + private long objectId; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setObjectId(data.getLong()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getObjectId() { + return objectId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/GetAuctionDetailsResponse.java b/src/protocol/swg/auctionManagerClientListener/GetAuctionDetailsResponse.java new file mode 100644 index 00000000..27fe7f85 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/GetAuctionDetailsResponse.java @@ -0,0 +1,21 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class GetAuctionDetailsResponse extends SWGMessage { + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/IsVendorOwnerMessage.java b/src/protocol/swg/auctionManagerClientListener/IsVendorOwnerMessage.java new file mode 100644 index 00000000..9492eb87 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/IsVendorOwnerMessage.java @@ -0,0 +1,31 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class IsVendorOwnerMessage extends SWGMessage { + + private long terminalId; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setTerminalId(data.getLong()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getTerminalId() { + return terminalId; + } + + public void setTerminalId(long terminalId) { + this.terminalId = terminalId; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/IsVendorOwnerResponseMessage.java b/src/protocol/swg/auctionManagerClientListener/IsVendorOwnerResponseMessage.java new file mode 100644 index 00000000..9f3e4aeb --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/IsVendorOwnerResponseMessage.java @@ -0,0 +1,42 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class IsVendorOwnerResponseMessage extends SWGMessage { + + private int permission; + private int errorCode; + private long terminalId; + private String terminalString; + + public IsVendorOwnerResponseMessage(int permission, int errorCode, long terminalId, String terminalString) { + this.permission = permission; + this.errorCode = errorCode; + this.terminalId = terminalId; + this.terminalString = terminalString; + } + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(26 + terminalString.length()).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 6); + result.putInt(0xCE04173E); + result.putInt(permission); + result.putInt(errorCode); + result.putLong(terminalId); + result.put(getAsciiString(terminalString)); + result.putShort((short) 0x64); // unk + return result.flip(); + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/ItemSoldMessage.java b/src/protocol/swg/auctionManagerClientListener/ItemSoldMessage.java new file mode 100644 index 00000000..3ff53489 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/ItemSoldMessage.java @@ -0,0 +1,55 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class ItemSoldMessage extends SWGMessage { + + public static final int SUCCESS = 0; + public static final int INVALIDAUCTIONER = 1; + public static final int INVALIDITEM = 2; + public static final int BADVENDOR = 3; + public static final int INVALIDPRICE = 4; + public static final int INVALIDDURATION = 5; + public static final int ALREADYFORSALE = 6; + public static final int UNKERROR = 6; + public static final int DONTOWNITEM = 8; + public static final int NOTENOUGHCREDITS = 9; + public static final int TOOMANYITEMS = 13; + public static final int PRICETOOHIGH = 14; + public static final int CANTSELLTRADINGITEM = 19; + public static final int VENDORFULL = 25; + + private long objectId; + private int status; + + public ItemSoldMessage(long objectId, int status) { + this.objectId = objectId; + this.status = status; + } + + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(18).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 3); + result.putInt(0x0E61CC92); + result.putLong(objectId); + result.putInt(status); + return result.flip(); + } + + public void setStatus(int status) { + this.status = status; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemMessage.java b/src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemMessage.java new file mode 100644 index 00000000..486d475c --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemMessage.java @@ -0,0 +1,41 @@ +package protocol.swg.auctionManagerClientListener; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class RetrieveAuctionItemMessage extends SWGMessage { + + private long objectId; + private long vendorId; + + @Override + public void deserialize(IoBuffer data) { + data.skip(6); + setObjectId(data.getLong()); + setVendorId(data.getLong()); + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public long getObjectId() { + return objectId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + + public long getVendorId() { + return vendorId; + } + + public void setVendorId(long vendorId) { + this.vendorId = vendorId; + } + +} diff --git a/src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemResponseMessage.java b/src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemResponseMessage.java new file mode 100644 index 00000000..dbd39f46 --- /dev/null +++ b/src/protocol/swg/auctionManagerClientListener/RetrieveAuctionItemResponseMessage.java @@ -0,0 +1,41 @@ +package protocol.swg.auctionManagerClientListener; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.SWGMessage; + +public class RetrieveAuctionItemResponseMessage extends SWGMessage { + + private long objectId; + private int status; + + public static final int SUCCESS = 0; + public static final int NOTALLOWED = 1; + public static final int FULLINVENTORY = 12; + public static final int TOOFAR = 0x100; + public static final int DONTRETRIEVE = 0x200; + + public RetrieveAuctionItemResponseMessage(long objectId, int status) { + this.objectId = objectId; + this.status = status; + } + + @Override + public void deserialize(IoBuffer data) { + // TODO Auto-generated method stub + + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(18).order(ByteOrder.LITTLE_ENDIAN); + result.putShort((short) 3); + result.putInt(0x9499EF8C); + result.putLong(objectId); + result.putInt(status); + return result.flip(); + } + +} diff --git a/src/resources/common/Opcodes.java b/src/resources/common/Opcodes.java index 4ac4d5ad..59b9880d 100644 --- a/src/resources/common/Opcodes.java +++ b/src/resources/common/Opcodes.java @@ -34,7 +34,7 @@ public class Opcodes { public static int ChatRequestRoomList = 0x4C3D2CFA; public static int ChatSystemMessage = CRC.StringtoCRC("ChatSystemMessage"); public static int ClientOpenContainerMessage = 0x2D2D6EE1; - public static int CommodotiesItemTypeListRequest = 0x48F493C5; + public static int CommoditiesItemTypeListRequest = 0x48F493C5; public static int CommoditiesResourceTypeListRequest = 0xCB1AE82D; public static int NewbieTutorialResponse = 0xCA88FBAD; public static int CmdSceneReady = 0x43FD1C22; @@ -45,6 +45,7 @@ public class Opcodes { public static int ClientVerifyAndLockNameRequest = 0x9eb04b9f; public static int DeleteCharacterMessage = 0xE87AD031; public static int GetMapLocationsMessage = 0x1A7AB839; + public static int IsVendorOwnerMessage = CRC.StringtoCRC("IsVendorOwnerMessage"); public static int LagRequest = 0x31805EE0; public static int LoginClientId = 0x41131F96; public static int ObjControllerMessage = 0x80CE5E46; @@ -77,9 +78,9 @@ public class Opcodes { public static int CollectionServerFirstListRequest = CRC.StringtoCRC("CollectionServerFirstListRequest"); public static int ShowHelmet = CRC.StringtoCRC("ShowHelmet"); public static int ShowBackpack = CRC.StringtoCRC("ShowBackpack"); + public static int CreateAuctionMessage = CRC.StringtoCRC("CreateAuctionMessage"); public static int ChatOnEnteredRoom = CRC.StringtoCRC("ChatOnEnteredRoom"); public static int ChatCreateRoom = CRC.StringtoCRC("ChatCreateRoom"); public static int ChatQueryRoom = 0x9CF2B192; - public static int Unknown = 0x173B91C2; // packet sent to server on every character load-in } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index a1dc9eb3..91a3eedd 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -361,11 +361,7 @@ public class PlayerService implements INetworkDispatch { swgOpcodes.put(Opcodes.SetLfgInterests, (session, data) -> { }); - - swgOpcodes.put(Opcodes.CommodotiesItemTypeListRequest, (session, data) -> { - - }); - + swgOpcodes.put(Opcodes.SetFurnitureRoationDegree, (session, data) -> { }); diff --git a/src/services/bazaar/AuctionItem.java b/src/services/bazaar/AuctionItem.java new file mode 100644 index 00000000..1eef0858 --- /dev/null +++ b/src/services/bazaar/AuctionItem.java @@ -0,0 +1,243 @@ +package services.bazaar; + +import com.sleepycat.je.Environment; +import com.sleepycat.je.Transaction; +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.PrimaryKey; +import engine.resources.objects.IPersistent; + +@Entity(version=0) +public class AuctionItem implements IPersistent { + + @PrimaryKey + private long objectId; + private long ownerId; + private long vendorId; + private long buyerId; + private long offerToId; + private int itemType; + private String ownerName; + private String bidderName; + private String itemName; + private String itemDescription; + private int price; + private int proxyBid; + private boolean auction; + private String vuid; + private int status; + private boolean onBazaar; + private long expireTime; + private int auctionOptions; + + public static final int PREMIUM = 0x400; + public static final int WITHDRAW = 0x800; + public final static int FORSALE = 1; + public final static int SOLD = 2; + public final static int EXPIRED = 4; + public final static int OFFERED = 5; + public final static int RETRIEVED = 6; + + @NotPersistent + private Transaction txn; + + public AuctionItem() { + + } + + public AuctionItem(long objectId, long ownerId) { + this.objectId = objectId; + this.ownerId = ownerId; + } + + + public long getObjectId() { + return objectId; + } + + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + + + public long getOwnerId() { + return ownerId; + } + + + public void setOwnerId(long ownerId) { + this.ownerId = ownerId; + } + + + public long getVendorId() { + return vendorId; + } + + + public void setVendorId(long vendorId) { + this.vendorId = vendorId; + } + + + public long getBuyerId() { + return buyerId; + } + + + public void setBuyerId(long buyerId) { + this.buyerId = buyerId; + } + + + public long getOfferToId() { + return offerToId; + } + + + public void setOfferToId(long offerToId) { + this.offerToId = offerToId; + } + + + public int getItemType() { + return itemType; + } + + + public void setItemType(int itemType) { + this.itemType = itemType; + } + + + public String getOwnerName() { + return ownerName; + } + + + public void setOwnerName(String ownerName) { + this.ownerName = ownerName; + } + + + public String getBidderName() { + return bidderName; + } + + + public void setBidderName(String bidderName) { + this.bidderName = bidderName; + } + + + public String getItemName() { + return itemName; + } + + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + + public String getItemDescription() { + return itemDescription; + } + + + public void setItemDescription(String itemDescription) { + this.itemDescription = itemDescription; + } + + + public int getPrice() { + return price; + } + + + public void setPrice(int price) { + this.price = price; + } + + + public int getProxyBid() { + return proxyBid; + } + + + public void setProxyBid(int proxyBid) { + this.proxyBid = proxyBid; + } + + + public boolean isAuction() { + return auction; + } + + + public void setAuction(boolean auction) { + this.auction = auction; + } + + + public String getVuid() { + return vuid; + } + + + public void setVuid(String vuid) { + this.vuid = vuid; + } + + + public int getStatus() { + return status; + } + + + public void setStatus(int status) { + this.status = status; + } + + + public boolean isOnBazaar() { + return onBazaar; + } + + + public void setOnBazaar(boolean onBazaar) { + this.onBazaar = onBazaar; + } + + + public long getExpireTime() { + return expireTime; + } + + + public void setExpireTime(long expireTime) { + this.expireTime = expireTime; + } + + + public int getAuctionOptions() { + return auctionOptions; + } + + + public void setAuctionOptions(int auctionOptions) { + this.auctionOptions = auctionOptions; + } + + @Override + public void createTransaction(Environment env) { + txn = env.beginTransaction(null, null); + } + + @Override + public Transaction getTransaction() { + return txn; + } + +} diff --git a/src/services/bazaar/BazaarService.java b/src/services/bazaar/BazaarService.java new file mode 100644 index 00000000..4d765826 --- /dev/null +++ b/src/services/bazaar/BazaarService.java @@ -0,0 +1,149 @@ +package services.bazaar; + +import java.nio.ByteOrder; +import java.util.Map; + +import main.NGECore; +import engine.clients.Client; +import engine.resources.objects.SWGObject; +import engine.resources.scene.Point3D; +import engine.resources.service.INetworkDispatch; +import engine.resources.service.INetworkRemoteEvent; +import resources.common.Opcodes; +import resources.objects.building.BuildingObject; +import resources.objects.creature.CreatureObject; +import protocol.swg.ClientIdMsg; +import protocol.swg.auctionManagerClientListener.CommoditiesItemTypeListResponse; +import protocol.swg.auctionManagerClientListener.CommoditiesResourceTypeListResponse; +import protocol.swg.auctionManagerClientListener.CreateAuctionMessage; +import protocol.swg.auctionManagerClientListener.IsVendorOwnerMessage; +import protocol.swg.auctionManagerClientListener.IsVendorOwnerResponseMessage; +import protocol.swg.auctionManagerClientListener.ItemSoldMessage; + +public class BazaarService implements INetworkDispatch { + + private NGECore core; + + public BazaarService(NGECore core) { + this.core = core; + } + + @Override + public void insertOpcodes(Map swgOpcodes, Map objControllerOpcodes) { + + swgOpcodes.put(Opcodes.CommoditiesItemTypeListRequest, (session, data) -> { + + Client client = core.getClient(session); + + if (client == null) + return; + + SWGObject player = client.getParent(); + + if (player == null) + return; + + session.write(new CommoditiesItemTypeListResponse().serialize()); + + }); + + swgOpcodes.put(Opcodes.IsVendorOwnerMessage, (session, data) -> { + + Client client = core.getClient(session); + + if (client == null) + return; + + SWGObject player = client.getParent(); + + if (player == null) + return; + + data = data.order(ByteOrder.LITTLE_ENDIAN); + data.position(0); + + IsVendorOwnerMessage request = new IsVendorOwnerMessage(); + request.deserialize(data); + long terminalId = request.getTerminalId(); + SWGObject terminal = core.objectService.getObject(terminalId); + if(terminal == null) + return; + Point3D pos = terminal.getWorldPosition(); + session.write(new IsVendorOwnerResponseMessage(2, 0, terminalId, "tatooine.@tatooine_region_names:mos_eisley.@terminal_name:terminal_bazaar." + terminalId + "#" + pos.x + "," + pos.z).serialize()); + + + }); + + swgOpcodes.put(Opcodes.CommoditiesResourceTypeListRequest, (session, data) -> { + + Client client = core.getClient(session); + + if (client == null) + return; + + SWGObject player = client.getParent(); + + if (player == null) + return; + + data = data.order(ByteOrder.LITTLE_ENDIAN); + + if(data.remaining() > 2) // if client attaches a string to the request then it has already recieved it on zone-in + return; + + //session.write(new CommoditiesResourceTypeListResponse(core.resourceService.getCompleteResourceNameHistory()).serialize()); + + }); + + swgOpcodes.put(Opcodes.CreateAuctionMessage, (session, data) -> { + + Client client = core.getClient(session); + + if (client == null) + return; + + SWGObject player = client.getParent(); + + if (player == null) + return; + + data = data.order(ByteOrder.LITTLE_ENDIAN); + data.position(0); + + CreateAuctionMessage createAuction = new CreateAuctionMessage(); + + SWGObject vendor = core.objectService.getObject(createAuction.getVendorId()); + SWGObject item = core.objectService.getObject(createAuction.getObjectId()); + + if(vendor == null || item == null || item instanceof CreatureObject || item instanceof BuildingObject) + return; + + + + }); + + + + } + + public void addAuction(CreatureObject player, SWGObject item, SWGObject vendor, int price, int duration, String description, boolean auction, boolean premium) { + + ItemSoldMessage itemSoldMsg = new ItemSoldMessage(item.getObjectID(), ItemSoldMessage.SUCCESS); + + if(item.getAttributes().containsKey("no_trade") || !item.isSubChildOf(player)) { + itemSoldMsg.setStatus(ItemSoldMessage.INVALIDITEM); + player.getClient().getSession().write(itemSoldMsg.serialize()); + return; + } + + + + } + + @Override + public void shutdown() { + + } + + +} diff --git a/src/services/resources/ResourceService.java b/src/services/resources/ResourceService.java index fa546a01..4d9e9eee 100644 --- a/src/services/resources/ResourceService.java +++ b/src/services/resources/ResourceService.java @@ -11343,4 +11343,8 @@ public class ResourceService implements INetworkDispatch { } return containerObject; } + + public Vector getCompleteResourceNameHistory() { + return completeResourceNameHistory; + } }