|
@@ -5,143 +5,79 @@
|
|
|
#include <core/Types.h>
|
|
|
|
|
|
typedef enum {
|
|
|
- CORE_PACKET_RELIABLE,
|
|
|
- CORE_PACKET_SEQUENCED,
|
|
|
- CORE_PACKET_UNSEQUENCED
|
|
|
-} CorePacketSendMode;
|
|
|
+ PACKET_RELIABLE,
|
|
|
+ PACKET_SEQUENCED,
|
|
|
+ PACKET_UNSEQUENCED
|
|
|
+} PacketSendMode;
|
|
|
|
|
|
typedef struct {
|
|
|
const char* data;
|
|
|
size_t size;
|
|
|
size_t index;
|
|
|
-} CoreInPacket;
|
|
|
+} InPacket;
|
|
|
|
|
|
-void coreInitInPacket(CoreInPacket* in, const void* data, size_t n);
|
|
|
-bool coreReadInPacketU8(CoreInPacket* in, u8* u);
|
|
|
-bool coreReadInPacketU16(CoreInPacket* in, u16* u);
|
|
|
-bool coreReadInPacketU32(CoreInPacket* in, u32* u);
|
|
|
-bool coreReadInPacketI8(CoreInPacket* in, i8* i);
|
|
|
-bool coreReadInPacketI16(CoreInPacket* in, i16* i);
|
|
|
-bool coreReadInPacketI32(CoreInPacket* in, i32* i);
|
|
|
-bool coreReadInPacketFloat(CoreInPacket* in, float* f);
|
|
|
-size_t coreReadInPacketString(CoreInPacket* in, char* buffer, size_t n);
|
|
|
-bool coreReadInPacket(CoreInPacket* in, void* buffer, size_t n);
|
|
|
+void initInPacket(InPacket* in, const void* data, size_t n);
|
|
|
+bool readInPacketU8(InPacket* in, u8* u);
|
|
|
+bool readInPacketU16(InPacket* in, u16* u);
|
|
|
+bool readInPacketU32(InPacket* in, u32* u);
|
|
|
+bool readInPacketI8(InPacket* in, i8* i);
|
|
|
+bool readInPacketI16(InPacket* in, i16* i);
|
|
|
+bool readInPacketI32(InPacket* in, i32* i);
|
|
|
+bool readInPacketFloat(InPacket* in, float* f);
|
|
|
+size_t readInPacketString(InPacket* in, char* buffer, size_t n);
|
|
|
+bool readInPacket(InPacket* in, void* buffer, size_t n);
|
|
|
|
|
|
typedef struct {
|
|
|
- CoreBuffer data;
|
|
|
-} CoreOutPacket;
|
|
|
+ Buffer data;
|
|
|
+} OutPacket;
|
|
|
|
|
|
-void coreInitOutPacket(CoreOutPacket* out);
|
|
|
-void coreDestroyOutPacket(CoreOutPacket* out);
|
|
|
-void coreWriteOutPacketU8(CoreOutPacket* out, u8 u);
|
|
|
-void coreWriteOutPacketU16(CoreOutPacket* out, u16 u);
|
|
|
-void coreWriteOutPacketU32(CoreOutPacket* out, u32 u);
|
|
|
-void coreWriteOutPacketI8(CoreOutPacket* out, i8 i);
|
|
|
-void coreWriteOutPacketI16(CoreOutPacket* out, i16 i);
|
|
|
-void coreWriteOutPacketI32(CoreOutPacket* out, i32 i);
|
|
|
-void coreWriteOutPacketFloat(CoreOutPacket* out, float f);
|
|
|
-void coreWriteOutPacketString(CoreOutPacket* out, const char* buffer);
|
|
|
-void coreWriteOutPacket(CoreOutPacket* out, const void* buffer, size_t n);
|
|
|
+void initOutPacket(OutPacket* out);
|
|
|
+void destroyOutPacket(OutPacket* out);
|
|
|
+void writeOutPacketU8(OutPacket* out, u8 u);
|
|
|
+void writeOutPacketU16(OutPacket* out, u16 u);
|
|
|
+void writeOutPacketU32(OutPacket* out, u32 u);
|
|
|
+void writeOutPacketI8(OutPacket* out, i8 i);
|
|
|
+void writeOutPacketI16(OutPacket* out, i16 i);
|
|
|
+void writeOutPacketI32(OutPacket* out, i32 i);
|
|
|
+void writeOutPacketFloat(OutPacket* out, float f);
|
|
|
+void writeOutPacketString(OutPacket* out, const char* buffer);
|
|
|
+void writeOutPacket(OutPacket* out, const void* buffer, size_t n);
|
|
|
|
|
|
-typedef u16 CorePort;
|
|
|
-typedef void (*CoreOnServerConnect)(void);
|
|
|
-typedef void (*CoreOnServerDisconnect)(void);
|
|
|
-typedef void (*CoreOnServerPacket)(CoreInPacket*);
|
|
|
+typedef u16 Port;
|
|
|
+typedef void (*OnServerConnect)(void);
|
|
|
+typedef void (*OnServerDisconnect)(void);
|
|
|
+typedef void (*OnServerPacket)(InPacket*);
|
|
|
|
|
|
-bool coreStartClient(void);
|
|
|
-void coreStopClient(void);
|
|
|
-bool coreConnectClient(const char* server, CorePort port, int timeoutTicks);
|
|
|
-void coreSetClientTimeout(u32 timeout, u32 timeoutMin, u32 timeoutMax);
|
|
|
-void coreDisconnectClient(int timeoutTicks);
|
|
|
-void coreSendClientPacket(const CoreOutPacket* p, CorePacketSendMode mode);
|
|
|
-void coreTickClient(void);
|
|
|
-void coreSetClientConnectHandler(CoreOnServerConnect oc);
|
|
|
-void coreSetClientDisconnectHandler(CoreOnServerDisconnect od);
|
|
|
-void coreSetClientPacketHandler(CoreOnServerPacket op);
|
|
|
-void coreResetClientHandler(void);
|
|
|
-bool coreIsClientConnecting(void);
|
|
|
-bool coreIsClientConnected(void);
|
|
|
+bool startClient(void);
|
|
|
+void stopClient(void);
|
|
|
+bool connectClient(const char* server, Port port, int timeoutTicks);
|
|
|
+void setClientTimeout(u32 timeout, u32 timeoutMin, u32 timeoutMax);
|
|
|
+void disconnectClient(int timeoutTicks);
|
|
|
+void sendClientPacket(const OutPacket* p, PacketSendMode mode);
|
|
|
+void tickClient(void);
|
|
|
+void setClientConnectHandler(OnServerConnect oc);
|
|
|
+void setClientDisconnectHandler(OnServerDisconnect od);
|
|
|
+void setClientPacketHandler(OnServerPacket op);
|
|
|
+void resetClientHandler(void);
|
|
|
+bool isClientConnecting(void);
|
|
|
+bool isClientConnected(void);
|
|
|
|
|
|
-typedef int CoreClient;
|
|
|
-typedef void (*CoreOnClientConnect)(CoreClient);
|
|
|
-typedef void (*CoreOnClientDisconnect)(CoreClient);
|
|
|
-typedef void (*CoreOnClientPacket)(CoreClient, CoreInPacket*);
|
|
|
+typedef int Client;
|
|
|
+typedef void (*OnClientConnect)(Client);
|
|
|
+typedef void (*OnClientDisconnect)(Client);
|
|
|
+typedef void (*OnClientPacket)(Client, InPacket*);
|
|
|
|
|
|
-bool coreStartServer(CorePort port, size_t maxClients);
|
|
|
-void coreStopServer(void);
|
|
|
-void coreTickServer(void);
|
|
|
-void coreSendServerPacketBroadcast(const CoreOutPacket* p,
|
|
|
- CorePacketSendMode mode);
|
|
|
-void coreSendServerPacket(CoreClient client, const CoreOutPacket* p,
|
|
|
- CorePacketSendMode mode);
|
|
|
-void coreSetServerTimeout(CoreClient client, u32 timeout, u32 timeoutMin,
|
|
|
- u32 timeoutMax);
|
|
|
-void coreDisconnectServerClient(CoreClient client);
|
|
|
-void coreSetServerConnectHandler(CoreOnClientConnect oc);
|
|
|
-void coreSetServerDisconnectHandler(CoreOnClientDisconnect od);
|
|
|
-void coreSetServerPacketHandler(CoreOnClientPacket op);
|
|
|
-void coreResetServerHandler(void);
|
|
|
-
|
|
|
-#ifdef IMPORT_CORE
|
|
|
-#define PacketSendMode CorePacketSendMode
|
|
|
-#define PACKET_RELIABLE CORE_PACKET_RELIABLE
|
|
|
-#define PACKET_SEQUENCED CORE_PACKET_SEQUENCED
|
|
|
-#define PACKET_UNSEQUENCED CORE_PACKET_UNSEQUENCED
|
|
|
-#define InPacket CoreInPacket
|
|
|
-#define initInPacket coreInitInPacket
|
|
|
-#define readInPacketU8 coreReadInPacketU8
|
|
|
-#define readInPacketU16 coreReadInPacketU16
|
|
|
-#define readInPacketU32 coreReadInPacketU32
|
|
|
-#define readInPacketI8 coreReadInPacketI8
|
|
|
-#define readInPacketI16 coreReadInPacketI16
|
|
|
-#define readInPacketI32 coreReadInPacketI32
|
|
|
-#define readInPacketFloat coreReadInPacketFloat
|
|
|
-#define readInPacketString coreReadInPacketString
|
|
|
-#define readInPacket coreReadInPacket
|
|
|
-#define OutPacket CoreOutPacket
|
|
|
-#define initOutPacket coreInitOutPacket
|
|
|
-#define destroyOutPacket coreDestroyOutPacket
|
|
|
-#define writeOutPacketU8 coreWriteOutPacketU8
|
|
|
-#define writeOutPacketU16 coreWriteOutPacketU16
|
|
|
-#define writeOutPacketU32 coreWriteOutPacketU32
|
|
|
-#define writeOutPacketI8 coreWriteOutPacketI8
|
|
|
-#define writeOutPacketI16 coreWriteOutPacketI16
|
|
|
-#define writeOutPacketI32 coreWriteOutPacketI32
|
|
|
-#define writeOutPacketFloat coreWriteOutPacketFloat
|
|
|
-#define writeOutPacketString coreWriteOutPacketString
|
|
|
-#define writeOutPacket coreWriteOutPacket
|
|
|
-#define Port CorePort
|
|
|
-#define OnServerConnect CoreOnServerConnect
|
|
|
-#define OnServerDisconnect CoreOnServerDisconnect
|
|
|
-#define OnServerPacket CoreOnServerPacket
|
|
|
-#define startClient coreStartClient
|
|
|
-#define stopClient coreStopClient
|
|
|
-#define connectClient coreConnectClient
|
|
|
-#define setClientTimeout coreSetClientTimeout
|
|
|
-#define disconnectClient coreDisconnectClient
|
|
|
-#define sendClientPacket coreSendClientPacket
|
|
|
-#define tickClient coreTickClient
|
|
|
-#define setClientConnectHandler coreSetClientConnectHandler
|
|
|
-#define setClientDisconnectHandler coreSetClientDisconnectHandler
|
|
|
-#define setClientPacketHandler coreSetClientPacketHandler
|
|
|
-#define resetClientHandler coreResetClientHandler
|
|
|
-#define isClientConnecting coreIsClientConnecting
|
|
|
-#define isClientConnected coreIsClientConnected
|
|
|
-#define Client CoreClient
|
|
|
-#define OnClientConnect CoreOnClientConnect
|
|
|
-#define OnClientDisconnect CoreOnClientDisconnect
|
|
|
-#define OnClientPacket CoreOnClientPacket
|
|
|
-#define startServer coreStartServer
|
|
|
-#define stopServer coreStopServer
|
|
|
-#define tickServer coreTickServer
|
|
|
-#define sendServerPacketBroadcast coreSendServerPacketBroadcast
|
|
|
-#define sendServerPacket coreSendServerPacket
|
|
|
-#define setServerTimeout coreSetServerTimeout
|
|
|
-#define disconnectServerClient coreDisconnectServerClient
|
|
|
-#define setServerConnectHandler coreSetServerConnectHandler
|
|
|
-#define setServerDisconnectHandler coreSetServerDisconnectHandler
|
|
|
-#define setServerPacketHandler coreSetServerPacketHandler
|
|
|
-#define resetServerHandler coreResetServerHandler
|
|
|
-#endif
|
|
|
+bool startServer(Port port, size_t maxClients);
|
|
|
+void stopServer(void);
|
|
|
+void tickServer(void);
|
|
|
+void sendServerPacketBroadcast(const OutPacket* p, PacketSendMode mode);
|
|
|
+void sendServerPacket(Client client, const OutPacket* p, PacketSendMode mode);
|
|
|
+void setServerTimeout(Client client, u32 timeout, u32 timeoutMin,
|
|
|
+ u32 timeoutMax);
|
|
|
+void disconnectServerClient(Client client);
|
|
|
+void setServerConnectHandler(OnClientConnect oc);
|
|
|
+void setServerDisconnectHandler(OnClientDisconnect od);
|
|
|
+void setServerPacketHandler(OnClientPacket op);
|
|
|
+void resetServerHandler(void);
|
|
|
|
|
|
#endif
|