def pack_sence_update_message(self, my_marines, other_marines): msg = api_pb2.Message() msg.msg = api_pb2.senceupdate for m in my_marines: msg_own = msg.update.own.add() msg_own.MergeFrom(marine_obj_to_protobuf(m)) for m in other_marines: msg_oth = msg.update.others.add() msg_oth.MergeFrom(marine_obj_to_protobuf(m, own=False)) return msg.SerializeToString()
def pack_join_room_response(self, room_id, map_size, marines): msg = api_pb2.Message() msg.msg = api_pb2.cmdresponse msg.response.ret = 0 msg.response.cmd = api_pb2.joinroom jrm = msg.response.jrmResponse jrm.id = room_id jrm.size.x, jrm.size.z = map_size for m in marines: msg_s = jrm.marines.add() msg_s.MergeFrom(marine_obj_to_protobuf(m)) return msg.SerializeToString()
def pack_join_room_error_response(self, error_code): msg = api_pb2.Message() msg.msg = api_pb2.joinroom msg.response.ret = error_code return msg.SerializeToString()
def pack_end_battle_message(self, reason, win): msg = api_pb2.Message() msg.msg = api_pb2.endbattle msg.endbattle.reason = reason msg.endbattle.win = win return msg.SerializeToString()
def pack_start_battle_message(self): msg = api_pb2.Message() msg.msg = api_pb2.startbattle return msg.SerializeToString()
def pack_operate_marine_response(self, error_code): msg = api_pb2.Message() msg.msg = api_pb2.cmdresponse msg.response.ret = error_code msg.response.cmd = api_pb2.marineoperate return msg.SerializeToString()