1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
128 | |
128 | |
129 | if (fcntl (fd, F_SETFL, O_NONBLOCK) == -1) |
129 | if (fcntl (fd, F_SETFL, O_NONBLOCK) == -1) |
130 | LOG (llevError, "InitConnection: Error on fcntl.\n"); |
130 | LOG (llevError, "InitConnection: Error on fcntl.\n"); |
131 | |
131 | |
132 | state = ST_SETUP; |
132 | state = ST_SETUP; |
133 | mapmode = Map1aCmd; |
|
|
134 | mapx = 11; |
133 | mapx = 11; |
135 | mapy = 11; |
134 | mapy = 11; |
136 | itemcmd = 1; /* Default is version item1 command */ |
135 | itemcmd = 1; /* Default is version item1 command */ |
137 | max_rate = 100000 / (1000000 / MAX_TIME); // ~1mbit is assumed per default |
136 | max_rate = 100000 / (1000000 / MAX_TIME); // ~1mbit is assumed per default |
138 | |
137 | |
… | |
… | |
146 | socket_ev.set (fd, EV_READ); |
145 | socket_ev.set (fd, EV_READ); |
147 | socket_ev.prio (2); // one higher than the ticker priority |
146 | socket_ev.prio (2); // one higher than the ticker priority |
148 | socket_ev.start (); |
147 | socket_ev.start (); |
149 | |
148 | |
150 | // initialisation done, kick it! |
149 | // initialisation done, kick it! |
151 | send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); |
150 | INVOKE_CLIENT (CONNECT, this); |
|
|
151 | |
152 | flush (); |
152 | flush (); |
153 | |
153 | |
154 | reset_stats (); |
154 | reset_stats (); |
155 | |
155 | |
156 | clients.insert (this); |
156 | clients.insert (this); |
… | |
… | |
167 | } |
167 | } |
168 | |
168 | |
169 | void |
169 | void |
170 | client::do_destroy () |
170 | client::do_destroy () |
171 | { |
171 | { |
|
|
172 | INVOKE_CLIENT (CLIENT_DESTROY, this); |
172 | attachable::do_destroy (); |
173 | attachable::do_destroy (); |
173 | |
174 | |
174 | if (pl) |
175 | if (pl) |
175 | pl->disconnect (); |
176 | pl->disconnect (); |
176 | |
177 | |
… | |
… | |
195 | /* we need to clear these to -1 and not zero - otherwise, |
196 | /* we need to clear these to -1 and not zero - otherwise, |
196 | * if a player quits and starts a new character, we wont |
197 | * if a player quits and starts a new character, we wont |
197 | * send new values to the client, as things like exp start |
198 | * send new values to the client, as things like exp start |
198 | * at zero. |
199 | * at zero. |
199 | */ |
200 | */ |
200 | for (int i = 0; i < NUM_SKILLS; i++) |
201 | for (int i = 0; i < array_length (last_skill_exp); i++) |
201 | last_skill_exp[i] = -1; |
202 | last_skill_exp[i] = -1; |
202 | |
203 | |
203 | for (int i = 0; i < NROFATTACKS; i++) |
204 | for (int i = 0; i < array_length (last_resist); i++) |
204 | last_resist[i] = -1; |
205 | last_resist[i] = -1; |
205 | |
206 | |
206 | last_weapon_sp = -1; |
207 | last_weapon_sp = -1; |
207 | last_level = -1; |
208 | last_level = -1; |
208 | last_stats.exp = -1; |
209 | last_stats.exp = -1; |
209 | last_flags = 0; |
210 | last_flags = 0; |
210 | last_weight = -1; |
211 | last_weight = -1; |
211 | last_weight_limit = 0; |
212 | last_weight_limit = 0; |
212 | last_path_attuned = 0; |
213 | last_path_attuned = 0; |
213 | last_path_repelled = 0; |
214 | last_path_repelled = 0; |
214 | last_path_denied = 0; |
215 | last_path_denied = 0; |
215 | last_speed = 0; |
216 | last_speed = 0; |
216 | last_flags = 0; |
217 | last_flags = 0; |
217 | |
218 | |
218 | static living zero_living; |
219 | static living zero_living; |
219 | last_stats = zero_living; |
220 | last_stats = zero_living; |
220 | } |
221 | } |
221 | |
222 | |
222 | client * |
223 | client * |
223 | client::create (int fd, const char *peername) |
224 | client::create (int fd, const char *peername) |
224 | { |
225 | { |
225 | client *ns = new client (dup (fd), peername); |
226 | client *ns = new client (dup (fd), peername); |
|
|
227 | |
226 | ns->instantiate (); // effectively a nop right now |
228 | ns->instantiate (); // effectively a nop right now |
227 | INVOKE_CLIENT (CONNECT, ns); |
229 | |
228 | return ns; |
230 | return ns; |
229 | } |
231 | } |
230 | |
232 | |