Search in sources :

Example 6 with Server

use of net.md_5.bungee.api.connection.Server in project LuckPerms by lucko.

the class BungeeConnectionListener method onPlayerLogin.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(LoginEvent e) {
    /* Called when the player first attempts a connection with the server.
           Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins)

           Delay the login here, as we want to cache UUID data before the player is connected to a backend bukkit server.
           This means that a player will have the same UUID across the network, even if parts of the network are running in
           Offline mode. */
    /* registers the plugins intent to modify this events state going forward.
           this will prevent the event from completing until we're finished handling. */
    e.registerIntent(this.plugin.getBootstrap());
    final PendingConnection c = e.getConnection();
    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
    }
    this.plugin.getBootstrap().getScheduler().doAsync(() -> {
        recordConnection(c.getUniqueId());
        /* Actually process the login for the connection.
               We do this here to delay the login until the data is ready.
               If the login gets cancelled later on, then this will be cleaned up.

               This includes:
               - loading uuid data
               - loading permissions
               - creating a user instance in the UserManager for this connection.
               - setting up cached data. */
        try {
            User user = loadUser(c.getUniqueId(), c.getName());
            this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
        } catch (Exception ex) {
            this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName());
            ex.printStackTrace();
            // there was some error loading
            if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
                // cancel the login attempt
                e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
                e.setCancelled(true);
            }
        }
        // finally, complete our intent to modify state, so the proxy can continue handling the connection.
        e.completeIntent(this.plugin.getBootstrap());
    });
}
Also used : User(me.lucko.luckperms.common.model.User) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 7 with Server

use of net.md_5.bungee.api.connection.Server in project SpecialSource by md-5.

the class JarMapping method loadMappingsDir.

/**
 * Load mappings from an MCP directory
 *
 * @param dirname MCP directory name, local file or remote URL ending in '/'
 * @param reverse If true, swap input and output
 * @param ignoreCsv If true, ignore fields.csv and methods.csv (but not
 * packages.csv)
 * @param numericSrgNames If true, load numeric "srg" names (num->mcp
 * instead of obf->mcp)
 */
private void loadMappingsDir(String dirname, boolean reverse, boolean ignoreCsv, boolean numericSrgNames) throws IOException {
    File dir = new File(dirname);
    if (!FileLocator.isHTTPURL(dirname) && !dir.isDirectory()) {
        throw new IllegalArgumentException("loadMappingsDir(" + dir + "): not a directory");
    }
    String sep = System.getProperty("file.separator");
    List<File> srgFiles = new ArrayList<File>();
    File joinedSrg = FileLocator.getFile(dirname + sep + "joined.srg");
    if (joinedSrg.exists()) {
        // FML/MCP client/server joined
        srgFiles.add(joinedSrg);
    } else {
        // vanilla MCP separated sides
        File serverSrg = FileLocator.getFile(dirname + sep + "server.srg");
        File clientSrg = FileLocator.getFile(dirname + sep + "client.srg");
        if (serverSrg.exists()) {
            srgFiles.add(serverSrg);
        }
        if (clientSrg.exists()) {
            srgFiles.add(clientSrg);
        }
    }
    if (srgFiles.size() == 0) {
        throw new IOException("loadMappingsDir(" + dirname + "): no joined.srg, client.srg, or server.srg found");
    }
    // Read output names through csv mappings, if available & enabled
    File fieldsCsv = FileLocator.getFile(dirname + sep + "fields.csv");
    File methodsCsv = FileLocator.getFile(dirname + sep + "methods.csv");
    // FML repackaging, optional
    File packagesCsv = FileLocator.getFile(dirname + sep + "packages.csv");
    MinecraftCodersPack outputTransformer;
    MappingTransformer inputTransformer;
    if (numericSrgNames) {
        // Wants numeric "srg" names -> descriptive "csv" names. To accomplish this:
        // 1. load obf->mcp (descriptive "csv") as chainMappings
        // 2. load again but chaining input (obf) through mcp, and ignoring csv on output
        // 3. result: mcp->srg, similar to MCP ./reobfuscate --srgnames
        JarMapping chainMappings = new JarMapping();
        chainMappings.loadMappingsDir(dirname, reverse, false, /*ignoreCsv*/
        false);
        inputTransformer = new ChainingTransformer(new JarRemapper(chainMappings));
        // keep numeric srg as output
        ignoreCsv = true;
    } else {
        inputTransformer = null;
    }
    if (fieldsCsv.exists() && methodsCsv.exists()) {
        outputTransformer = new MinecraftCodersPack(ignoreCsv ? null : fieldsCsv, ignoreCsv ? null : methodsCsv, packagesCsv);
    } else {
        outputTransformer = null;
    }
    for (File srg : srgFiles) {
        loadMappings(new BufferedReader(new FileReader(srg)), inputTransformer, outputTransformer, reverse);
    }
}
Also used : MinecraftCodersPack(net.md_5.specialsource.transformer.MinecraftCodersPack) MappingTransformer(net.md_5.specialsource.transformer.MappingTransformer) ChainingTransformer(net.md_5.specialsource.transformer.ChainingTransformer)

Example 8 with Server

use of net.md_5.bungee.api.connection.Server in project Parties by AlessioDP.

the class BungeeMetrics method startSubmitting.

private void startSubmitting() {
    // We use a timer cause want to be independent from the server tps
    final Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            // The data collection (e.g. for custom graphs) is done sync
            // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
            TaskScheduler scheduler = plugin.getProxy().getScheduler();
            scheduler.schedule(plugin, new Runnable() {

                @Override
                public void run() {
                    submitData();
                }
            }, 0L, TimeUnit.SECONDS);
        }
    }, 1000 * 60 * 2, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 2 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) TaskScheduler(net.md_5.bungee.api.scheduler.TaskScheduler)

Example 9 with Server

use of net.md_5.bungee.api.connection.Server in project Parties by AlessioDP.

the class BungeeListener method onConnect.

@EventHandler
public void onConnect(ServerConnectEvent event) {
    /*
		 * Connect chain starts here,
		 * this method will sent a PartiesPacket to the player server
		 */
    if (event.isCancelled())
        return;
    ProxiedPlayer proxyPlayer = event.getPlayer();
    // Return if its not a player
    if (proxyPlayer.getServer() == null)
        return;
    // Return if the player is already in the server
    if (proxyPlayer.getServer().getInfo().equals(event.getTarget()))
        return;
    // Return if the server is not into the follow list
    if (!listContains(ConfigMain.follow_listserver, proxyPlayer.getServer().getInfo().getName()))
        return;
    /*
		 * 
		 */
    try {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(stream);
        // Initialize packet
        Packet packet = new Packet(plugin.getDescription().getVersion(), event.getTarget().getName(), ConfigMain.follow_neededrank, ConfigMain.follow_minimumrank);
        // Write to the DataOutputStream the data
        packet.write(out);
        if (proxyPlayer.getServer() != null) {
            PartiesBungee.debugLog("Parties packet sent to " + proxyPlayer.getServer().getInfo().getName());
            proxyPlayer.getServer().sendData(partiesChannel, stream.toByteArray());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Packet(com.alessiodp.parties.bungeecord.utils.Packet) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) EventHandler(net.md_5.bungee.event.EventHandler)

Example 10 with Server

use of net.md_5.bungee.api.connection.Server in project DragonProxy by DragonetMC.

the class DPAddonBungee method onServerSwitch.

@EventHandler
public void onServerSwitch(ServerSwitchEvent event) {
    if (!bedrockPlayers.contains(event.getPlayer().getUniqueId()))
        return;
    // We don't know that another server supports forwarding or not so we disable forwarding for now!
    BinaryStream bis = new BinaryStream();
    bis.putString("PacketFoward");
    bis.putBoolean(false);
    event.getPlayer().sendData("DragonProxy", bis.getBuffer());
}
Also used : BinaryStream(org.dragonet.common.utilities.BinaryStream) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)6 Document (de.dytanic.cloudnet.lib.utility.document.Document)5 ServerInfo (net.md_5.bungee.api.config.ServerInfo)5 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)4 File (java.io.File)4 Configuration (net.md_5.bungee.config.Configuration)4 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)4 Path (java.nio.file.Path)3 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)3 UserPreference (com.github.games647.changeskin.core.model.UserPreference)2 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)2 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)2 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)2 Template (de.dytanic.cloudnet.lib.server.template.Template)2 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)2 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)2 Properties (java.util.Properties)2