예제 #1
0
    def StartClientExam(self):
        def _wait_func(channel, seconds):
            tasklet_sleep(seconds)
            channel.send(None)
        channel1 = stackless.channel()
        def _terminaltype_cb(terminalTypeName):
            channel1.send(terminalTypeName)
        self.user.connection.telneg_terminaltype_cb = _terminaltype_cb

        telneg = self.user.connection.telneg
        telneg.will_sga()        
        telneg.will_echo()
        telneg.do_naws()
        telneg.do_new_environ()
        telneg.do_ttype()

        # Wait for the soonest of a terminal type, give up after a short delay.
        stackless.tasklet(_wait_func)(channel1, 1.0)
        terminalTypeName = channel1.receive()
        
        if terminalTypeName:
            self.user.connection.SetClientName(terminalTypeName)
            if self.EndClientExam():
                self._WritePrompt()
            return

        # Ask the client terminal what their name is.
        self.oldOptionLineMode = self.user.connection.SetLineMode(False)
        self.user.connection.SetPasswordMode(True)
        self.user.Write(CTRL_E)

        tasklet_sleep(1.0)
        if self.EndClientExam():
            self._WritePrompt()
예제 #2
0
    def ReconnectToRouter(self):
        delay = float(sorrows.data.config.intermud3.reconnectiondelay)

        self.LogInfo("Retrying router connection in %d seconds", delay)
        tasklet_sleep(delay)

        self.LogInfo("Reconnecting")
        self.ConnectToRouter()
예제 #3
0
 def RunSimulation(self, seconds):
     startTime = self.simulationStartTime = time.time()
     print "Simulation: Start", startTime, "period (s)", seconds
     sorrows.entityVoid.StartSimulation(startTime)
     endTime = startTime + seconds
     tasklet_sleep(seconds)
     self.simulationStartTime = None
     print "Simulation: End", endTime, "period (s)", seconds
예제 #4
0
    def ReconnectToRouter(self):
        delay = float(sorrows.data.config.intermud3.reconnectiondelay)

        self.LogInfo("Retrying router connection in %d seconds", delay)
        tasklet_sleep(delay)

        self.LogInfo("Reconnecting")
        self.ConnectToRouter()
예제 #5
0
 def Run(self):
     # Place an entity.
     #  Ask the world service to allocate one of the free house squares.
     #  Ask the world service to find a field square.
     #  At sunrise, have the entity head out to the field.
     #  At mid-afternoon, have the entity head back home.
     #    That requires some sort of time service.
     while self.service.IsRunning():
         tasklet_sleep(10)
예제 #6
0
 def Run(self):
     # Place an entity.
     #  Ask the world service to allocate one of the free house squares.
     #  Ask the world service to find a field square.
     #  At sunrise, have the entity head out to the field.
     #  At mid-afternoon, have the entity head back home.
     #    That requires some sort of time service.
     while self.service.IsRunning():
         tasklet_sleep(10)
예제 #7
0
    def Wander(self):
        lastPosition = self.position
        while hasattr(sorrows, "world") and sorrows.world.IsRunning():
            currentPosition = self.position
            matches = sorrows.world.FindMovementDirections(self.position)
            if len(matches) > 1 and lastPosition in matches:
                matches.remove(lastPosition)
            if len(matches):
                lastPosition = currentPosition
                sorrows.world._MoveObject(self, random.choice(matches))

            tasklet_sleep(2.5 + -random.random())
예제 #8
0
    def Wander(self):
        lastPosition = self.position
        while hasattr(sorrows, "world") and sorrows.world.IsRunning():
            currentPosition = self.position
            matches = sorrows.world.FindMovementDirections(self.position)
            if len(matches) > 1 and lastPosition in matches:
                matches.remove(lastPosition)
            if len(matches):
                lastPosition = currentPosition
                sorrows.world._MoveObject(self, random.choice(matches))

            tasklet_sleep(2.5 + -random.random())
예제 #9
0
    def ManageFire(self):
        fireObject = FireObject()
        fireObject.generation = 0
        sorrows.world._MoveObject(fireObject, self.position, force=True)
        
        self.components.append(fireObject)
        self.componentsByPosition[self.position] = fireObject
        self.idx = -1

        tasklet_sleep(1.0)
        while hasattr(sorrows, "world") and sorrows.world.IsRunning() and len(self.components):
            if self.position is None:
                self.DieOut()
            else:
                self.Spread()

            tasklet_sleep(1.0 + -random.random() * 0.5)
예제 #10
0
    def ManageFire(self):
        fireObject = FireObject()
        fireObject.generation = 0
        sorrows.world._MoveObject(fireObject, self.position, force=True)

        self.components.append(fireObject)
        self.componentsByPosition[self.position] = fireObject
        self.idx = -1

        tasklet_sleep(1.0)
        while hasattr(sorrows, "world") and sorrows.world.IsRunning() and len(
                self.components):
            if self.position is None:
                self.DieOut()
            else:
                self.Spread()

            tasklet_sleep(1.0 + -random.random() * 0.5)
예제 #11
0
 def ManageFloraAndFauna(self):
     stackless.tasklet(self.RunNPC)(CUBE_TILE, COLOUR_YELLOW)
     tasklet_sleep(10.0)
     stackless.tasklet(self.RunNPC)(DRAGON_TILE, COLOUR_GREEN)
     tasklet_sleep(10.0)
     stackless.tasklet(self.RunNPC)(DRAGON_TILE, COLOUR_GREEN)
     tasklet_sleep(10.0)
     stackless.tasklet(self.RunNPC)(DRAGON_TILE, COLOUR_GREEN)
예제 #12
0
 def ManageFloraAndFauna(self):
     stackless.tasklet(self.RunNPC)(CUBE_TILE, COLOUR_YELLOW)
     tasklet_sleep(10.0)
     stackless.tasklet(self.RunNPC)(DRAGON_TILE, COLOUR_GREEN)
     tasklet_sleep(10.0)
     stackless.tasklet(self.RunNPC)(DRAGON_TILE, COLOUR_GREEN)
     tasklet_sleep(10.0)
     stackless.tasklet(self.RunNPC)(DRAGON_TILE, COLOUR_GREEN)
예제 #13
0
    def StartClientExam(self):
        def _wait_func(channel, seconds):
            tasklet_sleep(seconds)
            channel.send(None)

        channel1 = stackless.channel()

        def _terminaltype_cb(terminalTypeName):
            channel1.send(terminalTypeName)

        self.user.connection.telneg_terminaltype_cb = _terminaltype_cb

        telneg = self.user.connection.telneg
        telneg.will_sga()
        telneg.will_echo()
        telneg.do_naws()
        telneg.do_new_environ()
        telneg.do_ttype()

        # Wait for the soonest of a terminal type, give up after a short delay.
        stackless.tasklet(_wait_func)(channel1, 1.0)
        terminalTypeName = channel1.receive()

        if terminalTypeName:
            self.user.connection.SetClientName(terminalTypeName)
            if self.EndClientExam():
                self._WritePrompt()
            return

        # Ask the client terminal what their name is.
        self.oldOptionLineMode = self.user.connection.SetLineMode(False)
        self.user.connection.SetPasswordMode(True)
        self.user.Write(CTRL_E)

        tasklet_sleep(1.0)
        if self.EndClientExam():
            self._WritePrompt()
예제 #14
0
    def OnStop(self):
        cnt = 20
        skips = 0
        while len(self.runningServices) and cnt:
            for svcName, svc in self.runningServices.items():
                # Do not stop the current service if it has running dependencies.
                matches = [
                    svcName2
                    for svcName2 in self.dependenciesByService.get(svcName, [])
                    if self.runningServices.has_key(svcName2)
                ]
                if not len(matches):
                    self.StopService(svc)
                else:
                    skips += 1
                # Give tasklets that are no longer valid due to the stopping of their
                # service a chance to exit before further services in the dependency
                # order are stopped next.
                tasklet_sleep(0)
            cnt -= 1
        if not cnt:
            self.LogError("Unable to stop services: %s", self.runningServices.keys())

        events.ShutdownComplete()
예제 #15
0
    def _ManageConnectionPreLogin(self):
        dataQueue = []

        def CollectIncomingData():
            data = ""
            while not self.released and data is not None:
                data = self.read(65536)
                dataQueue.append(data)

        workerTasklet = stackless.tasklet(CollectIncomingData)()

        self.send("\x1b[0c")
        self.send("MUD\r\n")

        slept = 0
        while not self.released:
            for data in dataQueue:
                if data is None:
                    return
                # print "RECEIVED AFTER", slept, "DATA", data
            del dataQueue[:]

            tasklet_sleep(0.01)
            slept += 0.01
예제 #16
0
    def _ManageConnectionPreLogin(self):
        dataQueue = []

        def CollectIncomingData():
            data = ""
            while not self.released and data is not None:
                data = self.read(65536)
                dataQueue.append(data)

        workerTasklet = stackless.tasklet(CollectIncomingData)()

        self.send("\x1b[0c")
        self.send("MUD\r\n")

        slept = 0
        while not self.released:
            for data in dataQueue:
                if data is None:
                    return
                # print "RECEIVED AFTER", slept, "DATA", data
            del dataQueue[:]

            tasklet_sleep(0.01)
            slept += 0.01
예제 #17
0
 def ReceiveInput_EscapeTimeout(self):
     tasklet_sleep(0.1)
     self.ReceiveInput("", flush=True)
예제 #18
0
    def Run(self, startTime):
        while sorrows.worldVoid.IsSimulationRunning(startTime):
            sleepDelay = 5.0
            if self.profession == 'farmer':
                if self.goals.has_key("sell-grain"):
                    if self.inventory["grain"] == 1:
                        millers = self.FindEntitiesByProfession("miller")
                        if len(millers):
                            miller = millers[0]
                            if not self.ApproachPosition(miller.homePosition):
                                # Reached the miller's home.  Is it present?
                                if miller in sorrows.worldVoid.objectsByPosition[
                                        self.position]:
                                    if miller.inventory["bread"] > 0:
                                        self.Debug(
                                            "sell-grain - miller found / sale")

                                        miller.inventory["bread"] -= 1
                                        miller.inventory["grain"] += 1
                                        self.inventory["bread"] += 1
                                        self.inventory["grain"] -= 1

                                        self.GoalCompleted("sell-grain")
                                        self.InitialiseGoal("harvest-grain")
                                    else:
                                        self.Debug(
                                            "sell-grain - miller found / wait bread"
                                        )
                                else:
                                    self.Debug(
                                        "sell-grain - miller not present")
                        else:
                            self.Debug("sell-grain - no miller exists")
                            break
                    else:
                        self.Debug("sell-grain - no grain")
                        break
                elif self.goals.has_key("harvest-grain"):
                    # If distant from field, approach field.
                    if not self.ApproachPosition(self.homePosition):
                        # Start harvesting process.  Or end it.
                        if self.inventory["grain"] == 0:
                            self.inventory["grain"] += 1
                            self.inventory["bread"] -= 1
                            self.Debug("harvest-grain - harvested")
                        else:
                            self.GoalCompleted("harvest-grain")
                            self.InitialiseGoal("sell-grain")
                elif len(self.goals):
                    self.Debug("bad goals", self.goals)
                    break
            elif self.profession == 'miller':
                if self.goals.has_key("sell-flour"):
                    if self.inventory["flour"] == 1:
                        buyers = self.FindEntitiesByProfession("baker")
                        if len(buyers):
                            buyer = buyers[0]
                            if not self.ApproachPosition(buyer.homePosition):
                                # Reached the buyer's home.  Is it present?
                                if buyer in sorrows.worldVoid.objectsByPosition[
                                        self.position]:
                                    if buyer.inventory["bread"] > 0:
                                        self.Debug(
                                            "sell-flour - baker found / sale")

                                        buyer.inventory["bread"] -= 1
                                        buyer.inventory["flour"] += 1
                                        self.inventory["flour"] -= 1
                                        self.inventory["bread"] += 1

                                        self.GoalCompleted("sell-flour")
                                        self.InitialiseGoal("work")
                                    else:
                                        self.Debug(
                                            "sell-grain - baker found / wait bread"
                                        )
                                else:
                                    self.Debug(
                                        "sell-grain - miller not present")
                    else:
                        self.Debug("sell-flour - no flour")
                        break
                elif self.goals.has_key("work"):
                    # If distant from field, approach field.
                    if not self.ApproachPosition(self.homePosition):
                        grainCount = self.inventory["grain"]
                        if grainCount > 0:
                            self.inventory["grain"] -= grainCount
                            self.inventory["flour"] += grainCount

                            self.GoalCompleted("work")
                            self.InitialiseGoal("sell-flour")
                        else:
                            self.Debug("work - no grain to grind")
                elif len(self.goals):
                    self.Debug("bad goals", self.goals)
                    break
            elif self.profession == 'baker':
                flourCount = self.inventory["flour"]
                if flourCount > 0:
                    self.inventory["flour"] -= flourCount
                    self.inventory["bread"] += flourCount
                    self.Debug("bake", flourCount, "bread")
                else:
                    self.Debug("wait for customer")
            tasklet_sleep(sleepDelay)
        self.Debug("done")
예제 #19
0
 def ReceiveInput_EscapeTimeout(self):
     tasklet_sleep(0.1)
     self.ReceiveInput("", flush=True)
예제 #20
0
    def Run(self, startTime):
        while sorrows.worldVoid.IsSimulationRunning(startTime):
            sleepDelay = 5.0
            if self.profession == 'farmer':
                if self.goals.has_key("sell-grain"):
                    if self.inventory["grain"] == 1:
                        millers = self.FindEntitiesByProfession("miller")
                        if len(millers):
                            miller = millers[0]
                            if not self.ApproachPosition(miller.homePosition):
                                # Reached the miller's home.  Is it present?
                                if miller in sorrows.worldVoid.objectsByPosition[self.position]:
                                    if miller.inventory["bread"] > 0:
                                        self.Debug("sell-grain - miller found / sale")

                                        miller.inventory["bread"] -= 1
                                        miller.inventory["grain"] += 1
                                        self.inventory["bread"] += 1
                                        self.inventory["grain"] -= 1

                                        self.GoalCompleted("sell-grain")
                                        self.InitialiseGoal("harvest-grain")
                                    else:
                                        self.Debug("sell-grain - miller found / wait bread")
                                else:
                                    self.Debug("sell-grain - miller not present")
                        else:
                            self.Debug("sell-grain - no miller exists")
                            break
                    else:
                        self.Debug("sell-grain - no grain")
                        break
                elif self.goals.has_key("harvest-grain"):
                    # If distant from field, approach field.
                    if not self.ApproachPosition(self.homePosition):
                        # Start harvesting process.  Or end it.
                        if self.inventory["grain"] == 0:
                            self.inventory["grain"] += 1
                            self.inventory["bread"] -= 1
                            self.Debug("harvest-grain - harvested")
                        else:
                            self.GoalCompleted("harvest-grain")
                            self.InitialiseGoal("sell-grain")
                elif len(self.goals):
                    self.Debug("bad goals", self.goals)
                    break
            elif self.profession == 'miller':
                if self.goals.has_key("sell-flour"):
                    if self.inventory["flour"] == 1:
                        buyers = self.FindEntitiesByProfession("baker")
                        if len(buyers):
                            buyer = buyers[0]
                            if not self.ApproachPosition(buyer.homePosition):
                                # Reached the buyer's home.  Is it present?
                                if buyer in sorrows.worldVoid.objectsByPosition[self.position]:
                                    if buyer.inventory["bread"] > 0:
                                        self.Debug("sell-flour - baker found / sale")

                                        buyer.inventory["bread"] -= 1
                                        buyer.inventory["flour"] += 1
                                        self.inventory["flour"] -= 1
                                        self.inventory["bread"] += 1

                                        self.GoalCompleted("sell-flour")
                                        self.InitialiseGoal("work")
                                    else:
                                        self.Debug("sell-grain - baker found / wait bread")
                                else:
                                    self.Debug("sell-grain - miller not present")
                    else:
                        self.Debug("sell-flour - no flour")
                        break
                elif self.goals.has_key("work"):
                    # If distant from field, approach field.
                    if not self.ApproachPosition(self.homePosition):
                        grainCount = self.inventory["grain"]
                        if grainCount > 0:
                            self.inventory["grain"] -= grainCount
                            self.inventory["flour"] += grainCount

                            self.GoalCompleted("work")
                            self.InitialiseGoal("sell-flour")
                        else:
                            self.Debug("work - no grain to grind")
                elif len(self.goals):
                    self.Debug("bad goals", self.goals)
                    break
            elif self.profession == 'baker':
                flourCount = self.inventory["flour"]
                if flourCount > 0:
                    self.inventory["flour"] -= flourCount
                    self.inventory["bread"] += flourCount
                    self.Debug("bake", flourCount, "bread")
                else:
                    self.Debug("wait for customer")
            tasklet_sleep(sleepDelay)
        self.Debug("done")
예제 #21
0
 def _wait_func(channel, seconds):
     tasklet_sleep(seconds)
     channel.send(None)
예제 #22
0
 def _wait_func(channel, seconds):
     tasklet_sleep(seconds)
     channel.send(None)