celeron533 6 years ago
parent
commit
75a5b13a4f
3 changed files with 21 additions and 4 deletions
  1. +2
    -1
      shadowsocks-csharp/Controller/Service/UDPRelay.cs
  2. +10
    -0
      shadowsocks-csharp/Model/Configuration.cs
  3. +9
    -3
      shadowsocks-csharp/View/ConfigForm.cs

+ 2
- 1
shadowsocks-csharp/Controller/Service/UDPRelay.cs View File

@@ -40,10 +40,10 @@ namespace Shadowsocks.Controller
if (handler == null) if (handler == null)
{ {
handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint, null/*TODO: fix this*/), remoteEndPoint); handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint, null/*TODO: fix this*/), remoteEndPoint);
handler.Receive();
_cache.add(remoteEndPoint, handler); _cache.add(remoteEndPoint, handler);
} }
handler.Send(firstPacket, length); handler.Send(firstPacket, length);
handler.Receive();
return true; return true;
} }
@@ -74,6 +74,7 @@ namespace Shadowsocks.Controller
} }
_remoteEndPoint = new IPEndPoint(ipAddress, server.server_port); _remoteEndPoint = new IPEndPoint(ipAddress, server.server_port);
_remote = new Socket(_remoteEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); _remote = new Socket(_remoteEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
_remote.Bind(new IPEndPoint(IPAddress.Any, 0));
} }
public void Send(byte[] data, int length) public void Send(byte[] data, int length)


+ 10
- 0
shadowsocks-csharp/Model/Configuration.cs View File

@@ -125,6 +125,16 @@ namespace Shadowsocks.Model
} }
} }
public static Server AddDefaultServerOrServer(Configuration config, Server server = null)
{
if (config != null && config.configs != null)
{
server = (server ?? GetDefaultServer());
config.configs.Add(server);
}
return server;
}
public static Server GetDefaultServer() public static Server GetDefaultServer()
{ {
return new Server(); return new Server();


+ 9
- 3
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -273,8 +273,7 @@ namespace Shadowsocks.View
{ {
return; return;
} }
Server server = Configuration.GetDefaultServer();
_modifiedConfiguration.configs.Add(server);
Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1; ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1;
_lastSelectedIndex = ServersListBox.SelectedIndex; _lastSelectedIndex = ServersListBox.SelectedIndex;
@@ -282,7 +281,8 @@ namespace Shadowsocks.View
private void DuplicateButton_Click(object sender, EventArgs e) private void DuplicateButton_Click(object sender, EventArgs e)
{ {
if (!ValidateAndSaveSelectedServerDetails())
if (_lastSelectedIndex == -1 || _lastSelectedIndex > _modifiedConfiguration.configs.Count
|| !ValidateAndSaveSelectedServerDetails())
{ {
return; return;
} }
@@ -301,6 +301,10 @@ namespace Shadowsocks.View
{ {
_modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex); _modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);
} }
if (_modifiedConfiguration.configs.Count == 0)
{
Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
}
if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count) if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count)
{ {
// can be -1 // can be -1
@@ -310,6 +314,8 @@ namespace Shadowsocks.View
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
ServersListBox.SelectedIndex = _lastSelectedIndex; ServersListBox.SelectedIndex = _lastSelectedIndex;
LoadSelectedServerDetails(); LoadSelectedServerDetails();
UpdateButtons();
} }
private void OKButton_Click(object sender, EventArgs e) private void OKButton_Click(object sender, EventArgs e)


Loading…
Cancel
Save