def disconnect(reason, reason_str=''): msg = ghack_pb2.Message() msg.type = ghack_pb2.Message.DISCONNECT msg.disconnect.reason = reason if reason_str: msg.disconnect.reason_str = reason_str return msg
def login(name, authtoken='', permissions=0): msg = ghack_pb2.Message() msg.type = ghack_pb2.Message.LOGIN msg.login.name = name msg.login.authtoken = authtoken msg.login.permissions = permissions return msg
def move(direction): """This is weird, at least for now. Pass it something of the form: %(sign)s%(direction)s -- such as +x or -y. """ msg = ghack_pb2.Message() msg.type = ghack_pb2.Message.MOVE msg.move.direction.x = direction.x msg.move.direction.y = direction.y msg.move.direction.z = direction.z return msg
def get_message(self): "Dispatches the next message from the server (non-blocking)" if len(self._buffer) <= 2: return None msg_len = struct.unpack('H', self._buffer[:2])[0] if len(self._buffer) < 2 + msg_len: return None msg = ghack_pb2.Message() msg.ParseFromString(self._buffer[2:msg_len + 2]) self._buffer = self._buffer[2 + msg_len:] return msg
def connect(version): msg = ghack_pb2.Message() msg.type = ghack_pb2.Message.CONNECT msg.connect.version = version return msg