@Subscribe public void onPluginMessage(PluginMessageEvent e) { if (e.getIdentifier().equals(velocityChannelId)) { e.setResult(PluginMessageEvent.ForwardResult.handled()); } } }
/** * Denies the login with the specified reason. * * @param reason the reason for disallowing the connection * @return a new result */ public static PreLoginComponentResult denied(Component reason) { Preconditions.checkNotNull(reason, "reason"); return new PreLoginComponentResult(Result.DISALLOWED, reason); }
/** * Creates a new instance. * @param connection the connection logging into the proxy * @param username the player's username */ public PreLoginEvent(InboundConnection connection, String username) { this.connection = Preconditions.checkNotNull(connection, "connection"); this.username = Preconditions.checkNotNull(username, "username"); this.result = PreLoginComponentResult.allowed(); }
private void beginPreLogin() { ServerLogin login = this.login; if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } PreLoginEvent event = new PreLoginEvent(inbound, login.getUsername()); server.getEventManager().fire(event) .thenRunAsync(() -> { if (mcConnection.isClosed()) { // The player was disconnected return; } PreLoginComponentResult result = event.getResult(); Optional<Component> disconnectReason = result.getReason(); if (disconnectReason.isPresent()) { // The component is guaranteed to be provided if the connection was denied. mcConnection.closeWith(Disconnect.create(disconnectReason.get())); return; } if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result .isOnlineModeAllowed())) { // Request encryption. EncryptionRequest request = generateEncryptionRequest(); this.verify = Arrays.copyOf(request.getVerifyToken(), 4); mcConnection.write(request); } else { initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false); } }, mcConnection.eventLoop()); }
@Subscribe public void onPlayerQuit(DisconnectEvent quitEvent) { removePlayer(quitEvent.getPlayer()); }
@Override public boolean handle(PluginMessage packet) { if (!canForwardPluginMessage(packet)) { return true; } if (PluginMessageUtil.isMcBrand(packet)) { PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion()); serverConn.getPlayer().getMinecraftConnection().write(rewritten); return true; } if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) { // Handled. return true; } ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel()); if (id == null) { return false; } MinecraftConnection clientConn = serverConn.getPlayer().getMinecraftConnection(); PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, packet.getData()); server.getEventManager().fire(event) .thenAcceptAsync(pme -> { if (pme.getResult().isAllowed() && !clientConn.isClosed()) { clientConn.write(packet); } }, clientConn.eventLoop()); return true; }
mcConnection.setState(StateRegistry.PLAY); server.getEventManager().fire(new LoginEvent(player)) .thenAcceptAsync(event -> { if (mcConnection.isClosed()) { Optional<Component> reason = event.getResult().getReason(); if (reason.isPresent()) { player.disconnect(reason.get()); server.getEventManager().fire(new PostLoginEvent(player)) .thenRun(() -> player.createConnectionRequest(toTry.get()).fireAndForget());
/** * Creates a new instance. * * @param source the source of the plugin message * @param target the destination of the plugin message * @param identifier the channel for this plugin message * @param data the payload of the plugin message */ public PluginMessageEvent(ChannelMessageSource source, ChannelMessageSink target, ChannelIdentifier identifier, byte[] data) { this.source = Preconditions.checkNotNull(source, "source"); this.target = Preconditions.checkNotNull(target, "target"); this.identifier = Preconditions.checkNotNull(identifier, "identifier"); this.data = Preconditions.checkNotNull(data, "data"); this.result = ForwardResult.forward(); }
void teardown() { if (connectionInFlight != null) { connectionInFlight.disconnect(); } if (connectedServer != null) { connectedServer.disconnect(); } server.unregisterConnection(this); server.getEventManager().fireAndForget(new DisconnectEvent(this)); }
backendConn.write(packet); } else { PluginMessageEvent event = new PluginMessageEvent(player, serverConn, id, packet.getData()); server.getEventManager().fire(event).thenAcceptAsync(pme -> backendConn.write(packet),
server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); return true;
@Subscribe public void onPluginMessage(PluginMessageEvent e) { if (e.getIdentifier().equals(velocityChannelId)) { e.setResult(PluginMessageEvent.ForwardResult.handled()); } } }
@Subscribe public void onQuit(DisconnectEvent e) { UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId()); if (userConnection != null) { // Only remove if the connection is disconnected (eg. relogin) if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) { Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); } } }
@Subscribe public void onPostLogin(PostLoginEvent event) { try { Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); String name = player.getUsername(); InetAddress address = player.getRemoteAddress().getAddress(); long time = System.currentTimeMillis(); sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, null, null)); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); processing.submit(processors.player().proxyRegisterProcessor(uuid, name, time, gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null )); processing.submit(processors.info().playerPageUpdateProcessor(uuid)); ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); } catch (Exception e) { errorHandler.log(L.WARN, this.getClass(), e); } }
@Subscribe public void onLogout(DisconnectEvent event) { try { Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); sessionCache.endSession(uuid, System.currentTimeMillis()); processing.submit(processors.info().playerPageUpdateProcessor(uuid)); ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); } catch (Exception e) { errorHandler.log(L.WARN, this.getClass(), e); } }