예제 #1
0
 private void Load()  //加载配置文件函数
 {
     _config      = BConfig.Load(config_path);
     _translation = Translation.Load(translation_path);
     File.WriteAllText(config_path, JsonConvert.SerializeObject(_config, Formatting.Indented));
     File.WriteAllText(translation_path, JsonConvert.SerializeObject(_translation, Formatting.Indented));
 }
예제 #2
0
        private void bwl(CommandArgs args)
        {
            if (args.Parameters.Count < 1)
            {
                args.Player.SendErrorMessage(_translation.language["HelpText"]);
                return;
            }
            switch (args.Parameters[0])
            {
            case "add":
                if (_config.Disabled)    //检测配置文件的Disabled选项
                {
                    args.Player.SendErrorMessage(_translation.language["NotEnabled"]);
                }
                else
                {
                    _config.WhitePlayers.Add(args.Parameters[1]);
                    args.Player.SendSuccessMessage(_translation.language["SuccessfullyAdd"]);
                    File.WriteAllText(config_path, JsonConvert.SerializeObject(_config, Formatting.Indented));
                }
                break;

            case "del":
                if (_config.Disabled)    //检测配置文件的Disabled选项
                {
                    args.Player.SendErrorMessage(_translation.language["NotEnabled"]);
                }
                else
                {
                    if (_config.WhitePlayers.Contains(args.Parameters[1]))
                    {
                        _config.WhitePlayers.Remove(args.Parameters[1]);
                        args.Player.SendSuccessMessage(_translation.language["SuccessfullyDelete"]);
                        File.WriteAllText(config_path, JsonConvert.SerializeObject(_config, Formatting.Indented));
                        if (players[args.Parameters[1]].Active == true)                                        //检测玩家是否在线
                        {
                            players[args.Parameters[1]].Disconnect(_translation.language["DisconnectReason"]); //从白名单删除后,如果在线踢出玩家
                        }
                    }
                }
                break;

            case "list":
                foreach (var item in _config.WhitePlayers)
                {
                    args.Player.SendInfoMessage(item);
                }
                break;

            case "help":
                args.Player.SendInfoMessage("-------[BetterWhitelist]-------");
                args.Player.SendInfoMessage(_translation.language["AllHelpText"]);
                break;

            case "true":        //通过指令打开白名单时,检测玩家是否在已保存的白名单内,不在则踢出服务器//这里还是有问题
                if (_config.Disabled == false)
                {
                    args.Player.SendErrorMessage(_translation.language["FailedEnable"]);
                }
                else
                {
                    _config.Disabled = false;
                    args.Player.SendSuccessMessage(_translation.language["SuccessfullyEnable"]);
                    if (players.Count > 0)
                    {
                        if (_config.WhitePlayers.Count > 0)
                        {
                            for (int i = 0; i < players.Count; i++)
                            {
                                if (!_config.WhitePlayers.Contains(players.Keys.ToList()[i]))
                                {
                                    players[players.Keys.ToList()[i]].Disconnect(_translation.language["NotOnList"]);
                                }
                            }
                        }
                        else
                        {
                            foreach (var item in players.Values)
                            {
                                item.Disconnect(_translation.language["NotOnList"]);
                            }
                        }
                    }
                    File.WriteAllText(config_path, JsonConvert.SerializeObject(_config, Formatting.Indented));
                }
                break;

            case "false":
                if (_config.Disabled == true)
                {
                    args.Player.SendErrorMessage(_translation.language["FailedDisable"]);
                }
                else
                {
                    _config.Disabled = true;
                    args.Player.SendSuccessMessage(_translation.language["SuccessfullyDisable"]);
                    File.WriteAllText(config_path, JsonConvert.SerializeObject(_config, Formatting.Indented));
                }
                break;

            case "reload":
                _config      = JsonConvert.DeserializeObject <BConfig>(File.ReadAllText(config_path));
                _translation = JsonConvert.DeserializeObject <Translation>(File.ReadAllText(translation_path));
                args.Player.SendSuccessMessage(_translation.language["SuccessfullyReload"]);
                break;
            }
        }