ecsnet
Loading...
Searching...
No Matches
protocol_handler.h
1#pragma once
2
3#include <stdint.h>
4#include "ecs.h"
5#include "ecs_types.h"
6#include "network_architecture.h"
7#include "connection_manager.h"
8#ifdef __cplusplus
9extern "C" {
10#endif
16#define MAX_PACKET_SIZE 1024
17#define INPUT_UP 0x01
18#define INPUT_DOWN 0x02
19#define INPUT_SPAWN 0x80
20
26typedef enum {
27 PACKET_TYPE_INVALID,
28 PACKET_TYPE_ENTITY_UPDATE,
29 PACKET_TYPE_MULTI_ENTITY_UPDATE,
30 PACKET_TYPE_CLIENT_REGISTER,
31 PACKET_TYPE_SERVER_ACK,
32 PACKET_TYPE_CLIENT_INPUT,
33} packet_type_t;
34
41typedef struct {
42 uint16_t size;
43 packet_type_t type;
45
51typedef struct {
53 uint8_t data[MAX_PACKET_SIZE - sizeof(packet_header_t)];
55
56
66
71ECSNET_API void protocol_handler_init(protocol_handler_t *handler);
72
80ECSNET_API void protocol_handler_pack_entity_update(protocol_handler_t *handler, entity_t entity_id, const uint8_t *data,
81 uint16_t data_len);
82
88void protocol_handler_pack_client_register(protocol_handler_t *handler, uint16_t udp_port);
89
101bool protocol_handler_unpack_client_register(const network_packet_t* pkt, uint16_t* out_port);
102
107void protocol_handler_pack_server_ack(protocol_handler_t *handler);
117ECSNET_API void protocol_handler_pack_client_input(protocol_handler_t* handler, entity_t entity_id, uint8_t input_cmd, const void* extra, uint16_t extra_len);
118
119
137ECSNET_API bool protocol_handler_unpack_client_input(const network_packet_t* pkt, entity_t* out_eid, uint8_t* out_cmd, const void** out_extra, uint16_t* out_extra_len);
138
146void protocol_handler_process_received_data(protocol_handler_t *handler, ecs_t* ecs, peer_t *peer, const void *data, int len);
147
154ECSNET_API void protocol_handler_send_packet(connection_manager_t *cm, const char *peer_id, protocol_handler_t *handler);
155
156
157#ifdef __cplusplus
158}
159#endif
Manages all active network connections (peers) for a client or server.
Definition connection_manager.h:74
Internal structure representing the ECS world state. This holds:
Definition ecs_internal.h:44
A full network packet structure. This struct combines the header and the data payload,...
Definition protocol_handler.h:51
packet_header_t header
Definition protocol_handler.h:52
uint8_t data[MAX_PACKET_SIZE - sizeof(packet_header_t)]
Definition protocol_handler.h:53
The header of a network packet. Contains metadata about the packet, such as its size and type....
Definition protocol_handler.h:41
packet_type_t type
Definition protocol_handler.h:43
uint16_t size
Definition protocol_handler.h:42
Represents a connected network peer.
Definition connection_manager.h:45
The protocol handler structure. Manages the state for incoming and outgoing network packets,...
Definition protocol_handler.h:62
network_packet_t in_packet
Definition protocol_handler.h:64
network_packet_t out_packet
Definition protocol_handler.h:63