1 | /* |
1 | /* |
2 | * static char *rcsid_c_misc_c = |
2 | * static char *rcsid_c_misc_c = |
3 | * "$Id: c_misc.C,v 1.3 2006/08/29 08:01:37 root Exp $"; |
3 | * "$Id: c_misc.C,v 1.6 2006/09/04 11:08:00 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
114 | bug_report(buf); |
114 | bug_report(buf); |
115 | LOG(llevError,"%s\n",buf); |
115 | LOG(llevError,"%s\n",buf); |
116 | new_draw_info(NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
116 | new_draw_info(NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
117 | new_draw_info(NDI_UNIQUE, 0,op, "OK, thanks!"); |
117 | new_draw_info(NDI_UNIQUE, 0,op, "OK, thanks!"); |
118 | return 1; |
118 | return 1; |
119 | } |
|
|
120 | |
|
|
121 | |
|
|
122 | void malloc_info(object *op) { |
|
|
123 | int ob_used=count_used(),ob_free=count_free(),players,nrofmaps; |
|
|
124 | int nrm=0,mapmem=0,anr,anims,sum_alloc=0,sum_used=0,i,tlnr, alnr; |
|
|
125 | treasurelist *tl; |
|
|
126 | player *pl; |
|
|
127 | mapstruct *m; |
|
|
128 | archetype *at; |
|
|
129 | artifactlist *al; |
|
|
130 | |
|
|
131 | for(tl=first_treasurelist,tlnr=0;tl!=NULL;tl=tl->next,tlnr++); |
|
|
132 | for(al=first_artifactlist, alnr=0; al!=NULL; al=al->next, alnr++); |
|
|
133 | |
|
|
134 | for(at=first_archetype,anr=0,anims=0;at!=NULL; |
|
|
135 | at=at->more==NULL?at->next:at->more,anr++); |
|
|
136 | |
|
|
137 | for (i=1; i<num_animations; i++) |
|
|
138 | anims += animations[i].num_animations; |
|
|
139 | |
|
|
140 | for(pl=first_player,players=0;pl!=NULL;pl=pl->next,players++); |
|
|
141 | for(m=first_map,nrofmaps=0;m!=NULL;m=m->next,nrofmaps++) |
|
|
142 | if(m->in_memory == MAP_IN_MEMORY) { |
|
|
143 | mapmem+=MAP_WIDTH(m)*MAP_HEIGHT(m)*(sizeof(object *)+sizeof(MapSpace)); |
|
|
144 | nrm++; |
|
|
145 | } |
|
|
146 | sprintf(errmsg,"Sizeof: object=%ld player=%ld map=%ld", |
|
|
147 | (long)sizeof(object),(long)sizeof(player),(long)sizeof(mapstruct)); |
|
|
148 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
149 | sprintf(errmsg,"%4d used objects: %8d",ob_used,i=(ob_used*sizeof(object))); |
|
|
150 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
151 | sum_used+=i; sum_alloc+=i; |
|
|
152 | sprintf(errmsg,"%4d free objects: %8d",ob_free,i=(ob_free*sizeof(object))); |
|
|
153 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
154 | sprintf(errmsg,"%4d active objects: %8d",count_active(), 0); |
|
|
155 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
156 | sum_alloc+=i; |
|
|
157 | sprintf(errmsg,"%4d players: %8d",players,i=(players*sizeof(player))); |
|
|
158 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
159 | sum_alloc+=i; sum_used+=i; |
|
|
160 | |
|
|
161 | |
|
|
162 | sprintf(errmsg,"%4d maps allocated: %8d",nrofmaps, |
|
|
163 | i=(nrofmaps*sizeof(mapstruct))); |
|
|
164 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
165 | sum_alloc+=i; sum_used+=nrm*sizeof(mapstruct); |
|
|
166 | sprintf(errmsg,"%4d maps in memory: %8d",nrm,mapmem); |
|
|
167 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
168 | sum_alloc+=mapmem; sum_used+=mapmem; |
|
|
169 | sprintf(errmsg,"%4d archetypes: %8d",anr,i=(anr*sizeof(archetype))); |
|
|
170 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
171 | sum_alloc+=i; sum_used+=i; |
|
|
172 | sprintf(errmsg,"%4d animations: %8d",anims,i=(anims*sizeof(Fontindex))); |
|
|
173 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
174 | sum_alloc+=i; sum_used+=i; |
|
|
175 | |
|
|
176 | sprintf(errmsg,"%4d treasurelists %8d",tlnr,i=(tlnr*sizeof(treasurelist))); |
|
|
177 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
178 | sum_alloc+=i; sum_used+=i; |
|
|
179 | sprintf(errmsg,"%4ld treasures %8d",nroftreasures, |
|
|
180 | i=(nroftreasures*sizeof(treasure))); |
|
|
181 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
182 | sum_alloc+=i; sum_used+=i; |
|
|
183 | sprintf(errmsg,"%4ld artifacts %8d", nrofartifacts, |
|
|
184 | i=(nrofartifacts*sizeof(artifact))); |
|
|
185 | new_draw_info(NDI_UNIQUE, 0,op, errmsg); |
|
|
186 | sum_alloc+=i; sum_used +=i; |
|
|
187 | sprintf(errmsg,"%4ld artifacts strngs %8d", nrofallowedstr, |
|
|
188 | i=(nrofallowedstr*sizeof(linked_char))); |
|
|
189 | new_draw_info(NDI_UNIQUE, 0,op, errmsg); |
|
|
190 | sum_alloc += i;sum_used+=i; |
|
|
191 | sprintf(errmsg,"%4d artifactlists %8d",alnr,i=(alnr*sizeof(artifactlist))); |
|
|
192 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
193 | sum_alloc += i; sum_used += i; |
|
|
194 | |
|
|
195 | sprintf(errmsg,"Total space allocated:%8d",sum_alloc); |
|
|
196 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
197 | sprintf(errmsg,"Total space used: %8d",sum_used); |
|
|
198 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
199 | } |
119 | } |
200 | |
120 | |
201 | /* |
121 | /* |
202 | * Pretty much identical to current map_info, but on a bigger scale |
122 | * Pretty much identical to current map_info, but on a bigger scale |
203 | * This function returns the name of the players current region, and |
123 | * This function returns the name of the players current region, and |
… | |
… | |
342 | chars = (chars_names *) realloc(chars, num_players*sizeof(chars_names)); |
262 | chars = (chars_names *) realloc(chars, num_players*sizeof(chars_names)); |
343 | if (chars == NULL) { |
263 | if (chars == NULL) { |
344 | new_draw_info(NDI_UNIQUE, 0, op, "who failed - out of memory!"); |
264 | new_draw_info(NDI_UNIQUE, 0, op, "who failed - out of memory!"); |
345 | return 0; |
265 | return 0; |
346 | } |
266 | } |
347 | sprintf(chars[num_players-1].namebuf, "%s", pl->ob->name); |
267 | sprintf(chars[num_players-1].namebuf, "%s", &pl->ob->name); |
348 | chars[num_players-1].login_order = num_players; |
268 | chars[num_players-1].login_order = num_players; |
349 | /*Check for WIZ's & AFK's*/ |
269 | /*Check for WIZ's & AFK's*/ |
350 | if (QUERY_FLAG(pl->ob,FLAG_WIZ)) |
270 | if (QUERY_FLAG(pl->ob,FLAG_WIZ)) |
351 | num_wiz++; |
271 | num_wiz++; |
352 | if (QUERY_FLAG(pl->ob,FLAG_AFK)) |
272 | if (QUERY_FLAG(pl->ob,FLAG_AFK)) |
… | |
… | |
472 | new_draw_info(NDI_UNIQUE, 0, op, "You are now AFK"); |
392 | new_draw_info(NDI_UNIQUE, 0, op, "You are now AFK"); |
473 | } |
393 | } |
474 | return 1; |
394 | return 1; |
475 | } |
395 | } |
476 | |
396 | |
477 | int command_malloc (object *op, char *params) |
|
|
478 | { |
|
|
479 | malloc_info(op); |
|
|
480 | return 1; |
|
|
481 | } |
|
|
482 | |
|
|
483 | int command_mapinfo (object *op, char *params) |
397 | int command_mapinfo (object *op, char *params) |
484 | { |
398 | { |
485 | current_map_info(op); |
399 | current_map_info(op); |
486 | return 1; |
400 | return 1; |
487 | } |
401 | } |
… | |
… | |
495 | int command_maps (object *op, char *params) |
409 | int command_maps (object *op, char *params) |
496 | { |
410 | { |
497 | map_info(op,params); |
411 | map_info(op,params); |
498 | return 1; |
412 | return 1; |
499 | } |
413 | } |
500 | |
|
|
501 | int command_strings (object *op, char *params) |
|
|
502 | { |
|
|
503 | ss_dump_statistics(); |
|
|
504 | new_draw_info(NDI_UNIQUE, 0,op,errmsg); |
|
|
505 | new_draw_info(NDI_UNIQUE, 0,op,ss_dump_table(2)); |
|
|
506 | return 1; |
|
|
507 | } |
|
|
508 | |
|
|
509 | #ifdef DEBUG |
|
|
510 | int command_sstable (object *op, char *params) |
|
|
511 | { |
|
|
512 | ss_dump_table(1); |
|
|
513 | return 1; |
|
|
514 | } |
|
|
515 | #endif |
|
|
516 | |
414 | |
517 | int command_time (object *op, char *params) |
415 | int command_time (object *op, char *params) |
518 | { |
416 | { |
519 | print_tod (op); |
417 | print_tod (op); |
520 | return 1; |
418 | return 1; |
… | |
… | |
726 | { |
624 | { |
727 | dump_all_archetypes(); |
625 | dump_all_archetypes(); |
728 | return 0; |
626 | return 0; |
729 | } |
627 | } |
730 | |
628 | |
731 | int command_ssdumptable (object *op, char *params) |
|
|
732 | { |
|
|
733 | (void) ss_dump_table(1); |
|
|
734 | return 0; |
|
|
735 | } |
|
|
736 | |
|
|
737 | int command_dumpmap (object *op, char *params) |
629 | int command_dumpmap (object *op, char *params) |
738 | { |
630 | { |
739 | if(op) |
631 | if(op) |
740 | dump_map(op->map); |
632 | dump_map(op->map); |
741 | return 0; |
633 | return 0; |
… | |
… | |
769 | FILE * fp; |
661 | FILE * fp; |
770 | if((fp = fopen( BUG_LOG , "a")) != NULL){ |
662 | if((fp = fopen( BUG_LOG , "a")) != NULL){ |
771 | fprintf(fp,"%s\n", reportstring); |
663 | fprintf(fp,"%s\n", reportstring); |
772 | fclose(fp); |
664 | fclose(fp); |
773 | } else { |
665 | } else { |
774 | LOG(llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror_local(errno)); |
666 | LOG(llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror(errno)); |
775 | } |
667 | } |
776 | } |
668 | } |
777 | |
669 | |
778 | int command_output_sync(object *op, char *params) |
670 | int command_output_sync(object *op, char *params) |
779 | { |
671 | { |
… | |
… | |
1057 | next = obl->next; |
949 | next = obl->next; |
1058 | if (get_owner(ob) == op) { |
950 | if (get_owner(ob) == op) { |
1059 | if (target ==0) { |
951 | if (target ==0) { |
1060 | if (counter==0) |
952 | if (counter==0) |
1061 | new_draw_info(NDI_UNIQUE, 0, op, "Pets:"); |
953 | new_draw_info(NDI_UNIQUE, 0, op, "Pets:"); |
1062 | new_draw_info_format(NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, ob->name, ob->level ); |
954 | new_draw_info_format(NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level ); |
1063 | } |
955 | } |
1064 | else if (!have_shown_pet && ++counter==target) { |
956 | else if (!have_shown_pet && ++counter==target) { |
1065 | new_draw_info_format(NDI_UNIQUE, 0, op, "level %d %s", ob->level, ob->name); |
957 | new_draw_info_format(NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); |
1066 | new_draw_info_format(NDI_UNIQUE, 0, op, "%d/%d HP, %d/%d SP", |
958 | new_draw_info_format(NDI_UNIQUE, 0, op, "%d/%d HP, %d/%d SP", |
1067 | ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp); |
959 | ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp); |
1068 | /* this is not a nice way to do this, it should be made to be more like the statistics command */ |
960 | /* this is not a nice way to do this, it should be made to be more like the statistics command */ |
1069 | new_draw_info_format(NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); |
961 | new_draw_info_format(NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); |
1070 | new_draw_info_format(NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); |
962 | new_draw_info_format(NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); |
… | |
… | |
1259 | * Main help page? |
1151 | * Main help page? |
1260 | */ |
1152 | */ |
1261 | if (!params) { |
1153 | if (!params) { |
1262 | sprintf(filename, "%s/def_help", settings.datadir); |
1154 | sprintf(filename, "%s/def_help", settings.datadir); |
1263 | if ((fp=fopen(filename, "r")) == NULL) { |
1155 | if ((fp=fopen(filename, "r")) == NULL) { |
1264 | LOG(llevError, "Cannot open help file %s: %s\n", filename, strerror_local(errno)); |
1156 | LOG(llevError, "Cannot open help file %s: %s\n", filename, strerror(errno)); |
1265 | return 0; |
1157 | return 0; |
1266 | } |
1158 | } |
1267 | while (fgets(line, MAX_BUF, fp)) { |
1159 | while (fgets(line, MAX_BUF, fp)) { |
1268 | line[MAX_BUF-1] ='\0'; |
1160 | line[MAX_BUF-1] ='\0'; |
1269 | len =strlen(line)-1; |
1161 | len =strlen(line)-1; |
… | |
… | |
1323 | |
1215 | |
1324 | /* |
1216 | /* |
1325 | * Found that. Just cat it to screen. |
1217 | * Found that. Just cat it to screen. |
1326 | */ |
1218 | */ |
1327 | if ((fp=fopen(filename, "r")) == NULL) { |
1219 | if ((fp=fopen(filename, "r")) == NULL) { |
1328 | LOG(llevError, "Cannot open help file %s: %s\n", filename, strerror_local(errno)); |
1220 | LOG(llevError, "Cannot open help file %s: %s\n", filename, strerror(errno)); |
1329 | return 0; |
1221 | return 0; |
1330 | } |
1222 | } |
1331 | sprintf(line, "Help about '%s'", params); |
1223 | sprintf(line, "Help about '%s'", params); |
1332 | new_draw_info(NDI_UNIQUE, 0,op, line); |
1224 | new_draw_info(NDI_UNIQUE, 0,op, line); |
1333 | while (fgets(line, MAX_BUF, fp)) { |
1225 | while (fgets(line, MAX_BUF, fp)) { |
… | |
… | |
1434 | |
1326 | |
1435 | if(!check_name(op->contr,op->contr->write_buf+1)) { |
1327 | if(!check_name(op->contr,op->contr->write_buf+1)) { |
1436 | get_name(op); |
1328 | get_name(op); |
1437 | return; |
1329 | return; |
1438 | } |
1330 | } |
1439 | FREE_AND_COPY(op->name, op->contr->write_buf+1); |
1331 | op->name = op->contr->write_buf + 1; |
1440 | FREE_AND_COPY(op->name_pl, op->contr->write_buf+1); |
1332 | op->name_pl = op->contr->write_buf + 1; |
1441 | new_draw_info(NDI_UNIQUE, 0,op,op->contr->write_buf); |
1333 | new_draw_info(NDI_UNIQUE, 0,op,op->contr->write_buf); |
1442 | op->contr->name_changed=1; |
1334 | op->contr->name_changed=1; |
1443 | get_password(op); |
1335 | get_password(op); |
1444 | } |
1336 | } |
1445 | |
1337 | |
… | |
… | |
1451 | return; |
1343 | return; |
1452 | } |
1344 | } |
1453 | new_draw_info(NDI_UNIQUE, 0,op," "); /* To hide the password better */ |
1345 | new_draw_info(NDI_UNIQUE, 0,op," "); /* To hide the password better */ |
1454 | |
1346 | |
1455 | if (checkbanned(op->name, op->contr->socket.host)) { |
1347 | if (checkbanned(op->name, op->contr->socket.host)) { |
1456 | LOG(llevInfo, "Banned player tried to add: [%s@%s]\n", op->name, op->contr->socket.host); |
1348 | LOG(llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host); |
1457 | new_draw_info(NDI_UNIQUE|NDI_RED, 0, op, "You are not allowed to play."); |
1349 | new_draw_info(NDI_UNIQUE|NDI_RED, 0, op, "You are not allowed to play."); |
1458 | get_name(op); |
1350 | get_name(op); |
1459 | return; |
1351 | return; |
1460 | } |
1352 | } |
1461 | |
1353 | |
… | |
… | |
1656 | new_draw_info(NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
1548 | new_draw_info(NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
1657 | } |
1549 | } |
1658 | return 0; |
1550 | return 0; |
1659 | } |
1551 | } |
1660 | |
1552 | |
1661 | /** |
|
|
1662 | * Displays all non start/end tags for specified quest. |
|
|
1663 | **/ |
|
|
1664 | static void display_quest_details( object* pl, object* quest ) |
|
|
1665 | { |
|
|
1666 | /* object* item; */ |
|
|
1667 | |
|
|
1668 | new_draw_info_format( NDI_WHITE, 0, pl, "Quest: %s\n%s\n", |
|
|
1669 | quest_get_name( quest ), |
|
|
1670 | quest->lore ? quest->lore : "(no description available)" ); |
|
|
1671 | /* |
|
|
1672 | for ( item = pl->inv; item; item = item->below ) |
|
|
1673 | { |
|
|
1674 | if ( ( item != quest ) |
|
|
1675 | && ( quest_is_quest_marker( item ) ) |
|
|
1676 | && ( quest_is_same_quest( quest->slaying, item->slaying ) ) |
|
|
1677 | && ( item->lore ) ) |
|
|
1678 | { |
|
|
1679 | new_draw_info( NDI_WHITE, 0, pl, item->lore ); |
|
|
1680 | new_draw_info( NDI_WHITE, 0, pl, "------\n" ); |
|
|
1681 | } |
|
|
1682 | } |
|
|
1683 | */ |
|
|
1684 | } |
|
|
1685 | |
|
|
1686 | /** |
|
|
1687 | * Displays quest information to player. |
|
|
1688 | * Acceptable parameters: |
|
|
1689 | * * finished => finished quests only |
|
|
1690 | * * <name> => only this particular quest, finished or not, with details |
|
|
1691 | * * nothing => all current quests |
|
|
1692 | * |
|
|
1693 | * For current quests, will display either the lore of the non start tags, |
|
|
1694 | * or the lore of start tag if no other tag. |
|
|
1695 | **/ |
|
|
1696 | int command_quests( object *pl, char *params ) |
|
|
1697 | { |
|
|
1698 | object* item; |
|
|
1699 | |
|
|
1700 | if ( params && !strcmp( params, "finished" ) ) |
|
|
1701 | { |
|
|
1702 | new_draw_info( NDI_WHITE, 0, pl, "Completed quests:\n" ); |
|
|
1703 | for ( item = pl->inv; item; item = item->below ) |
|
|
1704 | { |
|
|
1705 | if ( quest_is_quest_marker( item, 0 ) ) |
|
|
1706 | { |
|
|
1707 | new_draw_info( NDI_WHITE, 0, pl, quest_get_name( item ) ); |
|
|
1708 | new_draw_info( NDI_WHITE, 0, pl, "\n" ); |
|
|
1709 | } |
|
|
1710 | } |
|
|
1711 | return 1; |
|
|
1712 | } |
|
|
1713 | |
|
|
1714 | if ( params ) |
|
|
1715 | { |
|
|
1716 | for ( item = pl->inv; item; item = item->below ) |
|
|
1717 | { |
|
|
1718 | if ( quest_is_quest_marker( item, 0 ) |
|
|
1719 | && !strcmp( quest_get_name( item ), params ) ) |
|
|
1720 | { |
|
|
1721 | display_quest_details( pl, item ); |
|
|
1722 | } |
|
|
1723 | } |
|
|
1724 | return 1; |
|
|
1725 | } |
|
|
1726 | |
|
|
1727 | /*Display current quests */ |
|
|
1728 | new_draw_info( NDI_WHITE, 0, pl, "Current quests:\n" ); |
|
|
1729 | for ( item = pl->inv; item; item = item->below ) |
|
|
1730 | { |
|
|
1731 | if ( quest_is_quest_marker( item, 0 ) |
|
|
1732 | && quest_is_in_progress( item, 0 ) ) |
|
|
1733 | { |
|
|
1734 | new_draw_info( NDI_WHITE, 0, pl, quest_get_name( item ) ); |
|
|
1735 | new_draw_info( NDI_WHITE, 0, pl, "\n" ); |
|
|
1736 | } |
|
|
1737 | } |
|
|
1738 | return 1; |
|
|
1739 | } |
|
|