 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
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) {
138 if (strlen(
buf) >=
sizeof(
buf)-1) {
143 fp = fopen(
buf,
"r");
153 if (!strncmp(
buf,
"password ", 9)) {
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);
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.");
int16_t gen_sp
Bonuses to regeneration speed of sp.
@ party_rejoin_no
Don't rejoin.
sstring name_pl
The plural name of the object.
int16_t bed_y
x,y - coordinates of respawn (savebed).
player * next
Pointer to next player, NULL if this is last.
player * first_player
First player.
struct Settings settings
Global settings.
#define SAVE_MODE
If you have defined SAVE_PLAYER, you might want to change this, too.
void pets_terminate_all(object *owner)
Removes all pets someone owns.
#define MSG_TYPE_COMMAND_SUCCESS
Successful result from command.
const char * unarmed_skill
Prefered skill to use in unarmed combat.
@ llevError
Error, serious thing.
#define MSG_TYPE_ADMIN_PLAYER
Player coming/going/death.
uint32_t mode
Mode of player for pickup.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
int of_close(OutputFile *of)
Closes an output file.
int16_t digestion
Any bonuses/penalties to digestion.
FILE * of_open(OutputFile *of, const char *fname)
Opens an output file.
object * inv
Pointer to the first object in the inventory.
int16_t gen_grace
Bonuses to regeneration speed of grace.
#define SAVE_FLAG_NO_REMOVE
If set, objects are not removed while saving.
char first_map_path[MAX_BUF]
The start-level.
#define QUERY_FLAG(xyz, p)
bool is_wraith
Whether this player is a wraith or not, initialized at load time.
void login_check_shutdown(object *const op)
Warn op if a server shutdown is scheduled.
uint8_t set_title
Players can set thier title.
mapstruct * has_been_loaded(const char *name)
Checks whether map has been loaded.
void esrv_new_player(player *pl, uint32_t weight)
Tells the client that here is a player it should start using.
bowtype_t
Bow firing mode.
void esrv_send_inventory(object *pl, object *op)
Sends inventory of a container.
struct archetype * arch
Pointer to archetype.
partylist * party_find(const char *partyname)
Find a party by name.
uint32_t no_shout
if True, player is *not *able to use shout command.
float speed
Frequency of object 'moves' relative to server tick rate.
uint32_t peaceful
If set, won't attack friendly creatures.
object * ob
The object representing the player.
static void copy_file(const char *filename, FILE *fpout)
Copy a file.
struct mapstruct * map
Pointer to the map in which this object is present.
void esrv_send_pickup(player *pl)
Sends the "pickup" state to pl if client wants it requested.
int8_t levhp[11]
What hp bonus the player gained on that level.
void player_set_own_title(struct player *pl, const char *title)
Sets the custom title.
@ range_none
No range selected.
non standard information is not specified or uptime this means how long since the executable has been started A particular host may have been running a server for quite a long time
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
static unsigned checksum(const mtar_raw_header_t *rh)
void object_reset(object *op)
Totally resets the specified object, without freeing associated memory.
#define NDI_ALL_DMS
Inform all logged in DMs.
uint32_t partial_commands
If 1, then first letters of a command are enough if no ambiguity in name.
int player_has_own_title(const struct player *pl)
Returns whether the player has a custom title.
int load_object(FILE *fp, object *op, int bufstate, int map_flags, bool artifact_init)
Loads an object from the given file-pointer.
int8_t levsp[11]
What sp bonus the player gained on that level.
char savebed_map[MAX_BUF]
Map where player will respawn after death.
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
#define PROFILE_BEGIN(expr)
int save_player(object *op, int flag)
Saves a player to disk.
int account_link(const char *account_name, const char *player_name)
Adds a player name to an account.
#define EVENT_LOGIN
Player login.
@ unapply_always
Will unapply whatever is necessary - this goes beyond no choice - if there are multiple ojbect of the...
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 ...
char path[HUGE_BUF]
Filename of the map.
int16_t level
Level of creature or object.
uint32_t pticks
Number of ticks since time reset.
void hiscore_check(object *op, int quiet)
Checks if player should enter the hiscore, and if so writes her into the list.
@ party_rejoin_always
If party doesn't exist, form it.
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
Plugin animator file specs[Config] name
uint32_t update_look
If true, we need to send the look window.
void party_join(object *op, partylist *party)
Makes a player join a party.
int32_t carrying
How much weight this object contains.
void remove_directory(const char *path)
This function removes everything in the directory, and the directory itself.
#define PROFILE_END(var, expr)
int16_t y
Position in the map for this object.
Account_Chars * account_chars
Detailed information on characters on this account.
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects,...
struct player * contr
Pointer to the player which control this object.
object * object_find_by_name(const object *who, const char *name)
Finds an object in inventory name.
void final_free_player(player *pl)
Sends the 'goodbye' command to the player, and closes connection.
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.
sstring i18n_get_language_code(language_t language)
Return the code of a specified language.
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 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...
object clone
An object from which to do object_copy()
sstring add_string(const char *str)
This will add 'str' to the hash table.
static void wrong_password(object *op)
Simple function to print errors when password is not correct, and reinitialise the name.
int legal_range(object *op, int r)
Check for the validity of a player range.
void enter_player_maplevel(object *op)
Move a player to its stored map level.
long trying_emergency_save
True when emergency_save() is reached.
int verify_player(const char *name, char *password)
This verify that a character of name exits, and that it matches password.
char * host
Which host it is connected from (ip address).
void delete_character(const char *name)
Totally deletes a character.
char * account_name
Name of the account logged in on this socket.
void object_update_speed(object *op)
Updates the speed of an object.
int8_t levgrace[11]
What grace bonus the player gained on that level.
#define FREE_AND_COPY(sv, nv)
Release the shared string if not NULL, and make it a reference to nv.
uint8_t type
PLAYER, BULLET, etc.
void party_set_password(partylist *party, const char *password)
Sets a party's password.
#define FLAG_USE_SHIELD
Can this creature use a shield?
void leave(player *pl, int draw_exit)
Player logs out, or was disconnected.
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
rangetype
What range is currently selected by the player.
rangetype shoottype
Which range-attack is being used by player.
#define MAX_SKILLS
This is the maximum number of skills the game may handle.
char * partyname
Party name.
char maplevel[MAX_BUF]
On which level is the player?
partylist * party_form(object *op, const char *partyname)
Forms the party struct for a party called 'partyname'.
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...
@ key_inventory
Only use keys in inventory.
object * last_skill_ob[MAX_SKILLS]
Exp objects sent to client.
int reset_loc_time
Number of seconds to put player back at home.
#define MAX_BUF
Used for all kinds of things.
#define MSG_TYPE_ADMIN_LOADSAVE
load/save operations
uint8_t listening
Which priority will be used in info_all.
size_t strlcpy(char *dst, const char *src, size_t size)
Portable implementation of strlcpy(3).
living orig_stats
Permanent real stats of player.
int32_t weight
Attributes of the object.
unapplymode unapply
Method for auto unapply.
const char * playerdir
Where the player files are.
void quest_first_player_save(player *pl)
Ensure the quest state is correctly saved for a player.
char search_str[MAX_BUF]
Item we are looking for.
#define ST_PLAYING
Usual state.
int16_t gen_hp
Bonuses to regeneration speed of hp.
#define FLAG_REMOVED
Object is not in any map or invenory.
#define FLAG_WIZ
Object has special privilegies.
char * emergency_mapname
Map to return players to in emergency.
#define NDI_UNIQUE
Print immediately, don't buffer.
void destroy_object(object *op)
Recursively object_free_drop_inventory() op and its inventory.
#define FLAG_FRIENDLY
Will help players.
sstring name
The name of the object, obviously...
const char * party_get_password(const partylist *party)
Returns the party's password.
language_t i18n_get_language_by_code(const char *code)
Find the identifier of a language from its code.
int is_dragon_pl(const object *op)
Checks if player is a dragon.
@ unapply_nochoice
Will unapply objects when there no choice to unapply.
#define FLAG_USE_ARMOUR
(Monster) can wear armour/shield/helmet
bool is_old_wraith
Whether this player is a "old" wraith, initialized at load time and updated when eating.
int check_name(player *me, const char *name)
Ensure player's name is valid.
#define NDI_ALL
Inform all players of this message.
#define MAX_PASSWORD_FAILURES
How many times we are allowed to give the wrong password before being kicked.
language_t language
The language the player wishes to use.
uint8_t state
Input state of the player (name, password, etc).
#define FLAG_NO_FIX_PLAYER
fix_object() won't be called
#define CLEAR_FLAG(xyz, p)
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.
void check_login(object *op, const char *password)
Actually login a player, load from disk and such.
#define NDI_DK_ORANGE
DarkOrange2.
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.
partylist * party
Party this player is part of.
@ containers
Use keys in inventory and active containers.
@ keyrings
Use keys in inventory and active key rings.
void account_char_add(Account_Chars *chars, player *pl)
This adds a player to the list of accounts.
#define MSG_TYPE_ADMIN_LOGIN
login messages/errors
void drop_all_unpaid(object *op)
#define SAVE_ERROR_OK
No error.
#define ST_GET_PARTY_PASSWORD
Player tried to join a password-protected party.
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to.
void player_set_state(player *pl, uint8_t state)
Set the player's state to the specified one.
signed long object_sum_weight(object *op)
object_sum_weight() is a recursive function which calculates the weight an object is carrying.
#define FLAG_UNPAID
Object hasn't been paid for yet.
uint32_t has_directory
If 0, the player was not yet saved, its directory doesn't exist.
bool check_password(const char *typed, const char *crypted)
Hash a password and compare it to the stored version.
void make_path_to_file(const char *filename)
Checks if any directories in the given path doesn't exist, and creates if necessary.
char password[16]
2 (seed) + 11 (crypted) + 1 (EOS) + 2 (safety) = 16
void emergency_save(int flag)
Save all players.
socket_struct * socket
Socket information for this player.
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.
uint8_t search_items
Search_items command.
living stats
Str, Con, Dex, etc.
@ unapply_never
Will not unapply objects automatically.
char title[BIG_NAME]
Default title, like fighter, wizard, etc.
Player Stats effect how well a character can survie and interact inside the crossfire world This section discusses the various what they and how they effect the player s actions Also in this section are the stat modifiers that specific classes professions bring Player and sps the current and maximum the Current and Maximum The Current Sp can go somewhat negative When Sp is negative not all spells can be and a more negative Sp makes spell casting less likey to succeed can affect Damage and how the characters as well as how often the character can attack this affects the prices when buying and selling items if this drops the player will start losing hit points wd Cleric or Dwarf sm Elf wd Fireborn ft Human ra Mage C Monk me
const char * tmpdir
Directory to use for temporary files.
const char * player_get_own_title(const struct player *pl)
Returns the player's own title.
void confirm_password(object *op)
Ask the player to confirm her password during creation.
petmode_t petmode
Which petmode?
char spellparam[MAX_BUF]
What param to add to spells.
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 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...
party_rejoin_mode
Whether to rejoin party at login or not.
void account_char_save(Account_Chars *chars)
Saves the character information for the given account.
#define SAVE_FLAG_SAVE_UNPAID
If set, unpaid items will be saved.
uint32_t name_changed
If true, the player has set a name.
int save_object(FILE *fp, object *op, int flag)
Dumps all variables in an object to a file.
void kill_player(object *op, const object *killer)
Handle a player's death.
bowtype_t bowtype
Which firemode?
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
int check_path(const char *name, int prepend_dir)
This function checks if a file with the given path exists.
uint32_t ticks_played
How many ticks this player has played.
usekeytype usekeys
Method for finding keys for doors.
party_rejoin_mode rejoin_party
Whether to rejoin or not party at login.
void events_execute_global_event(int eventcode,...)
Execute a global event.
@ llevDebug
Only for debugging purposes.
void quest_send_initial_states(player *pl)
Send the current quest states for the specified player, if the client supports those notifications.
void get_name(object *op)
Waiting for the player's name.
void knowledge_first_player_save(player *pl)
Ensure the knowledge state is correctly saved for the player.
const char * localdir
Read/write data files.