Ejemplo n.º 1
0
 /**
  * Run the login class to finish a new connection.
  *
  * <p>Loops through all the players looking for any that are not online. Because the socket can't
  * cause the server to process slower, there are multiple login stages, and the player will go
  * through the login class two or three times before fully logging in.
  */
 public void connectAwaitingPlayers() {
   RS2LoginProtocol login = null;
   for (Player p : players) {
     if (p == null || p.online) {
       continue;
     }
     if (login == null) login = new RS2LoginProtocol();
     login.login(p);
     if (!p.online && p.loginStage == -1
         || (System.currentTimeMillis() - p.loginTimeout) >= 15000) {
       /*
        * Remove the player if he failed to connect or it was the update server.
        */
       removePlayer(p.playerId);
     }
   }
 }
Ejemplo n.º 2
0
 /**
  * The thread's process.
  *
  * <p>This processes at a rate of 100 milliseconds, and the processing time is subtracted from the
  * amount of time it sleeps to keep at a rate of 100 milliseonds. Packets are checked every 100
  * milliseconds for faster response time, and most other updates are processed every 600
  * milliseconds.
  */
 public void run() {
   // addStaticObject(id, height, x, y, face, type);
   long lastEntityUpdate = 0;
   long lastEntityUpdate2 = 0;
   long curTime;
   Startup();
   while (engineRunning) {
     curTime = System.currentTimeMillis();
     connectAwaitingPlayers();
     packets.parseIncomingPackets();
     if (curTime - lastEntityUpdate2 >= 1000) {
       for (Player p : players) {
         if (p == null || !p.online) {
           continue;
         }
       }
       lastEntityUpdate2 = curTime;
     }
     if (curTime - lastEntityUpdate >= 600) {
       if (updateTime > 0) {
         updateTime--;
       }
       if (updateTime == 0) {
         try {
           Server.GrandExchangeLoader.saveOffers();
         } catch (Exception e) {
         }
         System.exit(0);
       }
       items.process();
       clanWars.process();
       for (Player p : players) {
         // Proccess and player movement, removing disconnected players.
         if (p == null || !p.online) {
           continue;
         }
         if (p.disconnected[0] && p.disconnected[1]) {
           removePlayer(p.playerId);
           continue;
         }
         p.process();
         playerMovement.getNextPlayerMovement(p);
       }
       for (Player p : players) {
         // Update players.
         if (p == null || !p.online) {
           continue;
         }
         playerUpdate.update(p);
       }
       for (Player p : players) {
         // Reset masks and send bytes.
         if (p == null || !p.online) {
           continue;
         }
         playerUpdate.clearUpdateReqs(p);
         Server.socketListener.writeBuffer(p);
       }
       for (NPC n : npcs) {
         if (n == null) {
           continue;
         }
         npcUpdate.clearUpdateMasks(n);
       }
       for (NPC n : npcs) {
         if (n == null) {
           continue;
         }
         n.process();
         if (!n.isDead) {
           if (n.randomWalk) {
             npcMovement.randomWalk(n);
           }
         } else {
           if (!n.deadEmoteDone) {
             n.deadEmoteDone = true;
             n.combatDelay = n.getDeathDelay1();
           } else if (n.deadEmoteDone && !n.hiddenNPC && n.combatDelay <= 0) {
             n.hiddenNPC = true;
           } else if (n.hiddenNPC && n.respawnDelay <= 0) {
             npcs[n.npcId] = null;
             rebuildNPCs();
             if (n.needsRespawn) {
               newNPC(
                   n.npcType,
                   n.makeX,
                   n.makeY,
                   n.heightLevel,
                   n.moveRangeX1,
                   n.moveRangeY1,
                   n.moveRangeX2,
                   n.moveRangeY2,
                   true,
                   0);
             }
           }
         }
         lastEntityUpdate = curTime;
       }
     }
     try {
       Thread.sleep(100 - (System.currentTimeMillis() - curTime));
     } catch (Exception e) {
     }
   }
 }