예제 #1
0
        private static void outbound(Server server, Mode mode, ref V2rayConfig v2rayConfig)
        {
            try
            {
                var outbound = new Outbounds
                {
                    settings       = new Outboundsettings(),
                    mux            = new Mux(),
                    streamSettings = new StreamSettings
                    {
                        network = "tcp"
                    }
                };

                switch (server)
                {
                case Socks5.Socks5 socks5:
                {
                    var serversItem = new ServersItem
                    {
                        users = new List <SocksUsersItem>()
                    };
                    outbound.settings.servers = new List <ServersItem>
                    {
                        serversItem
                    };

                    serversItem.address  = server.AutoResolveHostname();
                    serversItem.port     = server.Port;
                    serversItem.method   = null;
                    serversItem.password = null;

                    if (socks5.Auth())
                    {
                        var socksUsersItem = new SocksUsersItem
                        {
                            user  = socks5.Username,
                            pass  = socks5.Password,
                            level = 1
                        };

                        serversItem.users.Add(socksUsersItem);
                    }

                    outbound.mux.enabled     = false;
                    outbound.mux.concurrency = -1;
                    outbound.protocol        = "socks";
                    break;
                }

                case VLESS.VLESS vless:
                {
                    var vnextItem = new VnextItem
                    {
                        users = new List <UsersItem>()
                    };
                    outbound.settings.vnext = new List <VnextItem>
                    {
                        vnextItem
                    };

                    vnextItem.address = server.AutoResolveHostname();
                    vnextItem.port    = server.Port;

                    var usersItem = new UsersItem();
                    vnextItem.users.Add(usersItem);

                    usersItem.id         = vless.UserID;
                    usersItem.alterId    = 0;
                    usersItem.flow       = string.Empty;
                    usersItem.encryption = vless.EncryptMethod;

                    outbound.mux.enabled     = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux;
                    outbound.mux.concurrency = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;

                    var streamSettings = outbound.streamSettings;
                    boundStreamSettings(vless, ref streamSettings);

                    if (vless.TransferProtocol == "xtls")
                    {
                        usersItem.flow = string.IsNullOrEmpty(vless.Flow) ? "xtls-rprx-origin" : vless.Flow;

                        outbound.mux.enabled     = false;
                        outbound.mux.concurrency = -1;
                    }

                    outbound.protocol         = "vless";
                    outbound.settings.servers = null;
                    break;
                }

                case VMess vmess:
                {
                    var vnextItem = new VnextItem
                    {
                        users = new List <UsersItem>()
                    };
                    outbound.settings.vnext = new List <VnextItem>
                    {
                        vnextItem
                    };

                    vnextItem.address = server.AutoResolveHostname();
                    vnextItem.port    = server.Port;

                    var usersItem = new UsersItem();
                    vnextItem.users.Add(usersItem);

                    usersItem.id       = vmess.UserID;
                    usersItem.alterId  = vmess.AlterID;
                    usersItem.security = vmess.EncryptMethod;

                    outbound.mux.enabled     = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux;
                    outbound.mux.concurrency = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;

                    var streamSettings = outbound.streamSettings;
                    boundStreamSettings(vmess, ref streamSettings);

                    outbound.protocol = "vmess";
                    break;
                }
                }

                v2rayConfig.outbounds = new List <Outbounds>
                {
                    outbound,
                    new Outbounds
                    {
                        tag      = "direct",
                        protocol = "freedom"
                    }
                };
            }
            catch
            {
                // ignored
            }
        }
예제 #2
0
        /// <summary>
        /// vmess协议服务器配置
        /// </summary>
        /// <param name="config"></param>
        /// <param name="v2rayConfig"></param>
        /// <returns></returns>
        private static int outbound(Config config, ref V2rayConfig v2rayConfig)
        {
            try
            {
                if (config.configType() == (int)EConfigType.Vmess)
                {
                    VnextItem vnextItem;
                    if (v2rayConfig.outbound.settings.vnext.Count <= 0)
                    {
                        vnextItem = new VnextItem();
                        v2rayConfig.outbound.settings.vnext.Add(vnextItem);
                    }
                    else
                    {
                        vnextItem = v2rayConfig.outbound.settings.vnext[0];
                    }
                    //远程服务器地址和端口
                    vnextItem.address = config.address();
                    vnextItem.port    = config.port();

                    UsersItem usersItem;
                    if (vnextItem.users.Count <= 0)
                    {
                        usersItem = new UsersItem();
                        vnextItem.users.Add(usersItem);
                    }
                    else
                    {
                        usersItem = vnextItem.users[0];
                    }
                    //远程服务器用户ID
                    usersItem.id       = config.id();
                    usersItem.alterId  = config.alterId();
                    usersItem.email    = Global.userEMail;
                    usersItem.security = config.security();

                    //Mux
                    v2rayConfig.outbound.mux.enabled = config.muxEnabled;

                    //远程服务器底层传输配置
                    StreamSettings streamSettings = v2rayConfig.outbound.streamSettings;
                    boundStreamSettings(config, "out", ref streamSettings);

                    v2rayConfig.outbound.protocol         = "vmess";
                    v2rayConfig.outbound.settings.servers = null;
                }
                else if (config.configType() == (int)EConfigType.Shadowsocks)
                {
                    ServersItem serversItem;
                    if (v2rayConfig.outbound.settings.servers.Count <= 0)
                    {
                        serversItem = new ServersItem();
                        v2rayConfig.outbound.settings.servers.Add(serversItem);
                    }
                    else
                    {
                        serversItem = v2rayConfig.outbound.settings.servers[0];
                    }
                    //远程服务器地址和端口
                    serversItem.address  = config.address();
                    serversItem.port     = config.port();
                    serversItem.password = config.id();
                    serversItem.method   = config.security();

                    serversItem.ota   = false;
                    serversItem.level = 1;

                    v2rayConfig.outbound.mux.enabled = false;

                    v2rayConfig.outbound.protocol       = "shadowsocks";
                    v2rayConfig.outbound.settings.vnext = null;
                }
            }
            catch
            {
            }
            return(0);
        }
예제 #3
0
        /// <summary>
        /// vmess协议服务器配置
        /// </summary>
        /// <param name="config"></param>
        /// <param name="v2rayConfig"></param>
        /// <returns></returns>
        private static int outbound(Config config, ref V2rayConfig v2rayConfig)
        {
            try
            {
                var outbound = v2rayConfig.outbounds[0];
                if (config.configType() == (int)EConfigType.Vmess)
                {
                    VnextItem vnextItem;
                    if (outbound.settings.vnext.Count <= 0)
                    {
                        vnextItem = new VnextItem();
                        outbound.settings.vnext.Add(vnextItem);
                    }
                    else
                    {
                        vnextItem = outbound.settings.vnext[0];
                    }
                    //远程服务器地址和端口
                    vnextItem.address = config.address();
                    vnextItem.port    = config.port();

                    UsersItem usersItem;
                    if (vnextItem.users.Count <= 0)
                    {
                        usersItem = new UsersItem();
                        vnextItem.users.Add(usersItem);
                    }
                    else
                    {
                        usersItem = vnextItem.users[0];
                    }
                    //远程服务器用户ID
                    usersItem.id       = config.id();
                    usersItem.alterId  = config.alterId();
                    usersItem.email    = Global.userEMail;
                    usersItem.security = config.security();

                    //Mux
                    outbound.mux.enabled = config.muxEnabled;

                    //远程服务器底层传输配置
                    StreamSettings streamSettings = outbound.streamSettings;
                    boundStreamSettings(config, "out", ref streamSettings);

                    outbound.protocol         = "vmess";
                    outbound.settings.servers = null;
                }
                else if (config.configType() == (int)EConfigType.Shadowsocks)
                {
                    ServersItem serversItem;
                    if (outbound.settings.servers.Count <= 0)
                    {
                        serversItem = new ServersItem();
                        outbound.settings.servers.Add(serversItem);
                    }
                    else
                    {
                        serversItem = outbound.settings.servers[0];
                    }
                    //远程服务器地址和端口
                    serversItem.address  = config.address();
                    serversItem.port     = config.port();
                    serversItem.password = config.id();
                    serversItem.method   = config.security();

                    serversItem.ota   = false;
                    serversItem.level = 1;

                    outbound.mux.enabled = false;

                    outbound.protocol       = "shadowsocks";
                    outbound.settings.vnext = null;
                }

                int isBlacklist = 0;
                int.TryParse(config.blackOrWhite, out isBlacklist);
                if (isBlacklist == 0)
                {
                    //freedom优先
                    var vmess   = v2rayConfig.outbounds[0];
                    var freedom = v2rayConfig.outbounds[1];
                    v2rayConfig.outbounds[0] = freedom;
                    v2rayConfig.outbounds[1] = vmess;
                }
            }

            catch
            {
            }
            return(0);
        }