コード例 #1
0
ファイル: Api.cs プロジェクト: UofG-CS21/SGame
 /// <summary>
 /// Called when a a peer gets disconnected from us.
 /// </summary>
 private void OnPeerDisconnected(LiteNetLib.NetPeer peer, LiteNetLib.DisconnectInfo info)
 {
     if (peer == ArbiterPeer)
     {
         Console.Error.WriteLine(">>> Lost connection to arbiter! <<<");
     }
 }
コード例 #2
0
ファイル: NetClient.cs プロジェクト: RevenantX/LiteNetLib
        private void CloseConnection(bool force, DisconnectReason reason, int socketErrorCode)
        {
            lock (_connectionCloseLock)
            {
                //Nothing to do
                if (!IsRunning)
                    return;

                //Send goodbye
                if (_peer != null && !force && _connected)
                {
                    //Send disconnect data
                    var disconnectPacket = NetPacket.CreateRawPacket(PacketProperty.Disconnect, 8);
                    FastBitConverter.GetBytes(disconnectPacket, 1, _connectId);
                    SendRaw(disconnectPacket, _peer.EndPoint);
                }

                //Clear data
                _peer = null;
                _connected = false;
                _connectTimer = 0;
                _connectAttempts = 0;
                SocketClearPeers();

                //Send event to Listener
                var netEvent = CreateEvent(NetEventType.Disconnect);
                netEvent.DisconnectReason = reason;
                netEvent.AdditionalData = socketErrorCode;
                EnqueueEvent(netEvent);
            }
        }
コード例 #3
0
        public ReliableChannel(NetPeer peer, bool ordered, int windowSize)
        {
            _resendDelay = peer.Handler.ReliableResendTime;
            _windowSize = windowSize;
            _peer = peer;
            _ordered = ordered;

            _outgoingPackets = new Queue<NetPacket>(_windowSize);

            _outgoingAcks = new bool[_windowSize];
            _pendingPackets = new PendingPacket[_windowSize];
            for (int i = 0; i < _pendingPackets.Length; i++)
            {
                _pendingPackets[i] = new PendingPacket();
            }

            if (_ordered)
                _receivedPackets = new NetPacket[_windowSize];
            else
                _earlyReceived = new bool[_windowSize];

            _localWindowStart = 0;
            _localSeqence = 0;
            _remoteSequence = 0;
            _remoteWindowStart = 0;
        }
コード例 #4
0
ファイル: NetServer.cs プロジェクト: RevenantX/LiteNetLib
 private void RemovePeer(NetPeer peer)
 {
     lock (_peersToRemove)
     {
         _peersToRemove.Enqueue(peer.EndPoint);
     }
 }
コード例 #5
0
            public void OnPeerConnected(NetPeer peer)
            {
                Console.WriteLine("[Client] connected to: {0}:{1}", peer.EndPoint.Host, peer.EndPoint.Port);

                NetDataWriter dataWriter = new NetDataWriter();
                for (int i = 0; i < 5; i++)
                {
                    dataWriter.Reset();
                    dataWriter.Put(0);
                    dataWriter.Put(i);
                    peer.Send(dataWriter, SendOptions.ReliableUnordered);

                    dataWriter.Reset();
                    dataWriter.Put(1);
                    dataWriter.Put(i);
                    peer.Send(dataWriter, SendOptions.ReliableOrdered);

                    dataWriter.Reset();
                    dataWriter.Put(2);
                    dataWriter.Put(i);
                    peer.Send(dataWriter, SendOptions.Sequenced);

                    dataWriter.Reset();
                    dataWriter.Put(3);
                    dataWriter.Put(i);
                    peer.Send(dataWriter, SendOptions.Unreliable);
                }

                //And test fragment
                byte[] testData = new byte[13218];
                testData[0] = 192;
                testData[13217] = 31;
                peer.Send(testData, SendOptions.ReliableOrdered);
            }
コード例 #6
0
ファイル: LobbyMenu.cs プロジェクト: Fyffe/LiteNetLobby
    public void CreatePlayer(LiteNetLib.NetPeer peer, string name, bool self)
    {
        LobbyPlayer p = Instantiate(playerPrefab, playersList, false);

        p.Init();
        p.SetPlayer(peer, name, self, Players.Count);

        Players.Add(p);
    }
コード例 #7
0
ファイル: BroadcastTest.cs プロジェクト: RevenantX/LiteNetLib
 public void OnPeerConnected(NetPeer peer)
 {
     Console.WriteLine("[Server] Peer connected: " + peer.EndPoint);
     var peers = Server.GetPeers();
     foreach (var netPeer in peers)
     {
         Console.WriteLine("ConnectedPeersList: id={0}, ep={1}", netPeer.Id, netPeer.EndPoint);
     }
 }
コード例 #8
0
    public void SetPlayer(LiteNetLib.NetPeer p, string name, bool b, int id)
    {
        peer               = p;
        playerName         = name;
        playerNameTxt.text = name;

        this.id = id;

        kickBtn.gameObject.SetActive(!b);
    }
コード例 #9
0
ファイル: NetServer.cs プロジェクト: RevenantX/LiteNetLib
 /// <summary>
 /// Disconnect peer from server
 /// </summary>
 /// <param name="peer">peer to disconnect</param>
 public void DisconnectPeer(NetPeer peer)
 {
     if (peer != null && _peers.ContainsKey(peer.EndPoint))
     {
         peer.CreateAndSend(PacketProperty.Disconnect);
         var netEvent = CreateEvent(NetEventType.Disconnect);
         netEvent.Peer = peer;
         netEvent.DisconnectReason = DisconnectReason.DisconnectPeerCalled;
         EnqueueEvent(netEvent);
         RemovePeer(peer);
     }
 }
コード例 #10
0
ファイル: GameClient.cs プロジェクト: RevenantX/LiteNetLib
    public void OnNetworkReceive(NetPeer peer, NetDataReader reader)
    {
        _newBallPosX = reader.GetFloat();

        var pos = _clientBall.transform.position;

        _oldBallPosX = pos.x;
        pos.x = _newBallPosX;

        _clientBall.transform.position = pos;

        _lerpTime = 0f;
    }
コード例 #11
0
 public void OnNetworkReceive(NetPeer peer, NetDataReader reader)
 {
     if (reader.AvailableBytes == 13218)
     {
         Console.WriteLine("[{0}] TestFrag: {1}, {2}", peer.Handler.LocalEndPoint.Port, reader.Data[0], reader.Data[13217]);
     }
     else
     {
         int type = reader.GetInt();
         int num = reader.GetInt();
         _messagesReceivedCount++;
         Console.WriteLine("[{0}] CNT: {1}, TYPE: {2}, NUM: {3}", peer.Handler.LocalEndPoint.Port, _messagesReceivedCount, type, num);
     }
 }
コード例 #12
0
ファイル: LobbyMenu.cs プロジェクト: Fyffe/LiteNetLobby
    public LobbyPlayer GetPeer(LiteNetLib.NetPeer peer)
    {
        LobbyPlayer player = null;

        for (int i = 0; i < Players.Count; i++)
        {
            LobbyPlayer lp = Players[i];

            if (lp.peer == peer)
            {
                player = lp;
            }
        }

        return(player);
    }
コード例 #13
0
ファイル: NetServer.cs プロジェクト: RevenantX/LiteNetLib
        /// <summary>
        /// Get copy of current connected peers
        /// </summary>
        /// <returns>Array with connected peers</returns>
        public NetPeer[] GetPeers()
        {
            NetPeer[] peers;
            int num = 0;

            lock (_peers)
            {
                peers = new NetPeer[_peers.Count];
                foreach (NetPeer netPeer in _peers.Values)
                {
                    peers[num++] = netPeer;
                }
            }

            return peers;
        }
コード例 #14
0
        private void Listener_NetworkReceiveEvent(LiteNetLib.NetPeer peer, NetDataReader reader, DeliveryMethod deliveryMethod)
        {
            _packetProcessor.ReadAllPackets(reader, peer);

            // check if we even know this peer
            var key = peer.EndPoint.ToString();

            if (_knownPlayers.ContainsKey(key))
            {
            }
            else
            {
                Debug.Assert(false, "The Connected Peer was Unknown to us! (Did not exist in KnownPlayer list)");
                // TODO: should assert or at least log this properly for future debugging
                Console.WriteLine($"Unknown Client connected as:{key}!");
            }
        }
コード例 #15
0
ファイル: Api.cs プロジェクト: UofG-CS21/SGame
        /// <summary>
        /// Called when a a peer connects to us; sends a `NodeOnline` message, but only to the arbiter.
        /// </summary>
        private void OnPeerConnected(LiteNetLib.NetPeer peer)
        {
            if (peer == ArbiterPeer)
            {
                // TODO: Connect to http://icanhazip.org or similar to get the external IP instead?
                var apiUri          = new Uri(this.ApiUrl);
                var externalAddress = IPAddress.Parse(apiUri.Host);

                // WARNING: Ensure that ApiUrl is visible from outside - otherwise, all requests will fail to be forwarded to this node!
                var currentConfig = new SShared.Messages.NodeConfig()
                {
                    BusAddress = externalAddress,
                    BusPort    = this.LocalBusPort,
                    ApiUrl     = this.ApiUrl,
                    Path       = QuadTreeNode.Path(),
                    Bounds     = QuadTreeNode.Bounds,
                };
                this.Bus.SendMessage(currentConfig, peer);
            }
        }
コード例 #16
0
ファイル: GameClient.cs プロジェクト: RevenantX/LiteNetLib
 public void OnPeerDisconnected(NetPeer peer, DisconnectReason reason, int socketErrorCode)
 {
     Debug.Log("[CLIENT] We disconnected because " + reason);
 }
コード例 #17
0
 void INetEventListener.OnNetworkReceive(NetPeer peer, NetDataReader reader)
 {
     if (NetworkReceiveEvent != null)
         NetworkReceiveEvent(peer, reader);
 }
コード例 #18
0
 /// <summary>
 /// Disconnect peer from server and send additional data (Size must be less or equal MTU - 8)
 /// </summary>
 /// <param name="peer">peer to disconnect</param>
 /// <param name="data">additional data</param>
 public void DisconnectPeer(NetPeer peer, byte[] data)
 {
     DisconnectPeer(peer, data, 0, data.Length);
 }
コード例 #19
0
ファイル: NetServer.cs プロジェクト: RevenantX/LiteNetLib
 public void SendToClients(byte[] data, int start, int length, SendOptions options, NetPeer excludePeer)
 {
     lock (_peers)
     foreach (NetPeer netPeer in _peers.Values)
     {
         if (netPeer != excludePeer)
         {
             netPeer.Send(data, start, length, options);
         }
     }
 }
コード例 #20
0
ファイル: NetServer.cs プロジェクト: RevenantX/LiteNetLib
        private void SendConnectAccept(NetPeer peer, ulong id)
        {
            //Reset connection timer
            peer.StartConnectionTimer();

            //Make initial packet
            var connectPacket = NetPacket.CreateRawPacket(PacketProperty.ConnectAccept, 8);

            //Add data
            FastBitConverter.GetBytes(connectPacket, 1, id);

            //Send raw
            SendRaw(connectPacket, peer.EndPoint);
        }
コード例 #21
0
 /// <summary>
 /// Disconnect peer from server and send additional data (Size must be less or equal MTU - 8)
 /// </summary>
 /// <param name="peer">peer to disconnect</param>
 /// <param name="writer">additional data</param>
 public void DisconnectPeer(NetPeer peer, NetDataWriter writer)
 {
     DisconnectPeer(peer, writer.Data, 0, writer.Length);
 }
コード例 #22
0
 public void OnPeerDisconnected(NetPeer peer, DisconnectReason disconnectReason, int socketErrorCode)
 {
     Console.WriteLine("[Client] disconnected: " + disconnectReason);
 }
コード例 #23
0
ファイル: NetBase.cs プロジェクト: RevenantX/LiteNetLib
 internal void ConnectionLatencyUpdated(NetPeer fromPeer, int latency)
 {
     var evt = CreateEvent(NetEventType.ConnectionLatencyUpdated);
     evt.Peer = fromPeer;
     evt.AdditionalData = latency;
     EnqueueEvent(evt);
 }
コード例 #24
0
ファイル: NetBase.cs プロジェクト: RevenantX/LiteNetLib
 protected NetPeer CreatePeer(NetEndPoint remoteEndPoint)
 {
     var peer = new NetPeer(this, remoteEndPoint);
     peer.PingInterval = PingInterval;
     return peer;
 }
コード例 #25
0
 /// <summary>
 /// Send data to all connected peers
 /// </summary>
 /// <param name="data">Data</param>
 /// <param name="options">Send options (reliable, unreliable, etc.)</param>
 /// <param name="excludePeer">Excluded peer</param>
 public void SendToAll(byte[] data, DeliveryMethod options, NetPeer excludePeer)
 {
     SendToAll(data, 0, data.Length, options, excludePeer);
 }
コード例 #26
0
 void INetEventListener.OnNetworkLatencyUpdate(NetPeer peer, int latency)
 {
     if (NetworkLatencyUpdateEvent != null)
         NetworkLatencyUpdateEvent(peer, latency);
 }
コード例 #27
0
 /// <summary>
 /// Send data to all connected peers
 /// </summary>
 /// <param name="writer">DataWriter with data</param>
 /// <param name="options">Send options (reliable, unreliable, etc.)</param>
 /// <param name="excludePeer">Excluded peer</param>
 public void SendToAll(NetDataWriter writer, DeliveryMethod options, NetPeer excludePeer)
 {
     SendToAll(writer.Data, 0, writer.Length, options, excludePeer);
 }
コード例 #28
0
ファイル: NetClient.cs プロジェクト: RevenantX/LiteNetLib
        public void Connect(NetEndPoint target)
        {
            if (!IsRunning)
            {
                throw new Exception("Client is not running");
            }
            if (_peer != null)
            {
                //Already connected
                return;
            }

            //Create connect id for proper connection
            _connectId = (ulong)DateTime.UtcNow.Ticks;
            NetUtils.DebugWrite(ConsoleColor.Cyan, "[CC] ConnectId: {0}", _connectId);

            //Create reliable connection
            _peer = CreatePeer(target);
            _peer.DebugTextColor = ConsoleColor.Yellow;

            //Create connection packet and send
            SendConnectRequest();

            _connectAttempts = 0;
        }
コード例 #29
0
 public void OnNetworkLatencyUpdate(NetPeer peer, int latency)
 {
     
 }
コード例 #30
0
 public SequencedChannel(NetPeer peer)
 {
     _outgoingPackets = new Queue<NetPacket>();
     _peer = peer;
 }
コード例 #31
0
            public void OnNetworkReceive(NetPeer peer, NetDataReader reader)
            {
                //echo
                peer.Send(reader.Data, SendOptions.ReliableUnordered);

                //fragment log
                if (reader.AvailableBytes == 13218)
                {
                    Console.WriteLine("[Server] TestFrag: {0}, {1}", reader.Data[0], reader.Data[13217]);
                }
            }
コード例 #32
0
ファイル: NetServer.cs プロジェクト: RevenantX/LiteNetLib
 public void SendToClients(NetDataWriter writer, SendOptions options, NetPeer excludePeer)
 {
     lock (_peers)
     foreach (NetPeer netPeer in _peers.Values)
     {
         if (netPeer != excludePeer)
         {
             netPeer.Send(writer, options);
         }
     }
 }
コード例 #33
0
ファイル: GameClient.cs プロジェクト: RevenantX/LiteNetLib
 public void OnPeerConnected(NetPeer peer)
 {
     Debug.Log("[CLIENT] We connected to " + peer.EndPoint);
 }
コード例 #34
0
 void INetEventListener.OnPeerConnected(NetPeer peer)
 {
     if (PeerConnectedEvent != null)
         PeerConnectedEvent(peer);
 }
コード例 #35
0
ファイル: BroadcastTest.cs プロジェクト: RevenantX/LiteNetLib
            public void OnNetworkReceive(NetPeer peer, NetDataReader reader)
            {

            }
コード例 #36
0
 /// <summary>
 /// Disconnect peer from server
 /// </summary>
 /// <param name="peer">peer to disconnect</param>
 public void DisconnectPeer(NetPeer peer)
 {
     DisconnectPeer(peer, null, 0, 0);
 }
コード例 #37
0
 void INetEventListener.OnPeerDisconnected(NetPeer peer, DisconnectReason disconnectReason, int socketErrorCode)
 {
     if (PeerDisconnectedEvent != null)
         PeerDisconnectedEvent(peer, disconnectReason, socketErrorCode);
 }
コード例 #38
0
ファイル: BroadcastTest.cs プロジェクト: RevenantX/LiteNetLib
 public void OnPeerConnected(NetPeer peer)
 {
     Console.WriteLine("[Client {0}] connected to: {1}:{2}", Client.LocalEndPoint.Port, peer.EndPoint.Host, peer.EndPoint.Port);
 }
コード例 #39
0
 /// <summary>
 /// Send data to all connected peers
 /// </summary>
 /// <param name="data">Data</param>
 /// <param name="start">Start of data</param>
 /// <param name="length">Length of data</param>
 /// <param name="options">Send options (reliable, unreliable, etc.)</param>
 /// <param name="excludePeer">Excluded peer</param>
 public void SendToAll(byte[] data, int start, int length, DeliveryMethod options, NetPeer excludePeer)
 {
     lock (_peers)
     {
         for (int i = 0; i < _peers.Count; i++)
         {
             var netPeer = _peers[i];
             if (netPeer != excludePeer)
             {
                 netPeer.Send(data, start, length, options);
             }
         }
     }
 }
コード例 #40
0
ファイル: GameServer.cs プロジェクト: RevenantX/LiteNetLib
 public void OnPeerConnected(NetPeer peer)
 {
     Debug.Log("[SERVER] We have new peer " + peer.EndPoint);
     _ourPeer = peer;
 }
コード例 #41
0
ファイル: GameServer.cs プロジェクト: RevenantX/LiteNetLib
 public void OnPeerDisconnected(NetPeer peer, DisconnectReason reason, int socketErrorCode)
 {
     Debug.Log("[SERVER] peer disconnected " + peer.EndPoint + ", info: " + reason);
     if (peer == _ourPeer)
         _ourPeer = null;
 }
コード例 #42
0
 public void OnPeerDisconnected(NetPeer peer, DisconnectReason disconnectReason, int socketErrorCode)
 {
     Console.WriteLine("[Server] Peer disconnected: " + peer.EndPoint + ", reason: " + disconnectReason);
 }
コード例 #43
0
 /// <summary>
 /// Immediately disconnect peer from server without additional data
 /// </summary>
 /// <param name="peer">peer to disconnect</param>
 public void DisconnectPeerForce(NetPeer peer)
 {
     DisconnectPeer(peer, DisconnectReason.DisconnectPeerCalled, 0, true, null, 0, 0);
 }