Lesson 6: Messages
Plugins can use the engine's send and receive functions for sending user-defined
messages over the network in a multiplayer environment. For this, the SendPacket
and ReveivePacket function pointers are available in the ENGINE_VARS* ev struct.
SendPacket(long to,void *data,long size,long guaranteed)
sends a user defined packet of bytes from the client to the server, or vice versa.
Parameters:
to - Identifier number for the client to receive the message. Set to 0
for sending to all clients.
data - Data packet to be sent. First byte must be 17 (0x11) for identifying
a user-defined packet.
size - Size of the packet in bytes.
guaranteed - DPNSEND_GUARANTEED (0x08) for reliable mode, 0 for
unreliable mode.
ReceivePacket(long from,void *data,long size)
can be set to a user provided void(long,void*,long) function that receives and
interprets messages sent with SendPacket.
Parameters:
from - ID Number of the sender. If at 0, the message was received from
the server.
data - Data packet to be sent. First byte is always 17 (0x11)
for identifying a user-defined packet.
size - Size of the packet in bytes.
Note that the receive function should be very short and mainly just store
the message, for not interfering the receive process. It must not send, open
a file, render, or do anything time consuming.
Examples:
DLLFUNC var send_string(ENTITY_T* ent, char *string)
{
(*ev->SendPacket)(ent->client_id,string,strlen(string),0);
return _VAR(1);
}
typedef void (*type_receive)(long,void*,long);
DLLFUNC var init_receive(type_receive receivefunction)
{
ev->ReceivePacket = receivefunction;
return _VAR(1);
}
For handling windows messages to the engine window, the ScanMessage function pointer
can be set to a user defined message handler:
ScanMessage(UINT message, WPARAM w_param, LPARAM l_param)
can be set to a message handler that links into the engine's main
message loop. If is called every time a message event is sent to the engine window.
The parameters are the same as for window messages. If the user-provided handler returns 0, the engine's own message handler is executed afterwards. Returning nonzero prevents the engine message handler from interpreting that message
Parameters:
message - message identifier
w_param, l_param: message parameters
See also:
on_scanmessage
► latest
version online