Skip to content

Commit 21405f3

Browse files
committed
feat(主页): launch_game 新参数,支持指定快速加入服务器
1 parent d2a5205 commit 21405f3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/ui/activities/MainActivity.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import com.movtery.zalithlauncher.utils.festival.getTodayFestivals
6868
import com.movtery.zalithlauncher.utils.file.shareFile
6969
import com.movtery.zalithlauncher.utils.isChinese
7070
import com.movtery.zalithlauncher.utils.logging.Logger.lInfo
71+
import com.movtery.zalithlauncher.utils.logging.Logger.lWarning
7172
import com.movtery.zalithlauncher.utils.network.openLink
7273
import com.movtery.zalithlauncher.utils.network.openLinkInternal
7374
import com.movtery.zalithlauncher.utils.string.getMessageOrToString
@@ -481,7 +482,22 @@ class MainActivity : BaseAppCompatActivity() {
481482
//检查启动器更新
482483
"check_update" -> checkUpdate()
483484
//启动当前选中的游戏版本
484-
"launch_game" -> launchGameViewModel.tryLaunch()
485+
"launch_game" -> {
486+
if (data != null) {
487+
runCatching {
488+
val parms = data.split("=")
489+
if (parms.size == 2 && parms[0] == "server") {
490+
//指定快速启动的服务器ip
491+
val serverIp = parms[1].trim()
492+
launchGameViewModel.tryLaunchServer(serverIp)
493+
return
494+
}
495+
}.onFailure { e ->
496+
lWarning("Failed to parse quick join server parameters: $data", e)
497+
}
498+
}
499+
launchGameViewModel.tryLaunch()
500+
}
485501
//复制指定文本
486502
"copy" -> {
487503
if (data != null) {

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/viewmodel/LaunchGameViewModel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ class LaunchGameViewModel : ViewModel() {
6161
}
6262
}
6363

64+
/**
65+
* 尝试启动游戏快速游玩服务器
66+
* @param address 服务器地址
67+
*/
68+
fun tryLaunchServer(address: String) {
69+
val version = VersionsManager.currentVersion.value ?: return
70+
quickPlayServer(version, address)
71+
}
72+
6473
/**
6574
* 通过服务器列表快速游玩服务器
6675
* @param address 服务器地址

0 commit comments

Comments
 (0)