public void TestSocketAddress()
        {
            IPEndPoint    endPoint                = new IPEndPoint(new IPAddress(0), 1);
            SocketAddress socketAddress           = endPoint.Serialize();
            var           serializedSocketAddress = new SerializedSocketAddress(socketAddress);
            var           packet = new Packet {
                SerializedSocketAddress = serializedSocketAddress
            };

            var writer = new NetDataWriter();
            NetPacketProcessor processor = new NetPacketProcessor();

            SerializedSocketAddress.RegisterWith(processor);

            processor.Write(writer, packet);

            var    reader     = new NetDataReader(writer.CopyData());
            Packet readPacket = null;

            processor.Subscribe <Packet>(packet => readPacket = packet, () => new Packet());

            processor.ReadAllPackets(reader);

            Assert.IsNotNull(readPacket);
            Assert.AreEqual(serializedSocketAddress.SocketAddress, readPacket.SerializedSocketAddress.SocketAddress);
        }
        public void TestThingMessage()
        {
            // Test whether the serialization framework supports property inheritance.
            // ThingMessage.Create derives from CreateMessage which has an Id property.
            var createThingMessage = new ThingMessages.Create(1, new int[] { });

            var writer = new NetDataWriter();
            NetPacketProcessor processor = new NetPacketProcessor();

            processor.RegisterNestedType <DistributedId>();

            processor.Write(writer, createThingMessage);

            var reader = new NetDataReader(writer.CopyData());

            ThingMessages.Create readMessage = null;
            processor.Subscribe(
                createMessage => readMessage = createMessage,
                () => new ThingMessages.Create());

            processor.ReadAllPackets(reader);

            Assert.IsNotNull(readMessage);
            Assert.AreEqual(new DistributedId(1), readMessage.Id);
        }
Пример #3
0
        public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, SendType sendType)
        {
            var packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }

            var pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.ServerState:
                _cachedServerState.Deserialize(reader);
                OnServerState();     // <- 매번 서버에서 불러주고있음
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader);
                break;

            default:
                Debug.Log($"[Client] OnNetworkReceive - Unhandled packet : {pt}");
                break;
            }
        }
Пример #4
0
 private void NetworkReceiveUnconnectedEvent(IPEndPoint remoteEndPoint, NetPacketReader reader, UnconnectedMessageType messageType)
 {
     if (messageType == UnconnectedMessageType.Broadcast && remoteEndPoint.Port == Ports.LobbyScan)
     {
         _processor.ReadAllPackets(reader, remoteEndPoint);
     }
 }
Пример #5
0
        public void StartHost(GameObject canvas)
        {
            canvas.SetActive(false);

            Debug.LogError("starting host");

            netListener = new EventBasedNetListener();
            netListener.PeerConnectedEvent += (client) =>
            {
                Debug.LogError($"Connected to client: {client}");
                Debug.LogError("Sending InitialTickPacket");
                SendPacket(new InitialTickPacket {
                    tick = Tick
                }, DeliveryMethod.ReliableUnordered);
            };

            netListener.ConnectionRequestEvent += (request) =>
            {
                request.Accept();
            };

            netListener.NetworkReceiveEvent += (peer, reader, deliveryMethod) =>
            {
                packetProcessor.ReadAllPackets(reader);
            };

            packetProcessor = new NetPacketProcessor();
            writer          = new NetDataWriter();
            PacketRegistrar.RegisterPackets(packetProcessor);

            netManager = new NetManager(netListener);
            netManager.Start(12345);

            ticking = true;
        }
Пример #6
0
        void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            byte packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }
            PacketType pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.Movement:
                OnInputReceived(reader, peer);
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader, peer);
                break;

            default:
                Debug.Log("Unhandled packet: " + pt);
                break;
            }
        }
Пример #7
0
        public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, SendType sendType)
        {
            var packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }
            var pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.Movement:
                OnMovement(reader, peer);
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader, peer);
                break;

            default:
                Debug.Log($"[Server] OnNetworkReceive - Unhandled packet : {pt}");
                break;
            }
        }
Пример #8
0
        public virtual void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            try
            {
                var packetType = reader.GetByte();
                var pt         = (PacketType)packetType;

                switch (pt)
                {
                case PacketType.GameState:
                    break;

                case PacketType.Serialized:
                    NetPacketProcessor.ReadAllPackets(reader, peer);
                    break;

                case PacketType.Command:
                    break;

                case PacketType.SerializedComponent:
                    _onReceivedSerializedComponent.OnNext(new ComponentData {
                        Peer = peer, Reader = reader, DeliveryMethod = deliveryMethod
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e);
            }
        }
Пример #9
0
        void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            byte packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }
            PacketType pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.Spawn:
                break;

            case PacketType.ServerState:
                _cachedServerState.Deserialize(reader);
                OnServerState();
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader);
                break;

            case PacketType.Shoot:
                _cachedShootData.Deserialize(reader);
                OnShoot();
                break;

            default:
                Debug.Log("Unhandled packet: " + pt);
                break;
            }
        }
Пример #10
0
        public void Start()
        {
            listener = new EventBasedNetListener();
            listener.PeerConnectedEvent += (peer) => {
                Console.WriteLine("[DEBUG] Connected peer");
                SetState(State.Online);
            };

            listener.PeerDisconnectedEvent += (peer, disconnetInfo) =>
            {
                Console.WriteLine(
                    "Disconnected: {0}, Reason: {1}",
                    peer.EndPoint,
                    disconnetInfo.Reason
                    );
                SetState(State.Offline);
            };

            listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) => {
                packetProcessor.ReadAllPackets(dataReader, fromPeer);
            };

            client = new NetManager(listener);
            client.Start();
        }
Пример #11
0
        public void CustomPackageTest()
        {
            var writer = new NetDataWriter();

            _packetProcessor.Write(writer, _samplePacket);

            var          reader      = new NetDataReader(writer.CopyData());
            SamplePacket readPackage = null;

            _packetProcessor.SubscribeReusable <SamplePacket>(
                packet =>
            {
                readPackage = packet;
            });

            _packetProcessor.ReadAllPackets(reader);

            Assert.NotNull(readPackage);
            Assert.IsTrue(AreSame(_samplePacket.EmptyString, readPackage.EmptyString));
            Assert.AreEqual(_samplePacket.SomeFloat, readPackage.SomeFloat);
            Assert.AreEqual(_samplePacket.SomeIntArray, readPackage.SomeIntArray);
            Assert.IsTrue(AreSame(_samplePacket.SomeString, readPackage.SomeString));
            Assert.AreEqual(_samplePacket.SomeVector2, readPackage.SomeVector2);
            Assert.AreEqual(_samplePacket.SomeVectors, readPackage.SomeVectors);
            Assert.AreEqual(_samplePacket.SomeEnum, readPackage.SomeEnum);
            Assert.AreEqual(_samplePacket.TestObj.Value, readPackage.TestObj.Value);
            Assert.AreEqual(_samplePacket.TestArray, readPackage.TestArray);
            Assert.AreEqual(_samplePacket.SomeByteArray, readPackage.SomeByteArray);
            Assert.AreEqual(_samplePacket.SampleClassArray, readPackage.SampleClassArray);
        }
Пример #12
0
 internal void ProcessMessage(IPEndPoint senderEndPoint, NetPacket packet)
 {
     lock (_cacheReader) {
         _cacheReader.SetSource(packet.RawData, NetConstants.HeaderSize, packet.Size);
         _netPacketProcessor.ReadAllPackets(_cacheReader, senderEndPoint);
     }
 }
Пример #13
0
    public void StartClientConnection()
    {
        //Listener es el encargado de gestionar todos los paquetes recibidos
        netListenerClient = new EventBasedNetListener();
        //Packet processor es el encargado de procesar los paquetes creados por nosotros, pudiendo leerlos y enviarlos
        netPacketProcessorClient = new NetPacketProcessor();
        //Manager es donde tenemos todos los datos de la conexion, como el peer
        netManagerClient = new NetManager(netListenerClient);
        //netManagerServer.NatPunchEnabled = true;

        //Evento recibido al conectarse al servidor
        netListenerClient.PeerConnectedEvent += (server) =>
        {
            Debug.Log("Connected to server: " + server);
        };

        //Evento estandar, cualquier que no es especial como conectarse, desconectarse o ping
        netListenerClient.NetworkReceiveEvent += (server, reader, deliveryMethod) =>
        {
            //Lee los paquetes recibidos y llama a los listeners de cada paquete de los que haya recibido
            netPacketProcessorClient.ReadAllPackets(reader, server);
        };

        //Aqui estaran todos los listeners necesarios para cada paquete
        RegisterPacketsListeners();

        netManagerClient.Start();
        netManagerClient.Connect(ip, port, connectionKey);
    }
Пример #14
0
        public void StartClient(GameObject canvas)
        {
            canvas.SetActive(false);

            Debug.LogError("starting client");

            netListener = new EventBasedNetListener();
            netListener.PeerConnectedEvent += (server) =>
            {
                Debug.LogError($"Connected to server: {server}");
            };

            netListener.ConnectionRequestEvent += (request) =>
            {
                request.Accept();
            };

            netListener.NetworkReceiveEvent += (peer, reader, deliveryMethod) =>
            {
                packetProcessor.ReadAllPackets(reader);
            };

            packetProcessor = new NetPacketProcessor();
            writer          = new NetDataWriter();
            PacketRegistrar.RegisterPackets(packetProcessor);

            netManager = new NetManager(netListener);
            netManager.Start();
            netManager.Connect("localhost", 12345, "");

            connected = true;
        }
Пример #15
0
 public void Initialize()
 {
     networkObjects = GetComponent <NetworkObjects>();
     // network handlers
     natPunchEvent.NatIntroductionSuccess += (point, addrType, token) =>
     {
         var peer = netManager.Connect(point, ConnectionKey);
         Debug.Log($"NatIntroductionSuccess. Connecting to peer: {point}, type: {addrType}, connection created: {peer != null}");
     };
     netEvent.PeerConnectedEvent     += peer => { Debug.Log("PeerConnected: " + peer.EndPoint); };
     netEvent.ConnectionRequestEvent += request => { request.AcceptIfKey(ConnectionKey); };
     netEvent.NetworkReceiveEvent    += (peer, reader, deliveryMethod) => {
         netPacketProcessor.ReadAllPackets(reader, peer);
     };
     netEvent.PeerDisconnectedEvent += (peer, disconnectInfo) => { Debug.Log($"Peer {peer} Disconnected: {disconnectInfo.Reason}"); };
     // packet handlers
     netPacketProcessor.SubscribeReusable <NetworkMessagePacket, NetPeer>((packet, peer) =>
     {
         messages.SyncFromPacket(packet);
     });
     netPacketProcessor.SubscribeReusable <NetworkObjectDataPacket, NetPeer>((packet, peer) =>
     {
         data.SyncFromPacket(packet);
     });
     // connect
     netManager = new NetManager(netEvent)
     {
         IPv6Enabled     = IPv6Mode.Disabled,
         NatPunchEnabled = true
     };
     netManager.NatPunchModule.Init(natPunchEvent);
     netManager.Start();
     LoadObjectsInNewScene(0);
 }
Пример #16
0
 public void OnNetworkReceiveUnconnected(IPEndPoint remoteEndPoint, NetPacketReader reader, UnconnectedMessageType messageType)
 {
     // ipv4 only for the moment... maybe someday do ipv6 switch, and then later duplicate suppression
     if (remoteEndPoint.AddressFamily == AddressFamily.InterNetwork)
     {
         netPacketProcessor.ReadAllPackets(reader);
     }
 }
Пример #17
0
        public void Run()
        {
            //setup netpacketprocessor
            _netPacketProcessor.RegisterNestedType <CustomStruct>();
            _netPacketProcessor.SubscribeReusable <ArgumentsForLogin, NetPeer>(Method1);

            //setup events
            EventBasedNetListener clientListener = new EventBasedNetListener();
            EventBasedNetListener serverListener = new EventBasedNetListener();

            serverListener.ConnectionRequestEvent += request =>
            {
                request.AcceptIfKey("key");
            };
            serverListener.NetworkReceiveEvent +=
                (peer, reader, channel, method) =>
            {
                _netPacketProcessor.ReadAllPackets(reader, peer);
            };
            clientListener.PeerConnectedEvent += peer =>
            {
                //send after connect
                var testList = new List <CustomStruct>
                {
                    new CustomStruct {
                        X = 1, Y = -1
                    },
                    new CustomStruct {
                        X = 5, Y = -28
                    },
                    new CustomStruct {
                        X = -114, Y = 65535
                    }
                };
                _netPacketProcessor.Send(
                    peer,
                    new ArgumentsForLogin {
                    Password = "******", SomeInt = 5, UserId = "someUser", SomeList = testList
                },
                    DeliveryMethod.ReliableOrdered);
            };

            //start client/server
            _client = new NetManager(clientListener);
            _server = new NetManager(serverListener);
            _client.Start();
            _server.Start(9050);
            _client.Connect("localhost", 9050, "key");

            while (!Console.KeyAvailable)
            {
                _server.PollEvents();
                _client.PollEvents();
                Thread.Sleep(10);
            }
            _client.Stop();
            _server.Stop();
        }
Пример #18
0
        public void ProcessManuallySerializedPacket(PacketType packetType, NetPacketReader reader)
        {
            if (packetType == PacketType.Serialized)
            {
                _packetProcessor.ReadAllPackets(reader);
                return;
            }

            OnPacketReceived?.Invoke(packetType, reader);
        }
Пример #19
0
        public void Connect(string endpoint, int port)
        {
            if (manager != null)
            {
                throw new InvalidOperationException();
            }

            var listener = new EventBasedNetListener();

            manager = new NetManager(listener);
            manager.Start();
            manager.Connect(endpoint, port, nameof(MultiplayerTest));

            listener.PeerConnectedEvent += peer => server = peer;

            var processor = new NetPacketProcessor();

            processor.RegisterNestedType <Order>(() => new Order());
            processor.SubscribeReusable <OrderPacket>(packet =>
            {
                foreach (var order in packet.Orders)
                {
                    OrderReceived?.Invoke(order);
                }
            });

            listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) =>
            {
                var type = (PacketType)dataReader.GetByte();
                switch (type)
                {
                case PacketType.StartGame:
                    var players = dataReader.GetInt();
                    GameStarted?.Invoke(players);
                    break;

                case PacketType.Orders:
                    processor.ReadAllPackets(dataReader);
                    break;
                }

                dataReader.Recycle();
            };

            writer = new NetDataWriter();

            thread = new Thread(Run)
            {
                IsBackground = true
            };

            thread.Start();
        }
Пример #20
0
 private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     // throw new NotImplementedException();
     try
     {
         //   Console.WriteLine("Attempting to deserialize recieved data");
         localPacketProcessor.ReadAllPackets(reader, peer);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error1: " + ex.Message + ex.StackTrace);
     }
 }
Пример #21
0
        public void Start()
        {
            _listener   = new EventBasedNetListener();
            _lastUpdate = 0;


            _listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) =>
            {
                _packetProcessor.ReadAllPackets(dataReader, fromPeer);
            };
            _client = new NetManager(_listener);
            _client.Start();
            TryConnect();
        }
Пример #22
0
    void Start()
    {
        //Listener es el encargado de gestionar todos los paquetes recibidos
        netListenerServer = new EventBasedNetListener();
        //Packet processor es el encargado de procesar los paquetes creados por nosotros, pudiendo leerlos y enviarlos
        netManagerServer = new NetManager(netListenerServer);
        //Manager es donde tenemos todos los datos de la conexion, como el peer
        netPacketProcessorServer = new NetPacketProcessor();
        //netManagerServer.NatPunchEnabled = true;

        netManagerServer.Start(port);

        //Evento recibido al recibir un intento de conexion
        netListenerServer.ConnectionRequestEvent += (request) =>
        {
            if (netManagerServer.ConnectedPeersCount < maxConnections)
            {
                request.AcceptIfKey(connectionKey);
            }
            else
            {
                request.Reject();
            }
        };

        //Evento estandar, cualquiera que no es especial como conectarse, desconectarse o ping
        netListenerServer.NetworkReceiveEvent += (peer, reader, deliveryMethod) =>
        {
            //Lee los paquetes recibidos y llama a los listeners de cada paquete de los que haya recibido
            netPacketProcessorServer.ReadAllPackets(reader, peer);
        };

        //Aqui estaran todos los listeners necesarios para cada paquete
        RegisterPacketsListeners();
        //Evento lanzado al tener un nuevo cliente conectado
        netListenerServer.PeerConnectedEvent += (client) =>
        {
            Debug.Log("Client connected: " + client);
            netPacketProcessorServer.Send(client, new WelcomePacket()
            {
                NumberValue = 1, StringValue = "Hola"
            }, DeliveryMethod.ReliableOrdered);
            netPacketProcessorServer.Send(client, new PositionPacktet()
            {
                position = new Vector3(5, 6, 7)
            }, DeliveryMethod.ReliableOrdered);
        };
    }
Пример #23
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}!");
            }
        }
Пример #24
0
        public void Run()
        {
            //setup netpacketprocessor
            _netPacketProcessor.SubscribeReusable <ArgumentsForLogin, NetPeer>(Method1);

            //setup events
            EventBasedNetListener clientListener = new EventBasedNetListener();
            EventBasedNetListener serverListener = new EventBasedNetListener();

            serverListener.ConnectionRequestEvent += request =>
            {
                var key = System.Text.Encoding.UTF8.GetBytes("key");
                if (request.Data.SequenceEqual(key))
                {
                    request.Accept();
                }
            };
            serverListener.NetworkReceiveEvent +=
                (peer, reader, method) => _netPacketProcessor.ReadAllPackets(reader, peer);

            //start client/server
            _client = new NetManager(clientListener);
            _server = new NetManager(serverListener);
            _client.Start();
            _server.Start(9050);
            var clientPeer = _client.Connect("localhost", 9050, "key");

            //send
            _netPacketProcessor.Send(
                clientPeer,
                new ArgumentsForLogin {
                Password = "******", SomeInt = 5, UserId = "someUser"
            },
                DeliveryMethod.ReliableOrdered);

            while (!Console.KeyAvailable)
            {
                _server.PollEvents();
                Thread.Sleep(10);
            }
            _client.Stop();
            _server.Stop();
        }
Пример #25
0
    void Start()
    {
        count = 0;

        Debug.LogError("Client Start");
        netListener  = new EventBasedNetListener();
        netProcessor = new NetPacketProcessor();

        netListener.PeerConnectedEvent += (server) =>
        {
            Debug.LogError($"Connected to server: {server}");
        };

        netListener.NetworkReceiveEvent += (server, reader, deliveryMethod) => {
            netProcessor.ReadAllPackets(reader, server);
        };

        netProcessor.SubscribeReusable <MethodPacket>((packet) => {
            Debug.Log("Packet got.");

            if (packet.MethodValue == 0)
            {
                NewCube();
            }

            if (packet.MethodValue == 1)
            {
                CubePos();
            }

            if (packet.MethodValue == 2)
            {
                DestroyCube();
            }

            count = packet.CountValue;
        });

        netManager = new NetManager(netListener);
        netManager.Start();
        netManager.Connect("localhost", 9050, "Banana");
    }
Пример #26
0
 public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     packetProcessor.ReadAllPackets(reader, peer);
 }
Пример #27
0
 public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     Console.WriteLine($"{ClientSignature} Received data. Processing...");
     _netPacketProcessor.ReadAllPackets(reader, peer);
 }
Пример #28
0
        public void AcceptConnections()
        {
            NetDebug.Logger = this;

            _netPacketProcessor.SubscribeNetSerializable <VoicePaketSetup, NetPeer>(onVoiceSetup);
            _netPacketProcessor.SubscribeNetSerializable <VoicePaketCommand, NetPeer>(onVoiceCommand);
            _netPacketProcessor.SubscribeNetSerializable <VoicePaketUpdate, NetPeer>(onVoiceUpdate);
            _netPacketProcessor.SubscribeNetSerializable <VoicePaketMute, NetPeer>(onVoiceMute);
            _netPacketProcessor.SubscribeNetSerializable <VoicePaketBatchMute, NetPeer>(onVoiceBatchMute);
            _netPacketProcessor.SubscribeNetSerializable <VoicePaketBatchUpdate, NetPeer>(onVoiceBatchUpdate);
            _netPacketProcessor.SubscribeNetSerializable <VoicePaketConfigureClient, NetPeer>(onVoiceConfigureClient);

            clientListener.NetworkReceiveEvent +=
                (peer, reader, method) =>
            {
                _netPacketProcessor.ReadAllPackets(reader, peer);
            };
            clientListener.PeerConnectedEvent        += (p) => VoicePlugin.Log("PeerConnectedEvent {0}", p);
            clientListener.PeerDisconnectedEvent     += ClientListener_PeerDisconnectedEvent;
            clientListener.NetworkErrorEvent         += (p, e) => VoicePlugin.Log("NetworkErrorEvent {0} => {1}", p, e);
            clientListener.NetworkLatencyUpdateEvent += ClientListener_NetworkLatencyUpdateEvent;

            _timer          = new System.Timers.Timer();
            _timer.Interval = 100;
            _timer.Elapsed += (s, e) =>
            {
                if (_needConnection)
                {
                    if (IsConnected && DateTime.Now - _lastPureVoicePing > TimeSpan.FromSeconds(10))
                    {
                        _needConnection = false;
                        var con = VoicePlugin.GetConnection(_connectionInfo.ServerGUID);
                        if (con != null)
                        {
                            con.DisconnectVoiceServer();
                        }
                        OnDisconnected?.Invoke(this, this);
                        Disconnect();
                        return;
                    }

                    if (!IsConnected)
                    {
                        StartServerConnection();
                        return;
                    }
                }
                if (IsConnected)
                {
                    Client?.PollEvents();
                }
            };

            if (!_timer.Enabled)
            {
                _timer.Start();
            }

            var evL = new EventBasedNetListener();

            evL.NetworkReceiveUnconnectedEvent += (ep, reader, messageType) => ServerListener_NetworkReceiveUnconnectedEvent(ep, reader, messageType);
            ServerListener = new NetManager(evL)
            {
                UnconnectedMessagesEnabled = true, UnsyncedEvents = true
            };
            ServerListener.Start(4239);
            WebListener.ConnectionRequestReceived += WebListener_ConnectionRequestReceived;
            WebListener.StartListen();
            VoicePlugin.Log("voiceClient waiting for Connectioninfo...");
            _ShutDown = false;
        }
Пример #29
0
        public NetworkConnection(SkirmishGame game)
        {
            _numberOfOtherPlayers = game.Slots.Count(s => s.State == SkirmishSlotState.Human) - 1;
            _listener             = new EventBasedNetListener();
            _manager = new NetManager(_listener);

            if (Debugger.IsAttached)
            {
                _manager.DisconnectTimeout = 600000;
            }

            _listener.PeerConnectedEvent    += peer => Logger.Trace($"{peer.EndPoint} connected");
            _listener.PeerDisconnectedEvent += (peer, info) => Logger.Trace($"{peer.EndPoint} disconnected with reason {info.Reason}");
            _listener.NetworkReceiveEvent   += (NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) => _processor.ReadAllPackets(reader, peer);

            _writer    = new NetDataWriter();
            _processor = new NetPacketProcessor();
            _processor.RegisterNestedType <Order>(WriteOrder, ReadOrder);
            _processor.Subscribe <SkirmishOrderPacket, NetPeer>(ReceiveOrderPacket, () => new SkirmishOrderPacket());
        }
Пример #30
0
 public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     Debug.Log(reader);
     _processor.ReadAllPackets(reader, peer);
     reader.Recycle();
 }