sm64coopdx/lib/coopnet/include/libcoopnet.h

73 lines
2.8 KiB
C
Raw Normal View History

2023-04-10 00:20:07 +00:00
#ifndef LIBCOOPNET_H
#define LIBCOOPNET_H
2023-06-18 19:20:14 +00:00
#if defined(__cplusplus)
2023-04-10 00:20:07 +00:00
#include <cstdint>
extern "C" {
2023-06-18 19:20:14 +00:00
class Connection;
2023-04-10 00:20:07 +00:00
#endif
#include <stdbool.h>
#include <stdint.h>
typedef enum {
COOPNET_OK,
COOPNET_FAILED,
COOPNET_DISCONNECTED,
} CoopNetRc;
enum MPacketErrorNumber {
MERR_NONE,
MERR_LOBBY_NOT_FOUND,
MERR_LOBBY_JOIN_FULL,
MERR_LOBBY_JOIN_FAILED,
MERR_LOBBY_PASSWORD_INCORRECT,
2023-04-18 00:17:55 +00:00
MERR_COOPNET_VERSION,
2023-04-18 03:54:40 +00:00
MERR_PEER_FAILED,
2023-04-10 00:20:07 +00:00
MERR_MAX,
};
typedef struct {
void (*OnConnected)(uint64_t aUserId);
2023-04-16 23:06:30 +00:00
void (*OnDisconnected)(bool aIntentional);
void (*OnLobbyCreated)(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections);
2023-04-15 05:06:56 +00:00
void (*OnLobbyJoined)(uint64_t aLobbyId, uint64_t aUserId, uint64_t aOwnerId, uint64_t aDestId);
2023-04-10 00:20:07 +00:00
void (*OnLobbyLeft)(uint64_t aLobbyId, uint64_t aUserId);
2023-04-17 23:34:56 +00:00
void (*OnLobbyListGot)(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription);
2023-04-14 01:27:18 +00:00
void (*OnLobbyListFinish)(void);
2023-04-10 00:20:07 +00:00
void (*OnReceive)(uint64_t aFromUserId, const uint8_t* aData, uint64_t aSize);
2023-04-18 03:54:40 +00:00
void (*OnError)(enum MPacketErrorNumber aErrorNumber, uint64_t tag);
2023-04-10 00:20:07 +00:00
void (*OnPeerConnected)(uint64_t aPeerId);
void (*OnPeerDisconnected)(uint64_t aPeerId);
2023-06-18 19:20:14 +00:00
void (*OnLoadBalance)(const char* aHost, uint32_t port);
uint64_t (*DestIdFunction)(uint64_t aInput);
#if defined(__cplusplus)
bool (*ConnectionIsAllowed)(Connection*, bool);
void (*OnReceiveInfoBits)(Connection* aConnection, uint64_t aDestId, uint64_t aInfoBits, const char* aName);
#endif
2023-04-10 00:20:07 +00:00
} CoopNetCallbacks;
typedef struct {
bool SkipWinsockInit;
} CoopNetSettings;
extern CoopNetCallbacks gCoopNetCallbacks;
extern CoopNetSettings gCoopNetSettings;
bool coopnet_is_connected(void);
2023-06-18 19:20:14 +00:00
CoopNetRc coopnet_begin(const char* aHost, uint32_t aPort, const char* aName, uint64_t aDestId);
2023-04-10 00:20:07 +00:00
CoopNetRc coopnet_shutdown(void);
CoopNetRc coopnet_update(void);
2023-04-17 23:34:56 +00:00
CoopNetRc coopnet_lobby_create(const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections, const char* aPassword, const char* aDescription);
CoopNetRc coopnet_lobby_update(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription);
CoopNetRc coopnet_lobby_join(uint64_t aLobbyId, const char* aPassword);
2023-04-10 00:20:07 +00:00
CoopNetRc coopnet_lobby_leave(uint64_t aLobbyId);
CoopNetRc coopnet_lobby_list_get(const char* aGame, const char* aPassword);
2023-04-10 00:20:07 +00:00
CoopNetRc coopnet_send(const uint8_t* aData, uint64_t aDataLength);
CoopNetRc coopnet_send_to(uint64_t aPeerId, const uint8_t* aData, uint64_t aDataLength);
CoopNetRc coopnet_unpeer(uint64_t aPeerId);
2023-06-18 19:20:14 +00:00
#if defined(__cplusplus)
2023-04-10 00:20:07 +00:00
}
#endif
#endif