Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

All Data Structures Files Functions Variables Typedefs Macros Groups
Data Structures | Macros | Typedefs | Functions
NETWORK MESSAGE: tools to serialize integers, double, N_STR from and back to a single N_STRmessage

## Data Structures

struct | NETW_MSG

## Macros

#define | NETMSG_IDENT_REQUEST 0
#define | NETMSG_IDENT_REPLY_OK 1
#define | NETMSG_IDENT_REPLY_NOK 2
#define | NETMSG_STRING 3
#define | NETMSG_POSITION 4
#define | NETMSG_PING_REQUEST 5
#define | NETMSG_PING_REPLY 6
#define | NETMSG_GET_BOX 7
#define | NETMSG_BOX 8

## Typedefs

typedef struct NETW_MSG | NETW_MSG

## Functions

double | double_swap (double value)
| Swap bytes endiannes for a double. More...
double | htond (double value)
| If needed swap bytes for a double. More...
double | ntohd (double value)
| If needed swap bytes for a double. More...
int | create_msg (NETW_MSG **msg)
| Create a NETW_MSG *object. More...
int | delete_msg (NETW_MSG **msg)
| Delete a NETW_MSG *object. More...
int | empty_msg (NETW_MSG **msg)
| Empty a NETW_MSG *object. More...
int | add_nb_to_msg (NETW_MSG *msg, double value)
| Add an float to the message. More...
int | add_int_to_msg (NETW_MSG *msg, int value)
| Add an int to the int list int the message. More...
int | add_nstrptr_to_msg (NETW_MSG *msg, N_STR *str)
| Add a string to the string list in the message. More...
int | add_nstrdup_to_msg (NETW_MSG *msg, N_STR *str)
| Add a copy of str to the string list in the message. More...
int | add_strdup_to_msg (NETW_MSG *msg, char *str)
| Add a copy of char *str to the string list in the message. More...
int | get_int_from_msg (NETW_MSG *msg, int *value)
| Get a number from a message number list. More...
int | get_nb_from_msg (NETW_MSG *msg, double *value)
| Get a number from a message number list. More...
int | get_nstr_from_msg (NETW_MSG *msg, N_STR **str)
| Get a string from a message string list. More...
int | get_str_from_msg (NETW_MSG *msg, char **str)
| Get a string from a message string list. More...
N_STR * | make_str_from_msg (NETW_MSG *msg)
| Make a single string of the message. More...
NETW_MSG * | make_msg_from_str (N_STR *str)
| Make a single message of the string. More...
int | netw_msg_get_type (N_STR *msg)
| Get the type of message without killing the first number. Use with netw_get_XXX. More...
int | netw_send_ident (NETWORK *netw, int type, int id, N_STR *name, N_STR *passwd)
| Add a formatted NETWMSG_IDENT message to the specified network. More...
int | netw_send_position (NETWORK *netw, int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp)
| Add a formatted NETWMSG_IDENT message to the specified network. More...
int | netw_send_string_to_all (NETWORK *netw, int id, char *name, char *chan, char *txt, int color)
| Add a string to the network, aiming all server-side users. More...
int | netw_send_string_to (NETWORK *netw, int id_from, int id_to, char *name, char *txt, int color)
| Add a string to the network, aiming a specific user. More...
int | netw_send_ping (NETWORK *netw, int type, int id_from, int id_to, int time)
| Add a ping reply to the network. More...
int | netw_get_ident (N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd)
| Retrieves identification from netwmsg. More...
int | netw_get_position (N_STR *msg, int *id, double *X, double *Y, double *vx, double *vy, double *acc_x, double *acc_y, int *time_stamp)
| Retrieves position from netwmsg. More...
int | netw_get_string (N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color)
| Retrieves string from netwmsg. More...
int | netw_get_ping (N_STR *msg, int *type, int *from, int *to, int *time)
| Retrieves a ping travel elapsed time. More...

## Detailed Description

## Macro Definition Documentation

#define NETMSG_BOX 8

Network Message is box retrieving reply: (int x , int y , int z , N_STR *data )

Definition at line 44 of file n_network_msg.h.

#define NETMSG_GET_BOX 7

Network Message is box retrieve: int x , int y , int z

Definition at line 42 of file n_network_msg.h.

#define NETMSG_IDENT_REPLY_NOK 2

Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name , (N_STR *)password

Definition at line 32 of file n_network_msg.h.

#define NETMSG_IDENT_REPLY_OK 1

Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name , (N_STR *)password

Definition at line 30 of file n_network_msg.h.

#define NETMSG_IDENT_REQUEST 0

Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password

Definition at line 28 of file n_network_msg.h.

#define NETMSG_PING_REPLY 6

Network Message is ping reply: (int)type , (int)id_from , (int)id_to

Definition at line 40 of file n_network_msg.h.

#define NETMSG_PING_REQUEST 5

Network Message is ping request: (int)type , (int)id_from , (int)id_to

Definition at line 38 of file n_network_msg.h.

#define NETMSG_POSITION 4

Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,(int)vx ,(int)vy , (int)speed , (int)acceleration , (int)time_stamp

Definition at line 36 of file n_network_msg.h.

#define NETMSG_STRING 3

Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text , (int)color

Definition at line 34 of file n_network_msg.h.

## Typedef Documentation

typedef struct NETW_MSG NETW_MSG

network message, array of char and int

## Function Documentation

add_int_to_msg | ( | NETW_MSG * | msg,
|  | int | value
| ) |  |

Add an int to the int list int the message.

Parameters

  msg | A NETW_MSG *object to complete with the value
  value | The value to add to the message

Returns
  TRUE or FALSE

Definition at line 180 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

add_nb_to_msg | ( | NETW_MSG * | msg,
|  | double | value
| ) |  |

Add an float to the message.

Parameters

  msg | A NETW_MSG *object to complete with the value
  value | The value to add to the message

Warning
  The floating value will be rounded by the network serialization !

Returns
  TRUE or FALSE

Definition at line 158 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

add_nstrdup_to_msg | ( | NETW_MSG * | msg,
|  | N_STR * | str
| ) |  |

Add a copy of str to the string list in the message.

Parameters

  msg | A NETW_MSG *object to complete with the string
  str | The string to add to the message

Returns
  TRUE or FALSE

Definition at line 218 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

add_nstrptr_to_msg | ( | NETW_MSG * | msg,
|  | N_STR * | str
| ) |  |

Add a string to the string list in the message.

Parameters

  msg | A NETW_MSG *object to complete with the string
  str | The string to add to the message

Returns
  TRUE or FALSE

Definition at line 202 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

add_strdup_to_msg | ( | NETW_MSG * | msg,
|  | char * | str
| ) |  |

Add a copy of char *str to the string list in the message.

Parameters

  msg | A NETW_MSG *object to complete with the string
  str | The string to add to the message

Returns
  TRUE or FALSE

Definition at line 236 of file n_network_msg.c.

Here is the call graph for this function:

create_msg | ( | NETW_MSG ** | msg | ) |

Create a NETW_MSG *object.

Parameters

  msg | A NETW_MSG *object

Returns
  TRUE or FALSE

Definition at line 77 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

delete_msg | ( | NETW_MSG ** | msg | ) |

Delete a NETW_MSG *object.

Parameters

  msg | A NETW_MSG *object to delete

Returns
  TRUE or FALSE

Definition at line 105 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static double double_swap | ( | double | value | ) |

Swap bytes endiannes for a double.

Parameters

  value | The double to swap

Returns
  A swapped double

Definition at line 17 of file n_network_msg.c.

Here is the caller graph for this function:

empty_msg | ( | NETW_MSG ** | msg | ) |

Empty a NETW_MSG *object.

Parameters

  msg | A NETW_MSG **object

Returns
  TRUE or FALSE

Definition at line 138 of file n_network_msg.c.

Here is the call graph for this function:

get_int_from_msg | ( | NETW_MSG * | msg,
|  | int * | value
| ) |  |

Get a number from a message number list.

Parameters

  msg | A NETW_MSG *object for extracting number
  value | A int value where you want to store the result

Returns
  A pointer to the N_STR, Do not forget to free it !

Definition at line 280 of file n_network_msg.c.

Here is the caller graph for this function:

int get_nb_from_msg | ( | NETW_MSG * | msg,
|  | double * | value
| ) |  |

Get a number from a message number list.

Parameters

  msg | A NETW_MSG *object for extracting number
  value | A int value where you want to store the result

Returns
  A pointer to the N_STR, Do not forget to free it !

Definition at line 256 of file n_network_msg.c.

Here is the caller graph for this function:

get_nstr_from_msg | ( | NETW_MSG * | msg,
|  | N_STR ** | value
| ) |  |

Get a string from a message string list.

Parameters

  msg | The NETW_MSG where you have a str to get
  value | A pointer to a NULL N_STR for storage

Returns
  TRUE or FALSE

Definition at line 305 of file n_network_msg.c.

Here is the caller graph for this function:

get_str_from_msg | ( | NETW_MSG * | msg,
|  | char ** | value
| ) |  |

Get a string from a message string list.

Parameters

  msg | The NETW_MSG where you have a str to get
  value | A pointer to a NULL N_STR for storage

Returns
  TRUE or FALSE

Definition at line 332 of file n_network_msg.c.

Here is the caller graph for this function:

static double htond | ( | double | value | ) |

If needed swap bytes for a double.

Parameters

  value | The value to eventually swap

Returns
  The modified value

Definition at line 43 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

make_msg_from_str | ( | N_STR * | str | ) |

Make a single message of the string.

Parameters

  str | A N_STR structure to convert into a NETW_MSG one

Returns
  A pointer to the generated NETW_MSG, do not forget to free it after use !

Definition at line 476 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

make_str_from_msg | ( | NETW_MSG * | msg | ) |

Make a single string of the message.

Parameters

  msg | A NETW_MSG structure to convert into a N_STR one

Returns
  A pointer to the generated N_STR, do not forget to free it after use !

Definition at line 360 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int netw_get_ident | ( | N_STR * | msg,
|  | int * | type,
|  | int * | ident,
|  | N_STR ** | name,
|  | N_STR ** | passwd
| ) |  |

Retrieves identification from netwmsg.

Parameters

  msg | The source string from which we are going to extract the data
  type | NETMSG_IDENT_NEW , NETMSG_IDENT_REPLY_OK , NETMSG_IDENT_REPLY_NOK , NETMSG_IDENT_REQUEST
  ident | ID for the user
  name | Name of the user
  passwd | Password of the user

Returns
  TRUE or FALSE

Definition at line 817 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

netw_get_ping | ( | N_STR * | msg,
|  | int * | type,
|  | int * | from,
|  | int * | to,
|  | int * | time
| ) |  |

Retrieves a ping travel elapsed time.

Parameters

  msg | The source string from which we are going to extract the data
  type | NETW_PING_REQUEST or NETW_PING_REPLY
  from | Identifiant of the sender
  to | Targetted Identifiant, -1 for server ping
  time | The time it was when the ping was sended

Returns
  TRUE or FALSE

Definition at line 953 of file n_network_msg.c.

Here is the call graph for this function:

int netw_get_position | ( | N_STR * | msg,
|  | int * | id,
|  | double * | X,
|  | double * | Y,
|  | double * | vx,
|  | double * | vy,
|  | double * | acc_x,
|  | double * | acc_y,
|  | int * | time_stamp
| ) |  |

Retrieves position from netwmsg.

Parameters

  msg | The source string from which we are going to extract the data
  id |
  X | X position inside a big grid
  Y | Y position inside a big grid
  vx | X speed
  vy | Y speed
  acc_x | X acceleration
  acc_y | Y acceleration
  time_stamp | Current Time when it was sended (for some delta we would want to compute )

Returns
  TRUE or FALSE

Definition at line 860 of file n_network_msg.c.

Here is the call graph for this function:

netw_get_string | ( | N_STR * | msg,
|  | int * | id,
|  | N_STR ** | name,
|  | N_STR ** | chan,
|  | N_STR ** | txt,
|  | int * | color
| ) |  |

Retrieves string from netwmsg.

Parameters

  msg | The source string from which we are going to extract the data
  id | The ID of the sending client
  name | Name of user
  chan | Target Channel, if any. Pass "ALL" to target the default channel
  txt | The text to send
  color | The color of the text

Returns
  TRUE or FALSE

Definition at line 907 of file n_network_msg.c.

Here is the call graph for this function:

netw_msg_get_type | ( | N_STR * | msg | ) |

Get the type of message without killing the first number. Use with netw_get_XXX.

Parameters

  msg | A char *msg_object you want to have type

Returns
  The value corresponding to the type or FALSE

Definition at line 569 of file n_network_msg.c.

int netw_send_ident | ( | NETWORK * | netw,
|  | int | type,
|  | int | id,
|  | N_STR * | name,
|  | N_STR * | passwd
| ) |  |

Add a formatted NETWMSG_IDENT message to the specified network.

Parameters

  netw | The aimed NETWORK where we want to add something to send
  type | type of identification ( NETW_IDENT_REQUEST , NETW_IDENT_NEW )
  id | The ID of the sending client
  name | Username
  passwd | Password

Returns
  TRUE or FALSE

Definition at line 598 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

netw_send_ping | ( | NETWORK * | netw,
|  | int | id_from,
|  | int | id_to,
|  | int | time,
|  | int | type
| ) |  |

Add a ping reply to the network.

Parameters

  netw | The aimed NETWORK where we want to add something to send
  id_from | Identifiant of the sender
  id_to | Identifiant of the destination, -1 if the serveur itslef is targetted
  time | The time it was when the ping was sended
  type | NETW_PING_REQUEST or NETW_PING_REPLY

Returns
  TRUE or FALSE

Definition at line 781 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

netw_send_position | ( | NETWORK * | netw,
|  | int | id,
|  | double | X,
|  | double | Y,
|  | double | vx,
|  | double | vy,
|  | double | acc_x,
|  | double | acc_y,
|  | int | time_stamp
| ) |  |

Add a formatted NETWMSG_IDENT message to the specified network.

Parameters

  netw | The aimed NETWORK where we want to add something to send
  id | The ID of the sending client
  X | X position inside a big grid
  Y | Y position inside a big grid
  vx | X speed
  vy | Y speed
  acc_x | Y acceleration
  acc_y | X acceleration
  time_stamp | Current Time when sending (for some delta we would want to compute )

Returns
  TRUE or FALSE

Definition at line 637 of file n_network_msg.c.

Here is the call graph for this function:

netw_send_string_to | ( | NETWORK * | netw,
|  | int | id_from,
|  | int | id_to,
|  | char * | name,
|  | char * | txt,
|  | int | color
| ) |  |

Add a string to the network, aiming a specific user.

Parameters

  netw | The aimed NETWORK where we want to add something to send
  id_from | The ID of the sending client
  id_to | The ID of the targetted client
  name | Sender Name
  txt | Sender text
  color | Sender text color

Returns
  TRUE or FALSE

Definition at line 732 of file n_network_msg.c.

Here is the call graph for this function:

netw_send_string_to_all | ( | NETWORK * | netw,
|  | int | id,
|  | char * | name,
|  | char * | chan,
|  | char * | txt,
|  | int | color
| ) |  |

Add a string to the network, aiming all server-side users.

Parameters

  netw | The aimed NETWORK where we want to add something to send
  id | The ID of the sending client
  name | Name of user
  chan | Target Channel, if any. Pass "ALL" to target the default channel
  txt | The text to send
  color | The color of the text

Returns
  TRUE or FALSE;

Definition at line 678 of file n_network_msg.c.

Here is the call graph for this function:

static double ntohd | ( | double | value | ) |

If needed swap bytes for a double.

Parameters

  value | The value to eventually swap

Returns
  The modified value

Definition at line 60 of file n_network_msg.c.

Here is the call graph for this function:

Here is the caller graph for this function: