Ejemplo n.º 1
0
 /// <summary>
 /// Disconnect the connected UDPPeer</summary>
 public void KickClient(UDPPeer peer)
 {
     this._peers.RemoveAt(this._peers.IndexOf(peer));
     this._udpManager._udpServerPeers.RemoveAt(this._udpManager._udpServerPeers.IndexOf(peer));
     this._udpManager._RemoveHiddenClientPingChannel(peer.ID);
     peer.RemoveEventListener <Event>("ping", this._PingTimerHandler);
     peer.Close();
 }
Ejemplo n.º 2
0
 private void _CancelHandler(UDPManagerEvent e)
 {
     if (e.UDPdataInfo.ChannelName.Substring(0, 7) == UDPManager._UDPMRCP && e.UDPdataInfo.Data.messageType.ToString() == "ping")
     {   //implements time out feature
         UDPPeer peer = this._peers.Where(a => a.Address == e.UDPdataInfo.RemoteAddress).Where(a => a.Port == e.UDPdataInfo.RemotePort).FirstOrDefault();
         this.KickClient(peer);
         this.DispatchEvent(new UDPServerEvent(UDPServerEvent.Names.CLIENT_TIMED_OUT, peer));
     }
     else
     {
         this.DispatchEvent(new UDPManagerEvent(UDPManagerEvent.Names.DATA_CANCELED, e.UDPdataInfo));      //redispatch
     }
 }
Ejemplo n.º 3
0
 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
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Resets the UDPClient. Means disconnect, unbind, and remove the UDPChannels if you specify the parameter as true</summary>
 /// <param name='removeChannels'></param>
 public void Close(bool removeChannels = true)
 {
     this._connecting = false;
     this._udpManager._UDPClientConnecting = null;
     this._connected = false;
     if (this._udpServer != null)
     {
         this._udpServer.Close();
     }
     this._udpServer = null;
     if (removeChannels)
     {
         this._udpManager._CloseHiddenChannels();
     }
     this._udpManager.Close(removeChannels);
 }
Ejemplo n.º 5
0
 private void _DeliveryHandler(UDPManagerEvent e)
 {
     if (e.UDPdataInfo.ChannelName == UDPManager._UDPMRCC && e.UDPdataInfo.Data.messageType.ToString() == "newConnection")
     {
         this._udpServer = new UDPPeer(e.UDPdataInfo.RemoteAddress, e.UDPdataInfo.RemotePort);
         this._udpServer.AddEventListener <Event>("ping", this._PingTimerHandler);
         this._udpServer.StartPingTimer();
         this._connecting = false;
         this._udpManager._UDPClientConnecting = null;
         this._connected = true;
         this.DispatchEvent(new UDPClientEvent(UDPClientEvent.Names.CONNECTED_TO_SERVER, this._udpServer));
     }
     else if (e.UDPdataInfo.ChannelName == UDPManager._UDPMRCP && e.UDPdataInfo.Data.messageType.ToString() == "ping")
     {
         this._udpServer.SetPing(e.UDPdataInfo.Ping);
         this._udpServer.StartPingTimer();
         this.DispatchEvent(new UDPClientEvent(UDPClientEvent.Names.SERVER_PONG, this._udpServer));
     }
     else
     {
         this.DispatchEvent(new UDPManagerEvent(UDPManagerEvent.Names.DATA_DELIVERED, e.UDPdataInfo));
     }
 }
Ejemplo n.º 6
0
        //
        //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
            }
        }
Ejemplo n.º 7
0
        //ping handling event
        private void _PingTimerHandler(Event e)
        {
            UDPPeer peer = e.Target as UDPPeer;

            this.SendToClient(UDPManager._UDPMRCP + ":" + peer.ID, new { messageType = "ping" }, peer);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Disconnect the connected UDPClient and add its IP to the blacklist</summary>
 /// <remarks>The <paramref name="blackListEnabled"/> has to be true for the bannishment to be effective</remarks>
 public void BanClient(UDPPeer peer)
 {
     AddBlackAddress(peer.Address);
     KickClient(peer);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Send data through an UDPChannel to a distant user and returns an <see cref="UDPDataInfo"/> object.</summary>
 /// <param name='channelName'>The name of the channel you want to send your message through.</param>
 /// <c>It must be registered on this instance, if a channel with that name can't be found the method will throw an exception!</c>
 /// <remarks>You can check if the name is registered by calling <see cref="GetChannelByName"/></remarks>
 /// <param name="udpData">A literal object that contains the data to send</param>
 /// <param name="peer">A connected UDPPeer</param>
 public UDPDataInfo SendToClient(string channelName, object udpData, UDPPeer peer)
 {
     return(_udpManager.Send(channelName, udpData, peer.Address, peer.Port));
 }