32 static void copy_file(
const char *filename, FILE *fpout);
42 #ifndef NO_EMERGENCY_SAVE 62 if (pl->
ob->
map != NULL)
70 "Emergency save failed, checking score...");
77 LOG(
llevInfo,
"Emergency saves disabled, no save attempted\n");
116 if (strpbrk(name,
"/.\\") != NULL) {
117 LOG(
llevError,
"Username contains illegal characters: %s\n", name);
130 if (pltmp->
ob->
name != NULL && !strcmp(pltmp->
ob->
name, name)) {
138 if (strlen(buf) >=
sizeof(buf)-1) {
143 fp = fopen(buf,
"r");
152 while (fgets(buf,
MAX_BUF-1, fp) != NULL) {
153 if (!strncmp(buf,
"password ", 9)) {
154 buf[strlen(buf)-1] = 0;
164 LOG(
llevDebug,
"Could not find a password line in player %s\n", name);
184 "Your username cannot be blank.");
190 "That name contains illegal characters. Use letters, hyphens and underscores only. Hyphens and underscores are not allowed as the first character.");
195 "That name is too long. (Max length: %d characters)",
MAX_NAME);
210 while (op->
inv != NULL)
242 char filename[
MAX_BUF], *tmpfilename;
246 #ifdef BACKUP_SAVE_AT_HOME 247 int16_t backup_x, backup_y;
259 "Your game is not valid, game not saved.");
300 "Can't get secure temporary file for save.");
301 LOG(
llevDebug,
"Can't get secure temporary file for save.\n");
305 fprintf(fp,
"password %s\n", pl->
password);
310 fprintf(fp,
"gen_hp %d\n", pl->
gen_hp);
311 fprintf(fp,
"gen_sp %d\n", pl->
gen_sp);
312 fprintf(fp,
"gen_grace %d\n", pl->
gen_grace);
313 fprintf(fp,
"listening %d\n", pl->
listening);
314 fprintf(fp,
"shoottype %d\n", pl->
shoottype);
315 fprintf(fp,
"bowtype %d\n", pl->
bowtype);
316 fprintf(fp,
"petmode %d\n", pl->
petmode);
317 fprintf(fp,
"peaceful %d\n", pl->
peaceful);
318 fprintf(fp,
"no_shout %d\n", pl->
no_shout);
319 fprintf(fp,
"digestion %d\n", pl->
digestion);
320 fprintf(fp,
"pickup %u\n", pl->
mode);
328 fprintf(fp,
"outputs_sync %d\n", 16);
329 fprintf(fp,
"outputs_count %d\n", 1);
336 #ifdef BACKUP_SAVE_AT_HOME 337 if (op->
map != NULL && flag == 0)
341 fprintf(fp,
"map %s\n", op->
map->
path);
346 fprintf(fp,
"bed_x %d\nbed_y %d\n", pl->
bed_x, pl->
bed_y);
355 fprintf(fp,
"lev_array %d\n",
MIN(op->
level, 10));
356 for (i = 1; i <=
MIN(op->
level, 10) && i <= 10; i++) {
357 fprintf(fp,
"%d\n", pl->
levhp[i]);
358 fprintf(fp,
"%d\n", pl->
levsp[i]);
359 fprintf(fp,
"%d\n", pl->
levgrace[i]);
361 fprintf(fp,
"party_rejoin_mode %d\n", pl->
rejoin_party);
362 if (pl->
party != NULL) {
368 fprintf(fp,
"endplst\n");
372 #ifdef BACKUP_SAVE_AT_HOME 396 "Can't save character!");
412 while (op->
inv != NULL)
425 "Can't open file for save.");
430 fprintf(fp,
"checksum %lx\n", checksum);
436 "Can't close file for save.");
444 LOG(
llevError,
"Could not set permissions on '%s'\n", filename);
466 static void copy_file(
const char *filename, FILE *fpout) {
470 fp = fopen(filename,
"r");
472 LOG(
llevError,
"copy_file failed to open \"%s\", player file(s) may be corrupt.\n", filename);
475 while (fgets(buf,
MAX_BUF, fp) != NULL)
489 "\nA character with this name already exists. " 490 "Please choose another name, or make sure you entered your " 491 "password correctly.\n");
499 "You gave an incorrect password too many times, " 500 "you will now be dropped from the server.");
502 LOG(
llevInfo,
"A player connecting from %s has been dropped for password failure\n",
530 time_t elapsed_save_time = 0;
532 char *party_name = NULL, party_password[9];
535 party_password[0] = 0;
539 if (pltmp != pl && pltmp->
ob->
name != NULL && !strcmp(pltmp->ob->name, op->
name)) {
549 pltmp->socket->status =
Ns_Dead;
569 fp = fopen(filename,
"r");
574 if (fstat(fileno(fp), &statbuf)) {
576 elapsed_save_time = 0;
578 elapsed_save_time = time(NULL)-statbuf.st_mtime;
579 if (elapsed_save_time < 0) {
580 LOG(
llevError,
"Player file %s was saved in the future? (%ld time)\n", filename, (
long)elapsed_save_time);
581 elapsed_save_time = 0;
585 if (fgets(bufall,
MAX_BUF, fp) != NULL) {
586 if (!strncmp(bufall,
"checksum ", 9)) {
587 if ( fgets(bufall,
MAX_BUF, fp) == NULL ) {
591 if (sscanf(bufall,
"password %s\n", buf)) {
609 if (!correct && password) {
616 pl->last_save_time = time(NULL);
635 while (fgets(bufall,
MAX_BUF, fp) != NULL) {
636 char *val_string, *p;
638 sscanf(bufall,
"%s %d\n", buf, &value);
640 val_string = bufall + strlen(buf) +1;
641 p = strchr(val_string,
'\n');
650 uvalue = strtoul(val_string, (
char **)NULL, 10);
652 if (!strcmp(buf,
"endplst"))
656 else if (!strcmp(buf,
"unarmed_skill"))
658 else if (!strcmp(buf,
"explore"))
660 else if (!strcmp(buf,
"gen_hp"))
662 else if (!strcmp(buf,
"shoottype"))
664 else if (!strcmp(buf,
"bowtype"))
666 else if (!strcmp(buf,
"petmode"))
668 else if (!strcmp(buf,
"gen_sp"))
670 else if (!strcmp(buf,
"gen_grace"))
672 else if (!strcmp(buf,
"listening"))
674 else if (!strcmp(buf,
"peaceful"))
676 else if (!strcmp(buf,
"no_shout"))
678 else if (!strcmp(buf,
"digestion"))
680 else if (!strcmp(buf,
"pickup")) {
682 }
else if (!strcmp(buf,
"partial_commands")) {
685 else if (!strcmp(buf,
"map"))
687 else if (!strcmp(buf,
"savebed_map"))
689 else if (!strcmp(buf,
"bed_x"))
691 else if (!strcmp(buf,
"bed_y"))
693 else if (!strcmp(buf,
"Str"))
695 else if (!strcmp(buf,
"Dex"))
697 else if (!strcmp(buf,
"Con"))
699 else if (!strcmp(buf,
"Int"))
701 else if (!strcmp(buf,
"Pow"))
703 else if (!strcmp(buf,
"Wis"))
705 else if (!strcmp(buf,
"Cha"))
707 else if (!strcmp(buf,
"usekeys")) {
708 if (!strcmp(val_string,
"key_inventory"))
710 else if (!strcmp(val_string,
"keyrings"))
712 else if (!strcmp(val_string,
"containers"))
715 LOG(
llevDebug,
"load_player: got unknown usekeys type: %s\n", val_string);
716 }
else if (!strcmp(buf,
"unapply")) {
717 if (!strcmp(val_string,
"unapply_nochoice"))
719 else if (!strcmp(val_string,
"unapply_never"))
721 else if (!strcmp(val_string,
"unapply_always"))
724 LOG(
llevDebug,
"load_player: got unknown unapply type: %s\n", val_string);
725 }
else if (!strcmp(buf,
"lev_array")) {
726 for (i = 1; i <= value; i++) {
730 count = fscanf(fp,
"%d\n", &j);
737 count = fscanf(fp,
"%d\n", &j);
744 count = fscanf(fp,
"%d\n", &j);
752 }
else if (!strcmp(buf,
"party_rejoin_mode"))
754 else if (!strcmp(buf,
"party_rejoin_name"))
756 else if (!strcmp(buf,
"party_rejoin_password")) {
757 strncpy(party_password, val_string,
sizeof(party_password));
758 party_password[
sizeof(party_password) - 1] = 0;
759 }
else if (!strcmp(buf,
"language")) {
762 else if (!strcmp(buf,
"ticks_played")) {
826 pl->last_save_tick =
pticks;
848 "%s has entered the game.",
862 "Your character was dead last time you played.");
927 snprintf(buf,
MAX_BUF,
"Couldn't rejoin party %s: %s.", party_name, party ?
"invalid password." :
"no such party.");
int check_path(const char *name, int prepend_dir)
This function checks if a file with the given path exists.
Will unapply whatever is necessary - this goes beyond no choice - if there are multiple ojbect of the...
signed long object_sum_weight(object *op)
object_sum_weight() is a recursive function which calculates the weight an object is carrying...
int16_t gen_hp
Bonuses to regeneration speed of hp.
char first_map_path[MAX_BUF]
The start-level.
Use keys in inventory and active containers.
living orig_stats
Permanent real stats of player.
#define FLAG_UNPAID
Object hasn't been paid for yet.
#define MSG_TYPE_ADMIN_LOGIN
login messages/errors
#define ST_GET_PARTY_PASSWORD
Player tried to join a password-protected party.
Spell-related defines: spellpath, subtypes, ...
#define PROFILE_BEGIN(expr)
struct archetype * arch
Pointer to archetype.
void leave(player *pl, int draw_exit)
Player logs out, or was disconnected.
#define SAVE_ERROR_OK
No error.
char * account_name
Name of the account logged in on this socket.
static void copy_file(const char *filename, FILE *fpout)
Copy a file.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define NDI_ALL
Inform all players of this message.
bool check_password(const char *typed, const char *crypted)
Hash a password and compare it to the stored version.
int load_object(FILE *fp, object *op, int bufstate, int map_flags, bool artifact_init)
#define FLAG_USE_ARMOUR
(Monster) can wear armour/shield/helmet
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
void player_set_own_title(struct player *pl, const char *title)
Sets the custom title.
#define FLAG_FRIENDLY
Will help players.
uint32_t peaceful
If set, won't attack friendly creatures.
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
const char * account_get_account_for_char(const char *charname)
This looks at all the accounts and sees if charname is associated with any of them.
void party_set_password(partylist *party, const char *password)
Sets a party's password.
player * first_player
First player.
#define FLAG_NO_FIX_PLAYER
fix_object() won't be called
const char * playerdir
Where the player files are.
object * object_find_by_name(const object *who, const char *name)
Finds an object in inventory name.
void enter_player_maplevel(object *op)
Move a player to its stored map level.
partylist * party
Party this player is part of.
sstring add_string(const char *str)
Share a string.
long trying_emergency_save
True when emergency_save() is reached.
void link_player_skills(object *op)
This function goes through the player inventory and sets up the last_skills[] array in the player obj...
void esrv_send_inventory(object *pl, object *op)
Sends inventory of a container.
void make_path_to_file(const char *filename)
Checks if any directories in the given path doesn't exist, and creates if necessary.
const char * party_get_password(const partylist *party)
Returns the party's password.
#define EVENT_LOGIN
Player login.
int16_t y
Position in the map for this object.
int is_dragon_pl(const object *op)
Checks if player is a dragon.
uint32_t mode
Mode of player for pickup.
#define MSG_TYPE_ADMIN_LOADSAVE
load/save operations
int player_has_own_title(const struct player *pl)
Returns whether the player has a custom title.
char title[BIG_NAME]
Default title, like fighter, wizard, etc.
int legal_range(object *op, int r)
Check for the validity of a player range.
Use keys in inventory and active key rings.
#define PROFILE_END(var, expr)
Global type definitions and header inclusions.
struct player * contr
Pointer to the player which control this object.
bowtype_t
Bow firing mode.
void pets_terminate_all(object *owner)
Removes all pets someone owns.
Will not unapply objects automatically.
int save_player(object *op, int flag)
Saves a player to disk.
static unsigned checksum(const mtar_raw_header_t *rh)
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
int8_t levgrace[11]
What grace bonus the player gained on that level.
#define ST_PLAYING
Usual state.
#define NDI_DK_ORANGE
DarkOrange2.
#define MAX_PASSWORD_FAILURES
How many times we are allowed to give the wrong password before being kicked.
char * host
Which host it is connected from (ip address).
void esrv_add_spells(player *pl, object *spell)
This tells the client to add the spell *spell, if spell is NULL, then add all spells in the player's ...
#define FLAG_REMOVED
Object is not in any map or invenory.
int32_t weight
Attributes of the object.
void events_execute_global_event(int eventcode,...)
Execute a global event.
Account_Chars * account_chars
Detailed information on characters on this account.
void get_name(object *op)
Waiting for the player's name.
rangetype shoottype
Which range-attack is being used by player.
#define SAVE_FLAG_SAVE_UNPAID
If set, unpaid items will be saved.
uint32_t update_look
If true, we need to send the look window.
int16_t level
Level of creature or object.
party_rejoin_mode
Whether to rejoin party at login or not.
void login_check_shutdown(object *const op)
Warn op if a server shutdown is scheduled.
void remove_directory(const char *path)
This function removes everything in the directory, and the directory itself.
void esrv_new_player(player *pl, uint32_t weight)
Tells the client that here is a player it should start using.
object * object_find_by_type_and_arch_name(const object *who, int type, const char *name)
Find object in inventory by type and archetype name.
player * next
Pointer to next player, NULL if this is last.
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
static void wrong_password(object *op)
Simple function to print errors when password is not correct, and reinitialise the name...
char maplevel[MAX_BUF]
On which level is the player?
void kill_player(object *op, const object *killer)
Handle a player's death.
FILE * of_open(OutputFile *of, const char *fname)
Opens an output file.
#define MSG_TYPE_COMMAND_SUCCESS
Successful result from command.
If party doesn't exist, form it.
Defines for loader.l / loader.c.
uint8_t search_items
Search_items command.
float speed
Frequency of object 'moves' relative to server tick rate.
int32_t carrying
How much weight this object contains.
#define NDI_ALL_DMS
Inform all logged in DMs.
int16_t digestion
Any bonuses/penalties to digestion.
char path[HUGE_BUF]
Filename of the map.
const char * tmpdir
Directory to use for temporary files.
#define QUERY_FLAG(xyz, p)
#define FLAG_USE_SHIELD
Can this creature use a shield?
#define MSG_TYPE_ADMIN_PLAYER
Player coming/going/death.
void player_set_state(player *pl, uint8_t state)
Set the player's state to the specified one.
void account_char_save(Account_Chars *chars)
Saves the character information for the given account.
uint32_t has_directory
If 0, the player was not yet saved, its directory doesn't exist.
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
socket_struct * socket
Socket information for this player.
char password[16]
2 (seed) + 11 (crypted) + 1 (EOS) + 2 (safety) = 16
void object_reset(object *op)
Totally resets the specified object, without freeing associated memory.
int verify_player(const char *name, char *password)
This verify that a character of name exits, and that it matches password.
language_t i18n_get_language_by_code(const char *code)
Find the identifier of a language from its code.
char * partyname
Party name.
void delete_character(const char *name)
Totally deletes a character.
language_t language
The language the player wishes to use.
uint8_t state
Input state of the player (name, password, etc).
object * ob
The object representing the player.
void confirm_password(object *op)
Ask the player to confirm her password during creation.
void hiscore_check(object *op, int quiet)
Checks if player should enter the hiscore, and if so writes her into the list.
char spellparam[MAX_BUF]
What param to add to spells.
const char * player_get_own_title(const struct player *pl)
Returns the player's own title.
struct Settings settings
Global settings.
usekeytype usekeys
Method for finding keys for doors.
int16_t bed_y
x,y - coordinates of respawn (savebed).
partylist * party_find(const char *partyname)
Find a party by name.
unapplymode unapply
Method for auto unapply.
void set_dragon_name(object *pl, const object *abil, const object *skin)
Set the new dragon name after gaining levels or changing ability focus (later this can be extended to...
uint32_t pticks
Number of ticks since time reset.
char savebed_map[MAX_BUF]
Map where player will respawn after death.
void destroy_object(object *op)
Recursively object_free_drop_inventory() op and its inventory.
uint32_t ticks_played
How many ticks this player has played.
#define FLAG_WIZ
Object has special privilegies.
uint8_t listening
Which priority will be used in info_all.
living stats
Str, Con, Dex, etc.
#define MAX_BUF
Used for all kinds of things.
void quest_send_initial_states(player *pl)
Send the current quest states for the specified player, if the client supports those notifications...
size_t strlcpy(char *dst, const char *src, size_t size)
Portable implementation of strlcpy(3).
void knowledge_first_player_save(player *pl)
Ensure the knowledge state is correctly saved for the player.
int save_object(FILE *fp, object *op, int flag)
Dumps all variables in an object to a file.
struct mapstruct * map
Pointer to the map in which this object is present.
int8_t levsp[11]
What sp bonus the player gained on that level.
#define SAVE_FLAG_NO_REMOVE
If set, objects are not removed while saving.
void remove_unpaid_objects(object *op, object *env, int free_items)
This goes throws the inventory and removes unpaid objects, and puts them back in the map (location an...
uint8_t password_fails
How many times the player has failed to give the right password.
void knowledge_send_known(player *pl)
Send initial known knowledge to player, if requested.
int account_link(const char *account_name, const char *player_name)
Adds a player name to an account.
sstring name_pl
The plural name of the object.
bool is_old_wraith
Whether this player is a "old" wraith, initialized at load time and updated when eating.
#define FREE_AND_COPY(sv, nv)
Release the shared string if not NULL, and make it a reference to nv.
uint32_t name_changed
If true, the player has set a name.
int16_t gen_grace
Bonuses to regeneration speed of grace.
const char * localdir
Read/write data files.
object * last_skill_ob[MAX_SKILLS]
Exp objects sent to client.
sstring name
The name of the object, obviously...
FILE * tempnam_secure(const char *dir, const char *pfx, char **filename)
A replacement for the tempnam_local() function since that one is not very secure. ...
Only for debugging purposes.
uint32_t no_shout
if True, player is *not *able to use shout command.
void quest_first_player_save(player *pl)
Ensure the quest state is correctly saved for a player.
int of_close(OutputFile *of)
Closes an output file.
int check_name(player *me, const char *name)
Ensure player's name is valid.
#define CLEAR_FLAG(xyz, p)
uint8_t type
PLAYER, BULLET, etc.
bowtype_t bowtype
Which firemode?
char search_str[MAX_BUF]
Item we are looking for.
#define SAVE_MODE
If you have defined SAVE_PLAYER, you might want to change this, too.
rangetype
What range is currently selected by the player.
void party_join(object *op, partylist *party)
Makes a player join a party.
void object_update_speed(object *op)
Updates the speed of an object.
Functions for creating text output files.
int16_t gen_sp
Bonuses to regeneration speed of sp.
object * inv
Pointer to the first object in the inventory.
int8_t levhp[11]
What hp bonus the player gained on that level.
int party_confirm_password(const partylist *party, const char *password)
Checks whether a given password matches the party's password.
int playername_ok(const char *cp)
Is the player name valid.
int reset_loc_time
Number of seconds to put player back at home.
void check_login(object *op, const char *password)
Actually login a player, load from disk and such.
void esrv_send_pickup(player *pl)
Sends the "pickup" state to pl if client wants it requested.
Will unapply objects when there no choice to unapply.
uint8_t set_title
Players can set thier title.
#define NDI_UNIQUE
Print immediately, don't buffer.
void final_free_player(player *pl)
Sends the 'goodbye' command to the player, and closes connection.
uint32_t partial_commands
If 1, then first letters of a command are enough if no ambiguity in name.
mapstruct * has_been_loaded(const char *name)
Checks whether map has been loaded.
void drop_all_unpaid(object *op)
const char * unarmed_skill
Prefered skill to use in unarmed combat.
Only use keys in inventory.
void emergency_save(int flag)
Save all players.
#define MAX_SKILLS
This is the maximum number of skills the game may handle.
char * emergency_mapname
Map to return players to in emergency.
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Same as object_insert_in_map() except it handle separate coordinates and do a clean job preparing mul...
partylist * party_form(object *op, const char *partyname)
Forms the party struct for a party called 'partyname'.
petmode_t petmode
Which petmode?
sstring i18n_get_language_code(language_t language)
Return the code of a specified language.
bool is_wraith
Whether this player is a wraith or not, initialized at load time.
void account_char_add(Account_Chars *chars, player *pl)
This adds a player to the list of accounts.
object clone
An object from which to do object_copy()
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
party_rejoin_mode rejoin_party
Whether to rejoin or not party at login.
Core defines: object types, flags, etc.