TGB/Networking/Peer Access
From TDN
TGB Networking >> Peer Access
Connected Clients Knowing About their Peers
When a client connects to the server, all the clients already connected to the server are told about the new client's connection via the messaging system message callback "ClientJoined". Similarly, the client that is connecting to the server is told about all of the existing client connections via the "ClientJoined" message as well.
When any client disconnects from the server for any reason, the "ClientDropped" message is sent from the server to all clients with the client object as its parameter. When a client is kicked from the server, the clients are notified via the "MsgAdminForce" message with the kick or ban notice as a string parameter.
Clients can keep references to their peers in a group object by maintaining the group in the callbacks for the "ClientJoined" and "ClientDropped" messages.
$PeerGroup = new SimSet();
function clientJoined(%client)
{
$PeerGroup.add(%client);
}
function clientDropped(%client)
{
$PeerGroup.remove(%client);
}
At any time, the client can then check its client list by running through the $PeerGroup:
for (%i = 0; %i < $PeerGroup.getCount(); %i++) {
%peer = $PeerGroup.getObject(%i);
echo("Peer: " @ %peer);
}
Categories: Networking | Server | Client | TGB



