示例#1
0
文件: tower.py 项目: fycheung/misc
 def do_update(self):
         return {"tower":{"uid":self._c_owner._uid, "process":self._n_process, 
                          "active_chapters":json.dumps(self._list_active_chapters),
                          "auto_tower_info":json.dumps({"in_auto_tower":int(self._b_in_auto_tower),
                                                        "des_process":self._n_des_process}),
                          "max_floor":self._max_floor
                         }
                 }
示例#2
0
 def do_update(self):
     return {
         "tower": {
             "uid":
             self._c_owner._uid,
             "process":
             self._n_process,
             "active_chapters":
             json.dumps(self._list_active_chapters),
             "auto_tower_info":
             json.dumps({
                 "in_auto_tower": int(self._b_in_auto_tower),
                 "des_process": self._n_des_process
             }),
             "max_floor":
             self._max_floor
         }
     }
示例#3
0
 def main_loop(self):
         self._is_running = True
         
         self._n_conn_count = 0
         
         while self._is_running:
                 try:
                         net_trans.process()
                         
                         #新连接到达
                         new_conn_list = net_trans.get_new_conn_lst()
                         for new_conn_tuple in new_conn_list:
                                 conn = new_conn_tuple[0]
                                 type = new_conn_tuple[1]
                                 
                                 self._n_conn_count += 1
                                         
                         #只处理数据接收即可
                         recv_conn_list = net_trans.get_recv_conn_lst()
                         
                         for recv_conn in recv_conn_list:
                                 data = net_trans.recv_data(recv_conn)
                                 
                                 if not data:
                                         continue
                                 
                                 for detail in data:
                                         msg_id  = detail["msg_id"]
                                         content = detail["content"]
                                         
                                         #如未注册消息ID
                                         if not self._dict_msg_form.has_key(msg_id):
                                                 continue
                                                 
                                         try:
                                                 self._dict_msg_form[msg_id](recv_conn, content)
                                         except Exception, e:
                                                 if net_trans.msg_id_need_log(msg_id):
                                                         #仅出现错误时打印日志
                                                         dlog("[recv_msg] - msg_id:%s, content:%s", str(msg_id), json.dumps(content))
                                                     
                                                 dlog("%s", traceback.format_exc())
                         
                         #关闭连接
                         closed_conn_lst = net_trans.get_closed_conn_lst()
                         
                         for closed_conn in closed_conn_lst:
                                 self._n_conn_count -= 1
                         
                         self._n_conn_count = max(0, self._n_conn_count)
                                    
                         timer_manager.run()
                         
                         time.sleep(0.01)
                 except:
示例#4
0
文件: main.py 项目: hw233/python_misc
 def would_close_handler(hid, content):
         #向主游戏进程发送即将关闭确认的信息
         net_trans.direct_send_data(hid, json.dumps({"msg_id":message.MSG_DB_WOULD_CLOSE,"content":{}, "from":net_cfg.RECV_FROM_DATABASE}))
         
         daemon.signal_handle(10, None)