Crossfire Server, Trunk
|
#include "global.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "output_file.h"
#include "shared/newclient.h"
#include "sproto.h"
#include "stats.h"
Go to the source code of this file.
Functions | |
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, unsigned char data) |
void | SockList_AddData (SockList *sl, const void *data, size_t len) |
void | SockList_AddInt (SockList *sl, uint32_t data) |
void | SockList_AddInt64 (SockList *sl, uint64_t data) |
void | SockList_AddLen16Data (SockList *sl, const void *data, size_t len) |
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_t 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) |
static void | Write_To_Socket (socket_struct *ns, const unsigned char *buf, const 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.cpp.
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 254 of file lowlevel.cpp.
References navar-midane_time::data.
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 258 of file lowlevel.cpp.
References navar-midane_time::data.
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 447 of file lowlevel.cpp.
References SockList::buf, SockList::len, Ns_Dead, socket_struct::status, and Write_To_Socket().
Referenced by account_add_player_cmd(), account_login_cmd(), account_new_cmd(), account_password(), account_play_cmd(), add_me_cmd(), create_player_cmd(), draw_client_map2(), draw_magic_map(), 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(), init_connection(), knowledge_process_incremental(), knowledge_send_info(), map_newmap_cmd(), new_player_cmd(), play_again(), play_sound_player_only(), print_ext_msg(), quest_send_initial_states(), request_info_cmd(), send_account_players(), send_background_music(), send_class_info(), send_class_list(), send_delayed_buffers(), send_exp_table(), send_file(), send_image_info(), send_image_sums(), send_new_char_info(), send_plugin_custom_message(), send_query(), send_race_info(), send_race_list(), send_skill_extra(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), and set_up_cmd().
void SockList_AddChar | ( | SockList * | sl, |
unsigned char | data | ||
) |
Adds an 8 bit value.
sl | the SockList instance to add to |
data | the value to add |
Definition at line 106 of file lowlevel.cpp.
References SockList::buf, navar-midane_time::data, SockList::len, and SockList_Ensure().
Referenced by add_char_field(), add_object_to_socklist(), append_spell(), check_space_for_heads(), draw_client_map2(), draw_magic_map(), esrv_draw_look(), esrv_send_face(), esrv_send_inventory(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), map2_add_label(), map2_add_ob(), map2_delete_layer(), play_again(), play_sound_player_only(), quest_send_initial_states(), quest_set_state(), send_account_players(), send_arch_info(), send_file(), 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 167 of file lowlevel.cpp.
References SockList::buf, navar-midane_time::data, SockList::len, and SockList_Ensure().
Referenced by append_spell(), esrv_send_face(), send_arch_info(), SockList_AddLen16Data(), SockList_AddLen8Data(), and SockList_AddString().
void SockList_AddInt | ( | SockList * | sl, |
uint32_t | data | ||
) |
Adds a 32 bit value.
sl | the SockList instance to add to |
data | the value to add |
Definition at line 127 of file lowlevel.cpp.
References SockList::buf, navar-midane_time::data, 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(), knowledge_process_incremental(), new_player_cmd(), play_again(), quest_send_initial_states(), quest_set_state(), send_image_sums(), and send_tick().
void SockList_AddInt64 | ( | SockList * | sl, |
uint64_t | data | ||
) |
Adds a 64 bit value.
sl | the SockList instance to add to |
data | the value to add |
Definition at line 140 of file lowlevel.cpp.
References SockList::buf, navar-midane_time::data, SockList::len, and SockList_Ensure().
Referenced by esrv_update_stats(), and send_exp_table().
void SockList_AddLen16Data | ( | SockList * | sl, |
const void * | data, | ||
size_t | len | ||
) |
Adds a data block prepended with an 16 bit length field.
sl | the SockList instance to add to |
data | the value to add |
len | the length in byte; must not exceed 65535 |
Definition at line 191 of file lowlevel.cpp.
References navar-midane_time::data, SockList_AddData(), and SockList_AddShort().
Referenced by knowledge_process_incremental(), quest_send_initial_states(), quest_set_state(), and send_skill_extra().
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 179 of file lowlevel.cpp.
References navar-midane_time::data, SockList_AddChar(), and SockList_AddData().
Referenced by add_object_to_socklist(), append_spell(), esrv_draw_look(), esrv_new_player(), esrv_send_inventory(), esrv_update_item(), play_sound_player_only(), send_arch_info(), send_image_sums(), and send_new_char_info().
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 202 of file lowlevel.cpp.
References SockList::buf, SockList::len, llevError, and LOG().
Referenced by account_play_cmd(), create_player_cmd(), do_print_ext(), draw_magic_map(), esrv_draw_look(), esrv_send_inventory(), init_connection(), knowledge_send_info(), send_class_info(), send_image_info(), send_image_sums(), send_map_info(), send_query(), send_race_info(), send_skill_info(), send_spell_paths(), and set_up_cmd().
void SockList_AddShort | ( | SockList * | sl, |
uint16_t | data | ||
) |
Adds a 16 bit value.
sl | the SockList instance to add to |
data | the value to add |
Definition at line 116 of file lowlevel.cpp.
References SockList::buf, navar-midane_time::data, 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_send_inventory(), esrv_update_item(), esrv_update_spells(), handle_scroll(), map2_add_ob(), map2_delete_layer(), new_player_cmd(), quest_send_initial_states(), send_account_players(), send_arch_info(), send_exp_table(), send_image_sums(), send_skill_extra(), send_smooth(), and SockList_AddLen16Data().
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 157 of file lowlevel.cpp.
References navar-midane_time::data, and SockList_AddData().
Referenced by account_add_player_cmd(), account_login_cmd(), account_new_cmd(), account_password(), account_play_cmd(), add_char_field(), add_me_cmd(), build_class_list_reply(), build_race_list_reply(), create_player_cmd(), 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(), knowledge_process_incremental(), knowledge_send_info(), map2_add_label(), map_newmap_cmd(), new_player_cmd(), play_again(), play_sound_player_only(), quest_send_initial_states(), quest_set_state(), request_info_cmd(), send_account_players(), send_arch_info(), send_background_music(), send_exp_table(), send_file(), send_new_char_info(), send_plugin_custom_message(), send_skill_extra(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), set_up_cmd(), and SockList_AddStringBuffer().
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 225 of file lowlevel.cpp.
References SockList_AddString(), and stringbuffer_finish().
size_t SockList_Avail | ( | const SockList * | sl | ) |
Returns the available bytes in a SockList instance.
Definition at line 246 of file lowlevel.cpp.
References SockList::buf, and SockList::len.
Referenced by esrv_add_spells(), esrv_draw_look(), esrv_send_inventory(), knowledge_process_incremental(), quest_send_initial_states(), send_exp_table(), send_image_sums(), send_skill_extra(), 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 95 of file lowlevel.cpp.
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 55 of file lowlevel.cpp.
References SockList_Reset().
Referenced by account_add_player_cmd(), account_login_cmd(), account_new_cmd(), account_password(), account_play_cmd(), add_me_cmd(), create_player_cmd(), do_print_ext(), draw_client_map2(), draw_magic_map(), 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(), init_connection(), knowledge_process_incremental(), knowledge_send_info(), map_newmap_cmd(), new_player_cmd(), play_again(), play_sound_player_only(), player_get_delayed_buffer(), quest_send_initial_states(), request_info_cmd(), send_account_players(), send_background_music(), send_class_info(), send_class_list(), send_exp_table(), send_file(), send_image_info(), send_image_sums(), send_map_info(), send_new_char_info(), send_plugin_custom_message(), send_query(), send_race_info(), send_race_list(), send_skill_extra(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), and set_up_cmd().
void SockList_NullTerminate | ( | SockList * | sl | ) |
Adds a NUL byte without changing the length.
sl | the SockList instance to add to |
Definition at line 237 of file lowlevel.cpp.
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 275 of file lowlevel.cpp.
References SockList::buf, cst_lst, cst_tot, CS_Stats::ibytes, if(), SockList::len, llevDebug, llevError, LOG(), and nlohmann::detail::void().
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 74 of file lowlevel.cpp.
References SockList::len.
Referenced by build_class_list_reply(), esrv_add_spells(), esrv_draw_look(), esrv_send_inventory(), knowledge_process_incremental(), quest_send_initial_states(), 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 83 of file lowlevel.cpp.
References SockList::len.
Referenced by account_play_cmd(), handle_client(), init_connection(), and set_player_socket().
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 65 of file lowlevel.cpp.
References nlohmann::detail::void().
Referenced by account_add_player_cmd(), account_login_cmd(), account_new_cmd(), account_password(), account_play_cmd(), add_me_cmd(), create_player_cmd(), draw_client_map2(), draw_magic_map(), 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(), free_newsocket(), init_connection(), knowledge_process_incremental(), knowledge_send_info(), map_newmap_cmd(), new_player_cmd(), play_again(), play_sound_player_only(), print_ext_msg(), quest_send_initial_states(), request_info_cmd(), send_account_players(), send_background_music(), send_class_info(), send_exp_table(), send_file(), send_image_info(), send_image_sums(), send_new_char_info(), send_plugin_custom_message(), send_query(), send_race_info(), send_skill_extra(), send_skill_info(), send_smooth(), send_spell_paths(), send_tick(), and set_up_cmd().
|
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 399 of file lowlevel.cpp.
References buf, cst_lst, cst_tot, socket_struct::fd, llevDebug, llevError, llevInfo, LOG(), Ns_Dead, CS_Stats::obytes, and socket_struct::status.
Referenced by Send_With_Handling().