Network.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef CORE_NETWORK_H
  2. #define CORE_NETWORK_H
  3. #include "core/Buffer.h"
  4. #include "core/Types.h"
  5. typedef enum {
  6. CORE_RELIABLE,
  7. CORE_SEQUENCED,
  8. CORE_UNSEQUENCED
  9. } CorePacketSendMode;
  10. typedef struct {
  11. const char* data;
  12. size_t size;
  13. size_t index;
  14. } CoreInPacket;
  15. void coreInitInPacket(CoreInPacket* in, const void* data, size_t n);
  16. bool coreInPacketReadU8(CoreInPacket* in, u8* u);
  17. bool coreInPacketReadU16(CoreInPacket* in, u16* u);
  18. bool coreInPacketReadU32(CoreInPacket* in, u32* u);
  19. bool coreInPacketReadI8(CoreInPacket* in, i8* i);
  20. bool coreInPacketReadI16(CoreInPacket* in, i16* i);
  21. bool coreInPacketReadI32(CoreInPacket* in, i32* i);
  22. bool coreInPacketReadFloat(CoreInPacket* in, float* f);
  23. size_t coreInPacketReadString(CoreInPacket* in, char* buffer, size_t n);
  24. bool coreInPacketRead(CoreInPacket* in, void* buffer, size_t n);
  25. typedef struct {
  26. CoreBuffer data;
  27. } CoreOutPacket;
  28. void coreInitOutPacket(CoreOutPacket* out);
  29. void coreDestroyOutPacket(CoreOutPacket* out);
  30. CoreOutPacket* coreOutPacketWriteU8(CoreOutPacket* out, u8 u);
  31. CoreOutPacket* coreOutPacketWriteU16(CoreOutPacket* out, u16 u);
  32. CoreOutPacket* coreOutPacketWriteU32(CoreOutPacket* out, u32 u);
  33. CoreOutPacket* coreOutPacketWriteI8(CoreOutPacket* out, i8 i);
  34. CoreOutPacket* coreOutPacketWriteI16(CoreOutPacket* out, i16 i);
  35. CoreOutPacket* coreOutPacketWriteI32(CoreOutPacket* out, i32 i);
  36. CoreOutPacket* coreOutPacketWriteFloat(CoreOutPacket* out, float f);
  37. CoreOutPacket* coreOutPacketWriteString(CoreOutPacket* out, const char* buffer,
  38. size_t n);
  39. CoreOutPacket* coreOutPacketWrite(CoreOutPacket* out, const void* buffer,
  40. size_t n);
  41. typedef u16 CorePort;
  42. typedef void (*CoreClientOnConnect)(void);
  43. typedef void (*CoreClientOnDisconnect)(void);
  44. typedef void (*CoreClientOnPacket)(CoreInPacket*);
  45. bool coreClientStart(void);
  46. void coreClientStop(void);
  47. bool coreClientConnect(const char* server, CorePort port, int timeoutTicks);
  48. void coreClientDisconnect(int timeoutTicks);
  49. void coreClientSend(CoreOutPacket* p, CorePacketSendMode mode);
  50. void coreClientTick(void);
  51. void coreClientSetConnectHandler(CoreClientOnConnect oc);
  52. void coreClientSetDisconnectHandler(CoreClientOnDisconnect od);
  53. void coreClientSetPacketHandler(CoreClientOnPacket op);
  54. void coreClientResetHandler(void);
  55. bool coreClientIsConnecting(void);
  56. bool coreClientIsConnected(void);
  57. /*namespace Server {
  58. typedef uint16 Port;
  59. typedef int Client;
  60. typedef void (*OnConnect)(Client);
  61. typedef void (*OnDisconnect)(Client);
  62. typedef void (*OnPacket)(Client, InPacket&);
  63. Error start(Port port, int maxClients);
  64. void stop();
  65. void tick();
  66. void send(const OutPacket& p, PacketSendMode mode);
  67. void send(Client client, const OutPacket& p, PacketSendMode mode);
  68. void disconnect(Client client);
  69. void setConnectHandler(OnConnect oc);
  70. void setDisconnectHandler(OnDisconnect od);
  71. void setPacketHandler(OnPacket op);
  72. void resetHandler();
  73. }*/
  74. #endif