… | |
… | |
29 | * |
29 | * |
30 | * Mainly deals with initialization and higher level socket |
30 | * Mainly deals with initialization and higher level socket |
31 | * maintenance (checking for lost connections and if data has arrived.) |
31 | * maintenance (checking for lost connections and if data has arrived.) |
32 | * The reading of data is handled in ericserver.c |
32 | * The reading of data is handled in ericserver.c |
33 | */ |
33 | */ |
34 | |
|
|
35 | |
34 | |
36 | #include <global.h> |
35 | #include <global.h> |
37 | #include <sproto.h> |
36 | #include <sproto.h> |
38 | #include <sys/types.h> |
37 | #include <sys/types.h> |
39 | #include <sys/time.h> |
38 | #include <sys/time.h> |
… | |
… | |
54 | * client. |
53 | * client. |
55 | */ |
54 | */ |
56 | client::client (int fd, const char *peername) |
55 | client::client (int fd, const char *peername) |
57 | : fd (fd), host (strdup (peername)), |
56 | : fd (fd), host (strdup (peername)), |
58 | socket_ev (this, &client::socket_cb), |
57 | socket_ev (this, &client::socket_cb), |
59 | cmd_ev (this, &client::cmd_cb) |
58 | cmd_ev (this, &client::cmd_cb), |
|
|
59 | cc_inv (this), cc_other (this) |
60 | { |
60 | { |
61 | { |
61 | { |
62 | struct linger linger_opt; |
62 | struct linger linger_opt; |
63 | |
63 | |
64 | linger_opt.l_onoff = 0; |
64 | linger_opt.l_onoff = 0; |
… | |
… | |
118 | |
118 | |
119 | buflen = sizeof (oldbufsize); |
119 | buflen = sizeof (oldbufsize); |
120 | getsockopt (fd, SOL_SOCKET, SO_SNDBUF, (char *) &oldbufsize, (socklen_t *) & buflen); |
120 | getsockopt (fd, SOL_SOCKET, SO_SNDBUF, (char *) &oldbufsize, (socklen_t *) & buflen); |
121 | } |
121 | } |
122 | |
122 | |
|
|
123 | state = ST_SETUP; |
123 | mapmode = Map0Cmd; |
124 | mapmode = Map0Cmd; |
124 | darkness = 1; |
125 | darkness = 1; |
125 | status = Ns_Add; |
|
|
126 | mapx = 11; |
126 | mapx = 11; |
127 | mapy = 11; |
127 | mapy = 11; |
128 | itemcmd = 1; /* Default is version item1 command */ |
128 | itemcmd = 1; /* Default is version item1 command */ |
129 | |
129 | |
130 | faces_sent = salloc<uint8> (nrofpixmaps, 0); |
130 | faces_sent = salloc0<uint8> (nrofpixmaps); |
131 | |
131 | |
132 | /* Do this so we don't send a face command for the client for |
132 | /* Do this so we don't send a face command for the client for |
133 | * this face. Face 0 is sent to the client to say clear |
133 | * this face. Face 0 is sent to the client to say clear |
134 | * face information. |
134 | * face information. |
135 | */ |
135 | */ |
… | |
… | |
157 | } |
157 | } |
158 | |
158 | |
159 | client::~client () |
159 | client::~client () |
160 | { |
160 | { |
161 | if (pl) |
161 | if (pl) |
162 | pl->socket = 0; |
162 | pl->ns = 0; |
163 | |
163 | |
164 | if (fd >= 0) |
164 | if (fd >= 0) |
165 | close (fd); |
165 | close (fd); |
166 | |
166 | |
167 | sfree<uint8> (faces_sent); |
167 | sfree<uint8> (faces_sent, nrofpixmaps); |
168 | free (stats.range); |
168 | free (stats.range); |
169 | free (stats.title); |
169 | free (stats.title); |
170 | free (host); |
170 | free (host); |
171 | } |
171 | } |
172 | |
172 | |
173 | void |
173 | void |
174 | client::destroy () |
174 | client::destroy () |
175 | { |
175 | { |
176 | status = Ns_Dead; |
176 | INVOKE_CLIENT (DESTROY, this); |
|
|
177 | |
|
|
178 | state = ST_DEAD; |
|
|
179 | |
177 | socket_ev.suspend (); |
180 | socket_ev.suspend (); |
178 | cmd_ev.suspend (); |
181 | cmd_ev.suspend (); |
179 | } |
182 | } |
180 | |
183 | |
181 | /** This sets up the socket and reads all the image information into memory. */ |
184 | /** This sets up the socket and reads all the image information into memory. */ |
… | |
… | |
210 | final_free_player (player *pl) |
213 | final_free_player (player *pl) |
211 | { |
214 | { |
212 | free_player (pl); |
215 | free_player (pl); |
213 | } |
216 | } |
214 | |
217 | |
215 | bool |
218 | client * |
216 | add_client (int fd, const char *peername) |
219 | client::create (int fd, const char *peername) |
217 | { |
220 | { |
218 | if (checkbanned (NULL, peername)) |
221 | if (checkbanned (NULL, peername)) |
219 | { |
222 | { |
220 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
223 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
221 | return false; |
224 | return 0; |
222 | } |
225 | } |
223 | else |
226 | else |
224 | { |
227 | { |
225 | client *ns = new client (dup (fd), peername); |
228 | client *ns = new client (dup (fd), peername); |
226 | clients.push_back (ns); |
229 | clients.push_back (ns); |
|
|
230 | |
|
|
231 | ns->instantiate (); // effectively a nop right now |
|
|
232 | |
|
|
233 | INVOKE_CLIENT (CONNECT, ns); |
|
|
234 | |
227 | return true; |
235 | return ns; |
228 | } |
236 | } |
229 | } |
237 | } |
230 | |
238 | |