From ca2401147dfa9644a99a6f50f5bbf54b7a19def9 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Sat, 15 Mar 2014 13:50:36 -0400 Subject: [PATCH] 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()); }