Fixed packet struct issues in draft schematic packets, causing client crashes

This commit is contained in:
Ziggy
2023-07-28 21:37:03 +02:00
parent b76b0f4ebe
commit 084b1c8c24
5 changed files with 30 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// 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. *
@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import com.projectswg.common.data.CRC;
import com.projectswg.common.data.encodables.oob.StringId;
import com.projectswg.common.data.schematic.IngridientSlot.IngridientType;
public class DraftSchematic {
@@ -120,8 +121,8 @@ public class DraftSchematic {
complexity = 5;
canManufacture = true;
craftedSharedTemplate = clientTemplate;
IngridientSlot slot = new IngridientSlot("craft_food_ingredients_n.crystal", false);
slot.addSlotDataOption(new DraftSlotDataOption("craft_food_ingredients_n", "crystal", IngridientType.IT_RESOURCE_CLASS, 10));
IngridientSlot slot = new IngridientSlot(new StringId("craft_food_ingredients_n", "crystal"), false);
slot.addSlotDataOption(new DraftSlotDataOption(new StringId("craft_food_ingredients_n", "crystal"), "crystal", IngridientType.IT_RESOURCE_CLASS, 10));
ingridientSlot.add(slot);
}
}

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// 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. *
@@ -26,18 +26,19 @@
***********************************************************************************/
package com.projectswg.common.data.schematic;
import com.projectswg.common.data.encodables.oob.StringId;
import com.projectswg.common.data.schematic.IngridientSlot.IngridientType;
import com.projectswg.common.encoding.Encodable;
import com.projectswg.common.network.NetBuffer;
public class DraftSlotDataOption implements Encodable {
private String stfName;
private StringId stfName;
private String ingredientName;
private IngridientType ingredientType;
private int amount;
public DraftSlotDataOption(String stfName, String ingredientName, IngridientType ingredientType, int amount) {
public DraftSlotDataOption(StringId stfName, String ingredientName, IngridientType ingredientType, int amount) {
this.stfName = stfName;
this.ingredientName = ingredientName;
this.ingredientType = ingredientType;
@@ -45,13 +46,13 @@ public class DraftSlotDataOption implements Encodable {
}
public DraftSlotDataOption(){
this.stfName = "";
this.stfName = new StringId("", "");
this.ingredientName = "";
this.ingredientType = IngridientType.IT_NONE;
this.amount = 0;
}
public String getStfName() {
public StringId getStfName() {
return stfName;
}
@@ -69,24 +70,24 @@ public class DraftSlotDataOption implements Encodable {
@Override
public void decode(NetBuffer data) {
stfName = data.getAscii();
stfName = data.getEncodable(StringId.class);
ingredientName = data.getUnicode();
ingredientType = IngridientType.getTypeForInt(data.getInt());
ingredientType = IngridientType.getTypeForInt(data.getByte());
amount = data.getInt();
}
@Override
public byte[] encode() {
NetBuffer data = NetBuffer.allocate(getLength());
data.addAscii(stfName);
data.addEncodable(stfName);
data.addUnicode(ingredientName);
data.addInt(ingredientType.getId());
data.addByte(ingredientType.getId());
data.addInt(amount);
return data.array();
}
@Override
public int getLength() {
return 14 + stfName.length() + ingredientName.length() * 2;
return 9 + stfName.getLength() + ingredientName.length() * 2;
}
}

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// 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. *
@@ -31,6 +31,7 @@ import java.util.Collections;
import java.util.List;
import com.projectswg.common.data.EnumLookup;
import com.projectswg.common.data.encodables.oob.StringId;
import com.projectswg.common.encoding.Encodable;
import com.projectswg.common.network.NetBuffer;
@@ -38,11 +39,11 @@ public class IngridientSlot implements Encodable{
private final List<DraftSlotDataOption> slotOptions;
private String name;
private StringId name;
private boolean optional;
private String hardPoint;
public IngridientSlot(String name, boolean optional) {
public IngridientSlot(StringId name, boolean optional) {
this.name = name;
this.optional = optional;
this.slotOptions = new ArrayList<>();
@@ -50,13 +51,13 @@ public class IngridientSlot implements Encodable{
}
public IngridientSlot(){
this.name = "";
this.name = new StringId("", "");
this.optional = false;
this.slotOptions = new ArrayList<>();
this.hardPoint = "";
}
public String getName() {
public StringId getName() {
return name;
}
@@ -80,7 +81,7 @@ public class IngridientSlot implements Encodable{
@Override
public void decode(NetBuffer data) {
name = data.getAscii();
name = data.getEncodable(StringId.class);
optional = data.getBoolean();
slotOptions.clear();
slotOptions.addAll(data.getList(DraftSlotDataOption.class));
@@ -90,7 +91,7 @@ public class IngridientSlot implements Encodable{
@Override
public byte[] encode() {
NetBuffer data = NetBuffer.allocate(getLength());
data.addAscii(name);
data.addEncodable(name);
data.addBoolean(optional);
data.addList(slotOptions);
data.addAscii(hardPoint);
@@ -103,7 +104,7 @@ public class IngridientSlot implements Encodable{
for (DraftSlotDataOption draftSlotDataOption : slotOptions) {
length += draftSlotDataOption.getLength();
}
return 9 + name.length() + hardPoint.length() + length;
return 7 + name.getLength() + hardPoint.length() + length;
}
public enum IngridientType {

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// 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. *
@@ -36,7 +36,8 @@ public class DraftSlotsQueryResponse extends ObjectController {
private DraftSchematic schematic;
public DraftSlotsQueryResponse(DraftSchematic schematic) {
public DraftSlotsQueryResponse(DraftSchematic schematic, long objectId) {
super(objectId, CRC);
this.schematic = schematic;
}

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// 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. *
@@ -44,8 +44,8 @@ public class ResourceWeight extends ObjectController {
private int schematicId;
private int schematicCrc;
public ResourceWeight() {
super(CRC);
public ResourceWeight(long objectId) {
super(objectId, CRC);
attributes = new HashMap<>();
resourceMaxWeights = new HashMap<>();
}