From a907f479a90f8612f0901266f0a88423ded290fa Mon Sep 17 00:00:00 2001 From: Waverunner Date: Sat, 15 Mar 2014 11:48:59 -0400 Subject: [PATCH 1/3] Added Server Firsts packet --- .../CollectionServerFirstListResponse.java | 69 +++++++++++++++++++ src/services/PlayerService.java | 13 ++++ .../collections/CollectionService.java | 4 +- src/services/collections/ServerFirst.java | 25 ++++++- 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 src/protocol/swg/CollectionServerFirstListResponse.java diff --git a/src/protocol/swg/CollectionServerFirstListResponse.java b/src/protocol/swg/CollectionServerFirstListResponse.java new file mode 100644 index 00000000..74a01c2f --- /dev/null +++ b/src/protocol/swg/CollectionServerFirstListResponse.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package protocol.swg; + +import java.nio.ByteOrder; +import java.util.Map; +import java.util.Map.Entry; + +import main.NGECore; + +import org.apache.mina.core.buffer.IoBuffer; + +import services.collections.ServerFirst; +import engine.resources.common.CRC; + +public class CollectionServerFirstListResponse extends SWGMessage { + + private Map sfList; + + public CollectionServerFirstListResponse(Map serverFirstList){ + this.sfList = serverFirstList; + } + + @Override + public void deserialize(IoBuffer data) { + + } + + @Override + public IoBuffer serialize() { + IoBuffer buffer; + + synchronized (sfList) { + String galaxy = NGECore.getInstance().getConfig().getString("GALAXY_NAME"); + buffer = IoBuffer.allocate(14 + galaxy.length()).order(ByteOrder.LITTLE_ENDIAN); + buffer.putShort((short) 2); + buffer.putInt(CRC.StringtoCRC("CollectionServerFirstListResponse")); + + buffer.put(getAsciiString(galaxy + ".0")); + buffer.putInt(sfList.size()); + + for (Entry entry : sfList.entrySet()) { + buffer.expand(entry.getValue().getBytes().length); + buffer.put(entry.getValue().getBytes()); + + } + return buffer.flip(); + } + } +} diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index c1d1095d..d04a1f98 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -41,6 +41,7 @@ import org.apache.mina.core.session.IoSession; import protocol.swg.CharacterSheetResponseMessage; import protocol.swg.ClientIdMsg; import protocol.swg.ClientMfdStatusUpdateMessage; +import protocol.swg.CollectionServerFirstListResponse; import protocol.swg.CreateClientPathMessage; import protocol.swg.ExpertiseRequestMessage; import protocol.swg.GuildRequestMessage; @@ -392,7 +393,19 @@ public class PlayerService implements INetworkDispatch { @Override public void handlePacket(IoSession session, IoBuffer buffer) throws Exception { + + Client client = core.getClient(session); + if (client == null) + return; + + SWGObject player = client.getParent(); + + if (player == null) + return; + + CollectionServerFirstListResponse response = new CollectionServerFirstListResponse(core.guildService.getGuildObject().getServerFirst()); + session.write(response.serialize()); } }); diff --git a/src/services/collections/CollectionService.java b/src/services/collections/CollectionService.java index 61671372..f7cbe42e 100644 --- a/src/services/collections/CollectionService.java +++ b/src/services/collections/CollectionService.java @@ -142,7 +142,7 @@ public class CollectionService implements INetworkDispatch { int bits = 0; boolean noScriptOnModify = false; boolean clearOnComplete = false; - boolean noMessage = true; + boolean noMessage = false; boolean grantIfPreReqMet = true; boolean buddyCollection = false; int numAltTitles = 0; @@ -359,7 +359,7 @@ public class CollectionService implements INetworkDispatch { } if (trackServerFirst) { - if (core.guildService.getGuildObject().addServerFirst(collectionName, new ServerFirst(creature.getCustomName(), System.currentTimeMillis()))) { + if (core.guildService.getGuildObject().addServerFirst(collectionName, new ServerFirst(creature.getCustomName(), creature.getObjectId(), collectionName, System.currentTimeMillis()))) { addCollection(creature, "bdg_server_first_01"); } } diff --git a/src/services/collections/ServerFirst.java b/src/services/collections/ServerFirst.java index 1a955ed2..2b855fb4 100644 --- a/src/services/collections/ServerFirst.java +++ b/src/services/collections/ServerFirst.java @@ -21,6 +21,8 @@ ******************************************************************************/ package services.collections; +import org.apache.mina.core.buffer.IoBuffer; + import resources.objects.Delta; import com.sleepycat.persist.model.Persistent; @@ -29,11 +31,15 @@ import com.sleepycat.persist.model.Persistent; public class ServerFirst extends Delta { private String name; + private String collection; private long time; + private long objectId; - public ServerFirst(String name, long time) { + public ServerFirst(String name, long objectId, String collection, long time) { this.name = name; + this.objectId = objectId; this.time = time; + this.collection = collection; } public ServerFirst() { @@ -48,9 +54,24 @@ public class ServerFirst extends Delta { return time; } + public long getObjectId() { + return objectId; + } + + public String getCollection() { + return collection; + } + @Override public byte[] getBytes() { - return new byte[] { }; + synchronized(objectMutex) { + IoBuffer buffer = createBuffer(18 + collection.length() + (name.length() * 2)); + buffer.putInt((int) time / 1000); + buffer.put(getAsciiString(collection)); + buffer.putLong(objectId); + buffer.put(getUnicodeString(name)); + return buffer.array(); + } } } From ca2401147dfa9644a99a6f50f5bbf54b7a19def9 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Sat, 15 Mar 2014 13:50:36 -0400 Subject: [PATCH 2/3] Added Server First request, changed how response allocates bytes --- .../swg/CollectionServerFirstListRequest.java | 51 +++++++++++++++++++ .../CollectionServerFirstListResponse.java | 16 ++++-- src/services/PlayerService.java | 12 +++-- 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/protocol/swg/CollectionServerFirstListRequest.java diff --git a/src/protocol/swg/CollectionServerFirstListRequest.java b/src/protocol/swg/CollectionServerFirstListRequest.java new file mode 100644 index 00000000..d22ef081 --- /dev/null +++ b/src/protocol/swg/CollectionServerFirstListRequest.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package protocol.swg; + +import org.apache.mina.core.buffer.IoBuffer; + +public class CollectionServerFirstListRequest extends SWGMessage { + + private String server; + + public CollectionServerFirstListRequest() { + } + + @Override + public void deserialize(IoBuffer data) { + setServer(getAsciiString(data)); + } + + public String getServer() { + return server; + } + + @Override + public IoBuffer serialize() { + return null; + } + + public void setServer(String server) { + this.server = server; + } + +} diff --git a/src/protocol/swg/CollectionServerFirstListResponse.java b/src/protocol/swg/CollectionServerFirstListResponse.java index 74a01c2f..163627da 100644 --- a/src/protocol/swg/CollectionServerFirstListResponse.java +++ b/src/protocol/swg/CollectionServerFirstListResponse.java @@ -35,9 +35,11 @@ import engine.resources.common.CRC; public class CollectionServerFirstListResponse extends SWGMessage { private Map sfList; + private String server; - public CollectionServerFirstListResponse(Map serverFirstList){ + public CollectionServerFirstListResponse(String server, Map serverFirstList){ this.sfList = serverFirstList; + this.server = server; } @Override @@ -49,17 +51,21 @@ public class CollectionServerFirstListResponse extends SWGMessage { public IoBuffer serialize() { IoBuffer buffer; + int size = 0; + synchronized (sfList) { - String galaxy = NGECore.getInstance().getConfig().getString("GALAXY_NAME"); - buffer = IoBuffer.allocate(14 + galaxy.length()).order(ByteOrder.LITTLE_ENDIAN); + for (Entry entry : sfList.entrySet()) { + size += entry.getValue().getBytes().length; + } + + buffer = IoBuffer.allocate(12 + server.length() + size).order(ByteOrder.LITTLE_ENDIAN); buffer.putShort((short) 2); buffer.putInt(CRC.StringtoCRC("CollectionServerFirstListResponse")); - buffer.put(getAsciiString(galaxy + ".0")); + buffer.put(getAsciiString(server)); buffer.putInt(sfList.size()); for (Entry entry : sfList.entrySet()) { - buffer.expand(entry.getValue().getBytes().length); buffer.put(entry.getValue().getBytes()); } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index d04a1f98..1f2a7b6c 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -41,6 +41,7 @@ import org.apache.mina.core.session.IoSession; import protocol.swg.CharacterSheetResponseMessage; import protocol.swg.ClientIdMsg; import protocol.swg.ClientMfdStatusUpdateMessage; +import protocol.swg.CollectionServerFirstListRequest; import protocol.swg.CollectionServerFirstListResponse; import protocol.swg.CreateClientPathMessage; import protocol.swg.ExpertiseRequestMessage; @@ -58,6 +59,7 @@ import resources.common.ObjControllerOpcodes; import resources.common.Opcodes; import resources.common.RGB; import resources.common.SpawnPoint; +import resources.common.StringUtilities; import resources.datatables.PlayerFlags; import resources.guild.Guild; import resources.objects.Buff; @@ -392,8 +394,9 @@ public class PlayerService implements INetworkDispatch { swgOpcodes.put(Opcodes.CollectionServerFirstListRequest, new INetworkRemoteEvent() { @Override - public void handlePacket(IoSession session, IoBuffer buffer) throws Exception { - + public void handlePacket(IoSession session, IoBuffer data) throws Exception { + data.order(ByteOrder.LITTLE_ENDIAN); + Client client = core.getClient(session); if (client == null) @@ -404,7 +407,10 @@ public class PlayerService implements INetworkDispatch { if (player == null) return; - CollectionServerFirstListResponse response = new CollectionServerFirstListResponse(core.guildService.getGuildObject().getServerFirst()); + CollectionServerFirstListRequest request = new CollectionServerFirstListRequest(); + request.deserialize(data); + + CollectionServerFirstListResponse response = new CollectionServerFirstListResponse(request.getServer(), core.guildService.getGuildObject().getServerFirst()); session.write(response.serialize()); } From fc35adbf7863630f303da2c65446f7663343f45e Mon Sep 17 00:00:00 2001 From: Waverunner Date: Sat, 15 Mar 2014 14:30:09 -0400 Subject: [PATCH 3/3] ServerListResponse not sent on login anymore --- src/protocol/swg/CollectionServerFirstListRequest.java | 2 ++ src/services/PlayerService.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/protocol/swg/CollectionServerFirstListRequest.java b/src/protocol/swg/CollectionServerFirstListRequest.java index d22ef081..cc053664 100644 --- a/src/protocol/swg/CollectionServerFirstListRequest.java +++ b/src/protocol/swg/CollectionServerFirstListRequest.java @@ -32,6 +32,8 @@ public class CollectionServerFirstListRequest extends SWGMessage { @Override public void deserialize(IoBuffer data) { + data.getShort(); + data.getInt(); setServer(getAsciiString(data)); } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index 1f2a7b6c..5c6f5982 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -396,7 +396,8 @@ public class PlayerService implements INetworkDispatch { @Override public void handlePacket(IoSession session, IoBuffer data) throws Exception { data.order(ByteOrder.LITTLE_ENDIAN); - + data.position(0); + Client client = core.getClient(session); if (client == null) @@ -409,8 +410,13 @@ public class PlayerService implements INetworkDispatch { CollectionServerFirstListRequest request = new CollectionServerFirstListRequest(); request.deserialize(data); + + String server = request.getServer(); + System.out.println(server); + if (server == null || server.equals("")) + return; - CollectionServerFirstListResponse response = new CollectionServerFirstListResponse(request.getServer(), core.guildService.getGuildObject().getServerFirst()); + CollectionServerFirstListResponse response = new CollectionServerFirstListResponse(server, core.guildService.getGuildObject().getServerFirst()); session.write(response.serialize()); }