Skip to content

Commit

Permalink
Add share 4 Wireguard
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 16, 2024
1 parent 8f62e42 commit cf6c814
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,11 @@ object AngConfigManager {
try {
val config = MmkvManager.decodeServerConfig(guid) ?: return ""
val outbound = config.getProxyOutbound() ?: return ""
val streamSetting = outbound.streamSettings ?: return ""
val streamSetting =
outbound.streamSettings ?: V2rayConfig.OutboundBean.StreamSettingsBean()
if (config.configType != EConfigType.WIREGUARD) {
if (outbound.streamSettings == null) return ""
}
return config.configType.protocolScheme + when (config.configType) {
EConfigType.VMESS -> {
val vmessQRCode = VmessQRCode()
Expand Down Expand Up @@ -600,7 +604,8 @@ object AngConfigManager {
Utils.encode(json)
}

EConfigType.CUSTOM, EConfigType.WIREGUARD -> ""
EConfigType.CUSTOM -> ""

EConfigType.SHADOWSOCKS -> {
val remark = "#" + Utils.urlEncode(config.remarks)
val pw =
Expand Down Expand Up @@ -736,6 +741,36 @@ object AngConfigManager {
)
url + query + remark
}

EConfigType.WIREGUARD -> {
val remark = "#" + Utils.urlEncode(config.remarks)

val dicQuery = HashMap<String, String>()
dicQuery["publickey"] =
Utils.urlEncode(outbound.settings?.peers?.get(0)?.publicKey.toString())
dicQuery["reserved"] = Utils.urlEncode(
Utils.removeWhiteSpace(outbound.settings?.reserved?.joinToString())
.toString()
)
dicQuery["address"] = Utils.urlEncode(
Utils.removeWhiteSpace((outbound.settings?.address as List<*>).joinToString())
.toString()
)
if (outbound.settings?.mtu != null) {
dicQuery["mtu"] = outbound.settings?.mtu.toString()
}
val query = "?" + dicQuery.toList().joinToString(
separator = "&",
transform = { it.first + "=" + it.second })

val url = String.format(
"%s@%s:%s",
Utils.urlEncode(outbound.getPassword().toString()),
Utils.getIpv6Address(outbound.getServerAddress()!!),
outbound.getServerPort()
)
url + query + remark
}
}
} catch (e: Exception) {
e.printStackTrace()
Expand Down Expand Up @@ -861,17 +896,19 @@ object AngConfigManager {
return 0
}
val removedSelectedServer =
if (!TextUtils.isEmpty(subid) && !append) {
MmkvManager.decodeServerConfig(mainStorage?.decodeString(KEY_SELECTED_SERVER) ?: "")?.let {
if (it.subscriptionId == subid) {
return@let it
}
return@let null
if (!TextUtils.isEmpty(subid) && !append) {
MmkvManager.decodeServerConfig(
mainStorage?.decodeString(KEY_SELECTED_SERVER) ?: ""
)?.let {
if (it.subscriptionId == subid) {
return@let it
}
} else {
null
return@let null
}
if(!append) {
} else {
null
}
if (!append) {
MmkvManager.removeServerViaSubid(subid)
}
// var servers = server
Expand Down

0 comments on commit cf6c814

Please sign in to comment.