Code to Fix PvP Relog

Discussion in 'Resources' started by ResultStatic, Jun 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ResultStatic

    pvp servers have always had the complaint from their players that another pvper has relog over them. basically what relog does is let u hit players first / better / farther well im not even that sure how it effects players, for the most part, it lets them have an advantage over other players when they log out and log back in. its kind of complicated and most people dont understand it fully. on my server people would keep relogging to get that advantage. its so known throughout pvp servers that spigot has even made a config section PlayerShuffle that lets u toggle the intervals that it shuffles the "relog list".


    What it is on the serverside:
    there is a list of NetworkManager instances stored in the ServerConnection class. im assuming that when someone logs in, it puts their instance of NetworkManager in that list, therefore putting them at the top of the list and when it loops through the list to send packets to everyone they are at the top so they get it first and everything happens first for them. i created some code that shuffles the list when u call the method. its very compact but does use nms. im sure someone can write a version that doesnt use nms classes and only reflection. you will need to make a repeating task on ur onEnable(){ to call the method to shuffle the list, i would shuffle every 5 - 30 seconds. i did some testing in game with 2 accounts. with no shuffle the ips are shown in the same order everytime. with the shuffle its random. i dont think anyone has made a shuffle for it except spigot which edits the real method. Plugin awaiting approval. I created a plugin version that uses 100% reflection and works with 1.5.2 - 1.7.9 :D. http://dev.bukkit.org/bukkit-plugins/mcmechanic/

    Code:
    public static MinecraftServer getNMSServer(){
        return ((CraftServer)Bukkit.getServer()).getServer();
        }
     
    public static void shuffleList(){
        try {
            Field newlist;
            newlist = ServerConnection.class.getDeclaredField("f");
            newlist.setAccessible(true);
            List<NetworkManager>list = (List<NetworkManager>)newlist.get(Nms.getNMSServer().ai());
            Collections.shuffle(list);
      // u dont need the for loop its just debug and proves that it works
            for (NetworkManager players : list){
            Bukkit.broadcastMessage(players.getSocketAddress().toString());
     
            }
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
        }
     
  2. Offline

    ResultStatic

  3. Offline

    luigieai

    ResultStatic
    For SoupPvp servers this code is perfect!
    Thanks for posting this :D
     
Thread Status:
Not open for further replies.

Share This Page