blob: 02c99016b3f28845cc7b6d36182ca905dcd83c89 [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
int16_t world_name_offset;
int16_t entity_type_name_offset;
int16_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_item;
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;
uint32_t ticks;
union {
struct {
// Living entity properties
float max_health;
float health;
uint32_t idle_time;
uint32_t attack_target_id;
// Ageable entity property
int16_t growing_age;
} __attribute__((__packed__)) living;
struct {
// Item entity properties
int16_t health;
int16_t age;
int16_t pickup_delay;
int16_t owner_offset;
int16_t thrower_offset;
int16_t item_damage;
int32_t lifespan;
uint8_t item_count;
} __attribute__((__packed__)) item;
};
// 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