blob: aad7b15e59383ba2e7be3754e740b50c0616e0c1 [file] [log] [blame] [raw]
/* Minecraft Interprocess Management Client
* Copyright 2015-2020 Rivoreo
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#ifndef _MCIPM_PACKET_H
#define _MCIPM_PACKET_H
#include <sys/types.h>
#include <stdint.h>
#define MCIPM_GET_VERSION 1
#define MCIPM_GET_ENTITIES 2
#define MCIPM_KILL_ENTITY 3
#define MCIPM_REPLY_ERROR 128
#define MCIPM_REPLY_SUCCESS 129
#define MCIPM_REPLY_VERSION 130
#define MCIPM_REPLY_ENTITIES 131
#define MCIPM_GET_ENTITIES_SELECTOR_ALL 0
#define MCIPM_GET_ENTITIES_SELECTOR_WORLD 1
#define MCIPM_GET_ENTITIES_SELECTOR_ENTITY_ID 2
#define MCIPM_GET_ENTITIES_SELECTOR_ENTITY_TYPE 3
#define MCIPM_KILL_ENTITY_BY_ID 0
#define MCIPM_KILL_ENTITY_BY_UUID 1
#define MCIPM_ERROR_WORLD_NOT_FOUND 1
#define MCIPM_ERROR_PACKET_TYPE_NOT_RECOGNIZED 2
#define MCIPM_ERROR_INTERNAL_ERROR 3
#define MCIPM_ERROR_ENTITY_SELECTOR_NOT_RECOGNIZED 4
#define MCIPM_ERROR_ENTITY_TYPE_NOT_FOUND 5
#define MCIPM_PACKET_MAX_LENGTH (16 * 1024 * 1024)
#define GET_PACKET_EOF -1
#define GET_PACKET_ERROR -2
#define GET_PACKET_SHORT_READ -3
#define GET_PACKET_TOO_SMALL -4
#define GET_PACKET_TOO_LARGE -5
#define GET_PACKET_OUT_OF_MEMORY -6
#define GET_PACKET_INCOMPLETE -7
struct mcipm_packet {
uint32_t length;
uint8_t type;
uint8_t data[0];
};
struct entity {
uint16_t entry_length; // Including this variable
uint16_t world_name_offset;
uint16_t entity_type_name_offset;
uint16_t display_name_offset;
uint32_t entity_id;
double location_x;
double location_y;
double location_z;
float rotation_yaw;
float rotation_pitch;
uint8_t is_living_entity;
uint8_t is_on_ground;
uint8_t is_dead;
float width;
float height;
int32_t chunk_x;
int32_t chunk_y;
int32_t chunk_z;
uint64_t uuid_most_sig;
uint64_t uuid_least_sig;
// Living entity properties
float max_health;
float health;
uint32_t idle_time;
uint32_t attack_target_id;
// Variably-length data
uint8_t data[0];
} __attribute__((__packed__));
int send_packet_get_version(int);
int send_packet_get_entities(int, const void *, size_t, unsigned int);
int send_packet_kill_entity(int, const char *, long int);
int receive_packet(int, struct mcipm_packet **, int);
#endif