Awful Lag At Login

Discussion in 'Plugin Development' started by azoundria, Feb 11, 2011.

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

    azoundria

    Okay, so we have some awful lag at login, and I think it may be due to a mod I built. All it does is request a website URL which gives the user their title/rank.

    However, it seems that the entire server hangs and waits for this event to finish. That's the only logical explanation why things come to a standstill just after a new player logs in.

    Is this normal? How would I avoid this? Is there a way to multithread so things don't stop while it's waiting for a response?
    --- merged: Feb 11, 2011 11:09 PM ---
    I figured you may want the relevant code.

    Code:
        //Handle a new player joining.
        public void onPlayerJoin(PlayerEvent event) {
            plugin.handleLogin(event.getPlayer());
        }
    Code:
        /**
         * Handle a player logging into the server.
         *
         */
        public void handleLogin(Player player) {
            findPlayerClient(player).initiate();
            findPlayerClient(player).sendMOTD();
            findPlayerClient(player).loadProfile(towns);
        }
    findPlayerClient fetches the right PlayerClient from a list of PlayerClient objects. These basically represent all the players, and allow me to store extra data about each player like settings and how many towns they've discovered, and perform additional functions with each player.

    Code:
        public void initiate() {
            some_position_variable = new LocationClient(player.getLocation());
            URL url;
            try {
                url = new URL("http://somedomain.com/someurl.php?user="+this.player.getName());
                DataInputStream dis = new DataInputStream(new BufferedInputStream(url.openStream()));
                String s;
                if ((s = dis.readLine()) != null) {
                    this.status = Integer.parseInt(s);
                }
                if ((s = dis.readLine()) != null) {
                    this.motd = s;
                }
                if ((s = dis.readLine()) != null) {
                    this.giveGold(Integer.parseInt(s));
                }
                url = new URL(http://somedomain.com/gold_give_done.php?user="+this.player.getName());
                dis = new DataInputStream(new BufferedInputStream(url.openStream()));
                if ((s = dis.readLine()) != null) {    }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    Code:
        //Send the MOTD to the player.
        public void sendMOTD() {
            player.sendMessage(this.motd);
        }
    LoadProfile grabs the towns the player discovered from a text file.

    All of these should not slow the central operation of the server, but run on the side. So the user may experience lag, but the whole server shouldn't have to.
     
Thread Status:
Not open for further replies.

Share This Page