1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #ifndef CORE_NETWORK_H
- #define CORE_NETWORK_H
- #include "core/Buffer.h"
- #include "core/Types.h"
- typedef enum {
- CORE_RELIABLE,
- CORE_SEQUENCED,
- CORE_UNSEQUENCED
- } CorePacketSendMode;
- typedef struct {
- const char* data;
- size_t size;
- size_t index;
- } CoreInPacket;
- void coreInitInPacket(CoreInPacket* in, const void* data, size_t n);
- bool coreInPacketReadU8(CoreInPacket* in, u8* u);
- bool coreInPacketReadU16(CoreInPacket* in, u16* u);
- bool coreInPacketReadU32(CoreInPacket* in, u32* u);
- bool coreInPacketReadI8(CoreInPacket* in, i8* i);
- bool coreInPacketReadI16(CoreInPacket* in, i16* i);
- bool coreInPacketReadI32(CoreInPacket* in, i32* i);
- bool coreInPacketReadFloat(CoreInPacket* in, float* f);
- size_t coreInPacketReadString(CoreInPacket* in, char* buffer, size_t n);
- bool coreInPacketRead(CoreInPacket* in, void* buffer, size_t n);
- typedef struct {
- CoreBuffer data;
- } CoreOutPacket;
- void coreInitOutPacket(CoreOutPacket* out);
- void coreDestroyOutPacket(CoreOutPacket* out);
- CoreOutPacket* coreOutPacketWriteU8(CoreOutPacket* out, u8 u);
- CoreOutPacket* coreOutPacketWriteU16(CoreOutPacket* out, u16 u);
- CoreOutPacket* coreOutPacketWriteU32(CoreOutPacket* out, u32 u);
- CoreOutPacket* coreOutPacketWriteI8(CoreOutPacket* out, i8 i);
- CoreOutPacket* coreOutPacketWriteI16(CoreOutPacket* out, i16 i);
- CoreOutPacket* coreOutPacketWriteI32(CoreOutPacket* out, i32 i);
- CoreOutPacket* coreOutPacketWriteFloat(CoreOutPacket* out, float f);
- CoreOutPacket* coreOutPacketWriteString(CoreOutPacket* out, const char* buffer,
- size_t n);
- CoreOutPacket* coreOutPacketWrite(CoreOutPacket* out, const void* buffer,
- size_t n);
- typedef u16 CorePort;
- typedef void (*CoreClientOnConnect)(void);
- typedef void (*CoreClientOnDisconnect)(void);
- typedef void (*CoreClientOnPacket)(CoreInPacket*);
- bool coreClientStart(void);
- void coreClientStop(void);
- bool coreClientConnect(const char* server, CorePort port, int timeoutTicks);
- void coreClientDisconnect(int timeoutTicks);
- void coreClientSend(CoreOutPacket* p, CorePacketSendMode mode);
- void coreClientTick(void);
- void coreClientSetConnectHandler(CoreClientOnConnect oc);
- void coreClientSetDisconnectHandler(CoreClientOnDisconnect od);
- void coreClientSetPacketHandler(CoreClientOnPacket op);
- void coreClientResetHandler(void);
- bool coreClientIsConnecting(void);
- bool coreClientIsConnected(void);
- /*namespace Server {
- typedef uint16 Port;
- typedef int Client;
- typedef void (*OnConnect)(Client);
- typedef void (*OnDisconnect)(Client);
- typedef void (*OnPacket)(Client, InPacket&);
- Error start(Port port, int maxClients);
- void stop();
- void tick();
- void send(const OutPacket& p, PacketSendMode mode);
- void send(Client client, const OutPacket& p, PacketSendMode mode);
- void disconnect(Client client);
- void setConnectHandler(OnConnect oc);
- void setDisconnectHandler(OnDisconnect od);
- void setPacketHandler(OnPacket op);
- void resetHandler();
- }*/
- #endif
|