Refactored GCW & SWGMap, added factional presence

Might not work until next commit; I need to pull and commit due to an
outdated engine so I can test.

Fixed SWGList
Improved SWGMap
Added SWGMultiMap
Refactored GCWZones to be more flexible and scriptable.
Added Factional Presence.
~will have no effect in water.
Added minutely GCWZone updates.
Added 15-minutely other server GCWZone updates.
The GCWZone history should now work correctly.
Added two-daily weak GCW Zone resets.
Added a few datatables for PvpStatus and Factions.
Moved list objects to their own relevent resource folders.
This commit is contained in:
Treeku
2013-08-14 17:02:35 +01:00
parent 719024493e
commit cdb3823286
18 changed files with 1404 additions and 490 deletions
+91 -20
View File
@@ -22,11 +22,13 @@
package resources.objects;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
import org.apache.mina.core.buffer.IoBuffer;
@@ -54,6 +56,19 @@ public class SWGMap<K, V> implements Map<K, V> {
this.updateType = (short) updateType;
}
public SWGMap(Map<K, V> m) {
if (m instanceof SWGMap) {
this.messageBuilder = ((SWGMap<K, V>) m).messageBuilder;
this.viewType = ((SWGMap<K, V>) m).viewType;
this.updateType = ((SWGMap<K, V>) m).updateType;
map.putAll(m);
}
}
public SWGMap() {
}
public void clear() {
throw new UnsupportedOperationException();
}
@@ -96,19 +111,19 @@ public class SWGMap<K, V> implements Map<K, V> {
public V put(K key, V value) {
synchronized(objectMutex) {
if (key instanceof String && value instanceof IListObject) {
if ((key instanceof String || key instanceof Byte || key instanceof Short ||
key instanceof Integer || key instanceof Float ||key instanceof Long) &&
value instanceof IListObject) {
if (map.containsKey(key)) {
// Changing an existing map
V oldValue = map.put(key, value);
queue(item(2, key, ((IListObject) value).getBytes(), true, true));
queue(item(2, (String) key, ((IListObject) value).getBytes(), true, true));
return oldValue;
} else {
// Adding to the map
V oldValue = map.put(key, value);
queue(item(0, key, ((IListObject) value).getBytes(), true, true));
queue(item(0, (String) key, ((IListObject) value).getBytes(), true, true));
return oldValue;
}
@@ -119,11 +134,47 @@ public class SWGMap<K, V> implements Map<K, V> {
}
public void putAll(Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
synchronized(objectMutex) {
List<byte[]> buffer = new ArrayList<byte[]>();
for (Entry<? extends K, ? extends V> entry : m.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
if (key instanceof String || key instanceof Byte || key instanceof Short ||
key instanceof Integer || key instanceof Float || key instanceof Long ||
value instanceof IListObject) {
if (map.containsKey(key)) {
if (map.put(key, value) != null) {
buffer.add(item(2, (String) key, ((IListObject) value).getBytes(), true, true));
}
} else {
if (map.put(key, value) != null) {
buffer.add(item(0, (String) key, ((IListObject) value).getBytes(), true, true));
}
}
}
}
if (buffer.size() > 0) {
queue(buffer);
}
}
}
public V remove(Object arg0) {
throw new UnsupportedOperationException();
public V remove(Object key) {
synchronized(objectMutex) {
if (key instanceof String || key instanceof Byte || key instanceof Short ||
key instanceof Integer || key instanceof Float || key instanceof Long) {
V value = map.remove(key);
queue(item(1, key, ((IListObject) map.get(key)).getBytes(), true, true));
return value;
}
return null;
}
}
public int size() {
@@ -139,24 +190,44 @@ public class SWGMap<K, V> implements Map<K, V> {
}
public int getUpdateCounter() {
return updateCounter;
synchronized(objectMutex) {
return updateCounter;
}
}
private byte[] item(int type, K index, byte[] data, boolean useIndex, boolean useData) {
if (index instanceof String) {
int size = 1 + ((useIndex) ? (2 + ((String) index).getBytes().length) : 0) + ((useData) ? data.length : 0);
IoBuffer buffer = messageBuilder.bufferPool.allocate((size), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) type);
if (useIndex) buffer.put(((index instanceof String) ? StringUtilities.getAsciiString((String) index) : Integer.toString(0).getBytes()));
private byte[] item(int type, Object index, byte[] data, boolean useIndex, boolean useData) {
if (useIndex && !(index instanceof Byte) && !(index instanceof Short)
&& !(index instanceof Integer) && !(index instanceof Float)
&& !(index instanceof Long) && !(index instanceof String)) {
throw new IllegalArgumentException();
}
int size = 1 + ((useIndex) ? (2 + index.toString().getBytes().length) : 0) + ((useData) ? data.length : 0);
IoBuffer buffer = messageBuilder.bufferPool.allocate((size), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) type);
if (useIndex) {
if (index instanceof String) {
buffer.put(StringUtilities.getAsciiString((String) index));
} else if (index instanceof Byte) {
buffer.put(((Byte) index).byteValue());
} else if (index instanceof Short) {
buffer.putShort(((Short) index).shortValue());
} else if (index instanceof Integer) {
buffer.putInt(((Integer) index).intValue());
} else if (index instanceof Float) {
buffer.putFloat(((Float) index).floatValue());
} else if (index instanceof Long) {
buffer.putLong(((Long) index).longValue());
} else {
throw new IllegalArgumentException();
}
}
if (useData) buffer.put(data);
updateCounter++;
return buffer.array();
} else {
throw new IllegalArgumentException();
}
}
private void queue(byte[] data) {