Crossfire Client, Trunk
|
#include "client.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include "external.h"
#include "mapdata.h"
Go to the source code of this file.
Macros | |
#define | ASSERT_LEN(function, curpos, buflen) |
#define | NUM_LAYERS (MAP1_LAYERS-1) |
#define | NUM_STATS 7 |
Functions | |
void | AccountPlayersCmd (char *buf, int len) |
void | AddMeFail (char *data, int len) |
void | AddMeSuccess (char *data, int len) |
void | AddspellCmd (unsigned char *data, int len) |
void | AnimCmd (unsigned char *data, int len) |
void | DeleteInventory (unsigned char *data, int len) |
void | DeleteItem (unsigned char *data, int len) |
void | DeleteSpell (unsigned char *data, int len) |
void | DrawExtInfoCmd (char *data, int len) |
void | DrawInfoCmd (char *data, int len) |
int | ExtSmooth (unsigned char *data, int len, int x, int y, int layer) |
void | FailureCmd (char *buf, int len) |
void | free_all_race_class_info (Race_Class_Info *data, int num_entries) |
void | free_all_starting_map_info () |
static void | get_class_info (unsigned char *data, int len) |
static void | get_exp_info (const unsigned char *data, int len) |
static void | get_new_char_info (unsigned char *data, int len) |
static void | get_race_info (unsigned char *data, int len) |
static void | get_skill_info (char *data, int len) |
static void | get_starting_map_info (unsigned char *data, int len) |
static ExtTextManager | getTextManager (int type) |
void | GoodbyeCmd (char *data, int len) |
void | handle_query (char *data, int len) |
void | Item2Cmd (unsigned char *data, int len) |
void | item_actions (item *op) |
void | MagicMapCmd (unsigned char *data, int len) |
void | Map2Cmd (unsigned char *data, int len) |
void | map_scrollCmd (char *data, int len) |
void | MapExtendedCmd (unsigned char *data, int len) |
void | NewmapCmd (unsigned char *data, int len) |
void | PickupCmd (guint8 *data, int len) |
void | PlayerCmd (unsigned char *data, int len) |
static void | process_race_class_info (unsigned char *data, int len, Race_Class_Info *rci) |
static int | rc_compar (const Race_Class_Info *a, const Race_Class_Info *b) |
void | ReplyInfoCmd (unsigned char *buf, int len) |
static void | rstrip (char buf[static 1], size_t len) |
void | send_reply (const char *text) |
void | setTextManager (int type, ExtTextManager callback) |
void | SetupCmd (char *buf, int len) |
void | SinkCmd (unsigned char *data, int len) |
void | SmoothCmd (unsigned char *data, int len) |
void | StatsCmd (unsigned char *data, int len) |
void | TickCmd (guint8 *data, int len) |
void | UpdateItemCmd (unsigned char *data, int len) |
void | UpdspellCmd (unsigned char *data, int len) |
void | use_skill (int skill_id) |
Variables | |
Animations | animations [MAXANIM] |
Race_Class_Info * | classes =NULL |
TextManager * | firstTextManager = NULL |
int | mapupdatesent = 0 |
char * | motd =NULL |
char * | news =NULL |
int | num_classes = 0 |
int | num_races = 0 |
Race_Class_Info * | races =NULL |
char * | rules =NULL |
static const char *const | short_stat_name [NUM_STATS] |
static int | spellmon_level = 0 |
Starting_Map_Info * | starting_map_info = NULL |
int | starting_map_number = 0 |
struct Stat_Mapping | stat_mapping [NUM_NEW_CHAR_STATS] |
int | stat_maximum |
int | stat_min |
int | stat_points |
int | used_classes = 0 |
int | used_races = 0 |
Handles server->client commands; See player.c for client->server commands.
Not necessarily all commands are handled - some might be in other files (like init.c)
This file contains most of the commands for the dispatch loop. Most of the functions are self-explanatory.
pixmap/bitmap : receive the picture, and display it. drawinfo : draws a string in the info window. stats : updates the local copy of the stats and displays it. handle_query : prompts the user for input. send_reply : sends off the reply for the input. player : gets the player information. MapScroll : scrolls the map on the client by some amount. MapCmd : displays the map with layer packing or stack packing. packing/unpacking is best understood by looking at the server code (server/ericserver.c) stack packing: for every map entry that changed, we pack 1 byte for the x/y location, 1 byte for the count, and 2 bytes per face in the stack. layer packing is harder, but I seem to remember more efficient: first we pack in a list of all map cells that changed and are now empty. The end of this list is a 255, which is bigger that 121, the maximum packed map location. For each changed location we also pack in a list of all the faces and X/Y coordinates by layer, where the layer is the depth in the map. This essentially takes slices through the map rather than stacks. Then for each layer, (max is MAXMAPCELLFACES, a bad name) we start packing the layer into the message. First we pack in a face, then for each place on the layer with the same face, we pack in the x/y location. We mark the last x/y location with the high bit on (11*11 = 121 < 128). We then continue on with the next face, which is why the code marks the faces as -1 if they are finished. Finally we mark the last face in the layer again with the high bit, clearly limiting the total number of faces to 32767, the code comments it's 16384, I'm not clear why, but the second bit may be used somewhere else as well. The unpacking routines basically perform the opposite operations.
Definition in file commands.c.
#define ASSERT_LEN | ( | function, | |
curpos, | |||
buflen | |||
) |
Definition at line 76 of file commands.c.
#define NUM_STATS 7 |
Definition at line 105 of file commands.c.
void AccountPlayersCmd | ( | char * | buf, |
int | len | ||
) |
This handles the accountplayers command
Definition at line 2462 of file commands.c.
References ACL_CLASS, ACL_FACE, ACL_FACE_NUM, ACL_LEVEL, ACL_MAP, ACL_NAME, ACL_PARTY, ACL_RACE, choose_character_init(), GetShort_String(), LOG(), LOG_ERROR, map, MAX_BUF, and update_character_choose().
void AddMeFail | ( | char * | data, |
int | len | ||
) |
Handles when the server says we can't be added. In reality, we need to close the connection and quit out, because the client is going to close us down anyways.
data | |
len |
Definition at line 1110 of file commands.c.
References LOG(), and LOG_INFO.
void AddMeSuccess | ( | char * | data, |
int | len | ||
) |
This is really a throwaway command - there really isn't any reason to send addme_success commands.
data | |
len |
Definition at line 1126 of file commands.c.
References hide_all_login_windows(), LOG(), LOG_DEBUG, and show_main_client().
void AnimCmd | ( | unsigned char * | data, |
int | len | ||
) |
data | |
len |
Definition at line 1162 of file commands.c.
References animations, Animations::faces, Animations::flags, GetShort_String(), LOG(), LOG_DEBUG, LOG_WARNING, MAXANIM, Animations::num_animations, Animations::phase, Animations::speed, and Animations::speed_left.
void DeleteInventory | ( | unsigned char * | data, |
int | len | ||
) |
data | |
len |
Definition at line 1837 of file commands.c.
References locate_item(), LOG(), LOG_WARNING, and remove_item_inventory().
void DeleteItem | ( | unsigned char * | data, |
int | len | ||
) |
data | |
len |
Definition at line 1811 of file commands.c.
References GetInt_String(), locate_item(), LOG(), LOG_WARNING, and remove_item().
void DrawExtInfoCmd | ( | char * | data, |
int | len | ||
) |
We must extract color, type, subtype and dispatch to callback
data | |
len |
Definition at line 1291 of file commands.c.
References getTextManager(), LOG(), and LOG_WARNING.
void DrawInfoCmd | ( | char * | data, |
int | len | ||
) |
Draws a string in the info window.
data | |
len |
Definition at line 1227 of file commands.c.
References draw_ext_info(), LOG(), LOG_WARNING, MSG_TYPE_CLIENT, and MSG_TYPE_CLIENT_COMMAND.
void FailureCmd | ( | char * | buf, |
int | len | ||
) |
Handles a failure return from the server.
buf | buffer sent by server. |
len | length of data. |
Definition at line 2416 of file commands.c.
References account_add_character_failure(), account_change_password_failure(), account_creation_failure(), account_login_failure(), create_new_character_failure(), LOG(), and LOG_ERROR.
void free_all_race_class_info | ( | Race_Class_Info * | data, |
int | num_entries | ||
) |
This function clears the data from the Race_Class_Info array. Because the structure itself contains data that is allocated, some work needs to be done to clear that data.
data | array to clear |
num_entries | size of the array. |
Definition at line 420 of file commands.c.
References Race_Class_Info::num_rc_choice, RC_Choice::num_values, and Race_Class_Info::rc_choice.
Referenced by client_reset(), and ReplyInfoCmd().
void free_all_starting_map_info | ( | ) |
This function clears the data from the Race_Class_Info array. Because the structure itself contains data that is allocated, some work needs to be done to clear that data.
Definition at line 134 of file commands.c.
References starting_map_info, and starting_map_number.
Referenced by get_new_char_info().
|
static |
This is a little wrapper function that does some bounds checking and then calls process_race_info() to do the bulk of the work. Pretty much identical to get_race_info() except this is for classes.
data | data returned from server. Format is documented in protocol file. |
len | length of data. |
Definition at line 679 of file commands.c.
References classes, LOG(), LOG_ERROR, new_char_window_update_info(), num_classes, process_race_class_info(), rc_compar(), and used_classes.
Referenced by ReplyInfoCmd().
|
static |
data | |
len |
Definition at line 705 of file commands.c.
References exp_table, exp_table_max, GetInt64_String(), GetShort_String(), LOG(), and LOG_ERROR.
Referenced by ReplyInfoCmd().
|
static |
This is process the newcharinfo requestinfo. In some cases, it stores away the value, for others, it just makes sure we understand them.
The data is a series of length prefixed lines.
data | data returned from server. Format is documented in protocol file. |
len | length of data. |
Definition at line 247 of file commands.c.
References cs_print_string(), csocket, ClientSocket::fd, free_all_starting_map_info(), GetChar_String(), LOG(), LOG_ERROR, LOG_WARNING, new_char_window_update_info(), NUM_STATS, short_stat_name, stat_maximum, stat_min, and stat_points.
Referenced by ReplyInfoCmd().
|
static |
This is a little wrapper function that does some bounds checking and then calls process_race_info() to do the bulk of the work.
data | data returned from server. Format is documented in protocol file. |
len | length of data. |
Definition at line 648 of file commands.c.
References LOG(), LOG_ERROR, new_char_window_update_info(), num_races, process_race_class_info(), races, rc_compar(), and used_races.
Referenced by ReplyInfoCmd().
|
static |
data | |
len |
Definition at line 732 of file commands.c.
References CS_STAT_SKILLINFO, LOG(), LOG_WARNING, MAX_SKILL, and skill_names.
Referenced by ReplyInfoCmd().
|
static |
This processes the replyinfo starting_map_info
The data is a series of length prefixed lines.
data | data returned from server. Format is documented in protocol file. |
len | length of data. |
Definition at line 172 of file commands.c.
References Starting_Map_Info::arch_name, Starting_Map_Info::description, GetShort_String(), INFO_MAP_ARCH_NAME, INFO_MAP_DESCRIPTION, INFO_MAP_NAME, LOG(), LOG_ERROR, LOG_WARNING, Starting_Map_Info::public_name, starting_map_info, starting_map_number, and starting_map_update_info().
Referenced by ReplyInfoCmd().
|
static |
type |
Definition at line 1273 of file commands.c.
References TextManager::callback, firstTextManager, TextManager::next, and TextManager::type.
Referenced by DrawExtInfoCmd().
void GoodbyeCmd | ( | char * | data, |
int | len | ||
) |
data | |
len |
Definition at line 1142 of file commands.c.
References LOG(), and LOG_WARNING.
void handle_query | ( | char * | data, |
int | len | ||
) |
Prompts the user for input.
data | |
len |
Definition at line 1556 of file commands.c.
References cpl, CS_QUERY_HIDEINPUT, CS_QUERY_SINGLECHAR, CS_QUERY_YESNO, draw_ext_info(), draw_prompt(), Player_Struct::input_state, LOG(), LOG_DEBUG, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_QUERY, NDI_BLACK, Player_Struct::no_echo, Reply_Many, Reply_One, and x_set_echo().
void Item2Cmd | ( | unsigned char * | data, |
int | len | ||
) |
Parses the data sent to us from the server. revision is what item command the data came from - newer ones have addition fields.
data | |
len |
Definition at line 1677 of file commands.c.
References GetInt_String(), GetShort_String(), item_actions(), locate_item(), LOG(), LOG_WARNING, MAX_BUF, and update_item().
void item_actions | ( | item * | op | ) |
op |
Definition at line 1656 of file commands.c.
References close_container(), Player_Struct::container, cpl, item_struct::open, open_container(), and item_struct::was_open.
Referenced by Item2Cmd(), and UpdateItemCmd().
void PickupCmd | ( | guint8 * | data, |
int | len | ||
) |
Server gives us current player's pickup.
data | buffer sent by server. |
len | length of data. |
Definition at line 2402 of file commands.c.
References client_pickup(), and GetInt_String().
void PlayerCmd | ( | unsigned char * | data, |
int | len | ||
) |
Gets the player information. This function copies relevant data from the archetype to the object. Only copies data that was not set in the object structure.
data | |
len |
Definition at line 1629 of file commands.c.
References GetInt_String(), LOG(), LOG_WARNING, MAX_BUF, new_player(), and reset_player_data().
|
static |
This extracts the data from a replyinfo race_info/class_info request. We only get this data if the client has made a requestinfo of this data.
data | data returned from server. Format is documented in protocol file. |
len | length of data |
rci | Where to store the data. |
Definition at line 469 of file commands.c.
References Race_Class_Info::arch_name, ASSERT_LEN, RC_Choice::choice_desc, RC_Choice::choice_name, Stat_Mapping::cs_value, Race_Class_Info::description, GetChar_String(), GetShort_String(), LOG(), LOG_WARNING, NUM_NEW_CHAR_STATS, Race_Class_Info::num_rc_choice, RC_Choice::num_values, Race_Class_Info::public_name, Race_Class_Info::rc_choice, Stat_Mapping::rc_offset, Race_Class_Info::stat_adj, stat_mapping, RC_Choice::value_arch, and RC_Choice::value_desc.
Referenced by get_class_info(), and get_race_info().
|
static |
Used for bsearch searching.
Definition at line 405 of file commands.c.
References Race_Class_Info::public_name.
Referenced by get_class_info(), and get_race_info().
void ReplyInfoCmd | ( | unsigned char * | buf, |
int | len | ||
) |
Handles the response from a 'requestinfo' command. This function doesn't do much itself other than dispatch to other functions.
buf | |
len |
Definition at line 774 of file commands.c.
References classes, cs_print_string(), csocket, ClientSocket::fd, free_all_race_class_info(), get_class_info(), get_exp_info(), get_image_info(), get_image_sums(), get_new_char_info(), get_race_info(), get_skill_info(), get_starting_map_info(), INFO_MOTD, INFO_NEWS, INFO_RULES, LOG(), LOG_DEBUG, motd, news, num_classes, num_races, races, rules, update_login_info(), used_classes, and used_races.
|
static |
Remove trailing newlines from the given C string in-place.
Definition at line 1856 of file commands.c.
Referenced by AddspellCmd().
void send_reply | ( | const char * | text | ) |
Sends a reply to the server. This function basically just packs the stuff up.
text | contains the null terminated string of text to send. |
Definition at line 1612 of file commands.c.
References cpl, cs_print_string(), csocket, ClientSocket::fd, Player_Struct::no_echo, and x_set_echo().
Referenced by keyfunc(), and on_entry_commands_activate().
void setTextManager | ( | int | type, |
ExtTextManager | callback | ||
) |
type | |
callback |
Definition at line 1251 of file commands.c.
References TextManager::callback, firstTextManager, TextManager::next, and TextManager::type.
Referenced by info_init().
void SetupCmd | ( | char * | buf, |
int | len | ||
) |
Received a response to a setup from the server. This function is basically the same as the server side function - we just do some different processing on the data.
buf | |
len |
Definition at line 901 of file commands.c.
References client_disconnect(), client_mapsize(), CONFIG_CACHE, CONFIG_MAPHEIGHT, CONFIG_MAPWIDTH, cs_print_string(), ClientSocket::cs_version, csocket, draw_ext_info(), face_info, Face_Information_struct::faceset, ClientSocket::fd, LOG(), LOG_DEBUG, LOG_INFO, LOG_WARNING, mapdata_set_size(), MAX_BUF, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_SERVER, NDI_RED, resize_map_window(), spellmon_level, start_login(), use_config, and want_config.
void SinkCmd | ( | unsigned char * | data, |
int | len | ||
) |
data | |
len |
Definition at line 2377 of file commands.c.
void SmoothCmd | ( | unsigned char * | data, |
int | len | ||
) |
Receives the smooth mapping from the server. Because this information is reference a lot, the smoothing face is stored in the pixmap data - this makes access much faster than searching an array of data for the face to use.
data | |
len |
Definition at line 1207 of file commands.c.
References addsmooth(), and GetShort_String().
void StatsCmd | ( | unsigned char * | data, |
int | len | ||
) |
Updates the local copy of the stats and displays it.
data | |
len |
Definition at line 1368 of file commands.c.
References Stat_struct::ac, Stat_struct::attuned, Stat_struct::Cha, Stat_struct::Con, cpl, CS_NUM_SKILLS, CS_STAT_AC, CS_STAT_ARMOUR, CS_STAT_CHA, CS_STAT_CON, CS_STAT_DAM, CS_STAT_DEX, CS_STAT_EXP, CS_STAT_EXP64, CS_STAT_FLAGS, CS_STAT_FOOD, CS_STAT_GRACE, CS_STAT_HP, CS_STAT_INT, CS_STAT_LEVEL, CS_STAT_MAXGRACE, CS_STAT_MAXHP, CS_STAT_MAXSP, CS_STAT_POW, CS_STAT_RANGE, CS_STAT_RESIST_END, CS_STAT_RESIST_START, CS_STAT_SKILLINFO, CS_STAT_SP, CS_STAT_SPEED, CS_STAT_SPELL_ATTUNE, CS_STAT_SPELL_DENY, CS_STAT_SPELL_REPEL, CS_STAT_STR, CS_STAT_TITLE, CS_STAT_WC, CS_STAT_WEAP_SP, CS_STAT_WEIGHT_LIM, CS_STAT_WIS, Stat_struct::dam, Stat_struct::denied, Stat_struct::Dex, draw_message_window(), draw_stats(), Stat_struct::exp, Stat_struct::flags, Stat_struct::food, GetInt64_String(), GetInt_String(), GetShort_String(), Stat_struct::grace, Stat_struct::hp, Stat_struct::Int, item_struct::inv_updated, Stat_struct::level, LOG(), LOG_WARNING, Stat_struct::maxgrace, Stat_struct::maxhp, Stat_struct::maxsp, Player_Struct::ob, Stat_struct::Pow, Player_Struct::range, redraw(), Stat_struct::repelled, Stat_struct::resist_change, Stat_struct::resists, script_lua_stats(), set_weight_limit(), Stat_struct::skill_exp, Stat_struct::skill_level, Stat_struct::sp, Stat_struct::speed, Player_Struct::spells_updated, Player_Struct::stats, Stat_struct::Str, Player_Struct::title, use_skill(), Stat_struct::wc, Stat_struct::weapon_sp, Stat_struct::weight_limit, and Stat_struct::Wis.
void TickCmd | ( | guint8 * | data, |
int | len | ||
) |
Got a tick from the server. We currently don't care what tick number it is, but just have the code in case at some time we do.
data | |
len |
Definition at line 2388 of file commands.c.
References client_tick(), and GetInt_String().
void UpdateItemCmd | ( | unsigned char * | data, |
int | len | ||
) |
Updates some attributes of an item
data | |
len |
Definition at line 1727 of file commands.c.
References item_struct::anim_speed, item_struct::animation_id, item_struct::env, item_struct::face, item_struct::flagsval, GetInt_String(), GetShort_String(), item_actions(), locate_item(), LOG(), LOG_WARNING, MAX_BUF, item_struct::nrof, item_struct::tag, item_struct::type, UPD_ANIM, UPD_ANIMSPEED, UPD_FACE, UPD_FLAGS, UPD_LOCATION, UPD_NAME, UPD_NROF, UPD_WEIGHT, update_item(), and item_struct::weight.
void use_skill | ( | int | skill_id | ) |
Maintain the last_used_skills LRU list for displaying the recently used skills first.
skill_id |
Definition at line 1343 of file commands.c.
References last_used_skills.
Referenced by StatsCmd(), and trigger_skill().
Animations animations[MAXANIM] |
Definition at line 1155 of file commands.c.
Referenced by animate_inventory(), animate_look(), animate_objects(), AnimCmd(), draw_inv_table(), mapdata_animation(), and mapdata_set_anim_layer().
Race_Class_Info * classes =NULL |
Definition at line 98 of file commands.c.
Referenced by get_class_info(), and ReplyInfoCmd().
TextManager* firstTextManager = NULL |
Definition at line 1244 of file commands.c.
Referenced by getTextManager(), and setTextManager().
int mapupdatesent = 0 |
Definition at line 55 of file commands.c.
Referenced by Map2Cmd(), and MapExtendedCmd().
char * motd =NULL |
Definition at line 82 of file commands.c.
Referenced by client_reset(), ReplyInfoCmd(), and update_login_info().
char* news =NULL |
Definition at line 82 of file commands.c.
Referenced by ReplyInfoCmd().
int num_classes = 0 |
Definition at line 90 of file commands.c.
Referenced by get_class_info(), and ReplyInfoCmd().
int num_races = 0 |
Definition at line 87 of file commands.c.
Referenced by client_reset(), get_race_info(), new_char_window_update_info(), and ReplyInfoCmd().
Race_Class_Info* races =NULL |
Definition at line 98 of file commands.c.
Referenced by client_reset(), create_character_window_show(), get_race_info(), new_char_window_update_info(), on_combobox_rcs_changed(), ReplyInfoCmd(), and send_create_player_to_server().
char * rules =NULL |
Definition at line 82 of file commands.c.
Referenced by ReplyInfoCmd().
|
static |
Short name of stats.
Definition at line 107 of file commands.c.
Referenced by get_new_char_info().
|
static |
Keeps track of what spellmon command is supported by the server.
Definition at line 85 of file commands.c.
Referenced by AddspellCmd(), and SetupCmd().
Starting_Map_Info* starting_map_info = NULL |
Definition at line 99 of file commands.c.
Referenced by free_all_starting_map_info(), get_starting_map_info(), on_combobox_starting_map_changed(), send_create_player_to_server(), and starting_map_update_info().
int starting_map_number = 0 |
Definition at line 96 of file commands.c.
Referenced by character_data_ok(), create_character_set_sensitive(), free_all_starting_map_info(), get_starting_map_info(), send_create_player_to_server(), and starting_map_update_info().
struct Stat_Mapping stat_mapping[NUM_NEW_CHAR_STATS] |
Definition at line 118 of file commands.c.
Referenced by init_create_character_window(), on_combobox_rcs_changed(), process_race_class_info(), and send_create_player_to_server().
int stat_maximum |
Definition at line 95 of file commands.c.
Referenced by get_new_char_info().
int stat_min |
Definition at line 94 of file commands.c.
Referenced by get_new_char_info().
int stat_points |
Definition at line 93 of file commands.c.
Referenced by character_data_ok(), create_character_window_show(), get_new_char_info(), new_char_window_update_info(), reset_vars_common(), and update_all_stats().
int used_classes = 0 |
Definition at line 91 of file commands.c.
Referenced by get_class_info(), and ReplyInfoCmd().
int used_races = 0 |
Definition at line 88 of file commands.c.
Referenced by get_race_info(), and ReplyInfoCmd().