-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.h
86 lines (76 loc) · 2.2 KB
/
player.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
/**
* The server's conception of a player.
*
* Copyright (C) 2015 "Frostsnow" (Wade T. Cline).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef player_H
#define player_H
#include "include.h"
#include <fcntl.h>
#include <poll.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "global.h"
#include "gls.h"
struct player {
// Thread-specific flub.
struct flub flub;
// Private buffer for player identification.
char name[GLS_NICK_LENGTH];
// Player's nickname.
char nick[GLS_NICK_LENGTH];
// Pipes going to and from the server.
int pipe_server_from[2];
int pipe_server_to[2];
// Player connection.
int sockfd;
// Thread identifier.
pthread_t thread;
// Authentication status.
unsigned authenticated:1;
// Connection open.
unsigned connected:1;
// Killed by server.
unsigned killed:1;
// Protover verified.
unsigned protoverokay:1;
// Game state synchronized.
unsigned synchronized:1;
};
/**
* Free possibly disconnected player.
*/
void player_free(struct player* player, struct flub* status);
/**
* Initialize newly-connected player.
*/
struct flub* player_init(struct player* player, int fd);
/**
* Force player to prepare for player_free.
*/
struct flub* player_kill(struct player* player);
/**
* Returns a statically-allocated human-readable name for the player regardless
* of player state (unlike nickname, where the player must be authenticated).
* Not reentrant.
*/
char* player_name(struct player* player);
/**
* Thread to buffer data in-between the raw socket and the server.
*/
void* player_thread(void* player);
#endif // player_H