def sendToGame(self, uuid, opcode, data): message = NetMessage() message.opcode = opcode if data is not None: message.data = data.SerializeToString() gl.get_v("serverlogger").logger.info("发送%d给游戏服" % opcode) gl.get_v("redis").publish(uuid, message.SerializeToString())
def handle(self, queue): while not self.__close: try: messages = queue.getall(30, True, 20) for message in messages: s = GateWayMessage() s.ParseFromString(message) netMessage = NetMessage() netMessage.ParseFromString(s.data) gl.get_v("serverlogger").logger.info('''收到%d消息%d''' % (s.userId, netMessage.opcode)) self.__lock.acquire() if s.userId not in self.__user_queue: messagequeue = TestQueue() messagehandle = UserMessageHandle(s.userId, self) threading.Thread(target=UserMessageHandle.handle, args=(messagehandle, messagequeue,), name='handle').start() # 线程对象. self.__user_queue[s.userId] = messagequeue self.__user_queue[s.userId].put(netMessage) self.__lock.release() except Queue.Empty: gl.get_v("serverlogger").logger.info("Received timeout") except: print traceback.print_exc()
def send_to_gateway(self, opcode, data): send_data = NetMessage() send_data.opcode = opcode send_data.data = data.SerializeToString() s = GateWayMessage() s.userId = self.__userId s.data = send_data.SerializeToString() gl.get_v("redis").publish("server-gateway", s.SerializeToString()) gl.get_v("serverlogger").logger.info("发送%d给%s" % (opcode, self.__userId))
def send_to_coordinate(opcode, data): send_data = NetMessage() send_data.opcode = opcode send_data.data = data.SerializeToString() send_data.id = gl.get_v("uuid") gl.get_v("redis").publish("game-coordinate", send_data.SerializeToString())