Handle Events

RconEvent event

The most basic way to handle events is to create an event handler for RconEvent.

RconClient client;


//adding an event handler as a lambda, but usually better to create your own method
client.RconEvent += (sender, args) =>
    Console.WriteLine("Event: {0}", args.EventName);

RconEvent is a very simple event that provides the raw data of RCON's events. There is a more useful way to use RCON events, though.


The RconEventManager class provides a useful way to interact with RCON events.

RconClient client;
RconEventManager events = new RconEventManager ();


//add the source for events, the client
//if you desire, you can use one RconEventManager for multiple clients
events.AddEventProvider(client, client);

events.PlayerAuthenticated += (sender, e) =>
    Console.WriteLine("Player authenticated: {0}", e.Player.Id);

//it's usually a good idea to remove the client if you ever need to ditch it

One odd thing you may note is that we passed the client twice in AddEventProvider. AddEventProvider always takes an IRconEventProvider, which contains the RconEvent event, which RconClient implements. One overload of AddEventProvider also takes an ISynchronousRconClient, which RconClient also implements.

If you provide the ISynchronousRconClient, RconEventManager will attempt to get more information if necessary to make these events more useful.

For instance, some events only provide a player's name. This feature will attempt to get more information about a player, rather than leave you with just the name.

Last edited Dec 7, 2013 at 11:45 PM by Timiz0r, version 1