feat: implemented dynamic lobby server with specify group id
This commit is contained in:
parent
435e7d58dc
commit
775890f917
@ -63,18 +63,3 @@ spec:
|
|||||||
value: ws://kubik-discovery:8080
|
value: ws://kubik-discovery:8080
|
||||||
- name: KUBIK_GROUP_ID
|
- name: KUBIK_GROUP_ID
|
||||||
value: lobby
|
value: lobby
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
|
|
||||||
metadata:
|
|
||||||
name: lobby
|
|
||||||
|
|
||||||
spec:
|
|
||||||
type: NodePort
|
|
||||||
selector:
|
|
||||||
app: lobby
|
|
||||||
ports:
|
|
||||||
- port: 25565
|
|
||||||
targetPort: 25565
|
|
||||||
protocol: TCP
|
|
||||||
@ -3,6 +3,7 @@ package ru.dragonestia.kubik.plugin;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
@ -46,6 +47,9 @@ public class KubikPlugin implements ProxyServerRegistry {
|
|||||||
private final Map<String, Consumer<PluginMessageEvent>> pluginChannelHandlers = new ConcurrentHashMap<>();
|
private final Map<String, Consumer<PluginMessageEvent>> pluginChannelHandlers = new ConcurrentHashMap<>();
|
||||||
private final Map<String, RegisteredServer> registeredServers = new ConcurrentHashMap<>();
|
private final Map<String, RegisteredServer> registeredServers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private Kubik kubik;
|
||||||
|
private String initialServerGroupId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public KubikPlugin(ProxyServer proxyServer, Logger logger) {
|
public KubikPlugin(ProxyServer proxyServer, Logger logger) {
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
@ -56,8 +60,10 @@ public class KubikPlugin implements ProxyServerRegistry {
|
|||||||
|
|
||||||
logger.info("Using kubik urls: {}, {}", kubikHttpUrl, kubikWsUrl);
|
logger.info("Using kubik urls: {}, {}", kubikHttpUrl, kubikWsUrl);
|
||||||
|
|
||||||
var kubik = new Kubik(kubikHttpUrl, kubikWsUrl);
|
kubik = new Kubik(kubikHttpUrl, kubikWsUrl);
|
||||||
proxyControl = kubik.initProxy(this);
|
proxyControl = kubik.initProxy(this);
|
||||||
|
|
||||||
|
initialServerGroupId = EnvUtil.getString("KUBIK_INITIAL_SERVER_GROUP_ID", "lobby");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -86,6 +92,33 @@ public class KubikPlugin implements ProxyServerRegistry {
|
|||||||
proxyControl.dispose();
|
proxyControl.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChooseInitialServer(PlayerChooseInitialServerEvent event) {
|
||||||
|
var player = event.getPlayer();
|
||||||
|
|
||||||
|
if (initialServerGroupId == null) {
|
||||||
|
logger.error("Initial server group id is null");
|
||||||
|
player.disconnect(Component.text("Неправильно сконфигурировано лобби сервера"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverId = kubik.pickServer(initialServerGroupId);
|
||||||
|
if (serverId == null) {
|
||||||
|
logger.error("Could not find server with groupId '{}'", initialServerGroupId);
|
||||||
|
player.disconnect(Component.text("Нет доступных серверов для лобби"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var server = registeredServers.get(serverId);
|
||||||
|
if (server == null) {
|
||||||
|
logger.error("Server '{}' is not registered for groupId '{}'", serverId, initialServerGroupId);
|
||||||
|
player.disconnect(Component.text("Не зарегистрирован сервер для лобби"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setInitialServer(server);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onTakenPluginMessage(PluginMessageEvent event) {
|
public void onTakenPluginMessage(PluginMessageEvent event) {
|
||||||
var handler = pluginChannelHandlers.get(event.getIdentifier().getId());
|
var handler = pluginChannelHandlers.get(event.getIdentifier().getId());
|
||||||
|
|||||||
@ -29,6 +29,8 @@ spec:
|
|||||||
value: http://kubik-discovery:8080
|
value: http://kubik-discovery:8080
|
||||||
- name: KUBIK_DISCOVERY_WS_URL
|
- name: KUBIK_DISCOVERY_WS_URL
|
||||||
value: ws://kubik-discovery:8080
|
value: ws://kubik-discovery:8080
|
||||||
|
- name: KUBIK_INITIAL_SERVER_GROUP_ID
|
||||||
|
value: lobby
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
|
|||||||
@ -77,20 +77,15 @@ enable-player-address-logging = true
|
|||||||
[servers]
|
[servers]
|
||||||
# Configure your servers here. Each key represents the server's name, and the value
|
# Configure your servers here. Each key represents the server's name, and the value
|
||||||
# represents the IP address of the server to connect to.
|
# represents the IP address of the server to connect to.
|
||||||
lobby = "lobby:25565"
|
#lobby = "lobby:25565"
|
||||||
|
|
||||||
|
|
||||||
# In what order we should try servers when a player logs in or is kicked from a server.
|
# In what order we should try servers when a player logs in or is kicked from a server.
|
||||||
try = [
|
try = [
|
||||||
"lobby"
|
# "lobby"
|
||||||
]
|
]
|
||||||
|
|
||||||
[forced-hosts]
|
[forced-hosts]
|
||||||
# Configure your forced hosts here.
|
# Configure your forced hosts here.
|
||||||
"lobby.example.com" = [
|
|
||||||
"lobby"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
[advanced]
|
[advanced]
|
||||||
# How large a Minecraft packet has to be before we compress it. Setting this to zero will
|
# How large a Minecraft packet has to be before we compress it. Setting this to zero will
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user