Improved events

This commit is contained in:
MaxXor 2015-09-05 22:38:59 +02:00
parent 0327f1cff1
commit 0edef3cead
4 changed files with 39 additions and 26 deletions

View File

@ -34,9 +34,10 @@ namespace xClient.Core.Networking
/// <param name="ex">The exception containing information about the cause of the client's failure.</param>
private void OnClientFail(Exception ex)
{
if (ClientFail != null)
var handler = ClientFail;
if (handler != null)
{
ClientFail(this, ex);
handler(this, ex);
}
}
@ -62,9 +63,10 @@ namespace xClient.Core.Networking
Connected = connected;
if (ClientState != null)
var handler = ClientState;
if (handler != null)
{
ClientState(this, connected);
handler(this, connected);
}
}
@ -86,9 +88,10 @@ namespace xClient.Core.Networking
/// <param name="packet">The packet that has been received by the server.</param>
private void OnClientRead(IPacket packet)
{
if (ClientRead != null)
var handler = ClientRead;
if (handler != null)
{
ClientRead(this, packet);
handler(this, packet);
}
}
@ -114,9 +117,10 @@ namespace xClient.Core.Networking
/// <param name="rawData">The packet in raw bytes.</param>
private void OnClientWrite(IPacket packet, long length, byte[] rawData)
{
if (ClientWrite != null)
var handler = ClientWrite;
if (handler != null)
{
ClientWrite(this, packet, length, rawData);
handler(this, packet, length, rawData);
}
}

View File

@ -36,9 +36,10 @@ namespace xServer.Core.Networking
Connected = connected;
if (ClientState != null)
var handler = ClientState;
if (handler != null)
{
ClientState(this, connected);
handler(this, connected);
}
}
@ -61,9 +62,10 @@ namespace xServer.Core.Networking
/// <param name="packet">The packet that received by the client.</param>
private void OnClientRead(IPacket packet)
{
if (ClientRead != null)
var handler = ClientRead;
if (handler != null)
{
ClientRead(this, packet);
handler(this, packet);
}
}
@ -89,9 +91,10 @@ namespace xServer.Core.Networking
/// <param name="rawData">The packet in raw bytes.</param>
private void OnClientWrite(IPacket packet, long length, byte[] rawData)
{
if (ClientWrite != null)
var handler = ClientWrite;
if (handler != null)
{
ClientWrite(this, packet, length, rawData);
handler(this, packet, length, rawData);
}
}

View File

@ -35,9 +35,10 @@ namespace xServer.Core.Networking
Listening = listening;
if (ServerState != null)
var handler = ServerState;
if (handler != null)
{
ServerState(this, listening, Port);
handler(this, listening, Port);
}
}
@ -61,9 +62,10 @@ namespace xServer.Core.Networking
/// <param name="connected">The new connection state of the client.</param>
private void OnClientState(Client c, bool connected)
{
if (ClientState != null)
var handler = ClientState;
if (handler != null)
{
ClientState(this, c, connected);
handler(this, c, connected);
}
}
@ -88,9 +90,10 @@ namespace xServer.Core.Networking
/// <param name="packet">The packet that received by the client.</param>
private void OnClientRead(Client c, IPacket packet)
{
if (ClientRead != null)
var handler = ClientRead;
if (handler != null)
{
ClientRead(this, c, packet);
handler(this, c, packet);
}
}
@ -118,9 +121,10 @@ namespace xServer.Core.Networking
/// <param name="rawData">The packet in raw bytes.</param>
private void OnClientWrite(Client c, IPacket packet, long length, byte[] rawData)
{
if (ClientWrite != null)
var handler = ClientWrite;
if (handler != null)
{
ClientWrite(this, c, packet, length, rawData);
handler(this, c, packet, length, rawData);
}
}

View File

@ -28,9 +28,10 @@ namespace xServer.Core.Networking
/// <param name="client">The connected client.</param>
private void OnClientConnected(Client client)
{
if (ClientConnected != null)
var handler = ClientConnected;
if (handler != null)
{
ClientConnected(client);
handler(client);
}
}
@ -51,9 +52,10 @@ namespace xServer.Core.Networking
/// <param name="client">The disconnected client.</param>
private void OnClientDisconnected(Client client)
{
if (ClientDisconnected != null)
var handler = ClientDisconnected;
if (handler != null)
{
ClientDisconnected(client);
handler(client);
}
}