on_server

The event is executed when the server receives a message from a client. The event_type variable is set to the type of the message. When the message contains a string, a pointer to the received string is passed as parameter to the function.

Remarks:

There are 5 types of server events:
EVENT_JOIN A client has joined the session. The client name is passed as the first argument,  LC  the client number as the second argument.
EVENT_LEAVE A client has left the session. The client name is passed as the first argument,  LC  the client number as the second argument..
EVENT_STRING A client has updated a string to the server with send_string_to. The string pointer is passed as the first argument,  LC  the client number as the second argument.
EVENT_VAR A client has updated a variable or a struct to the server with send_var_to.  LC  The variable address is passed as the first argument, the client number as the second argument.
EVENT_DATA  LC  A client has sent a data buffer to the server with send_data_to. The buffer address is passed as the first argument, the client number as the second argument. The buffer is only valid during the first frame of the event function and deallocated afterwards.

Example (lite-C):

TEXT* tJoin = { string(""); flags = SHOW; }

function server_event(void* str,var id)
{
  if (event_type == EVENT_JOIN)
 	{
 	  str_cpy((tJoin.pstring)[0],str); // contains the client's name
 	  str_cat((tJoin.pstring)[0]," has just joined!");
 	}
	else if (event_type == EVENT_LEAVE)
	{
 	  str_cpy((tJoin.pstring)[0],str); 
 	  str_cat((tJoin.pstring)[0]," has just left!");
	}
	else if ((event_type == EVENT_STRING) && (str == &mystring)) 
	{
 	  str_cpy((tJoin.pstring)[0],"STRING mystring was just changed!"); 
	}
}

...
on_server = server_event;

See also:

on_client, send_string_to, send_var_to, send_data_to ► latest version online