-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet.h
64 lines (47 loc) · 1.25 KB
/
net.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef NET_H
#define NET_H
#include "minimal_state_info.h"
#ifdef __unix__
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#endif
#include <stdint.h>
#include "player.h"
#include "game_mode.h"
#include "hashset.h"
#define INVALID_SOCKET -1
#ifdef __WIN32__
#define socklen_t int
// winsock2.h conflicts with raylib, so I pull some defs insead
#include "winsock.h"
#endif
typedef struct NetPlayer {
char username[20];
uint64_t last_hurt_by;
bool shooting;
bool assigned_team_id;
MinimalPlayerInfo minimal_player_info;
} NetPlayer;
typedef struct TeamScore {
uint64_t id;
uint64_t score;
} TeamScore;
static_assert(sizeof(NetPlayer) % 8 == 0, "NetPlayer is the wrong size");
typedef struct Addr {
struct sockaddr_in sockaddr;
socklen_t addr_len;
} Addr;
typedef struct NetworkInfo {
void* prev_msg;
uint64_t prev_msg_len;
char* net_buffer;
bool is_server;
int socket;
HashSet addrs_to_send_to;
} NetworkInfo;
NetworkInfo init_networking(bool hosting, const char* ip_addr, Player* my_player, GameModeData* game_mode_data, const Map* map);
int handle_networking(NetworkInfo* network_info, Player* players, uint8_t num_players, GameModeData* game_mode_data, const Map* map);
#endif