What did i miss?

Discussion in 'Plugin Development' started by Benni1000, Jun 6, 2012.

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

    Benni1000

    Hello,
    i know that the "Plugin Development" section doesent match my question 100% but its about bukkit programming so i hope thats ok.

    Well i tried modifying the NetLoginHandler.class in bukkit/src/main/java/net/minecraft/server
    that the server allows non premium connections from a list of trusted players like adminstrators, if the login server is down. So i tried about 4 hours and now i am stuck.
    I sucessfully prevented the "User not premium" message but now i get "Bad Login".
    Here is my modyfied classfile:
    Code:
    package net.minecraft.server;
     
    import java.net.Socket;
    import java.util.Iterator;
    import java.util.Random;
    import java.util.logging.Logger;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.File;
    import java.util.Scanner;
     
    // CraftBukkit start
    import org.bukkit.ChatColor;
    import org.bukkit.craftbukkit.event.CraftEventFactory;
    import org.bukkit.event.server.ServerListPingEvent;
    // CraftBukkit end
     
    public class NetLoginHandler extends NetHandler {
     
        public static Logger logger = Logger.getLogger("Minecraft");
        private static Random random = new Random();
        public NetworkManager networkManager;
        public boolean c = false;
        private MinecraftServer server;
        private int f = 0;
        private String g = null;
        private Packet1Login h = null;
        private String loginKey = Long.toString(random.nextLong(), 16); // CraftBukkit - Security fix
        public String hostname = ""; // CraftBukkit - add field
     
        public NetLoginHandler(MinecraftServer minecraftserver, Socket socket, String s) {
            this.server = minecraftserver;
            this.networkManager = new NetworkManager(socket, s, this);
            this.networkManager.f = 0;
        }
     
        // CraftBukkit start
        public Socket getSocket() {
            return this.networkManager.socket;
        }
        // CraftBukkit end
     
        public void a() {
            if (this.h != null) {
                this.b(this.h);
                this.h = null;
            }
     
            if (this.f++ == 600) {
                this.disconnect("Took too long to log in");
            } else {
                this.networkManager.b();
            }
        }
     
        public void disconnect(String s) {
            try {
                logger.info("Disconnecting " + this.getName() + ": " + s);
                this.networkManager.queue(new Packet255KickDisconnect(s));
                this.networkManager.d();
                this.c = true;
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
     
        public void a(Packet2Handshake packet2handshake) {
            // CraftBukkit start
            int i = packet2handshake.a.indexOf(';');
            if (i == -1) {
                this.hostname = "";
            } else this.hostname = packet2handshake.a.substring(i + 1);
            // CraftBukkit end
        boolean allowed = false;
            File file = new File("not_premium_exceptions.txt");
            if(!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException ex) {
                    System.out.println("[ERROR] Creation of not_premium_exceptions.txt not sucessfull!");
                }
            }
            if(file.exists()) {
                try {
                    Scanner sc = new Scanner(file);
                    while(sc.hasNextLine()) {
                        if(sc.nextLine().equalsIgnoreCase(this.getName())) {
                            allowed = true;
                        }
                    }
                } catch (FileNotFoundException ex) {
                    System.out.println("[ERROR] Creation of not_premium_exceptions.txt not sucessfull!");
                }
            }
            else {
                System.out.println("[ERROR] Creation of not_premium_exceptions.txt not sucessfull!");
            }
     
     
     
     
            if (this.server.onlineMode && allowed) {
            this.networkManager.queue(new Packet2Handshake("-"));
        }
        else if(this.server.onlineMode) {
                this.loginKey = Long.toString(random.nextLong(), 16);
                this.networkManager.queue(new Packet2Handshake(this.loginKey));
            } else {
                this.networkManager.queue(new Packet2Handshake("-"));
            }
     
     
     
     
        }
     
        public void a(Packet1Login packet1login) {
     
            this.g = packet1login.name;
            if (packet1login.a != 29) {
                if (packet1login.a > 29) {
                    this.disconnect("Outdated server!");
                } else {
                    this.disconnect("Outdated client!");
                }
            } else {
     
     
     
     
        boolean allowed = false;
            File file = new File("not_premium_exceptions.txt");
            if(!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException ex) {
                    System.out.println("[ERROR] Creation of not_premium_exceptions.txt not sucessfull!");
                }
            }
            if(file.exists()) {
                try {
                    Scanner sc = new Scanner(file);
                    while(sc.hasNextLine()) {
                        if(sc.nextLine().equalsIgnoreCase(this.getName())) {
                            allowed = true;
                        }
                    }
                } catch (FileNotFoundException ex) {
                    System.out.println("[ERROR] Creation of not_premium_exceptions.txt not sucessfull!");
                }
            }
            else {
                System.out.println("[ERROR] Creation of not_premium_exceptions.txt not sucessfull!");
            }
     
     
     
     
     
     
                if (!this.server.onlineMode) {
                    // CraftBukkit start - disallow colour in names
                    if (!packet1login.name.equals(ChatColor.stripColor(packet1login.name))) {
                        this.disconnect("Colourful names are not permitted!");
                        return;
                    }
                    // CraftBukkit end
                    this.b(packet1login);
                }
            else if(this.server.onlineMode && allowed) {
    // CraftBukkit start - disallow colour in names
                    if (!packet1login.name.equals(ChatColor.stripColor(packet1login.name))) {
                        this.disconnect("Colourful names are not permitted!");
                        return;
                    }
                    // CraftBukkit end
                    this.b(packet1login);
    }
            else {
                    (new ThreadLoginVerifier(this, packet1login, this.server.server)).start(); // CraftBukkit
                }
            }
        }
     
        public void b(Packet1Login packet1login) {
            EntityPlayer entityplayer = this.server.serverConfigurationManager.attemptLogin(this, packet1login.name, this.hostname); // CraftBukkit - add hostname parameter
     
            if (entityplayer != null) {
                //this.server.serverConfigurationManager.b(entityplayer); // CraftBukkit - Moved to attemptLogin
                // entityplayer.a((World) this.server.a(entityplaReprogramming yer.dimension)); // CraftBukkit - set by Entity
                entityplayer.itemInWorldManager.a((WorldServer) entityplayer.world);
                // CraftBukkit - add world and location to 'logged in' message.
                logger.info(this.getName() + " logged in with entity id " + entityplayer.id + " at ([" + entityplayer.world.worldData.name + "] " + entityplayer.locX + ", " + entityplayer.locY + ", " + entityplayer.locZ + ")");
                WorldServer worldserver = (WorldServer) entityplayer.world; // CraftBukkit
                ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
     
                entityplayer.itemInWorldManager.b(worldserver.getWorldData().getGameType());
                NetServerHandler netserverhandler = new NetServerHandler(this.server, this.networkManager, entityplayer);
     
                // CraftBukkit start -- Don't send a higher than 60 MaxPlayer size, otherwise the PlayerInfo window won't render correctly.
                int maxPlayers = this.server.serverConfigurationManager.getMaxPlayers();
                if (maxPlayers > 60) {
                    maxPlayers = 60;
                }
                netserverhandler.sendPacket(new Packet1Login("", entityplayer.id, worldserver.getWorldData().getType(), entityplayer.itemInWorldManager.getGameMode(), worldserver.worldProvider.dimension, (byte) worldserver.difficulty, (byte) worldserver.getHeight(), (byte) maxPlayers));
                entityplayer.getBukkitEntity().sendSupportedChannels();
                // CraftBukkit end
     
                netserverhandler.sendPacket(new Packet6SpawnPosition(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z));
                netserverhandler.sendPacket(new Packet202Abilities(entityplayer.abilities));
                this.server.serverConfigurationManager.a(entityplayer, worldserver);
                // this.server.serverConfigurationManager.sendAll(new Packet3Chat("\u00A7e" + entityplayer.name + " joined the game.")); // CraftBukkit - message moved to join event
                this.server.serverConfigurationManager.c(entityplayer);
                netserverhandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
                this.server.networkListenThread.a(netserverhandler);
                netserverhandler.sendPacket(new Packet4UpdateTime(entityplayer.getPlayerTime())); // CraftBukkit - add support for player specific time
                Iterator iterator = entityplayer.getEffects().iterator();
     
                while (iterator.hasNext()) {
                    MobEffect mobeffect = (MobEffect) iterator.next();
     
                    netserverhandler.sendPacket(new Packet41MobEffect(entityplayer.id, mobeffect));
                }
     
                entityplayer.syncInventory();
            }
     
            this.c = true;
        }
     
        public void a(String s, Object[] aobject) {
            logger.info(this.getName() + " lost connection");
            this.c = true;
        }
     
        public void a(Packet254GetInfo packet254getinfo) {
            if (this.networkManager.getSocket() == null) return; // CraftBukkit - fix NPE when a client queries a server that is unable to handle it.
            try {
                // CraftBukkit start
                ServerListPingEvent pingEvent = CraftEventFactory.callServerListPingEvent(this.server.server, getSocket().getInetAddress(), this.server.motd, this.server.serverConfigurationManager.getPlayerCount(), this.server.serverConfigurationManager.getMaxPlayers());
                String s = pingEvent.getMotd() + "\u00A7" + this.server.serverConfigurationManager.getPlayerCount() + "\u00A7" + pingEvent.getMaxPlayers();
                // CraftBukkit end
     
                this.server.networkListenThread.a(this.networkManager.getSocket()); // CraftBukkit - cleanup before killing connection
                this.networkManager.queue(new Packet255KickDisconnect(s));
                this.networkManager.d();
                // this.server.networkListenThread.a(this.networkManager.getSocket()); // CraftBukkit - moved up
                this.c = true;
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
     
        public void onUnhandledPacket(Packet packet) {
            this.disconnect("Protocol error");
        }
     
        public String getName() {
            return this.g != null ? this.g + " [" + this.networkManager.getSocketAddress().toString() + "]" : this.networkManager.getSocketAddress().toString();
        }
     
        public boolean c() {
            return true;
        }
     
        static String a(NetLoginHandler netloginhandler) {
            return netloginhandler.loginKey;
        }
     
        static Packet1Login a(NetLoginHandler netloginhandler, Packet1Login packet1login) {
            return netloginhandler.h = packet1login;
        }
    }
    Do i have to patch another file? Because after some research that was the only file that was helpful.
     
  2. Offline

    ZeusAllMighty11

    I honestly don't think this is possible. If you have online-mode enabled/true, non-premium can't connect.

    This is due to the connection from the Minecraft Client/Server to the Minecraft.net official server handling where all the disconnects for non-premiums happen. This is purposely and solely due to the fact that Mojang did not want anyone to pirate the game, and online-mode was intended for users without internet to still have a server they could localhost whenever as long as their computers met the requirements.

    But the main point of my reply is; not possible as far as I can see. I'm still new to this, but I highly doubt it's possible to change the way nonpremiums connect to a premium server.
     
  3. Offline

    Benni1000

    This is definetly possible, i dont work with any minecraft.net connections, all i do is tell the Server to not drop all non premium connections like in offline mode. But i need to patch something else to get it fully working.
     
  4. Offline

    Benni1000

    *push*
     
  5. as I see the code, it looks good, except for the closing of the scanner
     
Thread Status:
Not open for further replies.

Share This Page