Esempio n. 1
0
    def run(self):
        global main
        try:
            while not main.terminate:
                try:
                    p = self.sock.recv(1024*128).strip().split(" ")
                    if p[0] == 'res':
                        i = int(p[1])
                        if i in self.callback:
                            self.callback[i](p[2:])
                            del self.callback[i]
                    elif p[0] == 'toggle':
                        print "Flush"
                        self.condition.acquire()
                        world.save()
                        self.pause = not self.pause
                        if self.pause: self.sock.send("stop")
                        self.condition.notify()
                        self.condition.release()

                except socket.timeout:
                    if len(self.callback) < 10:
                        self.async("pos", self.__loc_help)
                        self.async("list_inventory", self.__inventory_help)
                        if main.loc:
                            r=10
                            p = tuple(map(lambda x: int(math.floor(x)), main.loc))
                            p2=p
                            about = world.getAbout(p, r)
                            self.async("query", lambda res: self.__query_help(p2, r, res),
                                       *map(lambda (x,y,z): "%d %d %d"%(x,y,z), about))
        finally:
            self.condition.acquire()
            self.condition.notify()
            self.condition.release()
            print "Net thread exit"
Esempio n. 2
0
def queryAbout(p, r):
    about=world.getAbout(p, r)
    res = net.sync("query", *map(lambda (x,y,z): "%d %d %d"%(x,y,z), about))
    changed = world.updateAbout(p, r, map(int, res) )
    print "Changed?", changed