def handle(self): gui.updateStatus("Waiting for requests...") conn = self.request conn.setblocking(1) timestamp = 0 self.sendBGBPacket(conn, BGBPacket(1, 1, 4, 0, 0)) self.sendBGBPacket(conn, BGBPacket(108, 1, 0, 0, 0)) counter = 0 environment = util.DotDict({ 'handshake_counter': 0, 'content_length': 0, 'response_sent': False, 'request_buffer': [], 'state': States.WAIT_HANDSHAKE, 'last_active': time.time(), 'session_started_t': time.time() }) while 1: p = self.receiveBGBPacket(conn) if p is not None: if p['a'] == 106 or p['a'] == 108: timestamp = self.updateTimestamp(environment) self.sendBGBPacket(conn, BGBPacket(106, 0, 0, 0, timestamp)) if p['a'] == 104: environment.response_sent = False self.dataReceived(conn, environment, p['b'])
def sql(query, params=()): ret = [] with db_lock: cur = db.cursor() for i in cur.execute(query, params): ret.append(util.DotDict(i)) db.commit() return ret
def NormalizeData(self, data): """ Normalize Enum Definitions """ # The canonical member format is list of dicts: # name: # value: # desc: cmembers = [] members = data['members'] if type(members) != list: raise Exception("Enumeration members must be lists.") for m in members: if type(m) == util.DotDict: # We've already normalized this data return data nmember = util.DotDict(dict(name=None, value=None, desc=None)) if 'memberfilter' in data: nmember.update(eval(data['memberfilter'])) elif type(m) == str: # Just the name. No description, values are linearly assigned. nmember.name = m elif type(m) == list: # Don't support this anymore raise Exception( "List formats for enum keys no longer supported.") elif type(m) == dict: if len(m.keys()) != 1: raise Exception("Malformed dict for enum member: m") for (k, v) in m.iteritems(): if type(v) is dict: # Assumed this is just the member data. nmember.name = k nmember.update(v) elif type(v) is str: # Assumed to be the value for the member nmember.name = k nmember.value = v elif type(v) is int: # Assumed to be the value for the member nmember.name = k nmember.value = str(v) else: raise Exception("Bad dict case in enum member.") else: raise Exception("Input data for member %s is not understood." % (m)) cmembers.append(nmember) data['members'] = cmembers return data
def sql(query, params=(), log_errors=True): ret = [] with db_lock: try: cur = db.cursor() for i in cur.execute(query, params): ret.append(util.DotDict(i)) db.commit() except: if log_errors: logger.log( TAG, "sql query made a fucky wucky, a wittle fucko boingo") logger.log_exc(TAG) return ret
def begin(user_id, kingdom): sects = augments.sections() c = random.choice(sects) if kingdom != '@': while 1: c = random.choice(sects) if c.startswith(kingdom.upper() + "_"): break state = util.DotDict({ "id": c, "type": augments[c]["Type"], "max_length": int(augments[c]["Length"]), "context": augments[c]["Context"], "kingdom": kingdom, "sid": util.new_session_key() }) augment_states[user_id] = state return state