|
- #ifndef IZ_NET_H
- #define IZ_NET_H
-
- #include <minIni.h>
- #include <SDL_thread.h>
- #include "../IZ_common.h"
- #include "../IZ_config.h"
- #include "../input/IZ_action.h"
- #include "core/IZ_websocket.h"
- #include "svc/IZ_wsclient.h"
-
- typedef enum {
- IZ_NET_STATUS_PRISTINE,
- IZ_NET_STATUS_CONNECTING,
- IZ_NET_STATUS_ERROR,
- IZ_NET_STATUS_CONNECTED,
- } IZ_NetStatus;
-
- typedef struct {
- u16 packet_interval_ms;
- u8 max_reconnect_retries;
- u8 reconnect_interval_secs;
- char username[32];
- } IZ_NetConfig;
-
- typedef struct {
- SDL_Thread* client_thread;
- IZ_NetConfig config;
- IZ_Websocket ws;
- IZ_WSClientInitializeParams params;
- void* callback;
- IZ_Action action[IZ_PLAYERS];
- u8 retries;
- IZ_NetStatus status;
- // TODO add message queue
- } IZ_NetState;
-
- static IZ_NetState IZ_NET_DEFAULT_STATE = {
- .client_thread = NULL,
- .config = {
- .packet_interval_ms = 200,
- .max_reconnect_retries = 3,
- .reconnect_interval_secs = 3,
- .username = "Player",
- },
- .ws = {
- .interrupted = false,
- .context = NULL,
- .connection = NULL,
- .user_data = NULL,
- },
- .params = {
- .port = 42069,
- .path = "/",
- .host = "localhost",
- },
- .callback = NULL,
- .action = {},
- .retries = 3,
- .status = IZ_NET_STATUS_PRISTINE,
- };
-
- IZ_ProcedureResult IZ_NetInitialize(IZ_NetState*, void*, void*, const char*, u8, const char**);
-
- void IZ_NetConnect(IZ_NetState*, IZ_WSClientInitializeParams);
-
- void IZ_NetDisconnect(IZ_NetState*);
-
- IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState*, const char*);
-
- void IZ_NetSendBinaryMessage(IZ_NetState*, void*, size_t);
-
- void IZ_NetSendTextMessage(IZ_NetState*, char*, size_t);
-
- #endif
|