… | |
… | |
75 | * current state. we set up our on buffers for sending/receiving, so we can |
75 | * current state. we set up our on buffers for sending/receiving, so we can |
76 | * handle some higher level functions. fd is the actual file descriptor we |
76 | * handle some higher level functions. fd is the actual file descriptor we |
77 | * are using. |
77 | * are using. |
78 | */ |
78 | */ |
79 | |
79 | |
80 | enum Sock_Status { Ns_Avail, Ns_Add, Ns_Dead, Ns_Old }; |
80 | enum Sock_Status { Ns_Add, Ns_Dead }; |
81 | |
|
|
82 | /* Reserver 0 for neither of these being set */ |
|
|
83 | enum Old_Mode { Old_Listen = 1, Old_Player = 2 }; |
|
|
84 | |
81 | |
85 | /* Only one map mode can actually be used, so lets make it a switch |
82 | /* Only one map mode can actually be used, so lets make it a switch |
86 | * instead of having a bunch of different fields that needed to |
83 | * instead of having a bunch of different fields that needed to |
87 | * get toggled. |
84 | * get toggled. |
88 | */ |
85 | */ |
… | |
… | |
98 | int start; |
95 | int start; |
99 | int len; |
96 | int len; |
100 | }; |
97 | }; |
101 | |
98 | |
102 | /* how many times we are allowed to give the wrong password before being kicked. */ |
99 | /* how many times we are allowed to give the wrong password before being kicked. */ |
103 | # define MAX_PASSWORD_FAILURES 5 |
100 | #define MAX_PASSWORD_FAILURES 5 |
104 | |
101 | |
105 | ACC_CLASS (client_socket) // should become player when newsocket is a baseclass of player |
102 | ACC_CLASS (client_socket) // should become player when newsocket is a baseclass of player |
106 | struct NewSocket : zero_initialised |
103 | struct client_socket : zero_initialised, attachable_base |
107 | { |
104 | { |
108 | enum Sock_Status status; |
105 | enum Sock_Status status; |
109 | int ACC (RW, fd); |
106 | int ACC (RW, fd); |
110 | unsigned int inbuf_len; // number of bytes valid in inbuf |
107 | unsigned int inbuf_len; // number of bytes valid in inbuf |
111 | struct Map lastmap; |
108 | struct Map lastmap; |
… | |
… | |
150 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
147 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
151 | char ACC (RW, client)[64]; // CF+ client name/version |
148 | char ACC (RW, client)[64]; // CF+ client name/version |
152 | |
149 | |
153 | /* If we get an incomplete packet, this is used to hold the data. */ |
150 | /* If we get an incomplete packet, this is used to hold the data. */ |
154 | uint8 inbuf[MAXSOCKBUF]; |
151 | uint8 inbuf[MAXSOCKBUF]; |
|
|
152 | player *pl;//TODO should not be here, preferably |
|
|
153 | |
|
|
154 | client_socket (int fd, const char *from_ip); |
|
|
155 | ~client_socket (); |
155 | |
156 | |
156 | int read_packet (); // returns length of packet or 0 |
157 | int read_packet (); // returns length of packet or 0 |
157 | void skip_packet (int len); // we have processed the packet, skip it |
158 | void skip_packet (int len); // we have processed the packet, skip it |
158 | |
159 | |
|
|
160 | void send (void *buf_, int len); |
|
|
161 | |
159 | void send_packet (const char *buf); |
162 | void send_packet (const char *buf); |
160 | void send_packet (const char *buf, int len); |
163 | void send_packet (const char *buf, int len); |
161 | void send_packet (SockList &sl); |
164 | void send_packet (packet &sl); |
162 | }; |
165 | }; |
163 | |
166 | |
164 | #define CLIENT_SUPPORT_READABLES(__sockPtr,__type)\ |
167 | #define CLIENT_SUPPORT_READABLES(__sockPtr,__type)\ |
165 | ( ((__type)>0) &&\ |
168 | ( ((__type)>0) &&\ |
166 | ((__sockPtr)->has_readable_type) && \ |
169 | ((__sockPtr)->has_readable_type) && \ |
… | |
… | |
199 | #define EMI_HASMOREBITS 0x80 |
202 | #define EMI_HASMOREBITS 0x80 |
200 | |
203 | |
201 | #define FACE_TYPES 1 |
204 | #define FACE_TYPES 1 |
202 | #define PNG_FACE_INDEX 0 |
205 | #define PNG_FACE_INDEX 0 |
203 | |
206 | |
204 | struct Socket_Info |
|
|
205 | { |
|
|
206 | struct timeval timeout; /* Timeout for select */ |
|
|
207 | int max_filedescriptor; /* max filedescriptor on the system */ |
|
|
208 | int nconns; /* Number of connections */ |
|
|
209 | int allocated_sockets; /* number of allocated in init_sockets */ |
|
|
210 | }; |
|
|
211 | |
|
|
212 | extern Socket_Info socket_info; |
|
|
213 | |
|
|
214 | #define VERSION_CS 1023 /* version >= 1023 understand setup cmd */ |
207 | #define VERSION_CS 1023 /* version >= 1023 understand setup cmd */ |
215 | #define VERSION_SC 1027 |
208 | #define VERSION_SC 1027 |
216 | #define VERSION_INFO "Crossfire+ Server" |
209 | #define VERSION_INFO "Crossfire+ Server" |
217 | |
210 | |
|
|
211 | typedef unordered_vector<client_socket *> sockvec; |
|
|
212 | |
|
|
213 | extern sockvec client_sockets; |
|
|
214 | extern int nrofpixmaps; //TODO: hrmpf, should go |
|
|
215 | |
218 | #endif |
216 | #endif |
219 | |
217 | |