RevenantX / LiteNetLib

Lite reliable UDP library for Mono and .NET
https://revenantx.github.io/LiteNetLib/index.html
MIT License
3.06k stars 495 forks source link

Add TryGetPeerById helper method #479

Closed chrisnobrega closed 2 years ago

chrisnobrega commented 2 years ago

Added TryGet helper method for GetPeerById:

GetPeerById example usage (current):

NetPeer peer = this.netManager.GetPeerById (peerIdentifier);

if (peer != null)
{
    peer.Send (writer, deliveryMethod);
}

TryGetPeerById example usage (new):

if (this.netManager.TryGetPeerById (peerIdentifier, out NetPeer peer))
{
    peer.Send (writer, deliveryMethod);
}
RevenantX commented 2 years ago

@chrisnobrega what are you trying to do? This is strange library usage. In most cases you store peers or use Peer.Tag for storing your own info.

chrisnobrega commented 2 years ago

@chrisnobrega what are you trying to do? This is strange library usage. In most cases you store peers or use Peer.Tag for storing your own info.

I will probably roll my own id system, but at the moment I'm using NetPeer ids for identification.

I'm using TryGetPeerById to check if the given peer exists before messaging it.