Polling server events

This is the last step of the server integration! 😆

Events must be polled as often as possible, preferably every “server frame”.

The server-side events are:

  • equ8_event_id_send_request. EQU8 has data to send.

  • equ8_event_id_status. Status for the given user has changed (banned for instance).

If we received a equ8_event_id_send_request event, EQU8 has data that should be sent to the client.

If we received a equ8_event_id_status event, the status for the given client has changed; we simply re-run the user_is_allowed_to_play-function.

EQU8 will NEVER send more than 256 (0x100) bytes in a single packet.

C/C++

C/C++
C#
C/C++
switch(equ8_sm_poll_event(c.unique_id(), &equ8_data))
{
case equ8_event_id_send_request:
{
std::cout << "EQU8 Data Send Request: user: '"
<< c.unique_id() << "' size: "
<< equ8_data.send_request.size << std::endl;
packet_equ8_data session{
equ8_data.send_request.payload,
equ8_data.send_request.size };
//
// Send the EQU8 data to the client
//
send_packet(c, &session);
break;
}
case equ8_event_id_status:
{
if(!user_is_allowed_to_play(c.remote_in(), c.unique_id(),
equ8_data.status.action))
{
std::cout << "Client '" << c.unique_id()
<< "' kicked (action: "
<< equ8_data.status.action << ")" << std::endl;
return false;
}
break;
}
}
C#
switch (equ8.session_manager.poll_event(c.name, ev))
{
case equ8.equ8_event_id.send_request:
{
Console.WriteLine(
"EQU8 Data Send Request: user: '{0}' size: {1}",
c.name, ev.get_send_event_size());
send_packet(c, new packet_equ8_data(
ev.duplicate_send_event()));
}
break;
case equ8.equ8_event_id.status:
{
var action = ev.get_status_action();
if (!user_is_allowed_to_play(c.addr, c.name, action))
{
Console.WriteLine("Client '{0}' kicked (action: {1})",
c.name, action);
remove_client(i);
}
}
break;
}