From d4586fe13b0190b2d0cd84c74c0056f476b85c0a Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 30 Dec 2018 18:58:26 +0100 Subject: [PATCH 1/3] Created Client Path packets --- .../common/network/packets/PacketType.java | 2 + .../swg/zone/CreateClientPathMessage.java | 88 +++++++++++++++++++ .../swg/zone/DestroyClientPathMessage.java | 60 +++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java create mode 100644 src/main/java/com/projectswg/common/network/packets/swg/zone/DestroyClientPathMessage.java diff --git a/src/main/java/com/projectswg/common/network/packets/PacketType.java b/src/main/java/com/projectswg/common/network/packets/PacketType.java index a4d5efe..8dfe5d3 100644 --- a/src/main/java/com/projectswg/common/network/packets/PacketType.java +++ b/src/main/java/com/projectswg/common/network/packets/PacketType.java @@ -215,6 +215,8 @@ public enum PacketType { EXPERTISE_REQUEST_MESSAGE (ExpertiseRequestMessage.CRC, ExpertiseRequestMessage.class), CHANGE_ROLE_ICON_CHOICE (ChangeRoleIconChoice.CRC, ChangeRoleIconChoice.class), SHOW_LOOT_BOX (ShowLootBox.CRC, ShowLootBox.class), + CREATE_CLIENT_PATH_MESSAGE (CreateClientPathMessage.CRC, CreateClientPathMessage.class), + DESTROY_CLIENT_PATH_MESSAGE (DestroyClientPathMessage.CRC, DestroyClientPathMessage.class), // Chat CHAT_CREATE_ROOM (ChatCreateRoom.CRC, ChatCreateRoom.class), diff --git a/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java b/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java new file mode 100644 index 0000000..f7be7c5 --- /dev/null +++ b/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java @@ -0,0 +1,88 @@ +/*********************************************************************************** + * Copyright (c) 2018 /// 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 PSWGCommon. * + * * + * --------------------------------------------------------------------------------* + * * + * PSWGCommon 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. * + * * + * PSWGCommon 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 PSWGCommon. If not, see . * + ***********************************************************************************/ +package com.projectswg.common.network.packets.swg.zone; + +import com.projectswg.common.data.location.Point3D; +import com.projectswg.common.network.NetBuffer; +import com.projectswg.common.network.packets.SWGPacket; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * Makes the client construct a client path based on the given points + */ +public class CreateClientPathMessage extends SWGPacket { + + public static final int CRC = getCrc("CreateClientPathMessage"); + + private Collection points; + + public CreateClientPathMessage(Collection points) { + this.points = points; + } + + public CreateClientPathMessage(NetBuffer data) { + points = new LinkedList<>(); + decode(data); + } + + @Override + public void decode(NetBuffer data) { + if (!super.checkDecode(data, CRC)) + return; + + int pointCount = data.getInt(); + + for (int i = 0; i < pointCount; i++) { + Point3D point = new Point3D(); + + // Read point from packet + point.decode(data); + + points.add(point); + } + } + + @Override + public NetBuffer encode() { + int pointCount = points.size(); + int pointSize = pointCount * 3 * Integer.BYTES; // Three int coordinates, 3 * 4 = 12 + NetBuffer data = NetBuffer.allocate(10 + pointSize); + data.addShort(5); + data.addInt(CRC); + + data.addInt(pointCount); + + for (Point3D point : points) { + data.addEncodable(point); + } + + return data; + } + +} diff --git a/src/main/java/com/projectswg/common/network/packets/swg/zone/DestroyClientPathMessage.java b/src/main/java/com/projectswg/common/network/packets/swg/zone/DestroyClientPathMessage.java new file mode 100644 index 0000000..387b4a0 --- /dev/null +++ b/src/main/java/com/projectswg/common/network/packets/swg/zone/DestroyClientPathMessage.java @@ -0,0 +1,60 @@ +/*********************************************************************************** + * Copyright (c) 2018 /// 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 PSWGCommon. * + * * + * --------------------------------------------------------------------------------* + * * + * PSWGCommon 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. * + * * + * PSWGCommon 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 PSWGCommon. If not, see . * + ***********************************************************************************/ +package com.projectswg.common.network.packets.swg.zone; + +import com.projectswg.common.network.NetBuffer; +import com.projectswg.common.network.packets.SWGPacket; + +/** + * Destroys the currently active client path + */ +public class DestroyClientPathMessage extends SWGPacket { + + public static final int CRC = getCrc("DestroyClientPathMessage"); + + public DestroyClientPathMessage() { + } + + public DestroyClientPathMessage(NetBuffer data) { + decode(data); + } + + @Override + public void decode(NetBuffer data) { + + } + + @Override + public NetBuffer encode() { + NetBuffer data = NetBuffer.allocate(6); + data.addShort(5); + data.addInt(CRC); + + return data; + } + +} From 33bdc7f1be625302ee2d97b38fbbed401a123820 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 30 Dec 2018 19:07:10 +0100 Subject: [PATCH 2/3] CreateClientPathMessage encode and decode optimizations --- .../swg/zone/CreateClientPathMessage.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java b/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java index f7be7c5..3653fdb 100644 --- a/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java +++ b/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java @@ -56,16 +56,7 @@ public class CreateClientPathMessage extends SWGPacket { if (!super.checkDecode(data, CRC)) return; - int pointCount = data.getInt(); - - for (int i = 0; i < pointCount; i++) { - Point3D point = new Point3D(); - - // Read point from packet - point.decode(data); - - points.add(point); - } + points = data.getList(Point3D.class); } @Override @@ -75,12 +66,7 @@ public class CreateClientPathMessage extends SWGPacket { NetBuffer data = NetBuffer.allocate(10 + pointSize); data.addShort(5); data.addInt(CRC); - - data.addInt(pointCount); - - for (Point3D point : points) { - data.addEncodable(point); - } + data.addList(points); return data; } From 16b74d657dabf06cfe2395c23f4b5d9b3e54732f Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 30 Dec 2018 19:23:36 +0100 Subject: [PATCH 3/3] Implemented SWGPacket#getPacketData() in CreateClientPathMessage --- .../network/packets/swg/zone/CreateClientPathMessage.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java b/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java index 3653fdb..dba3cad 100644 --- a/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java +++ b/src/main/java/com/projectswg/common/network/packets/swg/zone/CreateClientPathMessage.java @@ -71,4 +71,10 @@ public class CreateClientPathMessage extends SWGPacket { return data; } + @Override + protected String getPacketData() { + return createPacketInformation( + "points", points + ); + } }