… | |
… | |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <loader.h> |
25 | #include <loader.h> |
26 | #ifndef __CEXTRACT__ |
|
|
27 | # include <sproto.h> |
26 | #include <sproto.h> |
28 | #endif |
27 | |
|
|
28 | #include <dirent.h> |
29 | |
29 | |
30 | extern weathermap_t **weathermap; |
30 | extern weathermap_t **weathermap; |
31 | |
31 | |
32 | /* Handles misc. input request - things like hash table, malloc, maps, |
32 | /* Handles misc. input request - things like hash table, malloc, maps, |
33 | * who, etc. |
33 | * who, etc. |
… | |
… | |
36 | void |
36 | void |
37 | map_info (object *op, char *search) |
37 | map_info (object *op, char *search) |
38 | { |
38 | { |
39 | maptile *m; |
39 | maptile *m; |
40 | char buf[MAX_BUF], map_path[MAX_BUF]; |
40 | char buf[MAX_BUF], map_path[MAX_BUF]; |
41 | long sec = seconds (); |
41 | long sec = time (0); |
42 | |
42 | |
43 | new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
43 | new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
44 | new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset"); |
44 | new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset"); |
45 | for (m = first_map; m != NULL; m = m->next) |
45 | for (m = first_map; m != NULL; m = m->next) |
46 | { |
46 | { |
… | |
… | |
226 | } chars_names; |
226 | } chars_names; |
227 | |
227 | |
228 | int |
228 | int |
229 | command_afk (object *op, char *params) |
229 | command_afk (object *op, char *params) |
230 | { |
230 | { |
231 | if QUERY_FLAG |
231 | if (QUERY_FLAG (op, FLAG_AFK)) |
232 | (op, FLAG_AFK) |
|
|
233 | { |
232 | { |
234 | CLEAR_FLAG (op, FLAG_AFK); |
233 | CLEAR_FLAG (op, FLAG_AFK); |
235 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
234 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
236 | } |
235 | } |
237 | else |
236 | else |
238 | { |
237 | { |
239 | SET_FLAG (op, FLAG_AFK); |
238 | SET_FLAG (op, FLAG_AFK); |
240 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
239 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
241 | } |
240 | } |
|
|
241 | |
242 | return 1; |
242 | return 1; |
243 | } |
243 | } |
244 | |
244 | |
245 | int |
245 | int |
246 | command_mapinfo (object *op, char *params) |
246 | command_mapinfo (object *op, char *params) |
… | |
… | |
610 | |
610 | |
611 | int |
611 | int |
612 | command_fix_me (object *op, char *params) |
612 | command_fix_me (object *op, char *params) |
613 | { |
613 | { |
614 | sum_weight (op); |
614 | sum_weight (op); |
615 | fix_player (op); |
615 | op->update_stats (); |
616 | return 1; |
616 | return 1; |
617 | } |
617 | } |
618 | |
618 | |
619 | int |
619 | int |
620 | command_players (object *op, char *paramss) |
620 | command_players (object *op, char *paramss) |
… | |
… | |
627 | t = buf + strlen (buf); |
627 | t = buf + strlen (buf); |
628 | if ((Dir = opendir (buf)) != NULL) |
628 | if ((Dir = opendir (buf)) != NULL) |
629 | { |
629 | { |
630 | const struct dirent *Entry; |
630 | const struct dirent *Entry; |
631 | |
631 | |
632 | while ((Entry = readdir (Dir)) != NULL) |
632 | while ((Entry = readdir (Dir))) |
633 | { |
633 | { |
634 | /* skip '.' , '..' */ |
634 | /* skip '.' , '..' */ |
635 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
635 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
636 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
636 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
637 | { |
637 | { |
… | |
… | |
785 | for (obl = first_friendly_object; obl != NULL; obl = next) |
785 | for (obl = first_friendly_object; obl != NULL; obl = next) |
786 | { |
786 | { |
787 | object *ob = obl->ob; |
787 | object *ob = obl->ob; |
788 | |
788 | |
789 | next = obl->next; |
789 | next = obl->next; |
790 | if (get_owner (ob) == op) |
790 | if (ob->owner == op) |
791 | { |
791 | { |
792 | if (target == 0) |
792 | if (target == 0) |
793 | { |
793 | { |
794 | if (counter == 0) |
794 | if (counter == 0) |
795 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
795 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
… | |
… | |
902 | char filename[MAX_BUF], line[80]; |
902 | char filename[MAX_BUF], line[80]; |
903 | int namelen, linelen = 0; |
903 | int namelen, linelen = 0; |
904 | |
904 | |
905 | switch (what) |
905 | switch (what) |
906 | { |
906 | { |
907 | case 1: |
907 | case 1: |
908 | sprintf (filename, "%s/wizhelp", settings.datadir); |
908 | sprintf (filename, "%s/wizhelp", settings.datadir); |
909 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
909 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
910 | break; |
910 | break; |
911 | case 3: |
911 | case 3: |
912 | sprintf (filename, "%s/mischelp", settings.datadir); |
912 | sprintf (filename, "%s/mischelp", settings.datadir); |
913 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
913 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
914 | break; |
914 | break; |
915 | default: |
915 | default: |
916 | sprintf (filename, "%s/help", settings.datadir); |
916 | sprintf (filename, "%s/help", settings.datadir); |
917 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
917 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
918 | break; |
918 | break; |
919 | } |
919 | } |
|
|
920 | |
920 | if (!(dirp = opendir (filename))) |
921 | if (!(dirp = opendir (filename))) |
921 | return; |
922 | return; |
922 | |
923 | |
923 | line[0] = '\0'; |
924 | line[0] = '\0'; |
924 | for (de = readdir (dirp); de; de = readdir (dirp)) |
925 | while (de = readdir (dirp)) |
925 | { |
926 | { |
926 | namelen = NAMLEN (de); |
927 | namelen = strlen (de->d_name); |
927 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
928 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
928 | continue; |
929 | continue; |
929 | linelen += namelen + 1; |
930 | linelen += namelen + 1; |
930 | if (linelen > 42) |
931 | if (linelen > 42) |
931 | { |
932 | { |
… | |
… | |
1146 | } |
1147 | } |
1147 | |
1148 | |
1148 | int |
1149 | int |
1149 | command_real_quit (object *op, char *params) |
1150 | command_real_quit (object *op, char *params) |
1150 | { |
1151 | { |
1151 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
1152 | send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
1152 | |
1153 | |
1153 | op->contr->state = ST_CONFIRM_QUIT; |
1154 | op->contr->ns->state = ST_CONFIRM_QUIT; |
1154 | return 1; |
1155 | return 1; |
1155 | } |
1156 | } |
1156 | |
1157 | |
1157 | /* |
1158 | /* |
1158 | * don't allow people to exit explore mode. It otherwise becomes |
1159 | * don't allow people to exit explore mode. It otherwise becomes |
… | |
… | |
1182 | } |
1183 | } |
1183 | |
1184 | |
1184 | int |
1185 | int |
1185 | command_sound (object *op, char *params) |
1186 | command_sound (object *op, char *params) |
1186 | { |
1187 | { |
1187 | if (op->contr->socket.sound) |
1188 | if (op->contr->ns->sound) |
1188 | { |
1189 | { |
1189 | op->contr->socket.sound = 0; |
1190 | op->contr->ns->sound = 0; |
1190 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
1191 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
1191 | } |
1192 | } |
1192 | else |
1193 | else |
1193 | { |
1194 | { |
1194 | op->contr->socket.sound = 1; |
1195 | op->contr->ns->sound = 1; |
1195 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
1196 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
1196 | } |
1197 | } |
1197 | return 1; |
|
|
1198 | } |
|
|
1199 | |
1198 | |
1200 | /* Perhaps these should be in player.c, but that file is |
|
|
1201 | * already a bit big. |
|
|
1202 | */ |
|
|
1203 | |
|
|
1204 | void |
|
|
1205 | receive_player_name (object *op, char k) |
|
|
1206 | { |
|
|
1207 | |
|
|
1208 | if (!check_name (op->contr, op->contr->write_buf + 1)) |
|
|
1209 | { |
|
|
1210 | get_name (op); |
|
|
1211 | return; |
|
|
1212 | } |
|
|
1213 | op->name = op->contr->write_buf + 1; |
|
|
1214 | op->name_pl = op->contr->write_buf + 1; |
|
|
1215 | new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf); |
|
|
1216 | op->contr->name_changed = 1; |
|
|
1217 | get_password (op); |
|
|
1218 | } |
|
|
1219 | |
|
|
1220 | void |
|
|
1221 | receive_player_password (object *op, char k) |
|
|
1222 | { |
|
|
1223 | |
|
|
1224 | unsigned int pwd_len = strlen (op->contr->write_buf); |
|
|
1225 | |
|
|
1226 | if (pwd_len <= 1 || pwd_len > 17) |
|
|
1227 | { |
|
|
1228 | get_name (op); |
|
|
1229 | return; |
|
|
1230 | } |
|
|
1231 | new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */ |
|
|
1232 | |
|
|
1233 | if (checkbanned (op->name, op->contr->socket.host)) |
|
|
1234 | { |
|
|
1235 | LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host); |
|
|
1236 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play."); |
|
|
1237 | get_name (op); |
|
|
1238 | return; |
|
|
1239 | } |
|
|
1240 | |
|
|
1241 | if (op->contr->state == ST_CONFIRM_PASSWORD) |
|
|
1242 | { |
|
|
1243 | if (!check_password (op->contr->write_buf + 1, op->contr->password)) |
|
|
1244 | { |
|
|
1245 | new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match."); |
|
|
1246 | get_name (op); |
|
|
1247 | return; |
|
|
1248 | } |
|
|
1249 | clear_win_info (op); |
|
|
1250 | display_motd (op); |
|
|
1251 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1252 | new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!"); |
|
|
1253 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1254 | Roll_Again (op); |
|
|
1255 | op->contr->state = ST_ROLL_STAT; |
|
|
1256 | return; |
|
|
1257 | } |
|
|
1258 | strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL)); |
|
|
1259 | op->contr->state = ST_ROLL_STAT; |
|
|
1260 | check_login (op); |
|
|
1261 | return; |
1199 | return 1; |
1262 | } |
1200 | } |
1263 | |
|
|
1264 | |
1201 | |
1265 | int |
1202 | int |
1266 | explore_mode (void) |
1203 | explore_mode (void) |
1267 | { |
1204 | { |
1268 | player *pl; |
1205 | player *pl; |
… | |
… | |
1273 | if (pl->explore) |
1210 | if (pl->explore) |
1274 | return 1; |
1211 | return 1; |
1275 | } |
1212 | } |
1276 | return 0; |
1213 | return 0; |
1277 | } |
1214 | } |
1278 | |
|
|
1279 | |
1215 | |
1280 | int |
1216 | int |
1281 | command_title (object *op, char *params) |
1217 | command_title (object *op, char *params) |
1282 | { |
1218 | { |
1283 | char buf[MAX_BUF]; |
1219 | char buf[MAX_BUF]; |
… | |
… | |
1324 | } |
1260 | } |
1325 | |
1261 | |
1326 | int |
1262 | int |
1327 | command_save (object *op, char *params) |
1263 | command_save (object *op, char *params) |
1328 | { |
1264 | { |
1329 | // if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) { |
|
|
1330 | // new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground"); |
|
|
1331 | // } else |
|
|
1332 | if (!op->stats.exp) |
1265 | if (!op->stats.exp) |
1333 | { |
|
|
1334 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
1266 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
|
|
1267 | else |
1335 | } |
1268 | { |
1336 | else |
1269 | op->contr->save (); |
1337 | { |
|
|
1338 | if (save_player (op, 1)) |
|
|
1339 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
1270 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
1340 | else |
|
|
1341 | new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!"); |
|
|
1342 | } |
1271 | } |
1343 | return 1; |
|
|
1344 | } |
|
|
1345 | |
1272 | |
|
|
1273 | return 1; |
|
|
1274 | } |
1346 | |
1275 | |
1347 | int |
1276 | int |
1348 | command_peaceful (object *op, char *params) |
1277 | command_peaceful (object *op, char *params) |
1349 | { |
1278 | { |
1350 | new_draw_info (NDI_UNIQUE, 0, op, |
1279 | new_draw_info (NDI_UNIQUE, 0, op, |
… | |
… | |
1359 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
1288 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
1360 | */ |
1289 | */ |
1361 | return 1; |
1290 | return 1; |
1362 | } |
1291 | } |
1363 | |
1292 | |
1364 | |
|
|
1365 | |
|
|
1366 | int |
1293 | int |
1367 | command_wimpy (object *op, char *params) |
1294 | command_wimpy (object *op, char *params) |
1368 | { |
1295 | { |
1369 | int i; |
1296 | int i; |
1370 | char buf[MAX_BUF]; |
1297 | char buf[MAX_BUF]; |
… | |
… | |
1379 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1306 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1380 | op->run_away = i; |
1307 | op->run_away = i; |
1381 | return 1; |
1308 | return 1; |
1382 | } |
1309 | } |
1383 | |
1310 | |
1384 | |
|
|
1385 | int |
1311 | int |
1386 | command_brace (object *op, char *params) |
1312 | command_brace (object *op, char *params) |
1387 | { |
1313 | { |
1388 | if (!params) |
1314 | if (!params) |
1389 | op->contr->braced = !op->contr->braced; |
1315 | op->contr->braced = !op->contr->braced; |
… | |
… | |
1393 | if (op->contr->braced) |
1319 | if (op->contr->braced) |
1394 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
1320 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
1395 | else |
1321 | else |
1396 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
1322 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
1397 | |
1323 | |
1398 | fix_player (op); |
1324 | op->update_stats (); |
1399 | return 0; |
1325 | return 0; |
1400 | } |
1326 | } |
1401 | |
1327 | |
1402 | int |
1328 | int |
1403 | command_style_map_info (object *op, char *params) |
1329 | command_style_map_info (object *op, char *params) |
… | |
… | |
1408 | object *tmp; |
1334 | object *tmp; |
1409 | |
1335 | |
1410 | for (mp = styles; mp != NULL; mp = mp->next) |
1336 | for (mp = styles; mp != NULL; mp = mp->next) |
1411 | { |
1337 | { |
1412 | maps_used++; |
1338 | maps_used++; |
1413 | mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile); |
1339 | mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (mapspace)) + sizeof (maptile); |
1414 | for (x = 0; x < MAP_WIDTH (mp); x++) |
1340 | for (x = 0; x < MAP_WIDTH (mp); x++) |
1415 | { |
1341 | { |
1416 | for (y = 0; y < MAP_HEIGHT (mp); y++) |
1342 | for (y = 0; y < MAP_HEIGHT (mp); y++) |
1417 | { |
1343 | { |
1418 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
1344 | for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) |
1419 | objects_used++; |
1345 | objects_used++; |
1420 | } |
1346 | } |
1421 | } |
1347 | } |
1422 | } |
1348 | } |
1423 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
1349 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
… | |
… | |
1446 | for (obl = first_friendly_object; obl != NULL; obl = next) |
1372 | for (obl = first_friendly_object; obl != NULL; obl = next) |
1447 | { |
1373 | { |
1448 | object *ob = obl->ob; |
1374 | object *ob = obl->ob; |
1449 | |
1375 | |
1450 | next = obl->next; |
1376 | next = obl->next; |
1451 | if (get_owner (ob) == op) |
1377 | if (ob->owner == op) |
1452 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1378 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1453 | { |
1379 | { |
1454 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
1455 | remove_ob (ob); |
|
|
1456 | remove_friendly_object (ob); |
|
|
1457 | free_object (ob); |
1380 | ob->destroy (); |
1458 | removecount++; |
1381 | removecount++; |
1459 | } |
1382 | } |
1460 | } |
1383 | } |
1461 | if (removecount != 0) |
1384 | if (removecount != 0) |
1462 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
1385 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |