Crossfire Server, Branches 1.12
R18729
|
#include <assert.h>
#include <stdarg.h>
#include <global.h>
#include <newclient.h>
#include <sproto.h>
#include <errno.h>
Go to the source code of this file.
Functions | |
static void | add_to_buffer (socket_struct *ns, const unsigned char *buf, int len) |
int | GetInt_String (const unsigned char *data) |
short | GetShort_String (const unsigned char *data) |
void | Send_With_Handling (socket_struct *ns, SockList *sl) |
void | SockList_AddChar (SockList *sl, char data) |
void | SockList_AddData (SockList *sl, const void *data, size_t len) |
void | SockList_AddInt (SockList *sl, uint32 data) |
void | SockList_AddInt64 (SockList *sl, uint64 data) |
void | SockList_AddLen8Data (SockList *sl, const void *data, size_t len) |
void | SockList_AddPrintf (SockList *sl, const char *format,...) |
void | SockList_AddShort (SockList *sl, uint16 data) |
void | SockList_AddString (SockList *sl, const char *data) |
void | SockList_AddStringBuffer (SockList *sl, StringBuffer *sb) |
size_t | SockList_Avail (const SockList *sl) |
static void | SockList_Ensure (const SockList *sl, size_t size) |
void | SockList_Init (SockList *sl) |
void | SockList_NullTerminate (SockList *sl) |
int | SockList_ReadPacket (int fd, SockList *sl, int len) |
void | SockList_Reset (SockList *sl) |
void | SockList_ResetRead (SockList *sl) |
void | SockList_Term (SockList *sl) |
void | write_socket_buffer (socket_struct *ns) |
static void | Write_To_Socket (socket_struct *ns, const unsigned char *buf, int len) |
Low-level socket-related functions.
Contains some base functions that both the client and server can use. As such, depending what we are being compiled for will determine what we can include. the client is designed have CFCLIENT defined as part of its compile flags.
Definition in file lowlevel.c.
|
static |
Adds data to a socket buffer for whatever reason.
ns is the socket we are adding the data to, buf is the start of the data, and len is the number of bytes to add.
Definition at line 383 of file lowlevel.c.
References buffer_struct::data, socket_struct::fd, buffer_struct::len, llevDebug, LOG(), Ns_Dead, socket_struct::outputbuffer, SOCKETBUFSIZE, buffer_struct::start, and socket_struct::status.
Referenced by Write_To_Socket().
int GetInt_String | ( | const unsigned char * | data | ) |
Basically does the reverse of SockList_AddInt, but on strings instead. Same for the GetShort, but for 16 bits.
Definition at line 239 of file lowlevel.c.
Referenced by inscribe_scroll_cmd(), lock_item_cmd(), mark_item_cmd(), and new_player_cmd().
short GetShort_String | ( | const unsigned char * | data | ) |
Definition at line 243 of file lowlevel.c.
Referenced by new_player_cmd().
void Send_With_Handling | ( | socket_struct * | ns, |
SockList * | sl | ||
) |
Calls Write_To_Socket to send data to the client.
The only difference in this function is that we take a SockList , and we prepend the length information.
Definition at line 541 of file lowlevel.c.
References SockList::buf, SockList::len, Ns_Dead, socket_struct::status, and Write_To_Socket().
Referenced by add_me_cmd(), draw_client_map2(), draw_magic_map(), esrv_add_spells(), esrv_del_item(), esrv_draw_look(), esrv_new_player(), esrv_print_ext_msg(), esrv_print_msg(), esrv_remove_spell(), esrv_send_animation(), esrv_send_face(), esrv_send_inventory(), esrv_send_item(), esrv_send_pickup(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), final_free_player(), init_connection(), map_newmap_cmd(), new_player_cmd(), play_sound_player_only(), request_info_cmd(), send_background_music(), send_class_list(), send_exp_table(), send_image_info(), send_image_sums(), send_plugin_custom_message(), send_query(), send_race_info(), send_race_list(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), set_face_mode_cmd(), set_up_cmd(), toggle_extended_infos_cmd(), and toggle_extended_text_cmd().
void SockList_AddChar | ( | SockList * | sl, |
char | data | ||
) |
Adds an 8 bit value. sl the SockList instance to add to
c | the value to add |
Definition at line 103 of file lowlevel.c.
References SockList::buf, SockList::len, and SockList_Ensure().
Referenced by add_object_to_socklist(), append_spell(), check_space_for_heads(), draw_client_map2(), draw_magic_map(), esrv_draw_look(), esrv_send_face(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), map2_add_ob(), map2_delete_layer(), play_sound_player_only(), send_image_sums(), and SockList_AddLen8Data().
void SockList_AddData | ( | SockList * | sl, |
const void * | data, | ||
size_t | len | ||
) |
Adds a data block.
sl | the SockList instance to add to |
data | the value to add |
len | the length in byte |
Definition at line 164 of file lowlevel.c.
References SockList::buf, SockList::len, and SockList_Ensure().
Referenced by append_spell(), esrv_send_face(), SockList_AddLen8Data(), and SockList_AddString().
Adds a 32 bit value. sl the SockList instance to add to
data | the value to add |
Definition at line 124 of file lowlevel.c.
References SockList::buf, SockList::len, and SockList_Ensure().
Referenced by add_object_to_socklist(), append_spell(), esrv_del_item(), esrv_draw_look(), esrv_new_player(), esrv_remove_spell(), esrv_send_face(), esrv_send_inventory(), esrv_send_item(), esrv_send_pickup(), esrv_update_item(), esrv_update_spells(), new_player_cmd(), send_image_sums(), and send_tick().
void SockList_AddInt64 | ( | SockList * | sl, |
uint64 | data | ||
) |
Adds a 64 bit value. sl the SockList instance to add to
data | the value to add |
Definition at line 137 of file lowlevel.c.
References SockList::buf, SockList::len, and SockList_Ensure().
Referenced by esrv_update_stats(), and send_exp_table().
void SockList_AddLen8Data | ( | SockList * | sl, |
const void * | data, | ||
size_t | len | ||
) |
Adds a data block prepended with an 8 bit length field.
sl | the SockList instance to add to |
data | the value to add |
len | the length in byte; must not exceed 255 |
Definition at line 176 of file lowlevel.c.
References SockList_AddChar(), and SockList_AddData().
Referenced by add_object_to_socklist(), append_spell(), esrv_draw_look(), esrv_new_player(), esrv_update_item(), play_sound_player_only(), and send_image_sums().
void SockList_AddPrintf | ( | SockList * | sl, |
const char * | format, | ||
... | |||
) |
Adds a printf like formatted string.
sl | the SockList instance to add to |
format | the format specifier |
Definition at line 187 of file lowlevel.c.
References SockList::buf, fatal(), SockList::len, OUT_OF_MEMORY, and vsnprintf.
Referenced by build_class_list_reply(), build_race_list_reply(), draw_magic_map(), esrv_draw_look(), esrv_print_ext_msg(), esrv_print_msg(), esrv_send_inventory(), init_connection(), send_image_info(), send_image_sums(), send_query(), send_race_info(), send_skill_info(), send_spell_paths(), set_face_mode_cmd(), set_up_cmd(), and toggle_extended_text_cmd().
Adds a 16 bit value. sl the SockList instance to add to
data | the value to add |
Definition at line 113 of file lowlevel.c.
References SockList::buf, SockList::len, and SockList_Ensure().
Referenced by add_object_to_socklist(), append_spell(), check_space_for_heads(), draw_client_map2(), esrv_draw_look(), esrv_send_animation(), esrv_send_face(), esrv_update_item(), esrv_update_spells(), map2_add_ob(), map2_delete_layer(), new_player_cmd(), send_exp_table(), send_image_sums(), and send_smooth().
void SockList_AddString | ( | SockList * | sl, |
const char * | data | ||
) |
Adds a string without length.
sl | the SockList instance to add to |
data | the value to add |
Definition at line 154 of file lowlevel.c.
References SockList_AddData().
Referenced by add_me_cmd(), build_class_list_reply(), build_race_list_reply(), draw_client_map2(), esrv_add_spells(), esrv_del_item(), esrv_draw_look(), esrv_new_player(), esrv_remove_spell(), esrv_send_animation(), esrv_send_face(), esrv_send_inventory(), esrv_send_item(), esrv_send_pickup(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), final_free_player(), map_newmap_cmd(), new_player_cmd(), play_sound_player_only(), request_info_cmd(), send_background_music(), send_exp_table(), send_plugin_custom_message(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), set_up_cmd(), SockList_AddStringBuffer(), toggle_extended_infos_cmd(), and toggle_extended_text_cmd().
void SockList_AddStringBuffer | ( | SockList * | sl, |
StringBuffer * | sb | ||
) |
Deallocates string buffer instance and appends its contents. The passed StringBuffer must not be accessed afterwards.
sl | the SockList instance to add to |
sb | the StringBuffer to deallocate |
Definition at line 210 of file lowlevel.c.
References SockList_AddString(), and stringbuffer_finish().
size_t SockList_Avail | ( | const SockList * | sl | ) |
Returns the available bytes in a SockList instance.
Definition at line 231 of file lowlevel.c.
References SockList::buf, and SockList::len.
Referenced by esrv_add_spells(), esrv_draw_look(), esrv_send_inventory(), send_exp_table(), send_image_sums(), send_skill_info(), and send_spell_paths().
|
static |
Checks that at least a given number of bytes is available in a SockList instance. Returns normal if the space is available. Otherwise calls fatal(OUT_OF_MEMORY);
sl | the SockList instance to check |
size | the number of bytes to ensure |
Definition at line 584 of file lowlevel.c.
References SockList::buf, fatal(), SockList::len, and OUT_OF_MEMORY.
Referenced by SockList_AddChar(), SockList_AddData(), SockList_AddInt(), SockList_AddInt64(), SockList_AddShort(), and SockList_NullTerminate().
void SockList_Init | ( | SockList * | sl | ) |
Initializes the SockList instance. Must be called before other socklist functions are called.
sl | the SockList instance to initialize |
Definition at line 67 of file lowlevel.c.
References SockList_Reset().
Referenced by add_me_cmd(), draw_client_map2(), draw_magic_map(), esrv_add_spells(), esrv_del_item(), esrv_draw_look(), esrv_new_player(), esrv_print_ext_msg(), esrv_print_msg(), esrv_remove_spell(), esrv_send_animation(), esrv_send_face(), esrv_send_inventory(), esrv_send_item(), esrv_send_pickup(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), final_free_player(), init_connection(), map_newmap_cmd(), new_player_cmd(), play_sound_player_only(), request_info_cmd(), send_background_music(), send_class_list(), send_exp_table(), send_image_info(), send_image_sums(), send_plugin_custom_message(), send_query(), send_race_info(), send_race_list(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), set_face_mode_cmd(), set_up_cmd(), toggle_extended_infos_cmd(), and toggle_extended_text_cmd().
void SockList_NullTerminate | ( | SockList * | sl | ) |
Adds a NUL byte without changing the length.
sl | the SockList instance to add to |
Definition at line 222 of file lowlevel.c.
References SockList::buf, SockList::len, and SockList_Ensure().
Referenced by handle_client().
int SockList_ReadPacket | ( | int | fd, |
SockList * | sl, | ||
int | len | ||
) |
This reads from fd and puts the data in sl. We return true if we think we have a full packet, 0 if we have a partial packet, or -1 if an error occurred. The only processing we do is remove the initial size value. len (As passed) is the size of the buffer allocated in the socklist. We make the assumption the buffer is at least 2 bytes long.
Definition at line 260 of file lowlevel.c.
References SockList::buf, cst_lst, cst_tot, CS_Stats::ibytes, SockList::len, llevDebug, llevError, LOG(), MAX_BUF, and strerror_local().
Referenced by handle_client().
void SockList_Reset | ( | SockList * | sl | ) |
Resets the length of the stored data for writing. Does not free or re-allocate resources.
sl | the SockList instance to reset |
Definition at line 85 of file lowlevel.c.
References SockList::len.
Referenced by build_class_list_reply(), esrv_add_spells(), esrv_draw_look(), esrv_send_inventory(), send_image_sums(), and SockList_Init().
void SockList_ResetRead | ( | SockList * | sl | ) |
Resets the length of the stored data for reading. Does not free or re-allocate resources.
sl | the SockList instance to reset |
Definition at line 94 of file lowlevel.c.
References SockList::len.
Referenced by add_player(), handle_client(), and init_connection().
void SockList_Term | ( | SockList * | sl | ) |
Frees all resources allocated by a SockList instance. Must be called when the instance is not needed anymore. Afterwards no socklist functions except SockList_Init may be called.
sl | the SockList instance to free |
Definition at line 77 of file lowlevel.c.
Referenced by add_me_cmd(), draw_client_map2(), draw_magic_map(), esrv_add_spells(), esrv_del_item(), esrv_draw_look(), esrv_new_player(), esrv_print_ext_msg(), esrv_print_msg(), esrv_remove_spell(), esrv_send_animation(), esrv_send_face(), esrv_send_inventory(), esrv_send_item(), esrv_send_pickup(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), final_free_player(), free_newsocket(), init_connection(), map_newmap_cmd(), new_player_cmd(), play_sound_player_only(), request_info_cmd(), send_background_music(), send_exp_table(), send_image_info(), send_image_sums(), send_plugin_custom_message(), send_query(), send_race_info(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), set_face_mode_cmd(), set_up_cmd(), toggle_extended_infos_cmd(), and toggle_extended_text_cmd().
void write_socket_buffer | ( | socket_struct * | ns | ) |
Writes data to socket.
When the socket is clear to write, and we have backlogged data, this is called to write it out.
Definition at line 418 of file lowlevel.c.
References socket_struct::can_write, cst_lst, cst_tot, buffer_struct::data, socket_struct::fd, buffer_struct::len, llevDebug, llevError, LOG(), MAX_BUF, Ns_Dead, CS_Stats::obytes, socket_struct::outputbuffer, SOCKETBUFSIZE, buffer_struct::start, socket_struct::status, and strerror_local().
Referenced by do_server().
|
static |
This writes data to the socket. - It is very low level - all we try and do is write out the data to the socket provided (ns). buf is the data to write, len is the number of bytes to write. IT doesn't return anything - rather, it updates the ns structure if we get an error.
Definition at line 477 of file lowlevel.c.
References add_to_buffer(), socket_struct::can_write, cst_lst, cst_tot, socket_struct::fd, llevDebug, llevError, LOG(), MAX_BUF, Ns_Dead, CS_Stats::obytes, socket_struct::status, and strerror_local().
Referenced by Send_With_Handling().