Ejemplo n.º 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string address        = txtAddress.Text;
            string port           = txtPort.Text;
            string id             = txtId.Text;
            string sni            = txtSNI.Text;
            string remarks        = txtRemarks.Text;
            string streamSecurity = cmbStreamSecurity.Text;
            string allowInsecure  = cmbAllowInsecure.Text;

            if (Utils.IsNullOrEmpty(address))
            {
                UI.Show(UIRes.I18N("FillServerAddress"));
                return;
            }
            if (Utils.IsNullOrEmpty(port) || !Utils.IsNumberic(port))
            {
                UI.Show(UIRes.I18N("FillCorrectServerPort"));
                return;
            }
            if (Utils.IsNullOrEmpty(id))
            {
                UI.Show(UIRes.I18N("FillPassword"));
                return;
            }

            vmessItem.address        = address;
            vmessItem.port           = Utils.ToInt(port);
            vmessItem.id             = id;
            vmessItem.sni            = sni.Replace(" ", "");
            vmessItem.remarks        = remarks;
            vmessItem.streamSecurity = streamSecurity;
            vmessItem.allowInsecure  = allowInsecure;

            if (ConfigHandler.AddTrojanServer(ref config, vmessItem, EditIndex) == 0)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                UI.ShowWarning(UIRes.I18N("OperationFailed"));
            }
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string address = txtAddress.Text;
            string port    = txtPort.Text;
            string id      = txtId.Text;
            string flow    = cmbFlow.Text;
            string remarks = txtRemarks.Text;

            if (Utils.IsNullOrEmpty(address))
            {
                UI.Show(UIRes.I18N("FillServerAddress"));
                return;
            }
            if (Utils.IsNullOrEmpty(port) || !Utils.IsNumberic(port))
            {
                UI.Show(UIRes.I18N("FillCorrectServerPort"));
                return;
            }
            if (Utils.IsNullOrEmpty(id))
            {
                UI.Show(UIRes.I18N("FillPassword"));
                return;
            }

            transportControl.EndBindingServer();

            vmessItem.address = address;
            vmessItem.port    = Utils.ToInt(port);
            vmessItem.id      = id;
            vmessItem.flow    = flow;
            vmessItem.remarks = remarks;

            if (ConfigHandler.AddTrojanServer(ref config, vmessItem) == 0)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                UI.ShowWarning(UIRes.I18N("OperationFailed"));
            }
        }
Ejemplo n.º 3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string remarks = txtRemarks.Text;
            string address = txtAddress.Text;
            string port    = txtPort.Text;

            string id       = string.Empty;
            string alterId  = string.Empty;
            string security = string.Empty;
            string flow     = string.Empty;

            switch (eConfigType)
            {
            case EConfigType.VMess:
                id       = txtId.Text;
                alterId  = txtAlterId.Text;
                security = cmbSecurity.Text;
                break;

            case EConfigType.Shadowsocks:
                id       = txtId3.Text;
                security = cmbSecurity3.Text;
                break;

            case EConfigType.Socks:
                id       = txtId4.Text;
                security = txtSecurity4.Text;
                break;

            case EConfigType.VLESS:
                id       = txtId5.Text;
                flow     = cmbFlow5.Text;
                security = cmbSecurity5.Text;
                break;

            case EConfigType.Trojan:
                id   = txtId6.Text;
                flow = cmbFlow6.Text;
                break;
            }

            if (Utils.IsNullOrEmpty(address))
            {
                UI.Show(ResUI.FillServerAddress);
                return;
            }
            if (Utils.IsNullOrEmpty(port) || !Utils.IsNumberic(port))
            {
                UI.Show(ResUI.FillCorrectServerPort);
                return;
            }
            if (eConfigType == EConfigType.Shadowsocks)
            {
                if (Utils.IsNullOrEmpty(id))
                {
                    UI.Show(ResUI.FillPassword);
                    return;
                }
                if (Utils.IsNullOrEmpty(security))
                {
                    UI.Show(ResUI.PleaseSelectEncryption);
                    return;
                }
            }
            if (eConfigType != EConfigType.Socks)
            {
                if (Utils.IsNullOrEmpty(id))
                {
                    UI.Show(ResUI.FillUUID);
                    return;
                }
            }

            transportControl.EndBindingServer();

            vmessItem.remarks  = remarks;
            vmessItem.address  = address;
            vmessItem.port     = Utils.ToInt(port);
            vmessItem.id       = id;
            vmessItem.alterId  = Utils.ToInt(alterId);
            vmessItem.security = security;

            if (Utils.IsNullOrEmpty(cmbCoreType.Text))
            {
                vmessItem.coreType = null;
            }
            else
            {
                vmessItem.coreType = (ECoreType)Enum.Parse(typeof(ECoreType), cmbCoreType.Text);
            }

            int ret = -1;

            switch (eConfigType)
            {
            case EConfigType.VMess:
                ret = ConfigHandler.AddServer(ref config, vmessItem);
                break;

            case EConfigType.Shadowsocks:
                ret = ConfigHandler.AddShadowsocksServer(ref config, vmessItem);
                break;

            case EConfigType.Socks:
                ret = ConfigHandler.AddSocksServer(ref config, vmessItem);
                break;

            case EConfigType.VLESS:
                vmessItem.flow = flow;
                ret            = ConfigHandler.AddVlessServer(ref config, vmessItem);
                break;

            case EConfigType.Trojan:
                vmessItem.flow = flow;
                ret            = ConfigHandler.AddTrojanServer(ref config, vmessItem);
                break;
            }

            if (ret == 0)
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                UI.ShowWarning(ResUI.OperationFailed);
            }
        }