From 8c19c68a582724aa7c80a88f1a22d229ef522953 Mon Sep 17 00:00:00 2001 From: LeeCenY <634348197@qq.com> Date: Wed, 10 Jun 2020 00:43:34 +0800 Subject: [PATCH] Fix socks5 protocol can't connect without a user bug --- V2rayU/ConfigWindow.swift | 12 ++++++++---- V2rayU/v2ray/v2rayOutbound.swift | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/V2rayU/ConfigWindow.swift b/V2rayU/ConfigWindow.swift index 3c09837..a1eb06f 100644 --- a/V2rayU/ConfigWindow.swift +++ b/V2rayU/ConfigWindow.swift @@ -279,7 +279,11 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel var sockUser = V2rayOutboundSockUser() sockUser.user = self.socks5User.stringValue sockUser.pass = self.socks5Pass.stringValue - v2rayConfig.serverSocks5.servers[0].users = [sockUser] + if self.socks5User.stringValue.count > 0 || self.socks5Pass.stringValue.count > 0 { + v2rayConfig.serverSocks5.servers[0].users = [sockUser] + } else { + v2rayConfig.serverSocks5.servers[0].users = nil + } // ========================== server end ======================= // ========================== stream start ======================= @@ -368,9 +372,9 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel // socks5 self.socks5Addr.stringValue = v2rayConfig.serverSocks5.servers[0].address self.socks5Port.stringValue = String(v2rayConfig.serverSocks5.servers[0].port) - if v2rayConfig.serverSocks5.servers[0].users.count > 0 { - self.socks5User.stringValue = v2rayConfig.serverSocks5.servers[0].users[0].user - self.socks5Pass.stringValue = v2rayConfig.serverSocks5.servers[0].users[0].pass + if let users = v2rayConfig.serverSocks5.servers[0].users, users.count > 0 { + self.socks5User.stringValue = users[0].user + self.socks5Pass.stringValue = users[0].pass } // ========================== server end ======================= diff --git a/V2rayU/v2ray/v2rayOutbound.swift b/V2rayU/v2ray/v2rayOutbound.swift index 68aa572..34eafff 100644 --- a/V2rayU/v2ray/v2rayOutbound.swift +++ b/V2rayU/v2ray/v2rayOutbound.swift @@ -196,7 +196,7 @@ struct V2rayOutboundSocks: Codable { struct V2rayOutboundSockServer: Codable { var address: String = "" var port: Int = 0 - var users: [V2rayOutboundSockUser] = [V2rayOutboundSockUser()] + var users: [V2rayOutboundSockUser]? } struct V2rayOutboundSockUser: Codable {