Ejemplo n.º 1
0
        public static void Send(this INetCommand command, NetworkDestination destination, Int32 recievedFrom = -1)
        {
            if (destination.ShouldRun())
            {
                command.OnRecieved();
            }

            if (destination.ShouldSend())
            {
                Header header = destination.GetHeader(NetworkCore.GetNetworkCoreHash(command.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;
                        }
                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkCore.GetWriter(NetworkCore.commandIndex, conn, NetworkCore.qos))
                        {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                        }
                    }
                }
                else if (NetworkClient.active)
                {
                    using (Writer netWriter = NetworkCore.GetWriter(NetworkCore.commandIndex, ClientScene.readyConnection, NetworkCore.qos))
                    {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                    }
                }
            }
        }
Ejemplo n.º 2
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;
                        }
                        if (NetworkServer.localClientActive && NetworkServer.localConnections.Contains(conn))
                        {
                            continue;
                        }

                        using (Writer netWriter = NetworkingAPI.GetWriter(NetworkingAPI.CommandIndex, conn, QosType.Reliable)) {
                            NetworkWriter writer = netWriter;
                            writer.Write(header);
                        }
                    }
                }
                else if (NetworkClient.active)
                {
                    using (var netWriter = NetworkingAPI.GetWriter(NetworkingAPI.CommandIndex, ClientScene.readyConnection, QosType.Reliable)) {
                        NetworkWriter writer = netWriter;
                        writer.Write(header);
                    }
                }
            }
        }