… | |
… | |
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> |
… | |
… | |
119 | |
118 | |
120 | buflen = sizeof (oldbufsize); |
119 | buflen = sizeof (oldbufsize); |
121 | getsockopt (fd, SOL_SOCKET, SO_SNDBUF, (char *) &oldbufsize, (socklen_t *) & buflen); |
120 | getsockopt (fd, SOL_SOCKET, SO_SNDBUF, (char *) &oldbufsize, (socklen_t *) & buflen); |
122 | } |
121 | } |
123 | |
122 | |
|
|
123 | state = ST_SETUP; |
124 | mapmode = Map0Cmd; |
124 | mapmode = Map0Cmd; |
125 | darkness = 1; |
125 | darkness = 1; |
126 | status = Ns_Add; |
|
|
127 | mapx = 11; |
126 | mapx = 11; |
128 | mapy = 11; |
127 | mapy = 11; |
129 | itemcmd = 1; /* Default is version item1 command */ |
128 | itemcmd = 1; /* Default is version item1 command */ |
130 | |
129 | |
131 | faces_sent = salloc<uint8> (nrofpixmaps, 0); |
130 | faces_sent = salloc0<uint8> (nrofpixmaps); |
132 | |
131 | |
133 | /* 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 |
134 | * 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 |
135 | * face information. |
134 | * face information. |
136 | */ |
135 | */ |
… | |
… | |
158 | } |
157 | } |
159 | |
158 | |
160 | client::~client () |
159 | client::~client () |
161 | { |
160 | { |
162 | if (pl) |
161 | if (pl) |
|
|
162 | { |
|
|
163 | pl->save (); |
|
|
164 | leave (pl, 1); |
163 | pl->socket = 0; |
165 | pl->ns = 0; |
|
|
166 | |
|
|
167 | delete pl; |
|
|
168 | } |
164 | |
169 | |
165 | if (fd >= 0) |
170 | if (fd >= 0) |
166 | close (fd); |
171 | close (fd); |
167 | |
172 | |
168 | sfree<uint8> (faces_sent, nrofpixmaps); |
173 | sfree<uint8> (faces_sent, nrofpixmaps); |
… | |
… | |
172 | } |
177 | } |
173 | |
178 | |
174 | void |
179 | void |
175 | client::destroy () |
180 | client::destroy () |
176 | { |
181 | { |
177 | status = Ns_Dead; |
182 | INVOKE_CLIENT (DESTROY, this); |
|
|
183 | |
|
|
184 | state = ST_DEAD; |
|
|
185 | |
178 | socket_ev.suspend (); |
186 | socket_ev.suspend (); |
179 | cmd_ev.suspend (); |
187 | cmd_ev.suspend (); |
180 | } |
188 | } |
181 | |
189 | |
182 | /** This sets up the socket and reads all the image information into memory. */ |
190 | /** This sets up the socket and reads all the image information into memory. */ |
… | |
… | |
204 | { |
212 | { |
205 | LOG (llevDebug, "Freeing all new client/server information.\n"); |
213 | LOG (llevDebug, "Freeing all new client/server information.\n"); |
206 | free_socket_images (); |
214 | free_socket_images (); |
207 | } |
215 | } |
208 | |
216 | |
209 | /** Sends the 'goodbye' command to the player, and closes connection. */ |
217 | client * |
210 | void |
|
|
211 | final_free_player (player *pl) |
|
|
212 | { |
|
|
213 | free_player (pl); |
|
|
214 | } |
|
|
215 | |
|
|
216 | bool |
|
|
217 | add_client (int fd, const char *peername) |
218 | client::create (int fd, const char *peername) |
218 | { |
219 | { |
219 | if (checkbanned (NULL, peername)) |
220 | if (checkbanned (NULL, peername)) |
220 | { |
221 | { |
221 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
222 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
222 | return false; |
223 | return 0; |
223 | } |
224 | } |
224 | else |
225 | else |
225 | { |
226 | { |
226 | client *ns = new client (dup (fd), peername); |
227 | client *ns = new client (dup (fd), peername); |
227 | clients.push_back (ns); |
228 | clients.push_back (ns); |
|
|
229 | |
|
|
230 | ns->instantiate (); // effectively a nop right now |
|
|
231 | |
|
|
232 | INVOKE_CLIENT (CONNECT, ns); |
|
|
233 | |
228 | return true; |
234 | return ns; |
229 | } |
235 | } |
230 | } |
236 | } |
231 | |
237 | |