Server Setup
The StarGate server accepts incoming connections from clients (your downstream game servers), authenticates them, and routes packets between them. It ships as a plugin for WaterdogPE and for BungeeCord (and its forks); both plugins share a very similar API and the same config file. The WaterdogPE plugin is the recommended one for new setups.
The server plugin
The server handles pending connections and routes/handles packets from the clients. It uses TCP sockets and listens on port 47007 by default.
If your own plugin uses the StarGate API, add StarGate to the depends list in your plugin.yml so your plugin is enabled after the StarGate plugin.
Config
# Port StarGate server will listen on for new connections.
serverPort: 47007
# Set a strong password to authenticate clients securely.
password: "123456789"
# Clients should not share a name, and the name should match the downstream server.
# Disabling this allows multiple clients to connect with the same client name,
# but some packets that identify a client by name may then not work correctly.
blockSameNames: true
# Enable the debug logger
debug: true- StarGate uses simple password authentication. You can add an extra layer of security by implementing your own authentication with custom packets.
- When
blockSameNamesis enabled and a client connects with a name that is already in use (as included in itsHandshakeData), it is disconnected. - When
debugis enabled,StarGateLogger#debug()messages are shown in the console.
Server events
Plugins can listen for session lifecycle events. The WaterdogPE plugin fires these as standard WaterdogPE events:
ClientConnectedEvent— a new session is created. At this point the session is not authenticated and only accepts aHandshakePacket.ClientAuthenticatedEvent— a session has authenticated with the password. This is where you typically attach a custom packet handler to the session. Annotated@AsyncEventin the WaterdogPE plugin.ClientDisconnectedEvent— a session has disconnected or been closed. Annotated@AsyncEventin the WaterdogPE plugin.
Registering packets
If your plugin is enabled after the StarGate server plugin, register your custom packets in onEnable():
ProtocolCodec codec = StarGate.getInstance().getServer().getProtocolCodec();
codec.registerPacket(StarGatePackets.SERVER_INFO_REQUEST_PACKET, ServerInfoRequestPacket.class);Running your own server instance
If you are building a standalone application (not a proxy plugin), you can create and run a StarGateServer directly. Implement the ServerLoader interface — currently used to supply your own StarGateLogger implementation — and pass it to the constructor:
public StarGateServer(InetSocketAddress bindAddress, String password, ServerLoader loader)StarGateServer extends Thread, so you start it with start():
MyServerLoader loader = new MyServerLoader();
InetSocketAddress address = new InetSocketAddress("0.0.0.0", 47007);
StarGateServer server = new StarGateServer(address, "12345", loader);
// Register custom packets on server.getProtocolCodec() here, before starting
server.start();