Commit 238d78cb authored by chenhuaqing's avatar chenhuaqing Committed by hanakeichen

add `proxyRules` field for advanced controlling client behaviors in the VPN service

parent a9e6bb57
......@@ -16,5 +16,6 @@ data class GameInfo(
val imgs: String,
val introduction: String,
val packageName: String,
val boosterPackageName :String
val boosterPackageName :String,
val proxyRules: String,
)
\ No newline at end of file
......@@ -149,14 +149,12 @@ object AcceleratorUtils {
fun startAccelerator(xPageFragment: XPageFragment) {
game?.let {
initAuthProfile(xPageFragment)
val serverPort = it.boosterServer.split(":")
DataStore.pingAccHost = serverPort[0]
DataStore.pingAccPort = serverPort[1].toInt()
}
}
private fun initAuthProfile(xPageFragment: XPageFragment) {
xPageFragment.lifecycleScope.launch(Dispatchers.IO) {
val game = AcceleratorUtils.game
val profileId = 1L
val profile = ProfileManager.getProfile(profileId) ?: Profile()
profile.proxyApps = true
......@@ -167,13 +165,19 @@ object AcceleratorUtils {
"com.activision.callofduty.shooter",
"com.pubg.krmobile",
)
game?.packageName?.let { proxyGames.add(it) }
game?.boosterPackageName?.split(",")?.forEach {
if (game != null) {
proxyGames.add(game.packageName)
game.boosterPackageName.split(",").forEach {
if (!StringUtils.isEmpty(it)) {
proxyGames.add(it)
}
}
// proxyGames.addAll(profile.individual.split("\n"))
DataStore.proxyRules = game.proxyRules
val serverPort = game.boosterServer.split(":")
DataStore.pingAccHost = serverPort[0]
DataStore.pingAccPort = serverPort[1].toInt()
}
profile.individual = proxyGames.joinToString("\n")
profile.route = Acl.BYPASS_LAN
profile.password = "barfoo!"
......
......@@ -2,6 +2,7 @@ package com.ccnet.acc
import android.content.Context
import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.preference.DataStore
import timber.log.Timber
import java.io.File
......@@ -14,6 +15,7 @@ object AccVpn {
}
fun writeConfig(context: Context, tunFd: Int, profile: Profile) {
val proxyRules = DataStore.proxyRules
val configContent = """
[General]
loglevel = trace
......@@ -23,7 +25,8 @@ object AccVpn {
Direct = direct
SS = ss, ${profile.host}, ${profile.remotePort}, encrypt-method=chacha20-ietf-poly1305, password=123456, auth_timeout=${profile.authTimeout}, beats_interval=${profile.beatsInterval}, retry_limit=${profile.retryLimit}, token=${profile.token}
[Rule]
FINAL, SS
$proxyRules
FINAL, Direct
"""
val configFile = configFile(context)
Timber.d("writeConfig ${configFile.absolutePath}")
......
......@@ -131,4 +131,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var pingNetReachableHost: String
get() = privateStore.getString(Key.pingNetReachableHost) ?: "baidu.com"
set(value) = privateStore.putString(Key.pingNetReachableHost, value)
var proxyRules: String
get() = privateStore.getString(Key.proxyRules) ?: ""
set(value) = privateStore.putString(Key.proxyRules, value)
}
......@@ -79,6 +79,8 @@ object Key {
const val pingAccPort = "pingAccPort"
const val pingNetReachableHost = "pingNetReachableHost"
const val proxyRules = "proxyRules"
// TV specific values
const val controlStats = "control.stats"
const val controlImport = "control.import"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment