def user_check(self, sockfd, params): """根据发给客户端的uniqid判断有没有player""" if self.uid not in params: return uid = params[self.uid] uniqid = params['id'] clientproxy = self._account_list.get(uid) if not clientproxy: return sql = Interface.join_get_sql("player", 'id', uniqid) SqlExec.SqlExec(sql, self._check_user_cb, json.dumps(params))
def _get_uniqid_cb(self, data, params): params = json.loads(params) save_data = {key: str(value) for key, value in params.items() if key in self._column_list} print "save_data:", save_data if not data: # 没有数据,插入 sql = Interface.join_insert_sql(self.table, save_data) print "insert sql:",sql SqlExec.SqlExec(sql) sql = Interface.join_get_sql(self.table, self.uid, params[self.uid]) SqlExec.SqlExec(sql, self._get_uniqid_cb2, json.dumps(params)) else: # 有数据,更新 self._get_uniqid_cb2(data, json.dumps(params))
def login_account(self, sockfd, params): """一般作为客户端第一条协议""" # 条件判断 # 判断成功 if self.uid not in params: return uid = params[self.uid] clientproxy = ClientProxy(sockfd) self[uid] = clientproxy sql = Interface.join_get_sql(self.table, self.uid, uid) print "sql:",sql SqlExec.SqlExec(sql, self._get_uniqid_cb, json.dumps(params))