Example #1
0
    def tick(self):
        if not self.running:
            return

        reactor.callLater(.5, self.tick)  #2x sec

        if False:  #CoreSettings.PGSERVER:
            if len(self.liveZoneInstances) == len(
                    self.staticZoneNames) and self.allowConnections:
                if not len(self.activePlayers) and self.priority:
                    self.priority = 0
                    win32process.SetPriorityClass(
                        win32process.GetCurrentProcess(),
                        win32process.IDLE_PRIORITY_CLASS)

                if len(self.activePlayers) and not self.priority:
                    self.priority = 1
                    win32process.SetPriorityClass(
                        win32process.GetCurrentProcess(),
                        win32process.NORMAL_PRIORITY_CLASS)

                #if not self.priority:
                #    win32api.Sleep(2000)
            elif not self.priority:
                self.priority = 1
                win32process.SetPriorityClass(
                    win32process.GetCurrentProcess(),
                    win32process.NORMAL_PRIORITY_CLASS)

        if False:  #RPG_BUILD_DEMO:
            t = sysTime() - self.pauseTime
            if 13 * 60 >= t >= 12 * 60:
                self.paused = True
            elif t > 13 * 60:
                self.paused = False
                self.pauseTime = sysTime()
            else:
                self.paused = False

        self.time.tick()

        #store in db
        if self.time.hour != self.hour:
            self.minute = self.time.minute
            self.hour = self.time.hour
            self.day = self.time.day

        CharacterServerAvatar.tick()

        #if self.lasttime == -1:
        #    self.lasttime = sysTime()-2
        #delta = sysTime()-self.lasttime

        #if delta > .5:
        #self.lasttime = sysTime()

        if CoreSettings.PGSERVER:
            if self.isShuttingDown:
                self.cpuSpawn = 0
                self.cpuDespawn = 0
            else:
                self.cpuSpawn = 4
                self.cpuDespawn = 8
        else:
            self.cpuSpawn = 1000000
            self.cpuDespawn = 1000000

        # Select the zone which will be allowed to spawn mobs.
        spawnZone = None
        if len(self.liveZoneInstances) > 0:
            if self.spawnZoneIndex > len(self.liveZoneInstances) - 1:
                self.spawnZoneIndex = 0
            spawnZone = self.liveZoneInstances[self.spawnZoneIndex]
            self.spawnZoneIndex += 1

        # Tick all live zone instances.
        for z in self.liveZoneInstances:
            z.tick(spawnZone)

        #weed out dynamic zones that haven't any players for x amount of time
        #we need to weed out failed zones (stuck in waiting, etc)

        if not self.singlePlayer:
            timedOut = []
            for z in self.liveZoneInstances:
                if not z.dynamic:
                    continue
                if not len(z.players) and not len(z.playerQueue):
                    if z.timeOut == -1:
                        z.timeOut = sysTime()
                    elif (sysTime() - z.timeOut) / 60 > 20:  # 20 minutes
                        timedOut.append(z)

                else:
                    z.timeOut = -1

            for z in timedOut:
                self.closeZone(z)

        # Backup single player data every minute.
        else:
            self.singlePlayerBackupTimer -= 1
            if self.singlePlayerBackupTimer < 0:
                # Reset timer to one minute.
                self.singlePlayerBackupTimer = 120

                for player in self.activePlayers:
                    # If there's no party, player hasn't logged in yet and
                    #  there's no need to back up.
                    if player.party:
                        player.backupPlayer()

                # Force a write to database.
                conn = Persistent._connection.getConnection()
                cursor = conn.cursor()
                cursor.execute("END;")
                cursor.execute("BEGIN;")
                cursor.close()
 def tick(self):
     if not self.running:
         return
     
     reactor.callLater(.5,self.tick) #2x sec
     
     if False:#CoreSettings.PGSERVER:
         if len(self.liveZoneInstances)==len(self.staticZoneNames) and self.allowConnections:
             if not len(self.activePlayers) and self.priority:
                 self.priority = 0
                 win32process.SetPriorityClass(win32process.GetCurrentProcess(),win32process.IDLE_PRIORITY_CLASS)
                 
             if len(self.activePlayers) and not self.priority:
                 self.priority = 1
                 win32process.SetPriorityClass(win32process.GetCurrentProcess(),win32process.NORMAL_PRIORITY_CLASS)
                 
             #if not self.priority:
             #    win32api.Sleep(2000)
         elif not self.priority:
             self.priority = 1
             win32process.SetPriorityClass(win32process.GetCurrentProcess(),win32process.NORMAL_PRIORITY_CLASS)
             
     
     if False:#RPG_BUILD_DEMO:
         t = sysTime() - self.pauseTime
         if 13*60 >= t >= 12*60:
             self.paused = True
         elif t>13*60:
             self.paused = False
             self.pauseTime = sysTime()
         else:
             self.paused=False
     
     
     
     self.time.tick()
     
     #store in db
     if self.time.hour != self.hour:
         self.minute = self.time.minute
         self.hour = self.time.hour
         self.day = self.time.day
         
     CharacterServerAvatar.tick()
         
     #if self.lasttime == -1:
     #    self.lasttime = sysTime()-2
     #delta = sysTime()-self.lasttime
     
     #if delta > .5:
         #self.lasttime = sysTime()
         
     
     if CoreSettings.PGSERVER:
         if self.isShuttingDown:
             self.cpuSpawn = 0
             self.cpuDespawn = 0
         else:
             self.cpuSpawn = 4
             self.cpuDespawn = 8
     else:
         self.cpuSpawn = 1000000
         self.cpuDespawn = 1000000
     
     # Select the zone which will be allowed to spawn mobs.
     spawnZone = None
     if len(self.liveZoneInstances) > 0:
         if self.spawnZoneIndex > len(self.liveZoneInstances) - 1:
             self.spawnZoneIndex = 0
         spawnZone = self.liveZoneInstances[self.spawnZoneIndex]
         self.spawnZoneIndex += 1
     
     # Tick all live zone instances.
     for z in self.liveZoneInstances:
         z.tick(spawnZone)
     
     #weed out dynamic zones that haven't any players for x amount of time
     #we need to weed out failed zones (stuck in waiting, etc)
     
     if not self.singlePlayer:
         timedOut = []
         for z in self.liveZoneInstances:
             if not z.dynamic:
                 continue
             if not len(z.players) and not len(z.playerQueue):
                 if z.timeOut == -1:
                     z.timeOut = sysTime()
                 elif (sysTime() - z.timeOut)/60 > 20: # 20 minutes
                     timedOut.append(z)
                 
             else:
                 z.timeOut = -1
         
         for z in timedOut:
             self.closeZone(z)
     
     # Backup single player data every minute.
     else:
         self.singlePlayerBackupTimer -= 1
         if self.singlePlayerBackupTimer < 0:
             # Reset timer to one minute.
             self.singlePlayerBackupTimer = 120
             
             for player in self.activePlayers:
                 # If there's no party, player hasn't logged in yet and
                 #  there's no need to back up.
                 if player.party:
                     player.backupPlayer()
             
             # Force a write to database.
             conn = Persistent._connection.getConnection()
             cursor = conn.cursor()
             cursor.execute("END;")
             cursor.execute("BEGIN;")
             cursor.close()