Example #1
0
    def spawnDedicatedZone(self, simAvatar, zoneName, simPort):
        if zoneName == 'any':
            #we pick
            znames = [zone.name for zone in self.zones]
            #list of all instances
            zinstances = []
            for zi in self.liveZoneInstances:
                zinstances.append(zi)
            for zi in self.waitingZoneInstances:
                zinstances.append(zi)

            for zi in zinstances:
                if zi.zone.name in znames:
                    znames.remove(zi.zone.name)

            if not len(znames):
                #all zones served
                raise "all zones server, this isn't actually an error... eventually we serve another zone instance, based on waiting etc"

            zoneName = znames[0]
        else:
            #let's see if we launched this zone
            for zi in self.waitingZoneInstances:
                if zi.port == simPort:
                    return zi

        #this is a dedicated server that has been launched remotely,
        #shouldn't happen for right now... so we'll assert
        traceback.print_stack()
        print "AssertionError: dedicated server launched remotely, shouldn't happen for now!"
        return

        zone = Zone.byName(zoneName)
        #hrm
        ip = self.zoneIP  #see world server main.py
        simPassword = ""
        z = ZoneInstance(zone, ip, simPort, simPassword, None)
        z.time = self.time
        self.waitingZoneInstances.append(z)
        return z
Example #2
0
    def getPlayerZone(self, pavatar, simPort, simPassword):
        # If the world is shutting down, return None.
        if self.shuttingDown:
            return None

        player = pavatar.player

        allzi = []
        allzi.extend(self.liveZoneInstances)
        allzi.extend(self.waitingZoneInstances)

        #select zone
        if player.darkness:
            logZone = player.darknessLogZone
        elif player.monster:
            logZone = player.monsterLogZone
        else:
            logZone = player.logZone

        for z in allzi:
            if z.zone == logZone:
                #for now if zone is up just join that one
                return z

        #zone isn't up
        if CoreSettings.PGSERVER:
            raise AssertionError, "Error, Zone %s isn't up!" % logZone.name

        if self.singlePlayer:
            ip = '127.0.0.1'
            z = ZoneInstance(logZone, ip, simPort, simPassword, None)
            z.world = self
            z.time = self.time
            self.waitingZoneInstances.append(z)
            return z
        else:
            #the zone isn't up and we are multiplayer, so we need to launch the process
            return self.startZoneProcess(logZone.name)

        return z
Example #3
0
    def startZoneProcess(self, zoneName, dynamic=True):
        port = None
        for x in xrange(self.zoneStartPort, self.zoneStartPort + 100):
            if x in self.usedZonePorts:
                continue
            port = x
            self.usedZonePorts.append(x)
            break

        if port == None:
            traceback.print_stack()
            print "AssertionError: no port assigned!"
            return

        zone = Zone.byName(zoneName)
        #hrm
        ip = self.zoneIP  #see world server main.py
        simPassword = ""
        z = ZoneInstance(zone, ip, port, simPassword, None)
        z.world = self
        z.time = self.time
        z.dynamic = dynamic

        self.waitingZoneInstances.append(z)

        if self.frozen:
            cmd = r'..\bin\ZoneServer.exe'
            args = ""
        else:
            cmd = sys.executable
            path = os.getcwd()
            args = r'%s/zoneserver.py' % path

        args += r' -dedicated'
        args += r' -serverport %i -zone %s -world %s -worldport %i' % (
            port, zoneName, self.multiName, self.worldPort)
        if dynamic:
            args += r' -dynamic'

        for arg in sys.argv:
            if arg.startswith("gameconfig="):
                args += " %s" % arg

        if sys.platform[:6] != "darwin":
            # Just don't provide cluster number via gameconfig until
            #  MoM uses gameconfig as well.
            args += r' -cluster=%i' % self.clusterNum
            s = 'start "%s" %s %s' % (os.getcwd(), cmd, args)
            s = os.path.normpath(s)
            print s
            os.system(s)

        else:
            if arg.startswith("-wx"):
                args += " -wx"

            cmd = sys.executable
            args = args.split(" ")
            args.insert(0, cmd)
            s = 'pythonw -c \'import os;os.spawnv(os.P_NOWAIT,"%s",[%s])\'' % (
                cmd, ','.join('"%s"' % arg for arg in args))
            print s
            os.system(s)

        return z