ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/main.C
(Generate patch)

Comparing deliantra/server/server/main.C (file contents):
Revision 1.22 by root, Sat Sep 9 21:48:29 2006 UTC vs.
Revision 1.23 by root, Sun Sep 10 15:59:57 2006 UTC

1
1/* 2/*
2 * static char *rcsid_main_c = 3 * static char *rcsid_main_c =
3 * "$Id: main.C,v 1.22 2006/09/09 21:48:29 root Exp $"; 4 * "$Id: main.C,v 1.23 2006/09/10 15:59:57 root Exp $";
4 */ 5 */
5 6
6/* 7/*
7 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
8 9
29#include <global.h> 30#include <global.h>
30#include <object.h> 31#include <object.h>
31#include <tod.h> 32#include <tod.h>
32 33
33#ifdef HAVE_DES_H 34#ifdef HAVE_DES_H
34#include <des.h> 35# include <des.h>
35#else 36#else
36# ifdef HAVE_CRYPT_H 37# ifdef HAVE_CRYPT_H
37# include <crypt.h> 38# include <crypt.h>
38# endif 39# endif
39#endif 40#endif
40 41
41#ifndef __CEXTRACT__ 42#ifndef __CEXTRACT__
42#include <sproto.h> 43# include <sproto.h>
43#endif 44#endif
44 45
45#ifdef HAVE_TIME_H 46#ifdef HAVE_TIME_H
46#include <time.h> 47# include <time.h>
47#endif 48#endif
48 49
49#include <../random_maps/random_map.h> 50#include <../random_maps/random_map.h>
50#include <../random_maps/rproto.h> 51#include <../random_maps/rproto.h>
51#include "path.h" 52#include "path.h"
53static char days[7][4] = { 54static char days[7][4] = {
54 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 55 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
55}; 56};
56 57
57void 58void
58version (object * op) 59version (object *op)
59{ 60{
60 if (op != NULL) 61 if (op != NULL)
61 clear_win_info (op); 62 clear_win_info (op);
62 63
63 new_draw_info_format (NDI_UNIQUE, 0, op, "This is Crossfire v%s", VERSION); 64 new_draw_info_format (NDI_UNIQUE, 0, op, "This is Crossfire v%s", VERSION);
116 new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]"); 117 new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]");
117 new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); 118 new_draw_info (NDI_UNIQUE, 0, op, "And many more!");
118} 119}
119 120
120void 121void
121info_keys (object * op) 122info_keys (object *op)
122{ 123{
123 clear_win_info (op); 124 clear_win_info (op);
124 new_draw_info (NDI_UNIQUE, 0, op, "Push `hjklynub' to walk in a direction."); 125 new_draw_info (NDI_UNIQUE, 0, op, "Push `hjklynub' to walk in a direction.");
125 new_draw_info (NDI_UNIQUE, 0, op, "Shift + dir = fire, Ctrl + dir = run"); 126 new_draw_info (NDI_UNIQUE, 0, op, "Shift + dir = fire, Ctrl + dir = run");
126 new_draw_info (NDI_UNIQUE, 0, op, "(To fire at yourself, hit `.'"); 127 new_draw_info (NDI_UNIQUE, 0, op, "(To fire at yourself, hit `.'");
139 new_draw_info (NDI_UNIQUE, 0, op, "You can type a number before most commands."); 140 new_draw_info (NDI_UNIQUE, 0, op, "You can type a number before most commands.");
140 new_draw_info (NDI_UNIQUE, 0, op, "(For instance 3d drops 3 items.)"); 141 new_draw_info (NDI_UNIQUE, 0, op, "(For instance 3d drops 3 items.)");
141} 142}
142 143
143void 144void
144start_info (object * op) 145start_info (object *op)
145{ 146{
146 char buf[MAX_BUF]; 147 char buf[MAX_BUF];
147 148
148 sprintf (buf, "Welcome to Crossfire, v%s!", VERSION); 149 sprintf (buf, "Welcome to Crossfire, v%s!", VERSION);
149 new_draw_info (NDI_UNIQUE, 0, op, buf); 150 new_draw_info (NDI_UNIQUE, 0, op, buf);
174 if (salt == NULL) 175 if (salt == NULL)
175 s[0] = c[RANDOM () % (int) strlen (c)], s[1] = c[RANDOM () % (int) strlen (c)]; 176 s[0] = c[RANDOM () % (int) strlen (c)], s[1] = c[RANDOM () % (int) strlen (c)];
176 else 177 else
177 s[0] = salt[0], s[1] = salt[1]; 178 s[0] = salt[0], s[1] = salt[1];
178 179
179# ifdef HAVE_LIBDES 180# ifdef HAVE_LIBDES
180 return (char *) des_crypt (str, s); 181 return (char *) des_crypt (str, s);
181# endif 182# endif
182 /* Default case - just use crypt */ 183 /* Default case - just use crypt */
183 return (char *) crypt (str, s); 184 return (char *) crypt (str, s);
184#endif 185#endif
185} 186}
186 187
194 * savebed. We do some error checking - its possible that the 195 * savebed. We do some error checking - its possible that the
195 * savebed map may no longer exist, so we make sure the player 196 * savebed map may no longer exist, so we make sure the player
196 * goes someplace. 197 * goes someplace.
197 */ 198 */
198void 199void
199enter_player_savebed (object * op) 200enter_player_savebed (object *op)
200{ 201{
201 mapstruct *oldmap = op->map; 202 mapstruct *oldmap = op->map;
202 object *tmp; 203 object *tmp;
203 204
204 tmp = get_object (); 205 tmp = get_object ();
229 230
230/* All this really is is a glorified remove_object that also updates 231/* All this really is is a glorified remove_object that also updates
231 * the counts on the map if needed. 232 * the counts on the map if needed.
232 */ 233 */
233void 234void
234leave_map (object * op) 235leave_map (object *op)
235{ 236{
236 mapstruct *oldmap = op->map; 237 mapstruct *oldmap = op->map;
237 238
238 remove_ob (op); 239 remove_ob (op);
239 240
254 * player to - it could be the map he just came from if the load failed for 255 * player to - it could be the map he just came from if the load failed for
255 * whatever reason. If default map coordinates are to be used, then 256 * whatever reason. If default map coordinates are to be used, then
256 * the function that calls this should figure them out. 257 * the function that calls this should figure them out.
257 */ 258 */
258static void 259static void
259enter_map (object * op, mapstruct * newmap, int x, int y) 260enter_map (object *op, mapstruct *newmap, int x, int y)
260{ 261{
261 mapstruct *oldmap = op->map; 262 mapstruct *oldmap = op->map;
262 263
263 if (out_of_map (newmap, x, y)) 264 if (out_of_map (newmap, x, y))
264 { 265 {
282 * if other spaces around are available. 283 * if other spaces around are available.
283 * Note that for the second and third calls, we could start at a position other 284 * Note that for the second and third calls, we could start at a position other
284 * than one, but then we could end up on the other side of walls and so forth. 285 * than one, but then we could end up on the other side of walls and so forth.
285 */ 286 */
286 int i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE1 + 1); 287 int i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE1 + 1);
288
287 if (i == -1) 289 if (i == -1)
288 { 290 {
289 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); 291 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1);
290 if (i == -1) 292 if (i == -1)
291 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); 293 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE);
337 /* Update any golems */ 339 /* Update any golems */
338 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) 340 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL)
339 { 341 {
340 int i = find_free_spot (op->contr->ranges[range_golem], newmap, 342 int i = find_free_spot (op->contr->ranges[range_golem], newmap,
341 x, y, 1, SIZEOFFREE); 343 x, y, 1, SIZEOFFREE);
344
342 remove_ob (op->contr->ranges[range_golem]); 345 remove_ob (op->contr->ranges[range_golem]);
343 if (i == -1) 346 if (i == -1)
344 { 347 {
345 remove_friendly_object (op->contr->ranges[range_golem]); 348 remove_friendly_object (op->contr->ranges[range_golem]);
346 free_object (op->contr->ranges[range_golem]); 349 free_object (op->contr->ranges[range_golem]);
348 op->contr->golem_count = 0; 351 op->contr->golem_count = 0;
349 } 352 }
350 else 353 else
351 { 354 {
352 object *tmp; 355 object *tmp;
356
353 for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) 357 for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
354 { 358 {
355 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 359 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
356 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 360 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
357 tmp->map = newmap; 361 tmp->map = newmap;
383 } 387 }
384 } 388 }
385} 389}
386 390
387void 391void
388set_map_timeout (mapstruct * oldmap) 392set_map_timeout (mapstruct *oldmap)
389{ 393{
390#if MAP_MAXTIMEOUT 394#if MAP_MAXTIMEOUT
391 oldmap->timeout = MAP_TIMEOUT (oldmap); 395 oldmap->timeout = MAP_TIMEOUT (oldmap);
392 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 396 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
393 * lower than the min value. 397 * lower than the min value.
394 */ 398 */
395#if MAP_MINTIMEOUT 399# if MAP_MINTIMEOUT
396 if (oldmap->timeout < MAP_MINTIMEOUT) 400 if (oldmap->timeout < MAP_MINTIMEOUT)
397 { 401 {
398 oldmap->timeout = MAP_MINTIMEOUT; 402 oldmap->timeout = MAP_MINTIMEOUT;
399 } 403 }
400#endif 404# endif
401 if (oldmap->timeout > MAP_MAXTIMEOUT) 405 if (oldmap->timeout > MAP_MAXTIMEOUT)
402 { 406 {
403 oldmap->timeout = MAP_MAXTIMEOUT; 407 oldmap->timeout = MAP_MAXTIMEOUT;
404 } 408 }
405#else 409#else
459/* The player is trying to enter a randomly generated map. In this case, generate the 463/* The player is trying to enter a randomly generated map. In this case, generate the
460 * random map as needed. 464 * random map as needed.
461 */ 465 */
462 466
463static void 467static void
464enter_random_map (object * pl, object * exit_ob) 468enter_random_map (object *pl, object *exit_ob)
465{ 469{
466 mapstruct *new_map; 470 mapstruct *new_map;
467 char newmap_name[HUGE_BUF], *cp; 471 char newmap_name[HUGE_BUF], *cp;
468 static int reference_number = 0; 472 static int reference_number = 0;
469 RMParms rp; 473 RMParms rp;
515 * the exit leading to it, that the exit will no longer work. 519 * the exit leading to it, that the exit will no longer work.
516 */ 520 */
517 if (new_map) 521 if (new_map)
518 { 522 {
519 int x, y; 523 int x, y;
524
520 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); 525 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map);
521 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); 526 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map);
522 EXIT_PATH (exit_ob) = newmap_name; 527 EXIT_PATH (exit_ob) = newmap_name;
523 strcpy (new_map->path, newmap_name); 528 strcpy (new_map->path, newmap_name);
524 enter_map (pl, new_map, x, y); 529 enter_map (pl, new_map, x, y);
528/* The player is trying to enter a non-randomly generated template map. In this 533/* The player is trying to enter a non-randomly generated template map. In this
529 * case, use a map file for a template 534 * case, use a map file for a template
530 */ 535 */
531 536
532static void 537static void
533enter_fixed_template_map (object * pl, object * exit_ob) 538enter_fixed_template_map (object *pl, object *exit_ob)
534{ 539{
535 mapstruct *new_map; 540 mapstruct *new_map;
536 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; 541 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap;
537 const char *new_map_name; 542 const char *new_map_name;
538 543
620/* The player is trying to enter a randomly generated template map. In this 625/* The player is trying to enter a randomly generated template map. In this
621 * case, generate the map as needed. 626 * case, generate the map as needed.
622 */ 627 */
623 628
624static void 629static void
625enter_random_template_map (object * pl, object * exit_ob) 630enter_random_template_map (object *pl, object *exit_ob)
626{ 631{
627 mapstruct *new_map; 632 mapstruct *new_map;
628 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; 633 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF];
629 const char *new_map_name; 634 const char *new_map_name;
630 RMParms rp; 635 RMParms rp;
679 * the exit leading to it, that the exit will no longer work. 684 * the exit leading to it, that the exit will no longer work.
680 */ 685 */
681 if (new_map) 686 if (new_map)
682 { 687 {
683 int x, y; 688 int x, y;
689
684 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); 690 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map);
685 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); 691 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map);
686 new_map->templatemap = 1; 692 new_map->templatemap = 1;
687 enter_map (pl, new_map, x, y); 693 enter_map (pl, new_map, x, y);
688 } 694 }
690 696
691 697
692/* Code to enter/detect a character entering a unique map. 698/* Code to enter/detect a character entering a unique map.
693 */ 699 */
694static void 700static void
695enter_unique_map (object * op, object * exit_ob) 701enter_unique_map (object *op, object *exit_ob)
696{ 702{
697 char apartment[HUGE_BUF]; 703 char apartment[HUGE_BUF];
698 mapstruct *newmap; 704 mapstruct *newmap;
699 705
700 if (EXIT_PATH (exit_ob)[0] == '/') 706 if (EXIT_PATH (exit_ob)[0] == '/')
780 * Largely redone by MSW 2001-01-21 - this function was overly complex 786 * Largely redone by MSW 2001-01-21 - this function was overly complex
781 * and had some obscure bugs. 787 * and had some obscure bugs.
782 */ 788 */
783 789
784void 790void
785enter_exit (object * op, object * exit_ob) 791enter_exit (object *op, object *exit_ob)
786{ 792{
787#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ 793#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
788 object *tmp; 794 object *tmp;
795
789 /* It may be nice to support other creatures moving across 796 /* It may be nice to support other creatures moving across
790 * exits, but right now a lot of the code looks at op->contr, 797 * exits, but right now a lot of the code looks at op->contr,
791 * so thta is an RFE. 798 * so thta is an RFE.
792 */ 799 */
793 if (op->type != PLAYER) 800 if (op->type != PLAYER)
821 enter_unique_map (op, exit_ob); 828 enter_unique_map (op, exit_ob);
822 } 829 }
823 else 830 else
824 { 831 {
825 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 832 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
833
826 /* 'Normal' exits that do not do anything special 834 /* 'Normal' exits that do not do anything special
827 * Simple enough we don't need another routine for it. 835 * Simple enough we don't need another routine for it.
828 */ 836 */
829 mapstruct *newmap; 837 mapstruct *newmap;
838
830 if (exit_ob->map) 839 if (exit_ob->map)
831 { 840 {
832 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 841 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0);
833 /* Random map was previously generated, but is no longer about. Lets generate a new 842 /* Random map was previously generated, but is no longer about. Lets generate a new
834 * map. 843 * map.
968 977
969#if 0 // dead code, schmorp 978#if 0 // dead code, schmorp
970void 979void
971process_active_maps () 980process_active_maps ()
972{ 981{
973 for (mapstruct * map = first_map; map != NULL; map = map->next) 982 for (mapstruct *map = first_map; map != NULL; map = map->next)
974 if (map->in_memory == MAP_IN_MEMORY) 983 if (map->in_memory == MAP_IN_MEMORY)
975 if (players_on_map (map, TRUE)) 984 if (players_on_map (map, TRUE))
976 process_events (map); 985 process_events (map);
977} 986}
978#endif 987#endif
984 * objects have been updated, process_players2() does the processing that 993 * objects have been updated, process_players2() does the processing that
985 * is needed after the players have been updated. 994 * is needed after the players have been updated.
986 */ 995 */
987 996
988void 997void
989process_players1 (mapstruct * map) 998process_players1 (mapstruct *map)
990{ 999{
991 int flag; 1000 int flag;
992 player *pl, *plnext; 1001 player *pl, *plnext;
993 1002
994 /* Basically, we keep looping until all the players have done their actions. */ 1003 /* Basically, we keep looping until all the players have done their actions. */
1056 { 1065 {
1057 pl->ob->start_holding = 0; 1066 pl->ob->start_holding = 0;
1058 } 1067 }
1059 } 1068 }
1060 do_some_living (pl->ob); 1069 do_some_living (pl->ob);
1061 /* draw(pl->ob);*//* updated in socket code */ 1070 /* draw(pl->ob); *//* updated in socket code */
1062 } 1071 }
1063} 1072}
1064 1073
1065void 1074void
1066process_players2 (mapstruct * map) 1075process_players2 (mapstruct *map)
1067{ 1076{
1068 player *pl; 1077 player *pl;
1069 1078
1070 /* Then check if any players should use weapon-speed instead of speed */ 1079 /* Then check if any players should use weapon-speed instead of speed */
1071 for (pl = first_player; pl != NULL; pl = pl->next) 1080 for (pl = first_player; pl != NULL; pl = pl->next)
1101 pl->ob->speed_left = pl->ob->speed; 1110 pl->ob->speed_left = pl->ob->speed;
1102 } 1111 }
1103} 1112}
1104 1113
1105void 1114void
1106process_events (mapstruct * map) 1115process_events (mapstruct *map)
1107{ 1116{
1108 object *op; 1117 object *op;
1109 object *marker = get_object (); 1118 object *marker = get_object ();
1110 tag_t tag; 1119 tag_t tag;
1111 1120
1293 free_all_recipes (); 1302 free_all_recipes ();
1294 free_all_readable (); 1303 free_all_readable ();
1295 free_all_god (); 1304 free_all_god ();
1296 free_all_anim (); 1305 free_all_anim ();
1297 /* See what the string data that is out there that hasn't been freed. */ 1306 /* See what the string data that is out there that hasn't been freed. */
1307
1298/* LOG(llevDebug, ss_dump_table(0xff));*/ 1308/* LOG(llevDebug, ss_dump_table(0xff));*/
1299#endif 1309#endif
1300 exit (0); 1310 exit (0);
1301} 1311}
1302 1312
1303void 1313void
1304leave (player * pl, int draw_exit) 1314leave (player *pl, int draw_exit)
1305{ 1315{
1306 if (pl != NULL) 1316 if (pl != NULL)
1307 { 1317 {
1308 /* We do this so that the socket handling routine can do the final 1318 /* We do this so that the socket handling routine can do the final
1309 * cleanup. We also leave that loop to actually handle the freeing 1319 * cleanup. We also leave that loop to actually handle the freeing
1324 INVOKE_PLAYER (LOGOUT, pl); 1334 INVOKE_PLAYER (LOGOUT, pl);
1325 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host); 1335 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host);
1326 } 1336 }
1327 1337
1328 char buf[MAX_BUF]; 1338 char buf[MAX_BUF];
1339
1329 sprintf (buf, "%s left the game.", &pl->ob->name); 1340 sprintf (buf, "%s left the game.", &pl->ob->name);
1330 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf); 1341 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf);
1331 } 1342 }
1332 1343
1333 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) 1344 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines