-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.h
127 lines (96 loc) · 3.81 KB
/
user.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#define NOT_READY 0
#define READY 1
#define PLAYING 2
#define WAITING 3
#define IDLE 4
typedef struct usertype *user;
//General Managment of the list
/*user_init
* Entry: Nothing
* Exit: gives address of user
*/
user user_init(void);
/* user_add: (call when ever a user joins,
* set status to NOT_READY if server state is LOBBY,
* and WAITING if a server state is GAME)
* entry: enet_peer of the user, status of the user
* exit: add the user to the user list and
* set the user's score to zero
*/
int user_add(user usr, ENetPeer *peer, int status);
/* user_remove:
* entry: takes the user list,
* takes the enet_peet to remove
* exit: removes the user from the list
* returns his assigned arena id to kill him
*/
int user_remove(user usr, ENetPeer *peer);
void user_render(user usr, int x, int y);
/* user_free:
* entry: takes the user list to free,
* exit: deletes list
*/
void user_free(user usr);
//These functions are for the game logic
/* user_update_score: (call at the end of an arena game)
* entry: takes the user list,
* takes the score for the certain round,
* takes the arena id of the person.
* exit: adds the score to the user's total score,
* sets everyone to not ready
*/
void user_update_score(user usr, int arna_id ,int score);
/* user_set_ready:
* entry: takes user list,
* takes enet_peer to set to ready
* exit: sets the specified user to a ready state
*/
void user_set_ready(user usr, ENetPeer *peer);
/* returns the numbers of users on the list*/
int user_number(user usr);
/* user_check_states:
* entry: takes user list
* exit: returns number of NOT_READY users
*/
int user_check_states(user usr);
/* user_set_arena_id:
* entry: takes the user list
* exit: sets an arena id for each ready member,
* returns number of ids set,
* also sets each READY player to PLAYING
*/
int user_set_arena_id(user usr);
/* user_all_not_ready:
* set the state of all users in usr to not ready execpt idle users
*/
void user_all_not_ready(user usr);
//These functions are for send and recieving packets
/* on connection the server gets a new client, this is w
* where the server sends the info about all clients that have joined
*/
void user_send_list(user usr, ENetHost * host, int channel);
/* for the client recieving the list */
/* this is what gets updates about the list too:
* call this function in the client to after calling these functions in the server:
* o user_send_list
* o user_send_new_client
*/
void user_get_list(user usr, ENetPacket * packet);
char * user_nameby_id(user usr, int id);
char * user_nameby_aid(user usr, int id);
/* when a client changes their name as it appears on the server */
/* for the server: usr is user list to modify, packet is the packet recived by the server with a string of the new name, channel is the new channel to send the name change out to.*/
void user_change_name_send(user usr, ENetHost * server, ENetEvent * event, enet_uint8 channel);
/* when a new user joins to send his userinfo to the rest of the clients*/
void user_send_new_client(user usr, ENetPeer * peer, ENetHost *host, enet_uint8 channel);
/* when a client disconnects, notify the other users that a user disconnected */
void user_send_disconnect(int id, int channel, ENetHost * host);
/* for the client */
void user_get_disconnect(user usr, ENetPacket * packet, chat cht);
void user_send_chat_message(user usr, ENetEvent * event, ENetHost * host, enet_uint8 channel);
void user_get_chat_message(user usr, chat cht, ENetPacket *packet);
void user_sget_send_pstate(user usr, ENetHost * server, ENetEvent * event, enet_uint8 channel);
int user_peer_aid(user usr, ENetPeer * peer);
void user_send_arena_ids(user usr, int channel);
int user_get_arena_id(ENetPacket * packet);
void user_disconnect_all(user usr, ENetHost * host);