예제 #1
0
        private void Introduce(RemoteConnection remote, IPEndPoint endPoint)
        {
            Debug.Log("NATServer: Introducing: ", endPoint.ToString(), " to: ", remote.EndPoint.ToString());
            OutgoingMessage message = MessagePool.CreateMessage();

            message.Write(NATMessageType.INTRODUCTION);
            message.Write(endPoint);
            remote.Send(message);

            MessagePool.Recycle(message);
        }
예제 #2
0
        // Param == connection to be introduced
        public void Introduce(NATRemote conn)
        {
            Debug.Log("NATServer: Introducing: ", conn.Remote.EndPoint.ToString(), " to: ", Remote.EndPoint.ToString());
            OutgoingMessage message = MessagePool.CreateMessage();

            message.Write(NATMessageType.INTRODUCTION);
            message.Write(conn.Remote.EndPoint);

            Remote.Send(message);

            MessagePool.Recycle(message);
        }
예제 #3
0
        /// <summary>
        /// Sends a message to a remote connection
        /// </summary>
        public void InformPunchthroughSuccess()
        {
            OutgoingMessage request = MessagePool.CreateMessage();

            request.Write(NATMessageType.NAT_PUNCH_SUCCESS);

            fixed(byte *bytes = request.Data)
            {
                ENet.MicroSend(Peer, 0, bytes, (IntPtr)request.ByteCount, DeliveryMethod.Reliable);
            }

            MessagePool.Recycle(request);
        }
예제 #4
0
        /// <summary>
        /// Sends a message to a remote connection. Default channel = 0
        /// </summary>
        public void RequestHostList()
        {
            OutgoingMessage regMessage = MessagePool.CreateMessage();

            regMessage.Write(NATMessageType.REQUEST_HOST_LIST);


            fixed(byte *bytes = regMessage.Data)
            {
                ENet.MicroSend(Peer, 0, bytes, (IntPtr)regMessage.ByteCount, DeliveryMethod.Reliable);
            }

            MessagePool.Recycle(regMessage);
        }
예제 #5
0
        /// <summary>
        /// Sends a message to a remote connection. Default channel = 0
        /// </summary>
        public void RegisterHosting()
        {
            OutgoingMessage regMessage = MessagePool.CreateMessage();
            IPAddress       local      = NetUtilities.GetLocalAddress();

            regMessage.Write(NATMessageType.INITIATE_HOST);
            regMessage.WriteString("hello");

            fixed(byte *bytes = regMessage.Data)
            {
                ENet.MicroSend(Peer, 0, bytes, (IntPtr)regMessage.ByteCount, DeliveryMethod.Reliable);
            }

            MessagePool.Recycle(regMessage);
        }
예제 #6
0
        /// <summary>
        /// Sends a message to a remote connection
        /// </summary>
        public void RequestIntroduction(ulong hostId)
        {
            OutgoingMessage request = MessagePool.CreateMessage();

            //  IPAddress local = NetUtilities.GetLocalAddress();
            request.Write(NATMessageType.REQUEST_INTRODUCTION);
            request.Write(hostId);


            fixed(byte *bytes = request.Data)
            {
                ENet.MicroSend(Peer, 0, bytes, (IntPtr)request.ByteCount, DeliveryMethod.Reliable);
            }

            MessagePool.Recycle(request);
        }
예제 #7
0
        public void HandleHostListRequest(RemoteConnection remote)
        {
            Debug.Log(config.Name, ": Request for a list of hosts was received");
            OutgoingMessage listMsg = MessagePool.CreateMessage();

            listMsg.Write(NATMessageType.REQUEST_HOST_LIST);
            listMsg.Write(registeredHosts.Count);

            foreach (NATHost item in registeredHosts.Values)
            {
                item.Info.WriteMessage(listMsg);
            }


            remote.Send(listMsg);

            MessagePool.Recycle(listMsg);
        }
예제 #8
0
        public void HandleHostSetup(IncomingMessage msg)
        {
            Debug.Log(config.Name, ": Received host register request");
            NATHost natHost = new NATHost(msg);

            Debug.Log(config.Name, ": Adding host as id: ", natHost.Info.HostId.ToString());

            // -- Why would it add them twice? -- //
            //        registeredHosts.Add(natHost.Info.HostId, natHost);
            registeredHosts[natHost.Info.HostId] = natHost;

            Debug.Log(config.Name, ": Host registered at: External IP: ", natHost.Remote.EndPoint.ToString());

            OutgoingMessage ackMsg = MessagePool.CreateMessage();

            ackMsg.Write(NATMessageType.ACK);
            msg.Remote.Send(ackMsg);


            MessagePool.Recycle(ackMsg);
        }
예제 #9
0
        public override void OnConnect(RemoteConnection remote)
        {
            PlayerBase player = new PlayerBase
            {
                Id = (int)remote.ConnectionId,
            };



            Spawn spawn = new Spawn()
            {
                Id = (int)remote.ConnectionId, Position = new Vector2(300, 300), Color = new Color(0.85f, 0.35f, 0.15f)
            };

            players.Add(player);
            SignalManager.Signal(spawn);

            WorldUpdate update = new WorldUpdate();

            update.Players[0] = new Spawn()
            {
                Id = -1, Position = players[0].Position, Color = players[0].Colour
            };
            update.Players[1] = new Spawn()
            {
                Id = players[1].Id, Position = players[1].Position, Color = players[1].Colour
            };

            OutgoingMessage message = MessagePool.CreateMessage();

            update.Write(message);

            remote.Send(message);

            MessagePool.Recycle(message);
        }