Skip to content

Commit

Permalink
feat: shadowsocket 2.2.35版本自动下发Hy2
Browse files Browse the repository at this point in the history
  • Loading branch information
gua committed Nov 17, 2023
1 parent 879b514 commit 637c0f9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/Http/Controllers/V1/Client/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function subscribe(Request $request)
$flag = $request->input('flag') ?? $request->header('User-Agent', '');
$ip = $request->input('ip') ?? $request->ip();

preg_match('/(\d+\.\d+\.\d+)/', $flag, $matches);
preg_match('/(?<=\/)(\d+\.\d+\.\d+)|(?<=\/)(\d+)/', $flag, $matches);
$version = $matches[0]??null;
$isNekoBox = (stripos($flag, 'NekoBox') !== false); //判断是否为Nekobox客户端
$isSingBox = (stripos($flag, 'sing-box') !== false); //判断是否为stash客户端
$isShadowsocket = (stripos($flag, 'Shadowrocket') !== false); //判断是否为shadowsocket客户端
$isStash = (strpos($flag, 'Stash') !== false);
if(config('app.debug')){
Log::channel('daily')->info($flag);
Expand All @@ -50,14 +51,15 @@ public function subscribe(Request $request)
$servers = $serverService->getAvailableServers($user);

// 判断不满足,不满足的直接过滤掉
$serversFiltered = collect($servers)->reject(function ($server) use ($typesArr, $filterArr, $region, $isNekoBox, $isStash, $version, $isSingBox){
$serversFiltered = collect($servers)->reject(function ($server) use ($typesArr, $filterArr, $region, $isNekoBox, $isStash, $version, $isSingBox, $isShadowsocket){
// 过滤类型
if($typesArr){
// 默认过滤掉hysteria2 线路
if($server['type'] == "hysteria" && $server['version'] == 2 && !in_array('hysteria2', $typesArr)
&& !($isNekoBox && $this->versionCompare($version, '1.2.7')) //1.2.7<=版本 自动下发hy2
&& !($isSingBox && $this->versionCompare($version, '1.5.0')) //1.5.0<=版本 自动下发hy2
&& !($isStash && $this->versionCompare($version, '2.5.0' )) //2.5.0或者以上版本自动下发hy2
&& !($isShadowsocket && $this->versionCompare($version, 1993)) //1993 版本或者以上的shadowsocket下发hy2
){
return true;
}
Expand Down Expand Up @@ -166,7 +168,7 @@ private function setSubscribeInfoToServers(&$servers, $user, $rejectServerCount
*/

function versionCompare($version1, $version2) {
if (!preg_match('/^\d+\.\d+\.\d+$/', $version1) || !preg_match('/^\d+\.\d+\.\d+$/', $version2)) {
if (!preg_match('/^\d+\.\d+\.\d+$|\d/', $version1) || !preg_match('/^\d+\.\d+\.\d+$|\d/', $version2)) {
return false;
}
$v1Parts = explode('.', $version1);
Expand Down

0 comments on commit 637c0f9

Please sign in to comment.