diff --git a/scripts/fzsd_score.sc b/scripts/fzsd_score.sc index 491a5b8..5ff8eda 100644 --- a/scripts/fzsd_score.sc +++ b/scripts/fzsd_score.sc @@ -19,41 +19,11 @@ require_not_null(value) -> ( ); require_version(requirement) -> ( - req_0 = slice(requirement, 0, 1); - req_1 = slice(requirement, 1, 2); - if(req_0 == '>', - if(req_1 == '=', - req_ver = split('>=|\\.', requirement); - print(player('all'), req_ver); - cur_ver = split('\\.', global_carpet_version); - return(number(req_ver:1) >= number(cur_ver:0) - && number(req_ver:2) >= number(cur_ver:1) - && number(req_ver:3) >= number(cur_ver:2)); - ); - req_ver = split('>|\\.', requirement); - print(player('all'), req_ver); - cur_ver = split('\\.', global_carpet_version); - return(number(req_ver:1) > number(cur_ver:0) - && number(req_ver:2) > number(cur_ver:1) - && number(req_ver:3) > number(cur_ver:2)); - ); - if(req_0 == '<', - if(req_1 == '=', - req_ver = split('<=|\\.', requirement); - print(player('all'), req_ver); - cur_ver = split('\\.', global_carpet_version); - return(number(req_ver:1) <= number(cur_ver:0) - && number(req_ver:2) <= number(cur_ver:1) - && number(req_ver:3) <= number(cur_ver:2)); - ); - req_ver = split('<|\\.', requirement); - print(player('all'), req_ver); - cur_ver = split('\\.', global_carpet_version); - return(number(req_ver:1) < number(cur_ver:0) - && number(req_ver:2) < number(cur_ver:1) - && number(req_ver:3) < number(cur_ver:2)); - ); - return(false); + req_ver = split('\\.', requirement); + cur_ver = split('\\.', global_carpet_version); + return(number(cur_ver:0) >= number(req_ver:0) + && number(cur_ver:1) >= number(req_ver:1) + && number(cur_ver:2) >= number(req_ver:2)); ); //** 主要逻辑 **// @@ -73,6 +43,7 @@ global_current_scoreboard_list = [ 'fzsd.module.scoreboard.display.aviating_distance', 'fzsd.module.scoreboard.display.placement_count' ]; +global_server_whitelist_cache = null; __config() -> { 'scope' -> 'global', @@ -145,22 +116,7 @@ __config() -> { }; __on_start() -> ( - // 读取配置文件 - global_config = read_file('config', 'json'); - if(global_config == null, // carpet 1.4.69 兼容 - global_config = {}; - ); - if(length(global_config) == 0, // 读取失败或不存在 - delete_file('config', 'json'); // 避免一些意外的问题 - global_config:'config_version' = '1.0.0'; // 占位用,无实际作用 - if(require_version('>=1.99.99'), // 等待新功能支持 - global_config:'allow_spawn_whitelist_player' = false; - write_file('config', 'json', global_config); - , - // else - write_file('config', 'json', global_config); - ); - ); + reload_configs(); global_team_cache = read_file('team_cache', 'json'); if(global_team_cache == null, // carpet 1.4.69 兼容 global_team_cache = {}; @@ -173,12 +129,14 @@ __on_close() -> ( write_file('team_cache', 'json', global_team_cache); ); -if(require_version('>=1.99.99'), // 等待新功能支持 - __on_player_command(player, message) -> ( - print(player('all'), 'command!'); - if(length(message) > 7 - && slice(message, 0, 7) == '/player' - && !(global_config:'allow_spawn_whitelist_player'), +if(require_version('1.4.112'), // 新功能支持 + __on_player_command(player, command) -> ( + l = length(command); + if(l > 13 + && slice(command, 0, 6) == 'player' + && slice(command, l - 5, l) == 'spawn' + && !(global_config:'allow_spawn_whitelist_player') + && contains(get_server_whitelist(), slice(command, 7, l - 6)), return('cancel'); ); ); @@ -186,11 +144,11 @@ if(require_version('>=1.99.99'), // 等待新功能支持 __on_player_connects(player) -> ( player_type = player ~ 'player_type'; - player_team = player ~ 'team'; - player_name = player ~ 'name'; if(player_type == 'fake', ( + player_team = player ~ 'team'; if(player_team != 'fzsd.module.scoreboard.fake', + player_name = player ~ 'name'; global_team_cache:player_name = player_team; ); team_add('fzsd.module.scoreboard.fake', player); @@ -198,7 +156,9 @@ __on_player_connects(player) -> ( ), player_type == 'shadow', ( + player_team = player ~ 'team'; if(player_team != 'fzsd.module.scoreboard.shadow', + player_name = player ~ 'name'; global_team_cache:player_name = player_team; ); team_add('fzsd.module.scoreboard.shadow', player); @@ -222,6 +182,38 @@ __on_player_disconnects(player, reason) -> ( try_restore_team_from_cache(player); ); +// 获取服务器白名单 +get_server_whitelist() -> ( + if(global_server_whitelist_cache == null, + global_server_whitelist_cache = keys(system_info('server_whitelist')); + ); + return(global_server_whitelist_cache); +); + +// 重载配置文件 +reload_configs() -> ( + // 读取配置文件 + global_config = read_file('config', 'json'); + if(global_config == null, // carpet 1.4.69 兼容 + global_config = {}; + ); + config_changed = false; + // 读取失败或不存在 + if(length(global_config) == 0, + global_config:'config_version' = '1.0.0'; // 占位用,无实际作用 + config_changed = true; + ); + // 新功能支持 + if(require_version('1.4.112') && !contains(global_config, 'allow_spawn_whitelist_player'), + global_config:'allow_spawn_whitelist_player' = false; + config_changed = true; + ); + if(config_changed == true, + delete_file('config', 'json'); // 避免一些意外的问题 + write_file('config', 'json', global_config); + ); +); + // 获取所有计分板下的所有玩家列表 get_scoreboard_player_list() -> ( set = m();