コード例 #1
0
 void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     if (reader.UserDataSize >= 1)
     {
         byte dataType = reader.GetByte();
         int  clientId = LiteNetLibUtil.Peer2ClientId(peer);
         OnNetworkEventReceived?.Invoke(dataType, reader, clientId);
     }
 }
コード例 #2
0
        void INetEventListener.OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
        {
            Console.WriteLine("OnPeerDisconnected : " + peer.EndPoint.Address + " : " + peer.EndPoint.Port + " Reason : " + disconnectInfo.Reason.ToString());

            int clientId = LiteNetLibUtil.Peer2ClientId(peer);

            if (_ConnectedClients.ContainsKey(clientId))
            {
                _ConnectedClients.Remove(clientId);
            }

            OnPeerDisconnectedHandler?.Invoke(clientId);
        }
コード例 #3
0
        void INetEventListener.OnPeerConnected(NetPeer peer)
        {
            int clientId = LiteNetLibUtil.Peer2ClientId(peer);

            if (!_ConnectedClients.ContainsKey(clientId))
            {
                _ConnectedClients.Add(clientId, peer);
            }

            Debug.Log("OnPeerConnected.clientId: " + clientId);

            NetDataWriter dataWriter = new NetDataWriter();

            dataWriter.Put(NetworkDataType.OnConnectedServer);
            dataWriter.Put(clientId);
            peer.Send(dataWriter, DeliveryMethod.ReliableOrdered);

            OnPeerConnectedHandler?.Invoke(clientId);
        }