Example #1
0
File: grid.py Project: pvh/thegrid
    def addUser(self, user, pid = None):
        if pid != None:
            if db.hexists(self.dbid + ":usr", pid):
                return False

            db.hset(self.dbid + ":usr", pid, user['id'])
            return pid
        
        # Get a pid
        pid = 0
        if db.hlen(self.dbid + ":usr") >= int(self['players']):
            return False

        for i in range(1, int(self['players']) + 1):
            if db.hexists(self.dbid + ":usr", i):
                continue
            pid = i
            break

        db.hset(self.dbid + ":usr", pid, user['id'])
        user['color'] = self.getColor(pid)

        # remove them from the nogrid list
        db.srem("nogrid", user['id'])

        return pid
Example #2
0
File: grid.py Project: pvh/thegrid
    def loadEvent(self, event):
        f = open("static/maps/%s_%s.json" % (self['size'], self['map']), "r")
        data = json.loads(f.read())
        f.close()

        if event == "init":
            for key in data:
                if key not in ["colors", "coords", "events"]:
                    self[key] = data[key]

            for pid in data['colors']:
                db.hset(self.dbid + ":clr", pid, data['colors'][pid])

        # Load event
        coords = {}
        for coord in data['events'][event]:
            coords[coord] = data['coords'][coord]

        self.load(coords)

        coords = []
        for coord in data['events'][event]:
            coords.append(self.get(coord))

        return coords
Example #3
0
File: grid.py Project: pvh/thegrid
    def create(obj, name, size, mapname):
        if re.match("^[A-z0-9]*$", name) is None:
                return (False, "name")

        # Generate an id for the game
        uid = db.incr("uid")
        # For matching names with ids
        db.hset("nameid", name, uid)

        db.hmset("g:%s" % uid, {
            "name": name,
            "size": size,
            "map": mapname,
            "started": int(time()),
        })

        # Load the initial coords from the map file
        g = obj(uid)
        g.loadEvent("init")
        if int(g['autogenerate']) == True:
            g.generateTerrain()

        return (True, g)
Example #4
0
File: user.py Project: pvh/thegrid
 def __setitem__(self, key, val):
     return db.hset(self.dbid, key, val)