private void _DeliveryHandler(UDPManagerEvent e) { if (e.UDPdataInfo.ChannelName.Substring(0, 7) == UDPManager._UDPMRCP && e.UDPdataInfo.Data.messageType.ToString() == "ping") { //implements ping feature UDPPeer peer = this._peers.Where(a => a.Address == e.UDPdataInfo.RemoteAddress).Where(a => a.Port == e.UDPdataInfo.RemotePort).FirstOrDefault(); peer.StartPingTimer(); peer.SetPing(e.UDPdataInfo.Ping); this.DispatchEvent(new UDPServerEvent(UDPServerEvent.Names.CLIENT_PONG, peer)); } else { this.DispatchEvent(new UDPManagerEvent(UDPManagerEvent.Names.DATA_DELIVERED, e.UDPdataInfo)); //redispatch } }
// //private methods // //UDPManagerEvents listeners private void _ReceivedDataHandler(UDPManagerEvent e) { UDPPeer peer; if (e.UDPdataInfo.ChannelName == UDPManager._UDPMRCC && e.UDPdataInfo.Data.messageType.ToString() == "newConnection") { //implements connection feature peer = this._GetPeerByAddress(e.UDPdataInfo.RemoteAddress, e.UDPdataInfo.RemotePort); if (peer == null) { peer = new UDPPeer(e.UDPdataInfo.RemoteAddress, e.UDPdataInfo.RemotePort); this._peers.Add(peer); this._udpManager._udpServerPeers.Add(peer); this._udpManager._AddHiddenClientPingChannel(peer.ID); peer.AddEventListener <Event>("ping", this._PingTimerHandler); peer.StartPingTimer(); this.DispatchEvent(new UDPServerEvent(UDPServerEvent.Names.CLIENT_CONNECTED, peer)); } else { this.DispatchEvent(new UDPServerEvent(UDPServerEvent.Names.CLIENT_RECONNECTED, peer)); } } else if (e.UDPdataInfo.ChannelName == UDPManager._UDPMRCP && e.UDPdataInfo.Data.messageType.ToString() == "ping") { //implements ping feature //do nothing } else { peer = this._peers.Where(a => a.Address == e.UDPdataInfo.RemoteAddress).Where(a => a.Port == e.UDPdataInfo.RemotePort).FirstOrDefault(); if (peer != null) { this.DispatchEvent(new UDPServerEvent(UDPServerEvent.Names.CLIENT_SENT_DATA, peer, e.UDPdataInfo)); } this.DispatchEvent(new UDPManagerEvent(UDPManagerEvent.Names.DATA_RECEIVED, e.UDPdataInfo)); //redispatch } }