mirror of
https://github.com/ProjectSWGCore/pswgcommon.git
synced 2026-01-15 23:04:19 -05:00
Removed classes relating to ObjectDatabase, as the last usage has been replaced with MongoDB
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
|
||||
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
|
||||
* *
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
|
||||
@@ -31,10 +31,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.projectswg.common.encoding.Encodable;
|
||||
import com.projectswg.common.network.NetBuffer;
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
import com.projectswg.common.persistable.Persistable;
|
||||
|
||||
public class ChatAvatar implements Encodable, Persistable {
|
||||
public class ChatAvatar implements Encodable {
|
||||
|
||||
private static final AtomicReference<String> GALAXY = new AtomicReference<>("");
|
||||
private static final ChatAvatar SYSTEM_AVATAR = new ChatAvatar("system");
|
||||
@@ -78,20 +76,6 @@ public class ChatAvatar implements Encodable, Persistable {
|
||||
name = data.getAscii().toLowerCase(Locale.US);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NetBufferStream stream) {
|
||||
stream.addByte(1);
|
||||
stream.addAscii(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NetBufferStream stream) {
|
||||
byte ver = stream.getByte();
|
||||
if (ver == 0)
|
||||
stream.getAscii();
|
||||
name = stream.getAscii();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ChatAvatar[name='%s']", name);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
|
||||
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
|
||||
* *
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
|
||||
@@ -28,16 +28,15 @@ package com.projectswg.common.data.encodables.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.projectswg.common.encoding.CachedEncode;
|
||||
import com.projectswg.common.encoding.Encodable;
|
||||
import com.projectswg.common.network.NetBuffer;
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
import com.projectswg.common.persistable.Persistable;
|
||||
|
||||
public class ChatRoom implements Encodable, Persistable {
|
||||
public class ChatRoom implements Encodable {
|
||||
|
||||
private final CachedEncode cache;
|
||||
private final Set<ChatAvatar> moderators;
|
||||
@@ -285,50 +284,23 @@ public class ChatRoom implements Encodable, Persistable {
|
||||
return 23 + path.length() + (title.length() * 2) + avatarIdSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NetBufferStream stream) {
|
||||
stream.addByte(0);
|
||||
owner.save(stream);
|
||||
creator.save(stream);
|
||||
stream.addInt(id);
|
||||
stream.addInt(type);
|
||||
stream.addAscii(path);
|
||||
stream.addUnicode(title);
|
||||
stream.addBoolean(moderated);
|
||||
stream.addList(moderators, (a) -> a.save(stream));
|
||||
stream.addList(invited, (a) -> a.save(stream));
|
||||
stream.addList(banned, (a) -> a.save(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NetBufferStream stream) {
|
||||
stream.getByte();
|
||||
owner.read(stream);
|
||||
creator.read(stream);
|
||||
id = stream.getInt();
|
||||
type = stream.getInt();
|
||||
path = stream.getAscii();
|
||||
title = stream.getUnicode();
|
||||
moderated = stream.getBoolean();
|
||||
stream.getList((i) -> moderators.add(inflateAvatar(stream)));
|
||||
stream.getList((i) -> invited.add(inflateAvatar(stream)));
|
||||
stream.getList((i) -> banned.add(inflateAvatar(stream)));
|
||||
}
|
||||
|
||||
private ChatAvatar inflateAvatar(NetBufferStream stream) {
|
||||
ChatAvatar avatar = new ChatAvatar();
|
||||
avatar.read(stream);
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChatRoom[id=" + id + ", type=" + type + ", path='" + path + "', title='" + title + '\'' + ", creator=" + creator + ", moderated=" + moderated + ", isPublic=" + isPublic() + "]";
|
||||
}
|
||||
|
||||
public static ChatRoom create(NetBufferStream stream) {
|
||||
ChatRoom room = new ChatRoom();
|
||||
room.read(stream);
|
||||
return room;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
ChatRoom chatRoom = (ChatRoom) o;
|
||||
return id == chatRoom.id && type == chatRoom.type && moderated == chatRoom.moderated && Objects.equals(moderators, chatRoom.moderators) && Objects.equals(invited, chatRoom.invited) && Objects.equals(banned, chatRoom.banned) && Objects.equals(path, chatRoom.path) && Objects.equals(owner, chatRoom.owner) && Objects.equals(creator, chatRoom.creator) && Objects.equals(title, chatRoom.title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(moderators, invited, banned, id, type, path, owner, creator, title, moderated);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
|
||||
* *
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
|
||||
* Our goal is to create an emulator which will provide a server for players to *
|
||||
* continue playing a game similar to the one they used to play. We are basing *
|
||||
* it on the final publish of the game prior to end-game events. *
|
||||
* *
|
||||
* This file is part of PSWGCommon. *
|
||||
* *
|
||||
* --------------------------------------------------------------------------------*
|
||||
* *
|
||||
* PSWGCommon is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* PSWGCommon 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 Affero General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Affero General Public License *
|
||||
* along with PSWGCommon. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
package com.projectswg.common.persistable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
|
||||
public class InputPersistenceStream extends InputStream {
|
||||
|
||||
private final InputStream is;
|
||||
|
||||
public InputPersistenceStream(InputStream is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
public int read() {
|
||||
throw new UnsupportedOperationException("Unable to read raw data");
|
||||
}
|
||||
|
||||
public int read(byte[] b) {
|
||||
throw new UnsupportedOperationException("Unable to read raw data");
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) {
|
||||
throw new UnsupportedOperationException("Unable to read raw data");
|
||||
}
|
||||
|
||||
public <T extends Persistable> T read(PersistableCreator<T> creator) throws IOException {
|
||||
int size = readInt();
|
||||
try (NetBufferStream stream = new NetBufferStream(size)) {
|
||||
byte [] buffer = new byte[Math.min(size, 2048)];
|
||||
int pos = 0;
|
||||
while (pos < size) {
|
||||
int n = is.read(buffer, 0, Math.min(size-pos, buffer.length));
|
||||
if (n == -1)
|
||||
break;
|
||||
stream.write(buffer, 0, n);
|
||||
pos += n;
|
||||
}
|
||||
stream.position(0);
|
||||
return creator.create(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public long skip(long n) throws IOException {
|
||||
return is.skip(n);
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return is.available();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
is.close();
|
||||
}
|
||||
|
||||
public void mark(int readlimit) {
|
||||
is.mark(readlimit);
|
||||
}
|
||||
|
||||
public void reset() throws IOException {
|
||||
is.reset();
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
return is.markSupported();
|
||||
}
|
||||
|
||||
private int readInt() throws IOException {
|
||||
int ret = 0;
|
||||
int b;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
b = is.read();
|
||||
if (b != -1)
|
||||
ret |= b << (i * 8);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static interface PersistableCreator<T extends Persistable> {
|
||||
T create(NetBufferStream stream);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
|
||||
* *
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
|
||||
* Our goal is to create an emulator which will provide a server for players to *
|
||||
* continue playing a game similar to the one they used to play. We are basing *
|
||||
* it on the final publish of the game prior to end-game events. *
|
||||
* *
|
||||
* This file is part of PSWGCommon. *
|
||||
* *
|
||||
* --------------------------------------------------------------------------------*
|
||||
* *
|
||||
* PSWGCommon is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* PSWGCommon 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 Affero General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Affero General Public License *
|
||||
* along with PSWGCommon. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
package com.projectswg.common.persistable;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
|
||||
public class OutputPersistenceStream extends OutputStream implements Closeable {
|
||||
|
||||
private final OutputStream os;
|
||||
|
||||
public OutputPersistenceStream(OutputStream os) {
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) {
|
||||
throw new UnsupportedOperationException("Unable to write raw data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) {
|
||||
throw new UnsupportedOperationException("Unable to write raw data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) {
|
||||
throw new UnsupportedOperationException("Unable to write raw data");
|
||||
}
|
||||
|
||||
public void write(Persistable p) throws IOException {
|
||||
NetBufferStream buffer = new NetBufferStream();
|
||||
p.save(buffer);
|
||||
writeInt(buffer.size());
|
||||
os.write(buffer.array(), 0, buffer.size());
|
||||
flush();
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
public <T extends Persistable> void write(T obj, PersistableSaver<T> saver) throws IOException {
|
||||
NetBufferStream buffer = new NetBufferStream();
|
||||
saver.save(obj, buffer);
|
||||
writeInt(buffer.size());
|
||||
os.write(buffer.array(), 0, buffer.size());
|
||||
flush();
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
os.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
os.close();
|
||||
}
|
||||
|
||||
private void writeInt(int i) throws IOException {
|
||||
os.write(i >>> 0);
|
||||
os.write(i >>> 8);
|
||||
os.write(i >>> 16);
|
||||
os.write(i >>> 24);
|
||||
}
|
||||
|
||||
public static interface PersistableSaver<T extends Persistable> {
|
||||
void save(T obj, NetBufferStream stream);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
|
||||
* *
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
|
||||
* Our goal is to create an emulator which will provide a server for players to *
|
||||
* continue playing a game similar to the one they used to play. We are basing *
|
||||
* it on the final publish of the game prior to end-game events. *
|
||||
* *
|
||||
* This file is part of PSWGCommon. *
|
||||
* *
|
||||
* --------------------------------------------------------------------------------*
|
||||
* *
|
||||
* PSWGCommon is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* PSWGCommon 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 Affero General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Affero General Public License *
|
||||
* along with PSWGCommon. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
package com.projectswg.common.persistable;
|
||||
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
|
||||
public interface Persistable {
|
||||
void save(NetBufferStream stream);
|
||||
void read(NetBufferStream stream);
|
||||
}
|
||||
@@ -74,7 +74,6 @@ module com.projectswg.common {
|
||||
exports com.projectswg.common.network.packets.swg.zone.structures;
|
||||
exports com.projectswg.common.network.packets.swg.zone.trade;
|
||||
exports com.projectswg.common.network.hcap;
|
||||
exports com.projectswg.common.persistable;
|
||||
exports com.projectswg.common.process;
|
||||
exports com.projectswg.common.utilities;
|
||||
}
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
|
||||
* *
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
|
||||
* Our goal is to create an emulator which will provide a server for players to *
|
||||
* continue playing a game similar to the one they used to play. We are basing *
|
||||
* it on the final publish of the game prior to end-game events. *
|
||||
* *
|
||||
* This file is part of PSWGCommon. *
|
||||
* *
|
||||
* --------------------------------------------------------------------------------*
|
||||
* *
|
||||
* PSWGCommon is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* PSWGCommon 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 Affero General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Affero General Public License *
|
||||
* along with PSWGCommon. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
package com.projectswg.common.data.persistable
|
||||
|
||||
import com.projectswg.common.network.NetBufferStream
|
||||
import com.projectswg.common.persistable.InputPersistenceStream
|
||||
import com.projectswg.common.persistable.OutputPersistenceStream
|
||||
import com.projectswg.common.persistable.Persistable
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.*
|
||||
|
||||
class TestSimplePersistable {
|
||||
@Test
|
||||
@Throws(IOException::class)
|
||||
fun testInputPersistenceStream() {
|
||||
InputPersistenceStream(ByteArrayInputStream(createBuffer())).use { `is` ->
|
||||
val po = `is`.read { stream: NetBufferStream -> PersistableObject.create(stream) }
|
||||
Assertions.assertEquals(13, po.someInt)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(IOException::class)
|
||||
fun testOutputPersistenceStream() {
|
||||
val baos = ByteArrayOutputStream(8)
|
||||
val po = PersistableObject(13)
|
||||
OutputPersistenceStream(baos).use { os ->
|
||||
os.write(po)
|
||||
Assertions.assertArrayEquals(createBuffer(), baos.toByteArray())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(IOException::class)
|
||||
fun testPersistenceStreams() {
|
||||
val tmp = File.createTempFile("PersistableTest", "odb")
|
||||
val original = PersistableObject(17)
|
||||
OutputPersistenceStream(FileOutputStream(tmp)).use { os ->
|
||||
os.write(original)
|
||||
}
|
||||
InputPersistenceStream(FileInputStream(tmp)).use { `is` ->
|
||||
val recreated = `is`.read { stream: NetBufferStream -> PersistableObject.create(stream) }
|
||||
Assertions.assertEquals(original.someInt, recreated.someInt)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(IOException::class)
|
||||
fun testPersistenceStreamMultiple() {
|
||||
val tmp = File.createTempFile("PersistableTest", "odb")
|
||||
val original = PersistableObject(17)
|
||||
OutputPersistenceStream(FileOutputStream(tmp)).use { os ->
|
||||
os.write(original)
|
||||
os.write(original)
|
||||
os.write(original)
|
||||
}
|
||||
InputPersistenceStream(FileInputStream(tmp)).use { persistenceStream ->
|
||||
Assertions.assertEquals(
|
||||
original.someInt,
|
||||
persistenceStream.read { stream: NetBufferStream -> PersistableObject.create(stream) }.someInt)
|
||||
Assertions.assertEquals(
|
||||
original.someInt,
|
||||
persistenceStream.read { stream: NetBufferStream -> PersistableObject.create(stream) }.someInt)
|
||||
Assertions.assertEquals(
|
||||
original.someInt,
|
||||
persistenceStream.read { stream: NetBufferStream -> PersistableObject.create(stream) }.someInt)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createBuffer(): ByteArray {
|
||||
val stream = NetBufferStream(8)
|
||||
stream.addInt(4)
|
||||
stream.addInt(13)
|
||||
val array = stream.array()
|
||||
stream.close()
|
||||
return array
|
||||
}
|
||||
|
||||
private class PersistableObject(val someInt: Int) : Persistable {
|
||||
|
||||
override fun save(stream: NetBufferStream) {
|
||||
stream.addInt(someInt)
|
||||
}
|
||||
|
||||
override fun read(stream: NetBufferStream) {}
|
||||
|
||||
companion object {
|
||||
fun create(stream: NetBufferStream): PersistableObject {
|
||||
return PersistableObject(stream.int)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user