Crossfire Server, Trunk
lowlevel.cpp File Reference
#include "global.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "shared/newclient.h"
#include "sproto.h"
+ Include dependency graph for lowlevel.cpp:

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)
 

Detailed Description

Low-level socket-related functions.

Date
2003-12-02

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.

Function Documentation

◆ GetInt_String()

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 251 of file lowlevel.cpp.

References navar-midane_time::data.

Referenced by inscribe_scroll_cmd(), lock_item_cmd(), mark_item_cmd(), and new_player_cmd().

+ Here is the caller graph for this function:

◆ GetShort_String()

short GetShort_String ( const unsigned char *  data)

Definition at line 255 of file lowlevel.cpp.

References navar-midane_time::data.

Referenced by new_player_cmd().

+ Here is the caller graph for this function:

◆ Send_With_Handling()

◆ SockList_AddChar()

◆ SockList_AddData()

void SockList_AddData ( SockList sl,
const void *  data,
size_t  len 
)

Adds a data block.

Parameters
slthe SockList instance to add to
datathe value to add
lenthe length in byte

Definition at line 164 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_AddInt()

void SockList_AddInt ( SockList sl,
uint32_t  data 
)

◆ SockList_AddInt64()

void SockList_AddInt64 ( SockList sl,
uint64_t  data 
)

Adds a 64 bit value.

Parameters
slthe SockList instance to add to
datathe value to add

Definition at line 137 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_AddLen16Data()

void SockList_AddLen16Data ( SockList sl,
const void *  data,
size_t  len 
)

Adds a data block prepended with an 16 bit length field.

Parameters
slthe SockList instance to add to
datathe value to add
lenthe length in byte; must not exceed 65535

Definition at line 188 of file lowlevel.cpp.

References navar-midane_time::data, SockList_AddData(), and SockList_AddShort().

Referenced by knowledge_process_incremental(), quest_send_initial_states(), and quest_set_state().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_AddLen8Data()

void SockList_AddLen8Data ( SockList sl,
const void *  data,
size_t  len 
)

Adds a data block prepended with an 8 bit length field.

Parameters
slthe SockList instance to add to
datathe value to add
lenthe length in byte; must not exceed 255

Definition at line 176 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_AddPrintf()

void SockList_AddPrintf ( SockList sl,
const char *  format,
  ... 
)

Adds a printf like formatted string.

Parameters
slthe SockList instance to add to
formatthe format specifier

Definition at line 199 of file lowlevel.cpp.

References SockList::buf, fatal(), SockList::len, and OUT_OF_MEMORY.

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_AddShort()

void SockList_AddShort ( SockList sl,
uint16_t  data 
)

◆ SockList_AddString()

◆ 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.

Parameters
slthe SockList instance to add to
sbthe StringBuffer to deallocate

Definition at line 222 of file lowlevel.cpp.

References SockList_AddString(), and stringbuffer_finish().

+ Here is the call graph for this function:

◆ SockList_Avail()

size_t SockList_Avail ( const SockList sl)

Returns the available bytes in a SockList instance.

Returns
the available bytes

Definition at line 243 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_info(), and send_spell_paths().

+ Here is the caller graph for this function:

◆ SockList_Ensure()

static void SockList_Ensure ( const SockList sl,
size_t  size 
)
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);

Parameters
slthe SockList instance to check
sizethe number of bytes to ensure

Definition at line 92 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_Init()

◆ SockList_NullTerminate()

void SockList_NullTerminate ( SockList sl)

Adds a NUL byte without changing the length.

Parameters
slthe SockList instance to add to

Definition at line 234 of file lowlevel.cpp.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by handle_client().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_ReadPacket()

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 272 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SockList_Reset()

void SockList_Reset ( SockList sl)

Resets the length of the stored data for writing. Does not free or re-allocate resources.

Parameters
slthe SockList instance to reset

Definition at line 71 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().

+ Here is the caller graph for this function:

◆ SockList_ResetRead()

void SockList_ResetRead ( SockList sl)

Resets the length of the stored data for reading. Does not free or re-allocate resources.

Parameters
slthe SockList instance to reset

Definition at line 80 of file lowlevel.cpp.

References SockList::len.

Referenced by account_play_cmd(), handle_client(), init_connection(), and set_player_socket().

+ Here is the caller graph for this function:

◆ SockList_Term()

◆ Write_To_Socket()

static void Write_To_Socket ( socket_struct ns,
const unsigned char *  buf,
const int  len 
)
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 396 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: