… | |
… | |
27 | #include <sounds.h> |
27 | #include <sounds.h> |
28 | #include <living.h> |
28 | #include <living.h> |
29 | #include <object.h> |
29 | #include <object.h> |
30 | #include <spells.h> |
30 | #include <spells.h> |
31 | #include <skills.h> |
31 | #include <skills.h> |
32 | #include <newclient.h> |
|
|
33 | |
32 | |
34 | #ifdef COZY_SERVER |
33 | #ifdef COZY_SERVER |
35 | extern int same_party (partylist *a, partylist *b); |
34 | extern int same_party (partylist *a, partylist *b); |
36 | #endif |
35 | #endif |
37 | |
36 | |
… | |
… | |
83 | int comp; |
82 | int comp; |
84 | int size; |
83 | int size; |
85 | |
84 | |
86 | sprintf (buf, "%s/%s", settings.confdir, settings.motd); |
85 | sprintf (buf, "%s/%s", settings.confdir, settings.motd); |
87 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
86 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
88 | { |
|
|
89 | return; |
87 | return; |
90 | } |
88 | |
91 | motd[0] = '\0'; |
89 | motd[0] = '\0'; |
92 | size = 0; |
90 | size = 0; |
|
|
91 | |
93 | while (fgets (buf, MAX_BUF, fp) != NULL) |
92 | while (fgets (buf, MAX_BUF, fp) != NULL) |
94 | { |
93 | { |
95 | if (*buf == '#') |
94 | if (*buf == '#') |
96 | continue; |
95 | continue; |
|
|
96 | |
97 | strncat (motd + size, buf, HUGE_BUF - size); |
97 | strncat (motd + size, buf, HUGE_BUF - size); |
98 | size += strlen (buf); |
98 | size += strlen (buf); |
99 | } |
99 | } |
|
|
100 | |
100 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); |
101 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); |
101 | close_and_delete (fp, comp); |
102 | close_and_delete (fp, comp); |
102 | } |
103 | } |
103 | |
104 | |
104 | void |
105 | void |
… | |
… | |
110 | int comp; |
111 | int comp; |
111 | int size; |
112 | int size; |
112 | |
113 | |
113 | sprintf (buf, "%s/%s", settings.confdir, settings.rules); |
114 | sprintf (buf, "%s/%s", settings.confdir, settings.rules); |
114 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
115 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
115 | { |
|
|
116 | return; |
116 | return; |
117 | } |
117 | |
118 | rules[0] = '\0'; |
118 | rules[0] = '\0'; |
119 | size = 0; |
119 | size = 0; |
|
|
120 | |
120 | while (fgets (buf, MAX_BUF, fp) != NULL) |
121 | while (fgets (buf, MAX_BUF, fp) != NULL) |
121 | { |
122 | { |
122 | if (*buf == '#') |
123 | if (*buf == '#') |
123 | continue; |
124 | continue; |
|
|
125 | |
124 | if (size + strlen (buf) >= HUGE_BUF) |
126 | if (size + strlen (buf) >= HUGE_BUF) |
125 | { |
127 | { |
126 | LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); |
128 | LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); |
127 | break; |
129 | break; |
128 | } |
130 | } |
|
|
131 | |
129 | strncat (rules + size, buf, HUGE_BUF - size); |
132 | strncat (rules + size, buf, HUGE_BUF - size); |
130 | size += strlen (buf); |
133 | size += strlen (buf); |
131 | } |
134 | } |
|
|
135 | |
132 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); |
136 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); |
133 | close_and_delete (fp, comp); |
137 | close_and_delete (fp, comp); |
134 | } |
138 | } |
135 | |
139 | |
136 | void |
140 | void |
… | |
… | |
144 | int size; |
148 | int size; |
145 | |
149 | |
146 | sprintf (buf, "%s/%s", settings.confdir, settings.news); |
150 | sprintf (buf, "%s/%s", settings.confdir, settings.news); |
147 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
151 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
148 | return; |
152 | return; |
|
|
153 | |
149 | news[0] = '\0'; |
154 | news[0] = '\0'; |
150 | subject[0] = '\0'; |
155 | subject[0] = '\0'; |
151 | size = 0; |
156 | size = 0; |
|
|
157 | |
152 | while (fgets (buf, MAX_BUF, fp) != NULL) |
158 | while (fgets (buf, MAX_BUF, fp) != NULL) |
153 | { |
159 | { |
154 | if (*buf == '#') |
160 | if (*buf == '#') |
155 | continue; |
161 | continue; |
|
|
162 | |
156 | if (*buf == '%') |
163 | if (*buf == '%') |
157 | { /* send one news */ |
164 | { /* send one news */ |
158 | if (size > 0) |
165 | if (size > 0) |
159 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ |
166 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ |
160 | strcpy (subject, buf + 1); |
167 | strcpy (subject, buf + 1); |
… | |
… | |
187 | return 0; |
194 | return 0; |
188 | |
195 | |
189 | for (; *cp != '\0'; cp++) |
196 | for (; *cp != '\0'; cp++) |
190 | if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') |
197 | if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') |
191 | return 0; |
198 | return 0; |
|
|
199 | |
192 | return 1; |
200 | return 1; |
193 | } |
201 | } |
194 | |
202 | |
195 | /* This no longer sets the player map. Also, it now updates |
203 | /* This no longer sets the player map. Also, it now updates |
196 | * all the pointers so the caller doesn't need to do that. |
204 | * all the pointers so the caller doesn't need to do that. |
… | |
… | |
255 | p->usekeys = containers; |
263 | p->usekeys = containers; |
256 | p->last_weapon_sp = -1; |
264 | p->last_weapon_sp = -1; |
257 | p->peaceful = 1; /* default peaceful */ |
265 | p->peaceful = 1; /* default peaceful */ |
258 | p->do_los = 1; |
266 | p->do_los = 1; |
259 | p->explore = 0; |
267 | p->explore = 0; |
260 | p->no_shout = 0; /* default can shout */ |
|
|
261 | |
268 | |
262 | assign (p->title, op->arch->clone.name); |
269 | assign (p->title, op->arch->clone.name); |
263 | op->race = op->arch->clone.race; |
270 | op->race = op->arch->clone.race; |
264 | |
271 | |
265 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
272 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
… | |
… | |
292 | set_first_map (object *op) |
299 | set_first_map (object *op) |
293 | { |
300 | { |
294 | strcpy (op->contr->maplevel, first_map_path); |
301 | strcpy (op->contr->maplevel, first_map_path); |
295 | op->x = -1; |
302 | op->x = -1; |
296 | op->y = -1; |
303 | op->y = -1; |
297 | enter_exit (op, NULL); |
304 | enter_exit (op, 0); |
298 | } |
305 | } |
299 | |
306 | |
300 | /* Tries to add player on the connection passwd in ns. |
307 | /* Tries to add player on the connection passwd in ns. |
301 | * All we can really get in this is some settings like host and display |
308 | * All we can really get in this is some settings like host and display |
302 | * mode. |
309 | * mode. |
303 | */ |
310 | */ |
304 | |
311 | |
305 | int |
312 | int |
306 | add_player (client_socket *ns) |
313 | add_player (client *ns) |
307 | { |
314 | { |
308 | player *p = new player; |
315 | player *p = new player; |
309 | |
316 | |
310 | p->socket = ns; |
317 | p->socket = ns; |
311 | ns->pl = p; |
318 | ns->pl = p; |
… | |
… | |
341 | { |
348 | { |
342 | if (at == NULL || at->next == NULL) |
349 | if (at == NULL || at->next == NULL) |
343 | at = first_archetype; |
350 | at = first_archetype; |
344 | else |
351 | else |
345 | at = at->next; |
352 | at = at->next; |
|
|
353 | |
346 | if (at->clone.type == PLAYER) |
354 | if (at->clone.type == PLAYER) |
347 | return at; |
355 | return at; |
|
|
356 | |
348 | if (at == start) |
357 | if (at == start) |
349 | { |
358 | { |
350 | LOG (llevError, "No Player archetypes\n"); |
359 | LOG (llevError, "No Player archetypes\n"); |
351 | exit (-1); |
360 | exit (-1); |
352 | } |
361 | } |
353 | } |
362 | } |
354 | } |
363 | } |
355 | |
|
|
356 | |
364 | |
357 | object * |
365 | object * |
358 | get_nearest_player (object *mon) |
366 | get_nearest_player (object *mon) |
359 | { |
367 | { |
360 | object *op = NULL; |
368 | object *op = NULL; |
… | |
… | |
1084 | * if the map isn't there, then stay on the |
1092 | * if the map isn't there, then stay on the |
1085 | * default initial map */ |
1093 | * default initial map */ |
1086 | tmp->destroy (); |
1094 | tmp->destroy (); |
1087 | } |
1095 | } |
1088 | else |
1096 | else |
1089 | { |
|
|
1090 | LOG (llevDebug, "first_map_ext_path not set\n"); |
1097 | LOG (llevDebug, "first_map_ext_path not set\n"); |
1091 | } |
1098 | |
1092 | return 0; |
1099 | return 0; |
1093 | } |
1100 | } |
1094 | |
1101 | |
1095 | /* Following actually changes the race - this is the default command |
1102 | /* Following actually changes the race - this is the default command |
1096 | * if we don't match with one of the options above. |
1103 | * if we don't match with one of the options above. |
… | |
… | |
2545 | |
2552 | |
2546 | /* call this here - we also will call this in do_ericserver, but |
2553 | /* call this here - we also will call this in do_ericserver, but |
2547 | * the players time has been increased when doericserver has been |
2554 | * the players time has been increased when doericserver has been |
2548 | * called, so we recheck it here. |
2555 | * called, so we recheck it here. |
2549 | */ |
2556 | */ |
2550 | HandleClient (op->contr->socket, op->contr); |
2557 | //TODO: better than handling 8 commands, use some more intelligent rate-limiting |
|
|
2558 | for (int rep = 8; --rep && op->contr->socket->handle_command (); ) |
|
|
2559 | ; |
|
|
2560 | |
2551 | if (op->speed_left < 0) |
2561 | if (op->speed_left < 0) |
2552 | return 0; |
2562 | return 0; |
2553 | |
2563 | |
2554 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2564 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2555 | { |
2565 | { |