Ejemplo n.º 1
0
        /// <summary>
        /// Send the passed command over the network
        /// </summary>
        /// <param name="command">Registered command</param>
        /// <param name="destination">Destination of the command</param>
        public static void Send(this INetCommand?command, NetworkDestination destination)
        {
            if (destination.ShouldRun())
            {
                command.OnReceived();
            }

            if (destination.ShouldSend())
            {
                var header = destination.GetHeader(NetworkingAPI.GetNetworkHash(command.GetType()));

                if (NetworkServer.active)
                {
                    for (int i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        SendCommand(header, conn);
                    }
                }
                else if (NetworkClient.active)
                {
                    SendCommand(header, ClientScene.readyConnection);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Send <T>(this T message, NetworkDestination destination, Int32 recievedFrom = -1)
            where T : INetMessage
        {
            if (destination.ShouldRun())
            {
                message.OnRecieved();
            }

            if (destination.ShouldSend())
            {
                Header header = destination.GetHeader(NetworkCore.GetNetworkCoreHash(typeof(T)));

                if (NetworkServer.active)
                {
                    for (Int32 i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        if (i == recievedFrom)
                        {
                            continue;
                        }

                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkCore.GetWriter(NetworkCore.messageIndex, conn, NetworkCore.qos))
                        {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                            writer.Write(message);
                        }
                    }
                }
                else if (NetworkClient.active)
                {
                    using (Writer netWriter = NetworkCore.GetWriter(NetworkCore.messageIndex, ClientScene.readyConnection, NetworkCore.qos))
                    {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                        writer.Write(message);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void Send <TRequest, TReply>(this TRequest request, NetworkDestination destination, Int32 recievedFrom = -1)
            where TRequest : INetRequest <TRequest, TReply>
            where TReply : INetRequestReply <TRequest, TReply>
        {
            if (destination.ShouldRun())
            {
                request.OnRequestRecieved().OnReplyRecieved();
            }

            if (destination.ShouldSend())
            {
                Header header = destination.GetHeader(NetworkCore.GetNetworkCoreHash(request.GetType()));

                if (NetworkServer.active)
                {
                    for (Int32 i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        if (i == recievedFrom)
                        {
                            continue;
                        }

                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkCore.GetWriter(NetworkCore.messageIndex, conn, NetworkCore.qos))
                        {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                            writer.Write(request);
                        }
                    }
                }

                if (NetworkClient.active)
                {
                    using (Writer netWriter = NetworkCore.GetWriter(NetworkCore.messageIndex, ClientScene.readyConnection, NetworkCore.qos))
                    {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                        writer.Write(request);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void Send <TRequest, TReply>(this TRequest request, NetworkDestination destination)
            where TRequest : INetRequest <TRequest, TReply>
            where TReply : INetRequestReply <TRequest, TReply>
        {
            if (destination.ShouldRun())
            {
                request.OnRequestReceived().OnReplyReceived();
            }

            if (destination.ShouldSend())
            {
                var header = destination.GetHeader(NetworkingAPI.GetNetworkHash(request.GetType()));

                if (NetworkServer.active)
                {
                    for (var i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkingAPI.GetWriter(NetworkingAPI.RequestIndex, conn, QosType.Reliable)) {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                            writer.Write(request);
                        }
                    }
                }
                else if (NetworkClient.active)
                {
                    using (Writer netWriter = NetworkingAPI.GetWriter(NetworkingAPI.RequestIndex, ClientScene.readyConnection, QosType.Reliable)) {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                        writer.Write(request);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void Send(this INetMessage?message, NetworkDestination destination)
        {
            if (destination.ShouldRun())
            {
                message.OnReceived();
            }

            if (destination.ShouldSend())
            {
                var header = destination.GetHeader(NetworkingAPI.GetNetworkHash(message.GetType()));

                if (NetworkServer.active)
                {
                    for (int i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkingAPI.GetWriter(NetworkingAPI.MessageIndex, conn, QosType.Reliable)) {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                            writer.Write(message);
                        }
                    }
                }
                else if (NetworkClient.active)
                {
                    using (Writer netWriter = NetworkingAPI.GetWriter(NetworkingAPI.MessageIndex, ClientScene.readyConnection, QosType.Reliable)) {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                        writer.Write(message);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void Send(this INetCommand command, NetworkDestination destination)
        {
            if (destination.ShouldRun())
            {
                command.OnReceived();
            }

            if (destination.ShouldSend())
            {
                var header = destination.GetHeader(NetworkingAPI.GetNetworkHash(command.GetType()));

                if (NetworkServer.active)
                {
                    for (int i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkingAPI.GetWriter(NetworkingAPI.CommandIndex, conn, QosType.Reliable)) {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                        }
                    }
                }

                if (NetworkClient.active)
                {
                    using (var netWriter = NetworkingAPI.GetWriter(NetworkingAPI.CommandIndex, ClientScene.readyConnection, QosType.Reliable)) {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Send the passed request over the network
        /// </summary>
        /// <param name="request">Registered request</param>
        /// <param name="destination">Destination of the request</param>
        public static void Send <TRequest, TReply>(this TRequest request, NetworkDestination destination)
            where TRequest : INetRequest <TRequest, TReply>
            where TReply : INetRequestReply <TRequest, TReply>
        {
            if (destination.ShouldRun())
            {
                request.OnRequestReceived().OnReplyReceived();
            }

            if (destination.ShouldSend())
            {
                var header = destination.GetHeader(NetworkingAPI.GetNetworkHash(request.GetType()));

                if (NetworkServer.active)
                {
                    for (var i = 0; i < NetworkServer.connections.Count; ++i)
                    {
                        NetworkConnection conn = NetworkServer.connections[i];
                        if (conn == null)
                        {
                            continue;
                        }

                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        SendRequest <TRequest, TReply>(request, header, conn);
                    }
                }
                else if (NetworkClient.active)
                {
                    SendRequest <TRequest, TReply>(request, header, ClientScene.readyConnection);
                }
            }
        }