Пример #1
0
        private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            PacketType packetType = (PacketType)reader.GetByte();

            if (packetType == PacketType.State)
            {
                queuedStatePackets.Enqueue(new StatePacket()
                {
                    PacketReader = reader, PeerID = peer.Id + 1
                });
            }
            // TODO: This is also server only logic.
            else if (packetType == PacketType.Join)
            {
                jitterBuffersByPeerId[peer.Id + 1] = new JitterBuffer(settings.JitterBufferDelayFrames);

                int remoteID = reader.GetInt();
                OnReceivePeerId?.Invoke(remoteID);

                int frame = reader.GetInt();

                StatefulWorld.Instance.Frame = frame;
                remote = new Remote(StatefulWorld.Instance, false, role == Role.ListenClient, remoteID);

                Debug.Log($"Local client assigned id <b>{remoteID}</b>", LogType.Connection);
            }
        }
Пример #2
0
        public void Listen(int port)
        {
            if (role != Role.Inactive)
            {
                throw new Exception($"Cannot start listening with peer already performing the {role} role.");
            }

            listener.PeerConnectedEvent += Listener_PeerConnectedEvent;
            netManager.Start(port);

            role = Role.Server;

            remote = new Remote(StatefulWorld.Instance, true, false, 0);

            StatefulWorld.Instance.Frame = 0;

            OnReceivePeerId?.Invoke(0);
        }