diff --git a/src/protocol/swg/CollectionServerFirstListRequest.java b/src/protocol/swg/CollectionServerFirstListRequest.java new file mode 100644 index 00000000..cc053664 --- /dev/null +++ b/src/protocol/swg/CollectionServerFirstListRequest.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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) { + data.getShort(); + data.getInt(); + 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 new file mode 100644 index 00000000..163627da --- /dev/null +++ b/src/protocol/swg/CollectionServerFirstListResponse.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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; + private String server; + + public CollectionServerFirstListResponse(String server, Map serverFirstList){ + this.sfList = serverFirstList; + this.server = server; + } + + @Override + public void deserialize(IoBuffer data) { + + } + + @Override + public IoBuffer serialize() { + IoBuffer buffer; + + int size = 0; + + synchronized (sfList) { + 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(server)); + buffer.putInt(sfList.size()); + + for (Entry entry : sfList.entrySet()) { + buffer.put(entry.getValue().getBytes()); + + } + return buffer.flip(); + } + } +} diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index 5c3eaf9c..71541bdb 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -41,6 +41,8 @@ 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; import protocol.swg.GuildRequestMessage; @@ -57,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; @@ -391,8 +394,30 @@ 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); + data.position(0); + + Client client = core.getClient(session); + if (client == null) + return; + + SWGObject player = client.getParent(); + + if (player == null) + return; + + 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(server, core.guildService.getGuildObject().getServerFirst()); + session.write(response.serialize()); } }); diff --git a/src/services/collections/CollectionService.java b/src/services/collections/CollectionService.java index 15567a6b..e82c61d8 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(); + } } }