Forms
AddServer6Form.cs
using System;
using System.Windows.Forms;
using v2rayN.Handler;
using v2rayN.Mode;
namespace v2rayN.Forms
{
public partial clast AddServer6Form : BaseServerForm
{
public AddServer6Form()
{
InitializeComponent();
}
private void AddServer6Form_Load(object sender, EventArgs e)
{
if (EditIndex >= 0)
{
vmessItem = config.vmess[EditIndex];
BindingServer();
}
else
{
vmessItem = new VmessItem();
ClearServer();
}
}
///
/// 绑定数据
///
private void BindingServer()
{
txtAddress.Text = vmessItem.address;
txtPort.Text = vmessItem.port.ToString();
txtId.Text = vmessItem.id;
txtSNI.Text = vmessItem.sni;
txtRemarks.Text = vmessItem.remarks;
cmbStreamSecurity.Text = vmessItem.streamSecurity;
cmbAllowInsecure.Text = vmessItem.allowInsecure;
}
///
/// 清除设置
///
private void ClearServer()
{
txtAddress.Text = "";
txtPort.Text = "";
txtId.Text = "";
txtSNI.Text = "";
txtRemarks.Text = "";
cmbStreamSecurity.Text = "tls";
cmbAllowInsecure.Text = "";
}
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("FillPastword"));
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"));
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}