Update SWGList, add gild deltas, play title delta

This commit is contained in:
Treeku
2013-07-24 01:50:51 +01:00
parent 04dabef565
commit a0afc196f4
18 changed files with 1092 additions and 340 deletions
@@ -22,15 +22,21 @@
package resources.objects.guild;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.GCWZone;
import resources.objects.CurrentServerGCWZoneHistory;
import resources.objects.CurrentServerGCWZonePercent;
import resources.objects.Guild;
import resources.objects.ObjectMessageBuilder;
import resources.objects.OtherServerGCWZonePercent;
public class GuildMessageBuilder extends ObjectMessageBuilder {
private List<IoBuffer> zoneUpdates = new ArrayList<IoBuffer>();
public GuildMessageBuilder(GuildObject guildObject) {
setObject(guildObject);
}
@@ -47,8 +53,8 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
buffer.put(getUnicodeString(guilds.getCustomName()));
buffer.putInt(guilds.getVolume());
buffer.putInt(guilds.getGuildList().size());
buffer.putInt(guilds.getGuildListUpdateCounter());
for (Guild object : guilds.getGuildList()) {
buffer.putInt(guilds.getGuildList().getUpdateCounter());
for (Guild object : guilds.getGuildList().get()) {
buffer.put(getAsciiString(object.getString()));
}
@@ -78,52 +84,52 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
buffer.putInt(guilds.getUnknown1());
buffer.putShort(guilds.getUnknown2());
buffer.putInt(guilds.getCurrentServerGCWZonePercentList().size());
buffer.putInt(guilds.getCurrentServerGCWZonePercentListUpdateCounter());
for (GCWZone object : guilds.getCurrentServerGCWZonePercentList()) {
buffer.putInt(guilds.getCurrentServerGCWZonePercentList().getUpdateCounter());
for (CurrentServerGCWZonePercent object : guilds.getCurrentServerGCWZonePercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getCurrentServerGCWTotalPercentList().size());
buffer.putInt(guilds.getCurrentServerGCWTotalPercentListUpdateCounter());
for (GCWZone object : guilds.getCurrentServerGCWTotalPercentList()) {
buffer.putInt(guilds.getCurrentServerGCWTotalPercentList().getUpdateCounter());
for (CurrentServerGCWZonePercent object : guilds.getCurrentServerGCWTotalPercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getCurrentServerGCWZoneHistoryList().size());
buffer.putInt(guilds.getCurrentServerGCWZoneHistoryListUpdateCounter());
for (GCWZone object : guilds.getCurrentServerGCWZoneHistoryList()) {
buffer.putInt(guilds.getCurrentServerGCWZoneHistoryList().getUpdateCounter());
for (CurrentServerGCWZoneHistory object : guilds.getCurrentServerGCWZoneHistoryList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getLastUpdateTime());
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getCurrentServerGCWTotalHistoryList().size());
buffer.putInt(guilds.getCurrentServerGCWTotalHistoryListUpdateCounter());
for (GCWZone object : guilds.getCurrentServerGCWTotalHistoryList()) {
buffer.putInt(guilds.getCurrentServerGCWTotalHistoryList().getUpdateCounter());
for (CurrentServerGCWZoneHistory object : guilds.getCurrentServerGCWTotalHistoryList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getLastUpdateTime());
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getOtherServerGCWZonePercentList().size());
buffer.putInt(guilds.getOtherServerGCWZonePercentListUpdateCounter());
for (GCWZone object : guilds.getOtherServerGCWZonePercentList()) {
buffer.putInt(guilds.getOtherServerGCWZonePercentList().getUpdateCounter());
for (OtherServerGCWZonePercent object : guilds.getOtherServerGCWZonePercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getServer()));
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getOtherServerGCWTotalPercentList().size());
buffer.putInt(guilds.getOtherServerGCWTotalPercentListUpdateCounter());
for (GCWZone object : guilds.getOtherServerGCWTotalPercentList()) {
buffer.putInt(guilds.getOtherServerGCWTotalPercentList().getUpdateCounter());
for (OtherServerGCWZonePercent object : guilds.getOtherServerGCWTotalPercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getServer()));
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(5); // Unknown
buffer.putInt(guilds.getUnknown3());
int size = buffer.position();
buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
@@ -133,14 +139,170 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
@Override
public void sendListDelta(short updateType, IoBuffer buffer) {
switch (updateType) {
default:
return;
public IoBuffer buildComplexity(float complexity) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putFloat(complexity);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 0, buffer, size + 4);
return buffer;
}
public IoBuffer buildSTF(String STFFile, int STFSpacer, String STFName) {
IoBuffer buffer = bufferPool.allocate((STFFile.length() + STFName.length() + 8), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(STFFile));
buffer.putInt(STFSpacer);
buffer.put(getAsciiString(STFName));
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 1, buffer, size + 4);
return buffer;
}
public IoBuffer buildCustomName(String customName) {
IoBuffer buffer = bufferPool.allocate((customName.length() + 4), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getUnicodeString(customName));
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 2, buffer, size + 4);
return buffer;
}
public IoBuffer buildVolume(int volume) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(volume);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 3, buffer, size + 4);
return buffer;
}
public IoBuffer buildServerId(int serverId) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(serverId);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 6, (short) 1, (short) 0, buffer, size + 4);
return buffer;
}
public IoBuffer buildUnknowns(int unknown1, short unknown2) {
IoBuffer buffer = bufferPool.allocate(6, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(unknown1);
buffer.putShort(unknown2);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 6, (short) 1, (short) 1, buffer, size + 4);
return buffer;
}
public IoBuffer buildGCWDelta() {
synchronized(zoneUpdates) {
if (zoneUpdates.size() > 0) {
int updates = zoneUpdates.size();
int size = 4;
for (int i = 0; i < zoneUpdates.size(); i++) {
size += zoneUpdates.get(i).position();
}
IoBuffer buffer = bufferPool.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < zoneUpdates.size(); i++) {
buffer.put(zoneUpdates.get(i).array());
}
zoneUpdates.clear();
buffer.flip();
return createDelta("GILD", (byte) 6, (short) updates, buffer, size);
} else {
return null;
}
}
}
public IoBuffer buildUnknown3(int unknown3) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(unknown3);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 6, (short) 1, (short) 8, buffer, size + 4);
return buffer;
}
final protected static char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int v;
for ( int j = 0; j < bytes.length; j++ ) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
synchronized(zoneUpdates) {
switch (viewType) {
case 3:
{
switch (updateType) {
case 4:
{
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 4, buffer, buffer.position() + 4);
for (int i = 0; i < ((GuildObject) object).core.getActiveConnectionsMap().size(); i++) {
((GuildObject) object).core.getActiveConnectionsMap().get(i).getSession().write(buffer);
}
break;
}
}
}
case 6:
{
switch (updateType) {
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
{
buffer = createDeltaObject(updateType, buffer, buffer.position());
//System.out.println("Packet: " + bytesToHex(buffer.array()));
zoneUpdates.add(buffer);
break;
}
default:
{
return;
}
}
}
}
}
}
@Override
public void sendBaselines() {
// TODO Auto-generated method stub
+75 -119
View File
@@ -21,11 +21,15 @@
******************************************************************************/
package resources.objects.guild;
import java.util.ArrayList;
import java.util.List;
import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.GCWZone;
import main.NGECore;
import resources.objects.CurrentServerGCWZoneHistory;
import resources.objects.CurrentServerGCWZonePercent;
import resources.objects.Guild;
import resources.objects.OtherServerGCWZonePercent;
import resources.objects.SWGList;
import com.sleepycat.persist.model.NotPersistent;
@@ -37,6 +41,10 @@ import engine.resources.scene.Quaternion;
public class GuildObject extends SWGObject {
protected NGECore core;
@NotPersistent
private GuildMessageBuilder messageBuilder = new GuildMessageBuilder(this);
// GILD 3
private float complexity = 0x803F0F00;
private String STFFile = "string_id_table";
@@ -44,46 +52,24 @@ public class GuildObject extends SWGObject {
private String STFName = "";
private String customName = "";
private int volume = 0;
private List<Guild> guildList = new ArrayList<Guild>();
@NotPersistent
private int guildListUpdateCounter = 0;
private SWGList<Guild> guildList = new SWGList<Guild>(messageBuilder, 3, 4);
// GILD 6
private int serverId = 0x00000041;
//private String STFName = "string_id_table";
private int unknown1 = 0;
private short unknown2 = 0;
private List<GCWZone> currentServerGCWZonePercentList = new ArrayList<GCWZone>();
@NotPersistent
private int currentServerGCWZonePercentListUpdateCounter = 0;
private List<GCWZone> currentServerGCWTotalPercentList = new ArrayList<GCWZone>();
@NotPersistent
private int currentServerGCWTotalPercentListUpdateCounter = 0;
private List<GCWZone> currentServerGCWZoneHistoryList = new ArrayList<GCWZone>();
@NotPersistent
private int currentServerGCWZoneHistoryListUpdateCounter = 0;
private SWGList<CurrentServerGCWZonePercent> currentServerGCWZonePercentList = new SWGList<CurrentServerGCWZonePercent>(messageBuilder, 6, 2);
private SWGList<CurrentServerGCWZonePercent> currentServerGCWTotalPercentList = new SWGList<CurrentServerGCWZonePercent>(messageBuilder, 6, 3);
private SWGList<CurrentServerGCWZoneHistory> currentServerGCWZoneHistoryList = new SWGList<CurrentServerGCWZoneHistory>(messageBuilder, 6, 4);
private SWGList<CurrentServerGCWZoneHistory> currentServerGCWTotalHistoryList = new SWGList<CurrentServerGCWZoneHistory>(messageBuilder, 6, 5);
private SWGList<OtherServerGCWZonePercent> otherServerGCWZonePercentList = new SWGList<OtherServerGCWZonePercent>(messageBuilder, 6, 6);
private SWGList<OtherServerGCWZonePercent> otherServerGCWTotalPercentList = new SWGList<OtherServerGCWZonePercent>(messageBuilder, 6, 7);
private int unknown3 = 5;
private List<GCWZone> currentServerGCWTotalHistoryList = new ArrayList<GCWZone>();
@NotPersistent
private int currentServerGCWTotalHistoryListUpdateCounter = 0;
private List<GCWZone> otherServerGCWZonePercentList = new ArrayList<GCWZone>();
@NotPersistent
private int otherServerGCWZonePercentListUpdateCounter = 0;
private List<GCWZone> otherServerGCWTotalPercentList = new ArrayList<GCWZone>();
@NotPersistent
private int otherServerGCWTotalPercentListUpdateCounter = 0;
@NotPersistent
private GuildMessageBuilder messageBuilder;
public GuildObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) {
public GuildObject(NGECore core, long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) {
super(objectID, planet, position, orientation, Template);
messageBuilder = new GuildMessageBuilder(this);
this.core = core;
}
public float getComplexity() {
@@ -96,6 +82,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.complexity = complexity;
}
notifyAll(messageBuilder.buildComplexity(complexity));
}
public String getSTFFile() {
@@ -108,6 +96,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.STFFile = STFFile;
}
notifyAll(messageBuilder.buildSTF(STFFile, STFSpacer, STFName));
}
public int getSTFSpacer() {
@@ -120,6 +110,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.STFSpacer = STFSpacer;
}
notifyAll(messageBuilder.buildSTF(STFFile, STFSpacer, STFName));
}
public String getSTFName() {
@@ -132,6 +124,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.STFName = STFName;
}
notifyAll(messageBuilder.buildSTF(STFFile, STFSpacer, STFName));
}
public String getCustomName() {
@@ -144,6 +138,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.customName = customName;
}
notifyAll(messageBuilder.buildCustomName(customName));
}
public int getVolume() {
@@ -156,24 +152,14 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.volume = volume;
}
notifyAll(messageBuilder.buildVolume(volume));
}
public List<Guild> getGuildList() {
public SWGList<Guild> getGuildList() {
return guildList;
}
public int getGuildListUpdateCounter() {
synchronized(objectMutex) {
return guildListUpdateCounter;
}
}
public void setGuildListUpdateCounter(int guildListUpdateCounter) {
synchronized(objectMutex) {
this.guildListUpdateCounter = guildListUpdateCounter;
}
}
public int getServerId() {
synchronized(objectMutex) {
return serverId;
@@ -184,6 +170,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.serverId = serverId;
}
notifyAll(messageBuilder.buildServerId(serverId));
}
public int getUnknown1() {
@@ -196,6 +184,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.unknown1 = unknown1;
}
notifyAll(messageBuilder.buildUnknowns(unknown1, unknown2));
}
public short getUnknown2() {
@@ -208,101 +198,53 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.unknown2 = unknown2;
}
notifyAll(messageBuilder.buildUnknowns(unknown1, unknown2));
}
public List<GCWZone> getCurrentServerGCWZonePercentList() {
public SWGList<CurrentServerGCWZonePercent> getCurrentServerGCWZonePercentList() {
return currentServerGCWZonePercentList;
}
public int getCurrentServerGCWZonePercentListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWZonePercentListUpdateCounter;
}
}
public void setCurrentServerGCWZonePercentListUpdateCounter(int currentServerGCWZonePercentListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWZonePercentListUpdateCounter = currentServerGCWZonePercentListUpdateCounter;
}
}
public List<GCWZone> getCurrentServerGCWTotalPercentList() {
public SWGList<CurrentServerGCWZonePercent> getCurrentServerGCWTotalPercentList() {
return currentServerGCWTotalPercentList;
}
public int getCurrentServerGCWTotalPercentListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWTotalPercentListUpdateCounter;
}
}
public void setCurrentServerGCWTotalPercentListUpdateCounter(int currentServerGCWTotalPercentListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWTotalPercentListUpdateCounter = currentServerGCWTotalPercentListUpdateCounter;
}
}
public List<GCWZone> getCurrentServerGCWZoneHistoryList() {
public SWGList<CurrentServerGCWZoneHistory> getCurrentServerGCWZoneHistoryList() {
return currentServerGCWZoneHistoryList;
}
public int getCurrentServerGCWZoneHistoryListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWZoneHistoryListUpdateCounter;
}
}
public void setCurrentServerGCWZoneHistoryListUpdateCounter(int currentServerGCWZoneHistoryListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWZoneHistoryListUpdateCounter = currentServerGCWZoneHistoryListUpdateCounter;
}
}
public List<GCWZone> getCurrentServerGCWTotalHistoryList() {
public SWGList<CurrentServerGCWZoneHistory> getCurrentServerGCWTotalHistoryList() {
return currentServerGCWTotalHistoryList;
}
public int getCurrentServerGCWTotalHistoryListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWTotalHistoryListUpdateCounter;
}
}
public void setCurrentServerGCWTotalHistoryListUpdateCounter(int currentServerGCWTotalHistoryListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWTotalHistoryListUpdateCounter = currentServerGCWTotalHistoryListUpdateCounter;
}
}
public List<GCWZone> getOtherServerGCWZonePercentList() {
public SWGList<OtherServerGCWZonePercent> getOtherServerGCWZonePercentList() {
return otherServerGCWZonePercentList;
}
public int getOtherServerGCWZonePercentListUpdateCounter() {
synchronized(objectMutex) {
return otherServerGCWZonePercentListUpdateCounter;
}
}
public void setOtherServerGCWZonePercentListUpdateCounter(int otherServerGCWZonePercentListUpdateCounter) {
synchronized(objectMutex) {
this.otherServerGCWZonePercentListUpdateCounter = otherServerGCWZonePercentListUpdateCounter;
}
}
public List<GCWZone> getOtherServerGCWTotalPercentList() {
public SWGList<OtherServerGCWZonePercent> getOtherServerGCWTotalPercentList() {
return otherServerGCWTotalPercentList;
}
public int getOtherServerGCWTotalPercentListUpdateCounter() {
public int getUnknown3() {
synchronized(objectMutex) {
return otherServerGCWTotalPercentListUpdateCounter;
return unknown3;
}
}
public void setOtherServerGCWTotalPercentListUpdateCounter(int otherServerGCWTotalPercentListUpdateCounter) {
public void setUnknown3(int unknown3) {
synchronized(objectMutex) {
this.otherServerGCWTotalPercentListUpdateCounter = otherServerGCWTotalPercentListUpdateCounter;
this.unknown3 = unknown3;
}
notifyAll(messageBuilder.buildUnknown3(unknown3));
}
public void sendGCWUpdate() {
IoBuffer buffer = messageBuilder.buildGCWDelta();
if (buffer != null) {
notifyAll(buffer);
}
}
@@ -311,6 +253,20 @@ public class GuildObject extends SWGObject {
destination.getSession().write(messageBuilder.buildBaseline3());
destination.getSession().write(messageBuilder.buildBaseline6());
}
private void notifyAll(IoBuffer buffer) {
//for (int i = 0; i < core.getActiveConnectionsMap().size(); i++) {
// core.getActiveConnectionsMap().get(i).getSession().write(buffer);
//}
System.out.println("Notifying all...");
synchronized(core.getActiveConnectionsMap()) {
for (Client client : core.getActiveConnectionsMap().values()) {
System.out.println("Notifying..." + client.getParent().getCustomName());
client.getSession().write(buffer);
System.out.println("Notified them.");
System.out.println("Packet: " + buffer.getHexDump());
}
}
}
}