Compare commits
2 Commits
c31641701d
...
1ca0a07b3a
Author | SHA1 | Date |
---|---|---|
|
1ca0a07b3a | |
|
84ade4ac37 |
241
pom.xml
241
pom.xml
|
@ -1,126 +1,131 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.krakatoa.proxy</groupId>
|
||||
<artifactId>KraProxySystem</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>net.krakatoa.proxy</groupId>
|
||||
<artifactId>KraProxySystem</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
</properties>
|
||||
<properties>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>msgpack-core</artifactId>
|
||||
<version>0.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>lombok</artifactId>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<scope>provided</scope>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>mongodb-driver-async</artifactId>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<version>3.12.10</version> <!-- 3.0.4 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.dytanic.cloudnet</groupId>
|
||||
<artifactId>cloudnet-bridge</artifactId>
|
||||
<version>3.4.0-RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.dytanic.cloudnet</groupId>
|
||||
<artifactId>cloudnet-driver</artifactId>
|
||||
<version>3.4.0-RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>earth.krakatoa</groupId>
|
||||
<artifactId>KraSocketClient</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>msgpack-core</artifactId>
|
||||
<version>0.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>lombok</artifactId>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<scope>provided</scope>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>mongodb-driver-async</artifactId>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<version>3.12.10</version> <!-- 3.0.4 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.dytanic.cloudnet</groupId>
|
||||
<artifactId>cloudnet-bridge</artifactId>
|
||||
<version>3.4.0-RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.dytanic.cloudnet</groupId>
|
||||
<artifactId>cloudnet-driver</artifactId>
|
||||
<version>3.4.0-RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>earth.krakatoa</groupId>
|
||||
<artifactId>KraSocketClient</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>earth.krakatoa</groupId>
|
||||
<artifactId>KraCore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<!-- https://github.com/TooTallNate/Java-WebSocket -->
|
||||
<repository>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>krakatoa-earth</id>
|
||||
<url>https://repo.krakatoa.umbach.dev/repository/krakatoa-earth/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>cloudnet-releases</id>
|
||||
<url>https://repo.cloudnetservice.eu/repository/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<!-- https://github.com/TooTallNate/Java-WebSocket -->
|
||||
<repository>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>krakatoa-earth</id>
|
||||
<url>https://repo.krakatoa.umbach.dev/repository/krakatoa-earth/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>cloudnet-releases</id>
|
||||
<url>https://repo.cloudnetservice.eu/repository/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
|
@ -5,6 +5,11 @@ import earth.krakatao.KraSocketClientConfig;
|
|||
import earth.krakatao.events.KraSocketClientEventInitiater;
|
||||
import earth.krakatao.events.KraSocketClientEventInterface;
|
||||
import earth.krakatao.protocol.KraSocketClientProtocol;
|
||||
import earth.krakatoa.core.config.MongoConfig;
|
||||
import earth.krakatoa.core.config.RedisConfig;
|
||||
import earth.krakatoa.core.mongo.MongoManager;
|
||||
import earth.krakatoa.core.redis.RedisManager;
|
||||
import earth.krakatoa.core.util.Formatter;
|
||||
import java.util.Arrays;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
|
@ -16,9 +21,6 @@ import net.krakatoa.proxy.listener.LoginListener;
|
|||
import net.krakatoa.proxy.listener.PlayerDisconnectListener;
|
||||
import net.krakatoa.proxy.listener.PostLoginListener;
|
||||
import net.krakatoa.proxy.listener.SocketClientMessageListener;
|
||||
import net.krakatoa.proxy.mongo.MongoManager;
|
||||
import net.krakatoa.proxy.redis.RedisManager;
|
||||
import net.krakatoa.proxy.util.Formatter;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
|
||||
|
@ -62,12 +64,13 @@ public class ProxySystem extends Plugin {
|
|||
|
||||
this.kraSocketClient.getSocketClient().connect();
|
||||
|
||||
this.mongoManager = new MongoManager(this.configHandler.getMongodbHost(),
|
||||
this.configHandler.getMongodbPort(), this.configHandler.getMongodbUsername(),
|
||||
this.configHandler.getMongodbPassword());
|
||||
this.mongoManager.connect(this.configHandler.getMongodbDatabase());
|
||||
this.mongoManager = new MongoManager(
|
||||
new MongoConfig(this.configHandler.getMongodbHost(), this.configHandler.getMongodbPort(),
|
||||
this.configHandler.getMongodbUsername(), this.configHandler.getMongodbPassword(),
|
||||
this.configHandler.getMongodbDatabase()));
|
||||
|
||||
this.redisManager = new RedisManager("redis://127.0.0.1:6379");
|
||||
this.redisManager = new RedisManager(
|
||||
new RedisConfig(this.configHandler.getRedisHost(), this.configHandler.getRedisPort()));
|
||||
this.redisManager.connect();
|
||||
|
||||
loadListeners();
|
||||
|
@ -79,9 +82,8 @@ public class ProxySystem extends Plugin {
|
|||
this.kraSocketClient.getSocketClient().getConnection().close();
|
||||
this.kraSocketClient.getSocketClient().getConnection().closeConnection(1, "");
|
||||
|
||||
this.mongoManager.getMongoClient().close();
|
||||
|
||||
this.redisManager.close();
|
||||
this.mongoManager.shutdown();
|
||||
this.redisManager.shutdown();
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,7 @@ public class KrakatoapCommand extends Command {
|
|||
.getKraSocketClientProtocol()
|
||||
.getReceivedQueueMessages().size())));
|
||||
|
||||
String uuid = ProxySystem.getInstance().getFormatter()
|
||||
.formatUuid(player.getUniqueId().toString());
|
||||
String uuid = ProxySystem.getInstance().getFormatter().formatUuid(player.getUniqueId());
|
||||
|
||||
RMap<String, String> map = ProxySystem.getInstance().getRedisManager()
|
||||
.getRedissonClient()
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.redisson.api.RMap;
|
||||
|
||||
|
@ -29,25 +30,29 @@ public class PlayerDisconnectListener implements Listener {
|
|||
.getMap("player:" + uuid);
|
||||
|
||||
// mongo
|
||||
ProxySystem.getInstance().getMongoManager().getPlayers()
|
||||
.find(Filters.eq("uuid", uuid))
|
||||
.first((document, throwable) -> {
|
||||
if (document != null) {
|
||||
List<Bson> updatesList = new ArrayList<>();
|
||||
Document document = (Document) ProxySystem.getInstance().getMongoManager()
|
||||
.getPlayersCollection()
|
||||
.find(Filters.eq("uuid", uuid)).first();
|
||||
|
||||
map.forEach((key, value) -> {
|
||||
if (!Objects.equals(key, "_id") && !Objects.equals(key, "uuid")) {
|
||||
updatesList.add(Updates.set(key, value));
|
||||
}
|
||||
});
|
||||
if (document != null) {
|
||||
List<Bson> updatesList = new ArrayList<>();
|
||||
|
||||
Bson updates = Updates.combine(updatesList);
|
||||
map.forEach((key, value) -> {
|
||||
if (!Objects.equals(key, "_id") && !Objects.equals(key, "uuid")) {
|
||||
updatesList.add(Updates.set(key, value));
|
||||
}
|
||||
});
|
||||
|
||||
UpdateOptions options = new UpdateOptions().upsert(true);
|
||||
Bson updates = Updates.combine(updatesList);
|
||||
|
||||
System.out.println("doc: " + document.keySet());
|
||||
UpdateOptions options = new UpdateOptions().upsert(true);
|
||||
|
||||
ProxySystem.getInstance().getMongoManager().getPlayers()
|
||||
System.out.println("doc: " + document.keySet());
|
||||
|
||||
ProxySystem.getInstance().getMongoManager().getPlayersCollection()
|
||||
.updateOne(Filters.eq("uuid", uuid), updates);
|
||||
/*
|
||||
ProxySystem.getInstance().getMongoManager().getPlayersCollection()
|
||||
.updateOne(document, updates, options, (result, t) -> {
|
||||
System.out.println(result == null);
|
||||
|
||||
|
@ -55,11 +60,10 @@ public class PlayerDisconnectListener implements Listener {
|
|||
System.out.println("Modified document count: " + result.getModifiedCount());
|
||||
System.out.println("Upserted id: " + result.getUpsertedId());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
System.out.println("Mongo player is null on disconnect");
|
||||
}
|
||||
});
|
||||
}); */
|
||||
} else {
|
||||
System.out.println("Mongo player is null on disconnect");
|
||||
}
|
||||
|
||||
// redis
|
||||
if (!map.isEmpty()) {
|
||||
|
|
|
@ -37,110 +37,107 @@ public class PostLoginListener implements Listener {
|
|||
String uuid = ProxySystem.getInstance().getFormatter()
|
||||
.formatUuid(proxiedPlayer.getUniqueId().toString());
|
||||
|
||||
ProxySystem.getInstance().getMongoManager().getPlayers()
|
||||
.find(Filters.eq("uuid", uuid))
|
||||
.first((document, throwable) -> {
|
||||
if (document == null) { // new player - create entries in databases
|
||||
System.out.println("create player in db");
|
||||
String voiceWebCode = generateVoiceWebCode(uuid);
|
||||
Document document = (Document) ProxySystem.getInstance().getMongoManager()
|
||||
.getPlayersCollection()
|
||||
.find(Filters.eq("uuid", uuid)).first();
|
||||
|
||||
document = new Document("uuid", uuid).append("voiceWebCode", voiceWebCode);
|
||||
if (document == null) { // new player - create entries in databases
|
||||
System.out.println("create player in db");
|
||||
String voiceWebCode = generateVoiceWebCode(uuid);
|
||||
|
||||
ProxySystem.getInstance().getMongoManager().getPlayers()
|
||||
.insertOne(document, (unused, throwable1) -> {
|
||||
System.out.println("insertOne");
|
||||
});
|
||||
document = new Document("uuid", uuid).append("voiceWebCode", voiceWebCode);
|
||||
|
||||
sendVoiceWebCodeUrl(proxiedPlayer, voiceWebCode);
|
||||
ProxySystem.getInstance().getMongoManager().getPlayersCollection().insertOne(document);
|
||||
|
||||
// redis
|
||||
sendVoiceWebCodeUrl(proxiedPlayer, voiceWebCode);
|
||||
|
||||
RMap<String, String> map = ProxySystem.getInstance().getRedisManager()
|
||||
.getRedissonClient()
|
||||
.getMap("player:" + uuid);
|
||||
// redis
|
||||
|
||||
if (map.isEmpty()) {
|
||||
map.put("uuid", uuid);
|
||||
map.put("voiceWebCode", "voiceWebCode");
|
||||
RMap<String, String> map = ProxySystem.getInstance().getRedisManager()
|
||||
.getRedissonClient()
|
||||
.getMap("player:" + uuid);
|
||||
|
||||
ProxySystem.getInstance().getLogger().info("PUT !");
|
||||
} else {
|
||||
ProxySystem.getInstance().getLogger()
|
||||
.warning("REDIS player " + uuid + " exists in the cache, but should not exist");
|
||||
}
|
||||
} else { // player found in the database
|
||||
if (map.isEmpty()) {
|
||||
map.put("uuid", uuid);
|
||||
map.put("voiceWebCode", "voiceWebCode");
|
||||
|
||||
// redis
|
||||
ProxySystem.getInstance().getLogger().info("mongodb player " + document.keySet());
|
||||
ProxySystem.getInstance().getLogger().info("PUT !");
|
||||
} else {
|
||||
ProxySystem.getInstance().getLogger()
|
||||
.warning("REDIS player " + uuid + " exists in the cache, but should not exist");
|
||||
}
|
||||
} else { // player found in the database
|
||||
|
||||
RMap<String, String> map = ProxySystem.getInstance().getRedisManager()
|
||||
.getRedissonClient()
|
||||
.getMap("player:" + uuid);
|
||||
// redis
|
||||
ProxySystem.getInstance().getLogger().info("mongodb player " + document.keySet());
|
||||
|
||||
if (map.isEmpty()) {
|
||||
map.put("uuid", uuid);
|
||||
map.put("voiceWebCode", "voiceWebCode");
|
||||
RMap<String, String> map = ProxySystem.getInstance().getRedisManager()
|
||||
.getRedissonClient()
|
||||
.getMap("player:" + uuid);
|
||||
|
||||
document.forEach((key, value) -> {
|
||||
if (!Objects.equals(key, "_id")) {
|
||||
ProxySystem.getInstance().getLogger()
|
||||
.info("key " + key + " value " + value.toString());
|
||||
map.put(key, value.toString());
|
||||
}
|
||||
});
|
||||
ProxySystem.getInstance().getLogger().info("PUT !");
|
||||
} else {
|
||||
ProxySystem.getInstance().getLogger()
|
||||
.warning("REDIS player " + uuid + " exists in the cache, but should not exist");
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
map.put("uuid", uuid);
|
||||
map.put("voiceWebCode", "voiceWebCode");
|
||||
|
||||
// check if both sockets connected
|
||||
int cmdID = ProxySystem.getInstance().getKraSocketClientProtocol().generateCmdID();
|
||||
|
||||
Document finalDocument = document;
|
||||
Consumer<KraSocketClientProtocolMessage> consumer = value -> {
|
||||
if (value.getArgs().equals("1")) {
|
||||
// connected! Send player to game server
|
||||
System.out.println(
|
||||
proxiedPlayer.getName() + " sockets connected! Send player to game server");
|
||||
proxiedPlayer.sendMessage(
|
||||
new TextComponent("§bWillkommen zurück §6" + proxiedPlayer.getDisplayName()));
|
||||
|
||||
ProxyServer.getInstance().getScheduler().schedule(ProxySystem.getInstance(), () -> {
|
||||
ServerInfo serverInfos = ProxyServer.getInstance().getServerInfo("NewYork-1");
|
||||
proxiedPlayer.connect(serverInfos);
|
||||
}, 2L, TimeUnit.SECONDS);
|
||||
} else {
|
||||
// not connected! Send voice url
|
||||
System.out.println(
|
||||
proxiedPlayer.getName() + " sockets not connected! Send voice url");
|
||||
|
||||
String voiceWebCode = generateVoiceWebCode(uuid);
|
||||
|
||||
Bson updates = Updates.combine(Updates.set("voiceWebCode", voiceWebCode));
|
||||
|
||||
UpdateOptions options = new UpdateOptions().upsert(true);
|
||||
|
||||
ProxySystem.getInstance().getMongoManager().getPlayers()
|
||||
.updateOne(finalDocument, updates, options, (updateResult, throwable1) -> {
|
||||
});
|
||||
|
||||
System.out.println("voiceWebCode " + voiceWebCode);
|
||||
|
||||
sendVoiceWebCodeUrl(proxiedPlayer, voiceWebCode);
|
||||
}
|
||||
|
||||
System.out.println(
|
||||
"consumer response value " + value.getUuid() + " " + value.getCmdID());
|
||||
};
|
||||
|
||||
ProxySystem.getInstance().getKraSocketClient().getSocketClient()
|
||||
.SendMessage(new KraSocketClientProtocolMessage(
|
||||
KraSocketClientProtocolStatus.GET.getStatus(), cmdID,
|
||||
KraSocketClientProtocolDest.BACKEND.getStatus(), proxiedPlayer.getUniqueId(),
|
||||
(short) 10, "", consumer));
|
||||
document.forEach((key, value) -> {
|
||||
if (!Objects.equals(key, "_id")) {
|
||||
ProxySystem.getInstance().getLogger()
|
||||
.info("key " + key + " value " + value.toString());
|
||||
map.put(key, value.toString());
|
||||
}
|
||||
});
|
||||
ProxySystem.getInstance().getLogger().info("PUT !");
|
||||
} else {
|
||||
ProxySystem.getInstance().getLogger()
|
||||
.warning("REDIS player " + uuid + " exists in the cache, but should not exist");
|
||||
}
|
||||
|
||||
// check if both sockets connected
|
||||
int cmdID = ProxySystem.getInstance().getKraSocketClientProtocol().generateCmdID();
|
||||
|
||||
Document finalDocument = document;
|
||||
Consumer<KraSocketClientProtocolMessage> consumer = value -> {
|
||||
if (value.getArgs().equals("1")) {
|
||||
// connected! Send player to game server
|
||||
System.out.println(
|
||||
proxiedPlayer.getName() + " sockets connected! Send player to game server");
|
||||
proxiedPlayer.sendMessage(
|
||||
new TextComponent("§bWillkommen zurück §6" + proxiedPlayer.getDisplayName()));
|
||||
|
||||
ProxyServer.getInstance().getScheduler().schedule(ProxySystem.getInstance(), () -> {
|
||||
ServerInfo serverInfos = ProxyServer.getInstance().getServerInfo("NewYork-1");
|
||||
proxiedPlayer.connect(serverInfos);
|
||||
}, 2L, TimeUnit.SECONDS);
|
||||
} else {
|
||||
// not connected! Send voice url
|
||||
System.out.println(
|
||||
proxiedPlayer.getName() + " sockets not connected! Send voice url");
|
||||
|
||||
String voiceWebCode = generateVoiceWebCode(uuid);
|
||||
|
||||
Bson updates = Updates.combine(Updates.set("voiceWebCode", voiceWebCode));
|
||||
|
||||
UpdateOptions options = new UpdateOptions().upsert(true);
|
||||
|
||||
ProxySystem.getInstance().getMongoManager().getPlayersCollection()
|
||||
.updateOne(finalDocument, updates, options);
|
||||
|
||||
System.out.println("voiceWebCode " + voiceWebCode);
|
||||
|
||||
sendVoiceWebCodeUrl(proxiedPlayer, voiceWebCode);
|
||||
}
|
||||
|
||||
System.out.println(
|
||||
"consumer response value " + value.getUuid() + " " + value.getCmdID());
|
||||
};
|
||||
|
||||
ProxySystem.getInstance().getKraSocketClient().getSocketClient()
|
||||
.SendMessage(new KraSocketClientProtocolMessage(
|
||||
KraSocketClientProtocolStatus.GET.getStatus(), cmdID,
|
||||
KraSocketClientProtocolDest.BACKEND.getStatus(), proxiedPlayer.getUniqueId(),
|
||||
(short) 10, "", consumer));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package net.krakatoa.proxy.mongo;
|
||||
|
||||
import com.mongodb.async.client.MongoClient;
|
||||
import com.mongodb.async.client.MongoClients;
|
||||
import com.mongodb.async.client.MongoCollection;
|
||||
import com.mongodb.async.client.MongoDatabase;
|
||||
import lombok.Getter;
|
||||
import org.bson.Document;
|
||||
|
||||
public class MongoManager {
|
||||
|
||||
private final String hostname;
|
||||
private final int port;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
// TODO: search for replacements for deprecated methods
|
||||
@Getter
|
||||
private MongoDatabase mongoDatabase;
|
||||
@Getter
|
||||
private MongoClient mongoClient;
|
||||
@Getter
|
||||
private MongoCollection<Document> players;
|
||||
|
||||
public MongoManager(String hostname, int port, String username, String password) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void connect(String database) {
|
||||
mongoClient = MongoClients.create(
|
||||
"mongodb://" + username + ":" + password + "@" + hostname + ":" + port + "/?authSource="
|
||||
+ database);
|
||||
|
||||
mongoDatabase = mongoClient.getDatabase(database);
|
||||
players = mongoDatabase.getCollection("players");
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package net.krakatoa.proxy.redis;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlayerTest {
|
||||
|
||||
private String name;
|
||||
private int money;
|
||||
private String car;
|
||||
|
||||
public PlayerTest(String name, int money, String car) {
|
||||
this.name = name;
|
||||
this.money = money;
|
||||
this.car = car;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package net.krakatoa.proxy.redis;
|
||||
|
||||
import lombok.Data;
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
|
||||
@Data
|
||||
public class RedisManager {
|
||||
|
||||
private final String connectionUri;
|
||||
|
||||
private Config config;
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
//private StatefulRedisConnection<String, String> connection;
|
||||
//private RedisStringCommands<String, String> commands;
|
||||
//private RedisKeyReactiveCommands<String, String> keyReactiveCommands;
|
||||
|
||||
|
||||
public void connect() {
|
||||
this.config = new Config();
|
||||
//this.config.setCodec(new MsgPackJacksonCodec());
|
||||
this.config.useSingleServer().setAddress(this.connectionUri);
|
||||
|
||||
this.redissonClient = Redisson.create(this.config);
|
||||
|
||||
//this.connection = client.connect();
|
||||
//this.commands = connection.sync();
|
||||
//this.keyReactiveCommands = this.connection.reactive();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.redissonClient.shutdown();
|
||||
}
|
||||
}
|
||||
// RedisKeyReactiveCommands
|
|
@ -1,19 +0,0 @@
|
|||
package net.krakatoa.proxy.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Formatter {
|
||||
|
||||
public String formatUuid(String uuid) {
|
||||
return uuid.replaceAll("-", "");
|
||||
}
|
||||
|
||||
public UUID stringToUuid(String s) {
|
||||
BigInteger bigInteger = new BigInteger(s.substring(0, 16), 16);
|
||||
BigInteger bigInteger1 = new BigInteger(s.substring(16, 32), 16);
|
||||
|
||||
return new UUID(bigInteger.longValue(), bigInteger1.longValue());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue