69 lines
1.6 KiB
Plaintext
69 lines
1.6 KiB
Plaintext
|
|
we will use this port in net.h
|
|
#define PORT 36911
|
|
|
|
here packet size is also defined, subject to change but makes it
|
|
easy to no block on send
|
|
#define PACKSZ 1024
|
|
|
|
|
|
pack type will be at the front of the packet to ensure we handle packets right
|
|
|
|
enum pack_type{
|
|
G_STATE, S_STATE, HOSTS_REQ, NEW_HOST, JOIN_REQ, U_NAME
|
|
};
|
|
|
|
packets are defined so that they keep the exact size of PACKSZ
|
|
typedef struct packet{
|
|
enum pack_type type;
|
|
char payload[PACKSZ - sizeof(enum pack_type)];
|
|
} packet;
|
|
|
|
|
|
JOIN GAME:
|
|
|
|
CLIENT | SERVER
|
|
|
|
HOSTS_REQ ----------->
|
|
<---------- HOSTS_REQ [ list of names that are open lobbies]
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
JOIN_REQ ----------->
|
|
[name of lobby, name of player]
|
|
<----------- JOIN_REQ [IP info of host with that name]
|
|
|
|
|
|
HOST GAME:
|
|
|
|
CLIENT | SERVER
|
|
|
|
NEW_HOST ------------>
|
|
[name of lobby]
|
|
<----------- NEW_HOST [ack]
|
|
|
|
(ON PLAYER JOIN REQUEST)
|
|
<------------ JOIN_REQ [player ip info]
|
|
|
|
JOIN_REQ ------------>
|
|
[lobby count]
|
|
|
|
(ON HOST START GAME)
|
|
|
|
S_STATE ----------->
|
|
[starting game]
|
|
<---------- S_STATE [ack]
|
|
|
|
(on timeout for lobbies ie games not started)
|
|
|
|
<--------- G_STATE [you alive?]
|
|
|
|
G_STATE --------->
|
|
[yup]
|
|
|
|
|
|
|
|
|
|
|
|
|