Ejemplo n.º 1
0
        public override void Execute(PluginArgs e)
        {
            state = PluginState.RUNNING;

            new Thread(delegate()
                {
                    scan();
                }).Start();
            base.Execute(e);
        }
Ejemplo n.º 2
0
 internal void Load() {
   if (!(pluginState == PluginState.Enabled || pluginState == PluginState.Loaded))
     throw new InvalidOperationException("Cannot load a plugin in state " + pluginState);
   pluginState = PluginState.Loaded;
   nTimesLoaded++;
 }
Ejemplo n.º 3
0
        private void SetState(PluginState newstate)
        {
            state = newstate;

            if (configurehero)
            {
                ShowOverlay(false);
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            } else if (!stablearena && state != PluginState.Done)
            {
                ShowOverlay(false);

                SetDetectingText(DetectingArena, DetectionWarning, "");
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (newstate == PluginState.SearchHeroes)
            {
                ShowValueOverlay(false);
                SetAdviceText(DetectingHeroes);
                ShowAdviceOverlay(configdata.overlay);

                SetDetectingText(DetectingHeroes, DetectionWarning, "Override hero selection by clicking the rectangle in the top-left corner.");
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (newstate == PluginState.SearchBigHero)
            {
                ShowOverlay(false);
                arenawindow.DetectedHeroesWarning.Text = "";
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (newstate == PluginState.DetectedHeroes)
            {
                ShowOverlay(false);
                arenawindow.DetectedHeroesWarning.Text = "";
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (newstate == PluginState.SearchCards)
            {
                ShowValueOverlay(false);
                SetAdviceText(DetectingCards);
                ShowAdviceOverlay(configdata.overlay);

                ClearDetected();
                SetDetectingText(DetectingCards, DetectionWarning, "");
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (newstate == PluginState.SearchCardValues)
            {
                ShowValueOverlay(false);
                SetAdviceText(DetectingValues);
                ShowAdviceOverlay(configdata.overlay);

                SetDetectingText(DetectingValues, DetectionWarning, "");
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (newstate == PluginState.DetectedCards)
            {
                ShowOverlay(configdata.overlay);
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Visible;
            }
            else if (newstate == PluginState.Done)
            {
                ShowOverlay(false);
                SetDetectingText("Done", DoneMessage, "");
                arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
                arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
                arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
            }
        }
Ejemplo n.º 4
0
        private void startWarnState(string sender, DateTime now) {
            if (!isPluginChecking()) {
                SendConsoleMessage(sender, "plugin is in " + pluginState.ToString() + " state");
                return;
            }

            pluginState = PluginState.warn;
            setStartTime(pluginState, now.AddSeconds(1));

            DebugWrite("^b" + pluginState + "^n state started " + getStartTime(pluginState).ToString(), 1);
        }
Ejemplo n.º 5
0
        public void startCheckState(DateTime now) {

            try {
                if (check_state_phase == 0) {
                    pluginState = PluginState.check;
                    setStartTime(pluginState, now.AddSeconds(1));
                    DebugWrite("^b" + pluginState + "^n state started " + getStartTime(pluginState).ToString() + "^n^0", 1);

                    DebugWrite("^b" + PluginState.check.ToString() + "^n state ^bphase-" + check_state_phase + "^n started " + getStartTime(pluginState).ToString() + "^0", 2);
                    DebugWrite("Requesting player list", 2);

                    check_state_phase = 1;
                    getPlayerList();


                    return;
                } else if (check_state_phase == 1) {

                    DebugWrite("^b" + PluginState.check.ToString() + "^n state ^bphase-" + check_state_phase + "^n started " + now.ToString() + "^0", 2);



                    if (teamsUnbalanced()) {
                        DebugWrite("Teams are unbalanced, going to ^b" + PluginState.warn.ToString() + "^n state", 2);
                        startWarnState(now);
                    } else {
                        DebugWrite("Teams are balanced, going to ^b" + PluginState.wait.ToString() + "^n state", 2);
                        restartWaitState(now);
                    }

                    check_state_phase = 0;

                    return;
                }
            } catch (Exception e) {
                dump_exception(e);
            }
        }
Ejemplo n.º 6
0
 public void setStartTime(PluginState state, DateTime now) {
     if (state.Equals(PluginState.wait))
         startWaitTime = now;
     else if (state.Equals(PluginState.warn))
         startWarnTime = now;
     else if (state.Equals(PluginState.check))
         startCheckTime = now;
     else if (state.Equals(PluginState.balance))
         startBalanceTime = now;
     else if (state.Equals(PluginState.stop))
         startStopTime = now;
     else
         DebugWrite("^1^bWARNING^0^n: cannot set start time for ^b" + state.ToString() + "^n^0", 1);
 }
Ejemplo n.º 7
0
 public PluginStateChangeEventArgs(PluginState previous, PluginState current)
 {
     this.previousState = previous;
     this.currentState = current;
 }
Ejemplo n.º 8
0
        public override void OnListPlayers(List<CPlayerInfo> players, CPlayerSubset subset)
        {
            if (!fIsEnabled) return;

            DebugWrite("^9^bGot OnListPlayers^n", 8);

            try {
            if (subset.Subset != CPlayerSubset.PlayerSubsetType.All) return;

            lock (fListPlayersQ) {
            fListPlayersTimestamp = DateTime.Now;
            Monitor.Pulse(fListPlayersQ);
            }

            /*
            Check if server crashed or Blaze dumped players or model invalid for too long.
            Detected by: last recorded server uptime is greater than zero and less than new uptime,
            or a player model timed out while still being on the all players list,
            or got an OnLogin callback, which is used in connection initialization for Procon,
            or the current list of players is more than CRASH_COUNT_HEURISTIC players less than the last
            recorded count, or the last known player count is greater than the maximum server size,
            or more than 3 minutes have elapsed since a move/reassign was started.
            Since these detections are not completely reliable, do a minimal  amount of recovery,
            don't do a full reset
            */
            if (fServerCrashed
            || fGotLogin
            || fRefreshCommand
            || (fServerCrashed = (this.TotalPlayerCount >= 16
            && this.TotalPlayerCount > players.Count
            && (this.TotalPlayerCount - players.Count) >= Math.Min(CRASH_COUNT_HEURISTIC, this.TotalPlayerCount)))
            || this.TotalPlayerCount > MaximumServerSize
            || (fTimeOutOfJoint > 0 && GetTimeInRoundMinutes() - fTimeOutOfJoint > 3.0))  {
            ValidateModel(players);
            fServerCrashed = false;
            fGotLogin = false;
            fRefreshCommand = false;
            fTimeOutOfJoint = 0;
            } else {
            fUnassigned.Clear();

            foreach (CPlayerInfo p in players) {
                try {
                    UpdatePlayerModel(p.SoldierName, p.TeamID, p.SquadID, p.GUID, p.Score, p.Kills, p.Deaths, p.Rank);
                } catch (Exception e) {
                    ConsoleException(e);
                    continue;
                }
            }
            }

            GarbageCollectKnownPlayers(); // also resets LastMoveTo

            UpdateTeams();

            LogStatus(false, DebugLevel);

            /* Special handling for JustEnabled state */
            if (fPluginState == PluginState.JustEnabled) {
            fPluginState = PluginState.Active;
            fRoundStartTimestamp = DateTime.Now;
            DebugWrite("^b^3State = " + fPluginState, 6);
            }

            // Use updated player list, one-time updates
            if (fNeedPlayerListUpdate) {
            try { AssignGroups(); } catch (Exception e) { ConsoleException(e); }
            try { RememberTeams(); } catch (Exception e) { ConsoleException(e); }
            fNeedPlayerListUpdate = false;
            }

            //CommandToLog("whitelist");
            foreach (CPlayerInfo p in players) {
            try {
                PlayerModel player = GetPlayer(p.SoldierName);
                if (player == null) continue;
                String guid = (String.IsNullOrEmpty(player.EAGUID)) ? INVALID_NAME_TAG_GUID : player.EAGUID;
                String xt = ExtractTag(player);
                if (String.IsNullOrEmpty(xt)) xt = INVALID_NAME_TAG_GUID;
                foreach (String item in fSettingWhitelist) {
                    List<String> tokens = new List<String>(Regex.Split(item, @"\s+"));
                    if (tokens.Count < 1) {
                        continue;
                    }
                    if (tokens[0] == player.Name || tokens[0] == xt || tokens[0] == guid) {
                        if (player.Whitelist == 0) {
                            DebugWrite("^8^bWARNING^n^0: (^b" + player.Name + ", " + xt + ", ^n" + guid + ") matches (" + String.Join(", ", tokens.ToArray()) + ") ^8^bBUT NO WHITELIST FLAGS SET!", 7);
                        }
                    }
                }
            } catch (Exception e) {
                ConsoleException(e);
            }
            }

            } catch (Exception e) {
            ConsoleException(e);
            }
        }
 public override void UnloadPlugin(PluginState state = PluginState.Unloaded)
 {
     base.UnloadPlugin(state);
     HarmonyInstance?.UnpatchAll("uEssentialsAntiTrack");
 }
 internal PluginInstanceLogMessage(DateTimeOffset now, string pluginId, PluginState state)
     : this(now, pluginId, state, processId : null)
 {
 }
Ejemplo n.º 11
0
        public void ReloadPlugin(bool actualyReload)
        {
            if (BPlugin != null)
            {
                BPlugin._OnClose(); //saving settings, closing opened threads (on plugin side)

                API.eRender        -= BPlugin._Render;
                API.eEntityAdded   -= BPlugin._EntityAdded;
                API.eEntityRemoved -= BPlugin._EntityRemoved;
                API.eClose         -= BPlugin._OnClose;
                API.eAreaChange    -= BPlugin._AreaChange;
                API.eInitialise    -= BPlugin._Initialise;
                BPlugin._OnPluginDestroyForHotReload();

                BPlugin = null;
                SettingPropertyDrawers.Clear();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            Assembly asmToLoad;
            var      debugCymboldFilePath = _dllPath.Replace(".dll", ".pdb");

            if (File.Exists(debugCymboldFilePath))
            {
                var dbgCymboldBytes = File.ReadAllBytes(debugCymboldFilePath);
                asmToLoad = Assembly.Load(File.ReadAllBytes(_dllPath), dbgCymboldBytes);
            }
            else
            {
                asmToLoad = Assembly.Load(File.ReadAllBytes(_dllPath));
            }

            if (asmToLoad == null)
            {
                State = PluginState.Reload_DllNotFound;
                return;
            }

            var pluginType = asmToLoad.GetType(_fullTypeName);

            if (pluginType == null)
            {
                State = PluginState.Reload_ClassNotFound;
                return;
            }

            //Spawning a new plugin class instance
            object pluginClassObj = null;

            try
            {
                pluginClassObj = Activator.CreateInstance(pluginType);
            }
            catch (Exception ex)
            {
                BasePlugin.LogMessage($"Error loading plugin {Path.GetFileNameWithoutExtension(_dllPath)}: " + ex.Message, 3);
                State = PluginState.ErrorClassInstance;
                return;
            }

            BPlugin = pluginClassObj as BasePlugin;
            BPlugin.InitPlugin(this);
            Settings = BPlugin._LoadSettings();

            if (!string.IsNullOrEmpty(BPlugin.PluginName))
            {
                PluginName = BPlugin.PluginName;
            }

            API.eRender        += BPlugin._Render;
            API.eEntityAdded   += BPlugin._EntityAdded;
            API.eEntityRemoved += BPlugin._EntityRemoved;
            API.eClose         += BPlugin._OnClose;
            API.eInitialise    += BPlugin._Initialise;
            API.eAreaChange    += BPlugin._AreaChange;

            BPlugin._Initialise();

            if (actualyReload)
            {
                BPlugin._AreaChange(GameController.Instance.Area);
            }

            foreach (var entity in GameController.Instance.EntityListWrapper.Entities.ToList())
            {
                BPlugin._EntityAdded(entity);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Hält den Betrieb des Plugins an.
 /// </summary>
 public void Pause()
 {
     pluginStatus = PluginState.Paused;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Funktionsaufruf zum Stoppen des Plugin-Betriebs.
 /// </summary>
 public void Stop()
 {
     window.Stop();
     pluginStatus = PluginState.Ready;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Funktionsaufruf zum Starten des Plugin-Betriebs.
 /// </summary>
 public void Start()
 {
     window.Start();
     pluginStatus = PluginState.Running;
 }
Ejemplo n.º 15
0
 public override void UnloadPlugin(PluginState state = PluginState.Unloaded)
 {
     base.UnloadPlugin(state);
     RPCDetectorCore.Unload(HarmonyInstance);
 }
Ejemplo n.º 16
0
        public void OnLoad()
        {
            plugins.LoadPlugins();

            state = PluginState.Idle;

            // Set hashes
            herohashlist.Clear();
            herohashlist.Add(new HeroHashData(0, "Warrior", 13776678289873991291, "warrior_small.png"));
            herohashlist.Add(new HeroHashData(1, "Shaman", 18366959783178990451, "shaman_small.png"));
            herohashlist.Add(new HeroHashData(2, "Rogue", 5643619427529904809, "rogue_small.png"));
            herohashlist.Add(new HeroHashData(3, "Paladin", 11505795398351105139, "paladin_small.png"));
            herohashlist.Add(new HeroHashData(4, "Hunter", 2294799430464257123, "hunter_small.png"));
            herohashlist.Add(new HeroHashData(5, "Druid", 5433851923975358071, "druid_small.png"));
            herohashlist.Add(new HeroHashData(6, "Warlock", 10186248321710093033, "warlock_small.png"));
            herohashlist.Add(new HeroHashData(7, "Mage", 15770007155810004267, "mage_small.png"));
            herohashlist.Add(new HeroHashData(8, "Priest", 15052908377040876499, "priest_small.png"));

            AddMenuItem();

            stopwatch = Stopwatch.StartNew();

            LoadCards();
        }
Ejemplo n.º 17
0
        public void OnLoad()
        {
            plugins.LoadPlugins();

            state = PluginState.Idle;

            // Set hashes
            herohashlist.Clear();
            herohashlist.Add(new HeroHashData(0, "Warrior", "warrior_small.png", 13776678289873991291, 13071189497635732127, 12080542990295427731)); // Garrosh, Magni small, Magni big
            herohashlist.Add(new HeroHashData(1, "Shaman", "shaman_small.png", 18366959783178990451));
            herohashlist.Add(new HeroHashData(2, "Rogue", "rogue_small.png", 5643619427529904809, 11263619176753353643, 10111770795730096827)); // Valeera, Valeera golden small, Valeera golden big
            herohashlist.Add(new HeroHashData(3, "Paladin", "paladin_small.png", 11505795398351105139));
            herohashlist.Add(new HeroHashData(4, "Hunter", "hunter_small.png", 2294799430464257123, 12942361696967163803, 17552924014479703963)); // Rexxar, Alleria small, Alleria big
            herohashlist.Add(new HeroHashData(5, "Druid", "druid_small.png", 5433851923975358071));
            herohashlist.Add(new HeroHashData(6, "Warlock", "warlock_small.png", 10186248321710093033));
            herohashlist.Add(new HeroHashData(7, "Mage", "mage_small.png", 15770007155810004267, 8631746754340092973, 8343516378188643373)); // Jaina, Medivh small, Medivh big
            herohashlist.Add(new HeroHashData(8, "Priest", "priest_small.png", 15052908377040876499));

            AddMenuItem();

            stopwatch = Stopwatch.StartNew();

            LoadCards();
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Translates the given <see cref="PluginState"/> into the string representation
 /// used in the XML.
 /// </summary>
 /// <param name="p_pstState">The <see cref="PluginState"/> to unparse.</param>
 /// <returns>The string representation used in the XML for the given <see cref="PluginState"/>.</returns>
 protected string UnparsePluginState(PluginState p_pstState)
 {
     return(p_pstState.ToString());
 }
Ejemplo n.º 19
0
        public void OnPluginEnable()
        {
            if (fFinalizerActive) {
            ConsoleWarn("Not done disabling, try again in 10 seconds!");
            return;
            }
            fIsEnabled = true;
            fPluginState = PluginState.JustEnabled;
            fGameState = GameState.Unknown;
            fEnabledTimestamp = DateTime.Now;
            fRoundOverTimestamp = DateTime.MinValue;
            fRoundStartTimestamp = DateTime.Now;

            // Determine BF3 vs. BF4
            fMaxSquadSize = (fGameVersion == GameVersion.BF4) ? 5 : 4;

            ConsoleWrite("^b^2Enabled!^0^n Version = " + GetPluginVersion(), 0);
            DebugWrite("^b^3State = " + fPluginState, 6);
            DebugWrite("^b^3Game state = " + fGameState, 6);

            GatherProconGoodies();

            StartThreads();

            ServerCommand("reservedSlotsList.list");
            ServerCommand("serverInfo");
            ServerCommand("admin.listPlayers", "all");

            LaunchCheckForPluginUpdate();

            fIsCacheEnabled = IsCacheEnabled(true);
        }
Ejemplo n.º 20
0
 public void Stop()
 {
     FinalizeAntVideo();
     state = PluginState.Ready;
 }
Ejemplo n.º 21
0
 public int getElapsedTime(DateTime now, PluginState state) {
     DateTime startTime = getStartTime(state);
     int elapsed = (int)now.Subtract(startTime).TotalSeconds;
     return elapsed;
 }
Ejemplo n.º 22
0
 public void Pause()
 {
     state = PluginState.Paused;
 }
Ejemplo n.º 23
0
        public int getRemainingTime(DateTime now, PluginState state) {

            int max_time = getMaxTime(state);
            int elapsed = getElapsedTime(now, state);

            int remain = max_time - elapsed;
            return remain;
        }
Ejemplo n.º 24
0
 public void Start()
 {
     state = PluginState.Running;
 }
Ejemplo n.º 25
0
        private int balanceTeams(DateTime now) {


            pluginState = PluginState.balance;
            setStartTime(pluginState, now.AddSeconds(1));
            DebugWrite("^b" + pluginState + "_live^n state started " + getStartTime(pluginState).ToString() + "^n^0", 1);

            bool keep_clans = getBooleanVarValue("keep_clans_live");
            Dictionary<int, int> player_count = getPlayerCount();

            if (player_count[1] == player_count[2])
                return 0;

            int team_sz = serverInfo.MaxPlayerCount / 2;
            int neutral_team = 0;
            int bigger_team = (player_count[1] > player_count[2]) ? 1 : 2;
            int smaller_team = (player_count[1] > player_count[2]) ? 2 : 1;
            int total = player_count[1] + player_count[2];
            int difference = Math.Abs(player_count[1] - player_count[2]);
            int needed = difference / 2;


            DebugWrite("Total of ^b" + total + "^n player/s in server^0", 3);
            for (int i = 1; i < 3; i++) {
                DebugWrite("^bTeam(" + TN(i) + ")^n has ^b" + player_count[i] + "^n player/s^0", 3);
            }

            DebugWrite("Teams differ by ^b" + difference + "^n player/s,  ^b" + needed + "^n player/s are needed on ^bTeam(" + TN(smaller_team) + ")^n^0", 3);

            int candidates = needed;

            //?????? jstmx - Wrong logic, some fixes
            if (getBooleanVarValue("wait_death")) {
                candidates = getIntegerVarValue("wait_death_count");

                int tsz = player_count[bigger_team];

                // check that the candidate list does not exceed the team size
                if (candidates > tsz) {
                    DebugWrite("cannot use candidate list size of ^b" + candidates + "^n, Team(" + TN(bigger_team) + ") has only ^b" + tsz + "^n player" + ((tsz > 1) ? "s" : ""), 3);
                    candidates = tsz;
                }

                // check that the candidates list size is bigger than needed 
                if (candidates > needed) {
                    needed = candidates;
                    DebugWrite("^bwait_death^n is on, will flag " + needed + " candidate" + ((needed > 1) ? "s" : "") + " for moving", 3);
                }
            }
            //??????

            DebugWrite("Building no-squad pool from ^bTeam(" + TN(bigger_team) + ")^n^0", 3);
            List<PlayerProfile> nosquad_pool = getNoSquadPlayers(bigger_team);
            DebugWrite("No-squad pool has ^b" + nosquad_pool.Count + "^n player/s^0", 3);

            DebugWrite("Building squad pool from ^bTeam(" + TN(bigger_team) + ")^n^0", 3);
            List<PlayerSquad> squad_pool = getNonEmptySquads(bigger_team);
            DebugWrite("Squad pool has ^b" + squad_pool.Count + "^n squads^0", 3);


            Dictionary<string, int>[] clan_stats = new Dictionary<string, int>[3];
            clan_stats[smaller_team] = new Dictionary<string, int>();
            clan_stats[bigger_team] = new Dictionary<string, int>();
            clan_stats[neutral_team] = new Dictionary<string, int>();

            if (keep_clans) {
                DebugWrite("Keeping clans in same team", 3);

                List<PlayerProfile> players_list = getPlayersProfile("");
                /* collect statistics about clans */
                DebugWrite("Collecting clan statistics", 3);
                getClanStatsByTeam(players_list, clan_stats);


                List<string> clanlist = new List<string>();
                clanlist.AddRange(clan_stats[1].Keys);

                DebugWrite("^b" + clanlist.Count + "^n clans in server: [^b" + String.Join("^n], [^b", clanlist.ToArray()) + "^n]", 3);
            }

            if (!getBooleanVarValue("keep_squads_live")) {
                DebugWrite("^bkeep_squads_live^n is off, moving players to no-squad pool before balancing", 3);
                foreach (PlayerSquad squad in squad_pool)
                    foreach (PlayerProfile player in squad.getMembers())
                        nosquad_pool.Add(player);

                squad_pool.Clear();
            }

            /* sort the no-squad pool */
            DebugWrite("Sorting the no-squad pool by ^b" + getStringVarValue("live_sort") + "^n^0", 3);
            nosquad_pool.Sort(new Comparison<PlayerProfile>(getPlayerSort("live_sort")));

            for (int i = 0; i < nosquad_pool.Count; i++)
                DebugWrite("      " + i + ". " + nosquad_pool[i] + "(" + getSortFieldValueStr(nosquad_pool[i], "live_sort") + ")", 3);


            DebugWrite("Moving ^b" + needed + "^n players from sorted no-squad pool to ^bTeam(" + TN(smaller_team) + ")^n^0", 3);
            while (needed > 0 && nosquad_pool.Count > 0) {
                PlayerProfile player = nosquad_pool[0];
                nosquad_pool.RemoveAt(0);
                string tag = player.getClanTag();

                /* if keeping clans together, and there are more than two players in the clan in the sever */
                if (keep_clans && shouldSkipClanPlayer(player, smaller_team, bigger_team, clan_stats))
                    continue;

                DebugWrite("Moving ^b" + player.ToString() + "^n to ^bTeam(^n" + TN(smaller_team) + ")^n^0", 3);
                if (movePlayer(player, smaller_team, 0, true))
                    needed--;
            }

            /* if teams are balanced, we are done */
            if (needed == 0) {
                DebugWrite("Teams should now be balanced!", 3);
                return needed;
            }

            /* teams are not balanced, proceed on squad balancing */

            DebugWrite("Teams are still unbalanced, " + needed + " more player/s needed", 3);

            /* sort the squad pool */
            DebugWrite("Sorting the squad pool by ^b" + getStringVarValue("live_sort") + "^n^0", 3);
            squad_pool.Sort(new Comparison<PlayerSquad>(getSquadSort("live_sort")));

            for (int i = 0; i < squad_pool.Count; i++) {
                DebugWrite("      " + i + ". " + squad_pool[i].ToString() + "(" + getSortFieldValueStr(squad_pool[i], "live_sort") + ")", 3);
            }

            DebugWrite("Moving squads from sorted squad pool to ^bTeam(" + TN(smaller_team) + ")^n^0", 3);
            while (needed > 0 && squad_pool.Count > 0) {
                PlayerSquad squad = squad_pool[0];
                squad_pool.RemoveAt(0);


                int squad_sz = squad.getCount();
                string squad_uid = squad.ToString();
                string smaller_team_uid = "^bTeam(" + TN(smaller_team) + ")^n";

                DebugWrite("^b" + needed + "^n players are needed on " + smaller_team_uid + "^0", 3);
                DebugWrite(squad_uid + " has ^b" + squad_sz + "^n player/s^0", 2);

                if (needed >= squad_sz) {
                    if (keep_clans && shouldSkipClanSquad(squad, smaller_team, bigger_team, clan_stats))
                        continue;


                    /* we can move the entrie squad */
                    DebugWrite("Moving entire " + squad_uid + " to " + smaller_team_uid + "^0", 3);
                    squad_sz = moveSquad(squad, smaller_team, team_sz);
                    needed -= squad_sz;
                } else {
                    /* we have to break up a squad */
                    PlayerSquad temp_squad = new PlayerSquad(squad.getTeamId(), squad.getSquadId());

                    DebugWrite("Breaking up " + squad_uid + " to get ^b" + needed + "^n player/s^0", 3);
                    DebugWrite("But, first I will sort the members of " + squad_uid, 3);
                    squad.sortMembers(getPlayerSort("live_sort"));
                    for (int i = 0; i < squad.getCount(); i++)
                        DebugWrite("      " + i + ". " + squad.getMembers()[i] + "(" + getSortFieldValueStr(squad.getMembers()[i], "live_sort") + ")", 3);

                    /* get as many players as needed */
                    while (needed > 0 && squad.getCount() > 0) {
                        PlayerProfile player = squad.getMembers()[0];
                        squad.dropPlayer(player);

                        if (keep_clans && shouldSkipClanPlayer(player, smaller_team, bigger_team, clan_stats))
                            continue;

                        if (isInMoveWhiteList(player))
                            continue;

                        temp_squad.addPlayer(player);
                        DebugWrite("Player " + player + " selected to move to " + smaller_team_uid + "^0", 3);
                        needed--;
                    }

                    /* move the temporary squad */
                    moveSquad(temp_squad, smaller_team, team_sz);
                }
            }


            if (needed == 0)
                DebugWrite("Teams should now be balanced!", 3);
            else
                DebugWrite("Teams are still ubalanced!", 3);

            return needed;
        }
Ejemplo n.º 26
0
        private void OnCommandsDisplayCommand(BotShell bot, CommandArgs e)
        {
            string internalName = e.Args[0].ToLower();

            if (!bot.Plugins.Exists(internalName))
            {
                bot.SendReply(e, "No such plugin!");
                return;
            }
            PluginState state = bot.Plugins.GetState(internalName);

            if (state == PluginState.Core)
            {
                bot.SendReply(e, "You can't change the command rights on Core plugins!");
                return;
            }
            if (state != PluginState.Loaded)
            {
                bot.SendReply(e, "A plugin is required to be loaded before configuring it!");
                return;
            }
            string[] commands = bot.Commands.GetCommands(internalName);
            if (commands.Length < 1)
            {
                bot.SendReply(e, "This plugin has no commands to configure");
                return;
            }
            RichTextWindow window = new RichTextWindow(bot);
            PluginLoader   loader = bot.Plugins.GetLoader(internalName);

            window.AppendTitle("Rights");

            window.AppendHighlight("S: ");
            window.AppendNormal("Super Admin");
            window.AppendLineBreak();

            window.AppendHighlight("A: ");
            window.AppendNormal("Admin");
            window.AppendLineBreak();

            window.AppendHighlight("L: ");
            window.AppendNormal("Leader");
            window.AppendLineBreak();

            window.AppendHighlight("M: ");
            window.AppendNormal("Member");
            window.AppendLineBreak();

            window.AppendHighlight("G: ");
            window.AppendNormal("Guest");
            window.AppendLineBreak();

            window.AppendHighlight("D: ");
            window.AppendNormal("Disabled");
            window.AppendLineBreak(2);

            window.AppendHeader("Tell               Private Group  Organization  Command");
            foreach (string command in commands)
            {
                this.CreateSelectLine(bot, ref window, command);
                window.AppendLineBreak();
            }
            bot.SendReply(e, "Commands »» " + loader.Name + " »» ", window);
        }
Ejemplo n.º 27
0
        private void startStopState(string sender, DateTime now) {
            virtual_mode = false;
            round_balancer = false;
            level_started = false;
            check_state_phase = 0;

            if (sender != null)
                setPluginVarValue("auto_start", "false");

            pluginState = PluginState.stop;
            setStartTime(pluginState, now.AddSeconds(1));

            SendConsoleMessage(sender, "^b" + pluginState + "^n state started " + getStartTime(pluginState).ToString());
        }
Ejemplo n.º 28
0
 public PluginInfo(CSPlugin plug, PluginState state, string msg)
 {
     Plugin  = plug;
     State   = state;
     Message = msg;
 }
Ejemplo n.º 29
0
 public void Stop()
 {
     control.Stop();
     pluginState = PluginState.Ready;
 }
Ejemplo n.º 30
0
 public PluginActionOnCreateBehavior(PluginState state) : base(state)
 {
 }
Ejemplo n.º 31
0
 internal void Unload() {
   if (pluginState != PluginState.Loaded)
     throw new InvalidOperationException("Cannot unload a plugin in state " + pluginState);
   nTimesLoaded--;
   if (nTimesLoaded == 0) pluginState = PluginState.Enabled;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_strPluginPath">The plugin that must be is the specified state.</param>
 /// <param name="p_pnsState">The state in which the specified plugin must be.</param>
 public PluginCondition(string p_strPluginPath, PluginState p_pnsState)
 {
     m_pnsState      = p_pnsState;
     m_strPluginPath = p_strPluginPath;
 }
Ejemplo n.º 33
0
    protected ICollection<PluginRuntime> _dependentPlugins = null; // Lazy initialized

    #endregion

    #region Ctor

    /// <summary>
    /// Creates a new plugin runtime data structure for the specified plugin metadata
    /// instance.
    /// </summary>
    /// <param name="metaData">The metadata of the plugin to create this runtime structure for.</param>
    /// <param name="syncObj">The object to synchronize multithreading access.</param>
    internal PluginRuntime(IPluginMetadata metaData, object syncObj)
    {
      _syncObj = syncObj;
      _pluginMetadata = metaData;
      _state = PluginState.Available;
    }
Ejemplo n.º 34
0
 public override void UnloadPlugin(PluginState state = PluginState.Unloaded)
 {
     Instance = null;
 }
Ejemplo n.º 35
0
        private void ValidateModel(List<CPlayerInfo> players)
        {
            if (fLastValidationTimestamp != DateTime.MinValue) {
            TimeSpan elapsed = DateTime.Now.Subtract(fLastValidationTimestamp);
            if (elapsed.TotalSeconds < 90.0) {
            DebugWrite("Skipping revalidation: too soon, only " + elapsed.TotalSeconds.ToString("F0") + " seconds since last ValidateModel", 4);
            return;
            }
            }
            fLastValidationTimestamp = DateTime.Now;

            DebugWrite("Revalidating all players and teams", 3);

            // forget the active list, might be incorrect
            lock (fAllPlayers) {
            fAllPlayers.Clear();
            }
            fUnassigned.Clear();

            if (fGotLogin || fServerCrashed || (fTimeOutOfJoint > 0 && GetTimeInRoundMinutes() - fTimeOutOfJoint > 3.0)) {
            fMoving.Clear();
            fReassigned.Clear();
            }

            if (players.Count == 0) {
            // no players, so waiting state
            fGameState = GameState.Warmup;
            } else {
            fPluginState = PluginState.Reconnected;
            // rebuild the data model and cancel any pending moves
            foreach (CPlayerInfo p in players) {
            try {
                UpdatePlayerModel(p.SoldierName, p.TeamID, p.SquadID, p.GUID, p.Score, p.Kills, p.Deaths, p.Rank);
                CheckAbortMove(p.SoldierName);
            } catch (Exception e) {
                ConsoleException(e);
            }
            }
            /* Special handling for Reconnected state */
            fGameState = (this.TotalPlayerCount < 4) ? GameState.Warmup : GameState.Unknown;
            UpdateTeams();
            UpdateAllFromWhitelist();
            }
            if (fServerCrashed) fRoundStartTimestamp = DateTime.Now;
            fPluginState = PluginState.Active;
            DebugWrite("^9ValidateModel: ^b^3State = " + fPluginState, 6);
            DebugWrite("^9ValidateModel: ^b^3Game state = " + fGameState, 6);
        }
Ejemplo n.º 36
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public PluginInfo()
 {
     State = PluginState.NotInstalled;
 }
Ejemplo n.º 37
0
        public void OnPluginDisable()
        {
            fIsEnabled = false;

            try {
            LaunchCheckForPluginUpdate();

            fEnabledTimestamp = DateTime.MinValue;

            StopThreads();

            Reset();

            ConsoleWrite("^bDisabling, stopping threads ...^n", 0);
            fPluginState = PluginState.Disabled;
            fGameState = GameState.Unknown;
            DebugWrite("^b^3State = " + fPluginState, 6);
            DebugWrite("^b^3Game state = " + fGameState, 6);
            } catch (Exception e) {
            ConsoleException(e);
            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Reads the condition from the given node.
        /// </summary>
        /// <param name="p_xelCondition">The node from which to load the condition.</param>
        /// <returns>An <see cref="ICondition"/> representing the condition described in the given node.</returns>
        protected override ICondition LoadCondition(XElement p_xelCondition)
        {
            if (p_xelCondition == null)
            {
                return(null);
            }
            switch (p_xelCondition.GetSchemaInfo().SchemaType.Name)
            {
            case "compositeDependency":
                ConditionOperator      copOperator   = (ConditionOperator)Enum.Parse(typeof(ConditionOperator), p_xelCondition.Attribute("operator").Value);
                CompositeCondition     cpdCondition  = new CompositeCondition(copOperator);
                IEnumerable <XElement> xeeConditions = p_xelCondition.Elements();
                foreach (XElement xelCondition in xeeConditions)
                {
                    cpdCondition.Conditions.Add(LoadCondition(xelCondition));
                }
                return(cpdCondition);

            case "fileDependency":
                string      strCondition = p_xelCondition.Attribute("file").Value.ToLower();
                PluginState plsModState  = (PluginState)Enum.Parse(typeof(PluginState), p_xelCondition.Attribute("state").Value);
                return(new PluginCondition(strCondition, plsModState));

            case "flagDependency":
                string strFlagName = p_xelCondition.Attribute("flag").Value;
                string strValue    = p_xelCondition.Attribute("value").Value;
                return(new FlagCondition(strFlagName, strValue));

            case "versionDependency":
                switch (p_xelCondition.Name.LocalName)
                {
                case "gameDependency":
                {
                    Version verMinFalloutVersion = ParseVersion(p_xelCondition.Attribute("version").Value);
                    return(new GameVersionCondition(verMinFalloutVersion));
                }

                case "fommDependency":
                {
                    Version verMinFommVersion = ParseVersion(p_xelCondition.Attribute("version").Value);
                    return(new ModManagerCondition(verMinFommVersion));
                }

                case "foseDependency":
                {
                    Version verMinSEVersion = ParseVersion(p_xelCondition.Attribute("version").Value);
                    return(new SEVersionCondition(verMinSEVersion, "fose"));
                }

                case "nvseDependency":
                {
                    Version verMinSEVersion = ParseVersion(p_xelCondition.Attribute("version").Value);
                    return(new SEVersionCondition(verMinSEVersion, "nvse"));
                }

                case "f4seDependency":
                {
                    Version verMinSEVersion = ParseVersion(p_xelCondition.Attribute("version").Value);
                    return(new SEVersionCondition(verMinSEVersion, "f4se"));
                }

                case "skseDependency":
                {
                    Version verMinSEVersion = ParseVersion(p_xelCondition.Attribute("version").Value);
                    return(new SEVersionCondition(verMinSEVersion, "skse"));
                }

                default:
                    throw new ParserException("Invalid plugin condition node: " + p_xelCondition.Name + ". At this point the config file has been validated against the schema, so there's something wrong with the parser.");
                }

            default:
                throw new ParserException("Invalid plugin condition node: " + p_xelCondition.Name + ". At this point the config file has been validated against the schema, so there's something wrong with the parser.");
            }
        }
Ejemplo n.º 39
0
        /* Constructor */
        public MULTIbalancer()
        {
            /* Private members */
            fIsEnabled = false;
            fFinalizerActive = false;
            fPluginState = PluginState.Disabled;
            fGameState = GameState.Unknown;
            fServerInfo = null;
            fRefreshCommand = false;
            fServerUptime = 0;
            fServerCrashed = false;
            fDebugScramblerBefore = new List<PlayerModel>[2]{new List<PlayerModel>(), new List<PlayerModel>()};
            fDebugScramblerAfter = new List<PlayerModel>[2]{new List<PlayerModel>(), new List<PlayerModel>()};
            fDebugScramblerStartRound = new List<PlayerModel>[2]{new List<PlayerModel>(), new List<PlayerModel>()};

            fBalancedRound = 0;
            fUnstackedRound = 0;
            fUnswitchedRound = 0;
            fExcludedRound = 0;
            fExemptRound = 0;
            fFailedRound = 0;
            fTotalRound = 0;
            fBalanceIsActive = false;
            fRoundsEnabled = 0;
            fGrandTotalQuits = 0;
            fGrandRageQuits = 0;
            fTotalQuits = 0;
            fRageQuits = 0;

            fMoveThread = null;
            fFetchThread = null;
            fListPlayersThread = null;
            fScramblerThread = null;
            fTimerThread = null;

            fModeToSimple = new Dictionary<String,String>();

            fEasyTypeDict = new Dictionary<int, Type>();
            fEasyTypeDict.Add(0, typeof(int));
            fEasyTypeDict.Add(1, typeof(Int16));
            fEasyTypeDict.Add(2, typeof(Int32));
            fEasyTypeDict.Add(3, typeof(Int64));
            fEasyTypeDict.Add(4, typeof(float));
            fEasyTypeDict.Add(5, typeof(long));
            fEasyTypeDict.Add(6, typeof(String));
            fEasyTypeDict.Add(7, typeof(string));
            fEasyTypeDict.Add(8, typeof(double));

            fBoolDict = new Dictionary<int, Type>();
            fBoolDict.Add(0, typeof(Boolean));
            fBoolDict.Add(1, typeof(bool));

            fListStrDict = new Dictionary<int, Type>();
            fListStrDict.Add(0, typeof(String[]));

            fPerMode = new Dictionary<String,PerModeSettings>();

            fAllPlayers = new List<String>();
            fKnownPlayers = new Dictionary<String, PlayerModel>();
            fTeam1 = new List<PlayerModel>();
            fTeam2 = new List<PlayerModel>();
            fTeam3 = new List<PlayerModel>();
            fTeam4 = new List<PlayerModel>();
            fUnassigned = new List<String>();
            fRoundStartTimestamp = DateTime.MinValue;
            fRoundOverTimestamp = DateTime.MinValue;
            fListPlayersTimestamp = DateTime.MinValue;
            fFullUnstackSwapTimestamp = DateTime.MinValue;
            fLastValidationTimestamp = DateTime.MinValue;
            fListPlayersQ = new Queue<DelayedRequest>();

            fPendingTeamChange = new Dictionary<String,int>();
            fMoving = new Dictionary<String, MoveInfo>();
            fMoveQ = new Queue<MoveInfo>();
            fReassigned = new List<String>();
            fReservedSlots = new List<String>();
            fTickets = new int[5]{0,0,0,0,0};
            fFriendlyMaps = new Dictionary<String,String>();
            fFriendlyModes = new Dictionary<String,String>();
            fMaxTickets = -1;
            fRushMaxTickets = -1;
            fLastBalancedTimestamp = DateTime.MinValue;
            fEnabledTimestamp = DateTime.MinValue;
            fFinalStatus = null;
            fIsFullRound = false;
            fUnstackState = UnstackState.Off;
            fLastMsg = null;
            fRushStage = 0;
            fRushPrevAttackerTickets = 0;
            fRushAttackerStageLoss = 0;
            fRushAttackerStageSamples = 0;
            fMoveStash = new List<MoveInfo>();
            fLastVersionCheckTimestamp = DateTime.MinValue;
            fTimeOutOfJoint = 0;
            fUnstackGroupCount = 0;
            fPriorityFetchQ = new PriorityQueue(this);
            fIsCacheEnabled = false;
            fScramblerLock = new DelayedRequest();
            fWinner = 0;
            fUpdateThreadLock = new DelayedRequest();
            fLastServerInfoTimestamp = DateTime.Now;
            fStageInProgress = false;
            fHost = String.Empty;
            fPort = String.Empty;
            fRushMap3Stages = new List<String>(new String[6]{"MP_007", "XP4_Quake", "XP5_002", "MP_012", "XP4_Rubble", "MP_Damage"});
            fRushMap5Stages = new List<String>(new String[6]{"MP_013", "XP3_Valley", "MP_017", "XP5_001", "MP_Prison", "MP_Siege"});
            fGroupAssignments = new int[5]{0,0,0,0,0};
            fDispersalGroups = new List<String>[5]{null, new List<String>(), new List<String>(), new List<String>(), new List<String>()};
            fNeedPlayerListUpdate = false;
            fFriends = new Dictionary<int, List<String>>();
            fAllFriends = new List<String>();
            fWhileScrambling = false;
            fExtrasLock = new DelayedRequest();
            fExtraNames = new List<String>();
            fGotLogin = false;
            fDebugScramblerSuspects = new Dictionary<String,String>();
            fTimerRequestList = new List<DelayedRequest>();
            fAverageTicketLoss = new Queue<double>[3]{null, new Queue<double>(), new Queue<double>()};
            fTicketLossHistogram = new Histogram();

            /* Settings */

            /* ===== SECTION 0 - Presets ===== */

            SettingsVersion = 1;
            Preset = PresetItems.Standard;
            EnableUnstacking = false;
            EnableSettingsWizard = false;
            WhichMode = "Conquest Large";
            MetroIsInMapRotation = false;
            MaximumPlayersForMode = 64;
            LowestMaximumTicketsForMode = 300;
            HighestMaximumTicketsForMode = 400;
            PreferredStyleOfBalancing = PresetItems.Standard;
            ApplySettingsChanges = false;

            /* ===== SECTION 1 - Settings ===== */

            DebugLevel = 2;
            MaximumServerSize = 64;
            EnableBattlelogRequests = true;
            MaximumRequestRate = 10; // in 20 seconds
            WaitTimeout = 30; // seconds
            WhichBattlelogStats = BattlelogStats.ClanTagOnly;
            MaxTeamSwitchesByStrongPlayers = 1;
            MaxTeamSwitchesByWeakPlayers = 2;
            UnlimitedTeamSwitchingDuringFirstMinutesOfRound = 5.0;
            Enable2SlotReserve = false;
            EnablerecruitCommand = false;
            EnableWhitelistingOfReservedSlotsList = true;
            Whitelist = new String[] {DEFAULT_LIST_ITEM};
            fSettingWhitelist = new List<String>(Whitelist);
            DisperseEvenlyList = new String[] {DEFAULT_LIST_ITEM};
            fSettingDisperseEvenlyList = new List<String>(DisperseEvenlyList);
            FriendsList = new String[] {DEFAULT_LIST_ITEM};
            fSettingFriendsList = new List<String>();
            SecondsUntilAdaptiveSpeedBecomesFast = 3*60; // 3 minutes default
            EnableInGameCommands = true;

            /* ===== SECTION 2 - Exclusions ===== */

            OnWhitelist = true;
            OnFriendsList = false;
            ApplyFriendsListToTeam = false;
            TopScorers = true;
            SameClanTagsInSquad = true;
            SameClanTagsInTeam = false;
            SameClanTagsForRankDispersal = false;
            LenientRankDispersal = false;
            MinutesAfterJoining = 5;
            MinutesAfterBeingMoved = 90; // 1.5 hours
            JoinedEarlyPhase = true;
            JoinedMidPhase = true;
            JoinedLatePhase = false;

            /* ===== SECTION 3 - Round Phase & Population Settings ===== */

            EarlyPhaseTicketPercentageToUnstack = new double[3]         {  0,120,120};
            MidPhaseTicketPercentageToUnstack = new double[3]           {  0,120,120};
            LatePhaseTicketPercentageToUnstack = new double[3]          {  0,  0,  0};

            EnableTicketLossRateLogging = false;

            SpellingOfSpeedNamesReminder = Speed.Click_Here_For_Speed_Names;

            EarlyPhaseBalanceSpeed = new Speed[3]           {     Speed.Fast, Speed.Adaptive, Speed.Adaptive};
            MidPhaseBalanceSpeed = new Speed[3]             {     Speed.Fast, Speed.Adaptive, Speed.Adaptive};
            LatePhaseBalanceSpeed = new Speed[3]            {     Speed.Stop,     Speed.Stop,     Speed.Stop};

            /* ===== SECTION 4 - Scrambler ===== */

            OnlyOnNewMaps = true; // false means scramble every round
            OnlyOnFinalTicketPercentage = 120; // 0 means scramble regardless of final score
            ScrambleBy = DefineStrong.RoundScore;
            KeepSquadsTogether = true;
            KeepClanTagsInSameTeam = true;
            KeepFriendsInSameTeam = false;
            DivideBy = DivideByChoices.None;
            ClanTagToDivideBy = String.Empty;
            DelaySeconds = 50;

            /* ===== SECTION 5 - Messages ===== */

            QuietMode = false; // false: chat is global, true: chat is private. Yells are always private
            YellDurationSeconds = 10;
            BadBecauseMovedByBalancer = "autobalance moved you to the %toTeam% team";
            BadBecauseWinningTeam = "switching to the winning team is not allowed";
            BadBecauseBiggestTeam = "switching to the biggest team is not allowed";
            BadBecauseRank = "this server splits Colonel 100's between teams";
            BadBecauseDispersalList = "you're on the list of players to split between teams";
            ChatMovedForBalance = "*** MOVED %name% for balance ...";
            YellMovedForBalance = "Moved %name% for balance ...";
            ChatMovedToUnstack = "*** MOVED %name% to unstack teams ...";
            YellMovedToUnstack = "Moved %name% to unstack teams ...";
            ChatDetectedBadTeamSwitch = "%name%, you can't switch to team %fromTeam%: %reason%, sending you back ...";
            YellDetectedBadTeamSwitch = "You can't switch to the %fromTeam% team: %reason%, sending you back!";
            ChatDetectedGoodTeamSwitch = "%name%, thanks for helping out the %toTeam% team!";
            YellDetectedGoodTeamSwitch = "Thanks for helping out the %toTeam% team!";
            ChatAfterUnswitching = "%name%, please stay on the %toTeam% team for the rest of this round";
            YellAfterUnswitching = "Please stay on the %toTeam% team for the rest of this round";

            /* ===== SECTION 6 - Unswitcher ===== */

            EnableImmediateUnswitch = true;
            ForbidSwitchingAfterAutobalance = UnswitchChoice.Always;
            ForbidSwitchingToWinningTeam = UnswitchChoice.Always;
            ForbidSwitchingToBiggestTeam = UnswitchChoice.Always;
            ForbidSwitchingAfterDispersal = UnswitchChoice.Always;

            /* ===== SECTION 7 - TBD ===== */

            /* ===== SECTION 8 - Per-Mode Settings ===== */

            /* ===== SECTION 9 - Debug Settings ===== */

            ShowInLog = INVALID_NAME_TAG_GUID;
            ShowCommandInLog = String.Empty;
            LogChat = true;
            EnableLoggingOnlyMode = false;
            EnableExternalLogging = false;
            ExternalLogSuffix = "_mb.log";
        }
Ejemplo n.º 40
0
        /// <summary>
        /// 通过插件类型和状态获取当前所有的插件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type">插件类型</param>
        /// <param name="state">插件状态</param>
        /// <returns>满足条件的所有插件</returns>
        public Dictionary <T, IPlugin> GetPluginsByType <T>(PluginType type = PluginType.SpfDataParse, PluginState state = PluginState.Normal) where T : AbstractPluginInfo
        {
            var plugin = state == PluginState.None ? Plugins.Where(p => p.Key.PluginType == type && p.Key is T) :
                         Plugins.Where(p => p.Key.PluginType == type && p.Key is T && state.HasFlag(p.Key.State));

            return(plugin.ToDictionary(x => (T)x.Key, x => x.Value));
        }
Ejemplo n.º 41
0
		/// <summary>
		/// Translates the given <see cref="PluginState"/> into the string representation
		/// used in the XML.
		/// </summary>
		/// <param name="p_pstState">The <see cref="PluginState"/> to unparse.</param>
		/// <returns>The string representation used in the XML for the given <see cref="PluginState"/>.</returns>
		protected string UnparsePluginState(PluginState p_pstState)
		{
			return p_pstState.ToString();
		}
Ejemplo n.º 42
0
 public IEnumerable <PluginManifestPlugin> GivePlugins(Guid applicationGuid, PluginState state = 0)
 {
     return(state == 0
                         ? Plugin.Where(plugin => new Guid(plugin.ApplicationGuid) == applicationGuid)
                         : Plugin.Where(plugin => new Guid(plugin.ApplicationGuid) == applicationGuid && plugin.PluginState == state).ToList());
 }
Ejemplo n.º 43
0
        public DateTime getStartTime(PluginState state) {
            if (state.Equals(PluginState.wait))
                return startWaitTime;
            else if (state.Equals(PluginState.warn))
                return startWarnTime;
            else if (state.Equals(PluginState.check))
                return startCheckTime;
            else if (state.Equals(PluginState.balance))
                return startBalanceTime;
            else if (state.Equals(PluginState.stop))
                return startStopTime;
            else
                DebugWrite("^1^bWARNING^0^n: cannot find start time for ^b" + state.ToString() + "^n^0", 1);

            return utc;
        }
Ejemplo n.º 44
0
 public bool HasAnyPluginByState(Guid applicationGuid, PluginState state)
 {
     return(Plugin.Any(plugin => new Guid(plugin.ApplicationGuid) == applicationGuid && plugin.PluginState == PluginState.Availible));
 }
Ejemplo n.º 45
0
        public int getMaxTime(PluginState state) {
            if (state.Equals(PluginState.wait))
                return getIntegerVarValue("live_interval_time");
            else if (state.Equals(PluginState.warn))
                return getIntegerVarValue("warn_msg_total_time");
            /*else
                DebugWrite("^1Getting max time for ^b" + state.ToString() + "^n state is not valid", 6);
            */

            return getElapsedTime(utc, PluginState.check);
        }
 public PluginInformation(PluginMetadata meta, PluginState state)
 {
     Plugin = meta;
     State  = state;
 }
Ejemplo n.º 47
0
 public bool isPluginState(PluginState state) {
     return pluginState.Equals(state);
 }
Ejemplo n.º 48
0
        protected ICollection <PluginRuntime> _dependentPlugins = null;              // Lazy initialized

        #endregion

        #region Ctor

        /// <summary>
        /// Creates a new plugin runtime data structure for the specified plugin metadata
        /// instance.
        /// </summary>
        /// <param name="metaData">The metadata of the plugin to create this runtime structure for.</param>
        /// <param name="syncObj">The object to synchronize multithreading access.</param>
        internal PluginRuntime(IPluginMetadata metaData, object syncObj)
        {
            _syncObj        = syncObj;
            _pluginMetadata = metaData;
            _state          = PluginState.Available;
        }
Ejemplo n.º 49
0
        private void balanceRound(int winTeamId) {
            if (winTeamId == 0)
                winTeamId = 1;

            if (serverInfo == null) {
                DebugWrite("^1^bERROR^0^n: will not run round-balancer, server size information is not available", 1);
                return;
            }

            if (!getBooleanVarValue("balance_round")) {
                DebugWrite("Round balancer disbaled, not running", 1);
                return;
            }

            int loseTeamId = getOpposingTeamId(winTeamId);
            int neutralTeamId = 0;
            int team_sz = serverInfo.MaxPlayerCount / 2;

            /* find where the free slot is */
            Dictionary<int, int> pcounts = getPlayerCount();
            int total = pcounts[winTeamId] + pcounts[loseTeamId];


            if (total > serverInfo.MaxPlayerCount) {
                DebugWrite("^1^bWARNING^n^0: detected that there are ^b" + total + "^n players, but DICE says the server size is ^b" + serverInfo.MaxPlayerCount + "^n ", 1);
                DebugWrite("^1^bWARNING^n^0: This makes no sense, DICE be trolling you! ", 1);
                DebugWrite("The highest player count I saw this round was ^b" + max_player_count + "^n, I will use that as server size instead (cross fingers)", 1);
                team_sz = max_player_count / 2;
            }


            Dictionary<int, int> fslots = new Dictionary<int, int>();
            fslots.Add(neutralTeamId, 0);
            fslots.Add(winTeamId, team_sz - pcounts[winTeamId]);
            fslots.Add(loseTeamId, team_sz - pcounts[loseTeamId]);

            if (!(fslots[winTeamId] > 0 || fslots[loseTeamId] > 0)) {
                if (getBooleanVarValue("kick_idle")) {
                    Dictionary<int, List<PlayerProfile>> idle = getAllIdle();
                    DebugWrite("^bkick_idle^n is ^bon^n, will try to find idle players to kick on Team(" + TN(winTeamId) + ") or Team(" + TN(loseTeamId) + ")", 3);


                    if (idle[winTeamId].Count == 0 && idle[loseTeamId].Count == 0) {
                        DebugWrite("^1^bWARNING^0^n: No free player slots in either team, and no idle players, not balancing", 1);
                        return;
                    }

                    /* kick at least 1 from win team */
                    fslots[winTeamId] += kickOnePlayer(idle[winTeamId]);

                    /* kick at least 1 from lose team */
                    fslots[loseTeamId] += kickOnePlayer(idle[loseTeamId]);

                    if (!(fslots[winTeamId] > 0 || fslots[loseTeamId] > 0)) {
                        DebugWrite("^1^bWARNING^0^n: Cannot find at least one idle player that is not in white-list, not balancing", 1);
                        return;
                    }
                }

                DebugWrite("^1^bWARNING^0^n: No free player slots in either team, not balancing", 1);
                return;
            }

            DebugWrite("Team(" + TN(winTeamId) + ") has " + fslots[winTeamId] + " free slots", 3);
            DebugWrite("Team(" + TN(loseTeamId) + ") has " + fslots[loseTeamId] + " free slots", 3);


            int max_squads = 16;
            int max_squad_size = 4;
            virtual_mode = true;
            DateTime now = utc;
            pluginState = PluginState.balance;
            setStartTime(pluginState, now.AddSeconds(1));
            DebugWrite("^b" + pluginState + "_clans^n state started " + getStartTime(pluginState).ToString() + "^n^0", 1);


            DebugWrite("Saving original teams state", 3);
            List<PlayerProfile> all = getPlayersProfile("");
            all.ForEach(delegate(PlayerProfile pp) { pp.saveTeamSquad(); });
            listPlayers();



            DebugWrite("Building no-squad pool from ^bTeam(" + TN(winTeamId) + ")^n and ^bTeam(" + TN(loseTeamId) + ")^n^0", 3);
            List<PlayerProfile> win_nosquad_pool = getNoSquadPlayers(winTeamId);
            List<PlayerProfile> lose_nosquad_pool = getNoSquadPlayers(loseTeamId);
            List<PlayerProfile> nosquad_pool = new List<PlayerProfile>();
            nosquad_pool.AddRange(win_nosquad_pool);
            nosquad_pool.AddRange(lose_nosquad_pool);

            DebugWrite("No-squad pool has ^b" + nosquad_pool.Count + "^n player/s^0", 2);
            DebugWrite("Building squad pool from ^bTeam(" + TN(winTeamId) + ")^n and ^bTeam(" + TN(loseTeamId) + ")^n^0", 3);

            List<PlayerSquad> win_squad_pool = getNonEmptySquads(winTeamId);
            List<PlayerSquad> lose_squad_pool = getNonEmptySquads(loseTeamId);
            List<PlayerSquad> squad_pool = new List<PlayerSquad>();
            squad_pool.AddRange(win_squad_pool);
            squad_pool.AddRange(lose_squad_pool);



            DebugWrite("Squad pool has ^b" + squad_pool.Count + "^n squads^0", 3);
            listSquads(squad_pool);

            if (!getBooleanVarValue("keep_squads_round")) {
                foreach (PlayerSquad squad in squad_pool) {
                    DebugWrite("Breaking up ^bTeam(" + TN(squad.getTeamId()) + ").Squad(" + SQN(squad.getSquadId()) + ")^n^0", 3);
                    while (squad.getCount() > 0) {
                        PlayerProfile player = squad.removeRandomPlayer();
                        if (movePlayer(player, player.getTeamId(), 0, true))
                            nosquad_pool.Add(player); /* only add to no-squad list if move succeeded */
                    }
                }
            }

            DebugWrite("Moving no-squad pool to neutral ^bTeam(" + TN(neutralTeamId) + ")^n^0", 3);
            List<PlayerProfile> nosquad_pool_remove = new List<PlayerProfile>();
            foreach (PlayerProfile player in nosquad_pool) {
                if (!movePlayer(player, neutralTeamId, 0, true))
                    nosquad_pool_remove.Add(player); /*  move failed, remove him from no squad pool (probably in whitelist) */

            }

            /* remove the players that were marked for removing */
            foreach (PlayerProfile pp in nosquad_pool_remove)
                nosquad_pool.Remove(pp);

            DebugWrite("Moving squad pool to neutral ^bTeam(" + TN(neutralTeamId) + ")^n^0", 3);
            foreach (PlayerSquad squad in squad_pool)
                moveSquad(squad, neutralTeamId, team_sz * 2);


            /* re-build the pools */
            DebugWrite("", 3);
            DebugWrite("Rebuilding no-squad pool from ^bTeam(" + TN(winTeamId) + ")^n and ^bTeam(" + TN(loseTeamId) + ")^n^0", 3);
            nosquad_pool = getNoSquadPlayers(neutralTeamId);
            DebugWrite("No-squad pool has ^b" + nosquad_pool.Count + "^n player/s^0", 3);


            DebugWrite("", 3);
            DebugWrite("Rebuilding squad pool from ^bTeam(" + TN(winTeamId) + ")^n and ^bTeam(" + TN(loseTeamId) + ")^n^0", 3);
            squad_pool = getNonEmptySquads(neutralTeamId);
            DebugWrite("Squad pool has ^b" + squad_pool.Count + "^n squads^0", 2);
            listSquads(squad_pool);


            if (getBooleanVarValue("keep_clans_round")) {
                DebugWrite("Keeping clans in same team", 3);

                /* collect statistics about clans */
                DebugWrite("Collecting clan statistics", 3);
                Dictionary<string, int> clan_stats = new Dictionary<string, int>();
                getClanStats(nosquad_pool, clan_stats);
                foreach (PlayerSquad squad in squad_pool)
                    getClanStats(squad.getMembers(), clan_stats);


                List<string> clanlist = new List<string>(clan_stats.Keys);
                DebugWrite("^b" + clanlist.Count + "^n clans in server: [^b" + String.Join("^n], [^b", clanlist.ToArray()) + "^n]", 3);


                int count = 1;
                foreach (KeyValuePair<string, int> pair in clan_stats) {
                    DebugWrite("    " + count + ". clan [^b" + pair.Key + "^n] has ^b" + pair.Value + "^n member/s", 3);
                    count++;
                }


                /* for clans with more than two players in game, create a new squad for them, and remove them from their current squads */
                Dictionary<string, List<PlayerSquad>> clan_squads = new Dictionary<string, List<PlayerSquad>>();
                DebugWrite("Creating clan squads from ^bno-squad^n pool", 3);
                getClanSquads(nosquad_pool, clan_squads, clan_stats);
                DebugWrite("Creating clan squads from ^bsquad-spool^n pool", 3);
                foreach (PlayerSquad squad in squad_pool)
                    getClanSquads(squad.getMembers(), clan_squads, clan_stats);

                /* remove the empty squads */
                DebugWrite("Removing empty squads", 3);
                squad_pool.RemoveAll(delegate(PlayerSquad squad) { return squad.getCount() == 0; });
                DebugWrite("squad-pool has now " + squad_pool.Count, 3);


                int new_squads_count = 0;
                List<PlayerSquad> clan_squad_pool = new List<PlayerSquad>();
                foreach (KeyValuePair<string, List<PlayerSquad>> pair in clan_squads) {
                    List<PlayerSquad> csquads = pair.Value;
                    DebugWrite(csquads.Count + " squads for clan ^b[" + csquads[0].getMajorityClanTag() + "]^n", 3);
                    DebugWrite("----------------------------------------------------------", 3);
                    listSquads(csquads);

                    clan_squad_pool.AddRange(csquads);
                    new_squads_count += csquads.Count;
                }



                List<int> empty_squad_ids = new List<int>();
                DebugWrite("Total of ^b" + new_squads_count + "^n new clan-squads created", 3);
                if ((max_squads - squad_pool.Count) < new_squads_count) {
                    int squads_to_remove_count = 0;
                    int squads_to_ignore_count = 0;
                    int fixed_new_count = 0;

                    int free_squad_slots = (max_squads - squad_pool.Count);
                    int extra = new_squads_count - free_squad_slots;

                    if (extra < squad_pool.Count)
                        squads_to_remove_count = extra;
                    else
                        squads_to_remove_count = squad_pool.Count;


                    squads_to_ignore_count = extra - squads_to_remove_count;

                    fixed_new_count = new_squads_count - squads_to_ignore_count;

                    if (squads_to_ignore_count > 0)
                        DebugWrite("Out of those new clan-squads,  ^b" + squads_to_ignore_count + "^n  will be ignored", 3);

                    DebugWrite("There are already " + squad_pool.Count + "^n non-clan squads in ^bTeam(" + TN(neutralTeamId) + ")^n", 3);
                    DebugWrite("Out of those non-clan squads, " + squads_to_remove_count + " will be removed to make room for " + fixed_new_count + " new clan-squads", 3);


                    List<PlayerSquad> squads_to_remove = new List<PlayerSquad>();

                    /* find squads to remove from the list of squads without players in white-list*/
                    List<PlayerSquad> no_whitelist_squads = getSquadsNotInWhiteList(squad_pool);

                    /* we may have not found enough squads to remove from the non-whitelist squads */
                    int extra_squads_needed = 0;
                    if (no_whitelist_squads.Count < squads_to_remove_count) {
                        extra_squads_needed = squads_to_remove_count - no_whitelist_squads.Count;
                        squads_to_remove_count = no_whitelist_squads.Count;
                        DebugWrite("Only found ^b" + no_whitelist_squads.Count + " non-clan squads without players in white-list, ^b" + squads_to_remove_count + "^n are needed", 3);
                        DebugWrite("Will pick ^b" + extra_squads_needed + "^n extra squads from non-clan pool to remove regardless of white-list", 3);
                    }

                    squads_to_remove.AddRange(no_whitelist_squads.GetRange(0, squads_to_remove_count));
                    if (extra_squads_needed > 0) {
                        List<PlayerSquad> whitelisted_squads = getSquadsInWhiteList(squad_pool);
                        squads_to_remove.AddRange(whitelisted_squads.GetRange(0, extra_squads_needed));
                    }

                    DebugWrite("The following squads will be removed removed from ^bTeam(" + TN(neutralTeamId) + ")", 3);
                    DebugWrite("----------------------------------------------------------------------", 3);
                    listSquads(squads_to_remove);

                    while (squads_to_remove.Count > 0) {
                        PlayerSquad squad_to_remove = squads_to_remove[0];
                        squads_to_remove.RemoveAt(0);
                        empty_squad_ids.Add(squad_to_remove.getSquadId());
                        int squad_sz = squad_to_remove.getCount();

                        DebugWrite("Looking for empty slots in existing squads, for memebers of " + squad_to_remove, 3);

                        squad_sz -= mergeSquadWithPool(squad_to_remove, clan_squad_pool);
                        squad_sz -= mergeSquadWithPool(squad_to_remove, squad_pool);


                        if (squad_sz > 0) {
                            DebugWrite("Did not find empty slots for all members of, " + squad_to_remove, 3);
                            DebugWrite("Will move them to no-squad spool, " + squad_to_remove, 3);
                            while (squad_to_remove.getCount() > 0) {
                                PlayerProfile player = squad_to_remove.removeRandomPlayer();
                                if (movePlayer(player, player.getTeamId(), 0))
                                    nosquad_pool.Add(player);
                            }
                        }

                        /* remove the empty squads */
                        DebugWrite("Removing empty squads", 3);
                        squad_pool.RemoveAll(delegate(PlayerSquad squad) { return squad.getCount() == 0; });
                    }



                }


                DebugWrite("Team(" + TN(neutralTeamId) + ") squad pool before move", 3);
                DebugWrite("=====================================================", 3);
                List<PlayerSquad> temp_pool = getNonEmptySquads(neutralTeamId);
                DebugWrite("Temp pool has ^b" + temp_pool.Count + "^n squads^0", 2);
                temp_pool.Sort(new Comparison<PlayerSquad>(getSquadSort("round_sort")));
                for (int i = 0; i < squad_pool.Count; i++) {
                    DebugWrite("      " + i + ". " + temp_pool[i].ToString() + "(" + getSortFieldValueStr(temp_pool[i], "round_sort") + ")", 3);
                }


                /* add clan squads to the squad pool */
                DebugWrite("Moving ^b" + clan_squad_pool.Count + "^n from clan-squad pool to Team(" + TN(neutralTeamId) + ")", 3);
                foreach (PlayerSquad squad in clan_squad_pool)
                    moveSquad(squad, neutralTeamId, team_sz * 2);

            }

            /* re-build the pools */

            DebugWrite("Rebuilding no-squad pool", 3);
            nosquad_pool = getNoSquadPlayers(neutralTeamId);
            DebugWrite("No-squad pool has ^b" + nosquad_pool.Count + "^n player/s^0", 3);
            listPlayers(nosquad_pool);

            DebugWrite("Rebuilding squad pool", 3);
            squad_pool = getNonEmptySquads(neutralTeamId);
            DebugWrite("Squad pool has ^b" + squad_pool.Count + "^n squads^0", 2);


            if (squad_pool.Count > max_squads)
                DebugWrite("^1^bWARNING^0^n: There are still more squads than allowed!", 1);

            /* sort the no-squad pool */
            DebugWrite("Sorting the no-squad pool by ^b" + getStringVarValue("round_sort") + "^n^0", 3);
            nosquad_pool.Sort(new Comparison<PlayerProfile>(getPlayerSort("round_sort")));

            for (int i = 0; i < nosquad_pool.Count; i++) {
                DebugWrite("      " + i + ". " + nosquad_pool[i] + "(" + getSortFieldValueStr(nosquad_pool[i], "round_sort") + ")", 3);
            }


            /* sort the squad pool */
            DebugWrite("Sorting the squad pool by ^b" + getStringVarValue("round_sort") + "^n^0", 3);
            squad_pool.Sort(new Comparison<PlayerSquad>(getSquadSort("round_sort")));

            for (int i = 0; i < squad_pool.Count; i++) {
                DebugWrite("      " + i + ". " + squad_pool[i].ToString() + "(" + getSortFieldValueStr(squad_pool[i], "round_sort") + ")", 3);
            }

            int[] teamCount = new int[3];
            teamCount[neutralTeamId] = sumSquadPlayers(squad_pool) + nosquad_pool.Count;
            teamCount[winTeamId] = getPlayerCount()[winTeamId];
            teamCount[loseTeamId] = getPlayerCount()[loseTeamId];

            DebugWrite("Team counts, ^bTeam(" + TN(neutralTeamId) + ")^n: " + teamCount[neutralTeamId] + ", ^bTeam(" + TN(winTeamId) + ")^n: " + teamCount[winTeamId] + ", ^bTeam(" + TN(loseTeamId) + ")^n: " + teamCount[loseTeamId], 3);

            Dictionary<string, int> clanTeam = new Dictionary<string, int>();

            /* assume the smaller team */
            int smallTeamId = loseTeamId;

            DebugWrite("Moving ^b" + squad_pool.Count + "^n squads from neutral ^bTeam(" + TN(neutralTeamId) + ")^n into ^bTeam(" + TN(winTeamId) + ")^n and ^bTeam(" + TN(loseTeamId) + ")^n^0", 3);

            while (squad_pool.Count > 0) {
                /* get the top squad */
                PlayerSquad squad = squad_pool[0];
                squad_pool.RemoveAt(0);

                if (getBooleanVarValue("keep_clans_round")) {
                    string tag = squad.getMajorityClanTag();
                    /* if squad has a clan tag, determine where most of his team is already */
                    if (!Regex.Match(tag, @"^\s*$").Success) {
                        if (clanTeam.ContainsKey(tag)) {
                            int clan_team_id = clanTeam[tag];
                            DebugWrite("There is already a clan squad for ^b[" + tag + "]^n in ^bTeam(" + TN(clan_team_id) + ")^n^0", 3);
                            smallTeamId = clan_team_id;
                        } else {
                            DebugWrite("First time seeing clan ^b[" + tag + "]^n will assign to ^bTeam(" + TN(smallTeamId) + ")^n^0", 3);
                            clanTeam.Add(tag, smallTeamId);
                        }
                    }
                }

                int squad_sz = squad.getCount();

                /* move top squad to the smaller team */
                DebugWrite("Moving entire " + squad.ToString() + " to ^bTeam(" + TN(smallTeamId) + ")^n^0", 3);
                /* squad size may change if not all players were moved, i.e. someone was in white list */
                squad_sz = moveSquad(squad, smallTeamId, team_sz);


                /* update the team counts */
                teamCount[smallTeamId] += squad_sz;
                teamCount[neutralTeamId] -= squad_sz;

                /* determine the smaller team */
                smallTeamId = getSmallTeamId(winTeamId, teamCount[winTeamId], loseTeamId, teamCount[loseTeamId]);
                DebugWrite("Team counts, ^bTeam(" + TN(neutralTeamId) + ")^n: " + teamCount[neutralTeamId] + ", ^bTeam(" + TN(winTeamId) + ")^n: " + teamCount[winTeamId] + ", ^bTeam(" + TN(loseTeamId) + ")^n: " + teamCount[loseTeamId] + ", ^b Small Team(" + TN(smallTeamId) + ")^n: " + teamCount[smallTeamId], 3);
                DebugWrite("------------------------------------------------------------------------------------------------", 3);
            }

            DebugWrite("^bTeam(" + TN(winTeamId) + ")^n has now ^b" + teamCount[winTeamId] + "^n player/s", 3);
            DebugWrite("^bTeam(" + TN(loseTeamId) + ")^n has now ^b" + teamCount[loseTeamId] + "^n player/s", 3);

            DebugWrite("Moving ^b" + nosquad_pool.Count + "^n player/s from neutral ^bTeam(" + TN(neutralTeamId) + ")^n into ^bTeam(" + TN(winTeamId) + ")^n and ^bTeam(" + TN(loseTeamId) + ")^n^0", 3);

            while (nosquad_pool.Count > 0) {
                /* get the top player */
                PlayerProfile player = nosquad_pool[0];
                nosquad_pool.RemoveAt(0);

                /* move the top player to the smaller team */
                DebugWrite("Moving ^b" + player.ToString() + "^n to ^bTeam(^n" + TN(smallTeamId) + ")^n^0", 3);
                int moved = 1;
                if (!movePlayer(player, smallTeamId, 0, true))
                    moved = 0;

                /* update the team counts */
                teamCount[neutralTeamId] -= moved;
                teamCount[smallTeamId] += moved;

                /* determine the smaller team */
                smallTeamId = getSmallTeamId(winTeamId, teamCount[winTeamId], loseTeamId, teamCount[loseTeamId]);
            }


            DebugWrite("^bTeam(" + TN(winTeamId) + ")^n has now ^b" + teamCount[winTeamId] + "^n player/s", 3);
            DebugWrite("^bTeam(" + TN(loseTeamId) + ")^n has now ^b" + teamCount[loseTeamId] + "^n player/s", 3);

            if (teamsUnbalanced()) {
                DebugWrite("Teams are still unbalanced, applying the live balancing logic", 3);
                balanceLive(utc, true);


            } else
                DebugWrite("Teams should now be balanced!", 3);

            DebugWrite("Doing sanity check now", 3);
            DebugWrite("========================", 3);

            List<PlayerProfile> moving_from_win_to_lose = getPlayersMoving(winTeamId, loseTeamId);
            List<PlayerProfile> moving_from_lose_to_win = getPlayersMoving(loseTeamId, winTeamId);



            DebugWrite(moving_from_win_to_lose.Count + " players will be moving from Team(" + TN(winTeamId) + ") to Team(" + TN(loseTeamId) + ")", 3);
            DebugWrite(moving_from_lose_to_win.Count + " players will be moving from Team(" + TN(loseTeamId) + ") to Team(" + TN(winTeamId) + ")", 3);

            int teamWithMoreMoving = 0;
            int players_needing_moving = 0;
            List<PlayerProfile> players_moving = null;

            if (moving_from_win_to_lose.Count > moving_from_lose_to_win.Count) {
                teamWithMoreMoving = winTeamId;
                players_moving = moving_from_win_to_lose;
                int slots_needed_in_lose_team = moving_from_win_to_lose.Count - moving_from_lose_to_win.Count;
                DebugWrite(slots_needed_in_lose_team + " free slots are needed in Team(" + TN(loseTeamId) + "), and there are " + fslots[loseTeamId], 3);
                if (slots_needed_in_lose_team > fslots[loseTeamId]) {
                    DebugWrite("There are only " + fslots[loseTeamId] + " free slots in Team(" + TN(loseTeamId) + ")", 3);
                    players_needing_moving = slots_needed_in_lose_team - fslots[loseTeamId];
                    DebugWrite("Meaning that, " + players_needing_moving + " players will not be able to move from Team(" + TN(winTeamId) + ") to Team(" + TN(loseTeamId) + ")", 3);
                }
            } else if (moving_from_lose_to_win.Count > moving_from_win_to_lose.Count) {
                teamWithMoreMoving = loseTeamId;
                players_moving = moving_from_lose_to_win;
                int slots_needed_in_win_team = moving_from_lose_to_win.Count - moving_from_win_to_lose.Count;
                DebugWrite(slots_needed_in_win_team + " free slots are needed in Team(" + TN(winTeamId) + "), and there are " + fslots[winTeamId], 3);
                if (slots_needed_in_win_team > fslots[winTeamId]) {
                    DebugWrite("There are only " + fslots[winTeamId] + " free slots in Team(" + TN(winTeamId) + ")", 3);
                    players_needing_moving = slots_needed_in_win_team - fslots[winTeamId];
                    DebugWrite("Meaning that, " + players_needing_moving + " players will not be able to move from Team(" + TN(loseTeamId) + ") to Team(" + TN(winTeamId) + ")", 3);
                }
            }

            if (players_needing_moving > 0) {
                DebugWrite("I have determined that " + players_needing_moving + " players will need to stay in Team(" + TN(teamWithMoreMoving) + ") to remedy this situation", 3);

                while (players_needing_moving > 0 && players_moving.Count > 0) {
                    PlayerProfile pp = players_moving[0];
                    players_moving.RemoveAt(0);

                    /* he already stays, leave him alone */
                    if (pp.getSavedTeamId() == pp.getTeamId())
                        continue;

                    /* move him back to where he was */
                    players_needing_moving -= mergePlayerWithTeam(pp, pp.getSavedTeamId());

                }

            }

            DebugWrite("Re-doing sanity check now", 3);
            DebugWrite("========================", 3);

            moving_from_win_to_lose = getPlayersMoving(winTeamId, loseTeamId);
            moving_from_lose_to_win = getPlayersMoving(loseTeamId, winTeamId);

            DebugWrite(moving_from_win_to_lose.Count + " players will be moving from Team(" + TN(winTeamId) + ") to Team(" + TN(loseTeamId) + ")", 3);
            DebugWrite(moving_from_lose_to_win.Count + " players will be moving from Team(" + TN(loseTeamId) + ") to Team(" + TN(winTeamId) + ")", 3);

            virtual_mode = false;

            /* swap players that are moving across teams only, and put them in no-squad */
            fixTeams(winTeamId, pcounts, fslots);

            /* fix the squads for players */
            sleep = true;
            fixSquads();
            sleep = false;
        }
Ejemplo n.º 50
0
 internal PluginDescription()
 {
     pluginState = PluginState.Undefined;
 }
Ejemplo n.º 51
0
        private string state2strWHILE(PluginState state) {
            if (state.Equals(PluginState.balance)) {
                return "balancing";
            } else if (state.Equals(PluginState.check)) {
                return "checking";
            } else if (state.Equals(PluginState.warn)) {
                return "warning";
            } else if (state.Equals(PluginState.stop)) {
                return "stopped";
            } else if (state.Equals(PluginState.wait)) {
                return "waiting";
            }

            return "unknown state";
        }
Ejemplo n.º 52
0
 private void ChangePluginState(PluginState state)
 {
     Plugin.State = state;
     Bridge.Logger.Debug("Plugin {ID} changed state to {STATE}", Path, Enum.GetName(typeof(PluginState), state));
 }
Ejemplo n.º 53
0
        private void startWaitState(string sender, DateTime now) {

            if (!isPluginStopped()) {
                SendConsoleMessage(sender, "cannot start while balancer is in " + pluginState.ToString() + " state");
                return;
            }

            if (sender != null)
                setPluginVarValue("auto_start", "true");


            pluginState = PluginState.wait;
            setStartTime(pluginState, now.AddSeconds(1));


            SendConsoleMessage(sender, "^b" + pluginState + "^n state started " + getStartTime(pluginState).ToString());
        }
Ejemplo n.º 54
0
 public StateChangeEventArgs(IPlugin plugin, PluginState oldState, PluginState newState)
 {
     this.Plugin   = plugin;
     this.OldState = oldState;
     this.NewState = newState;
 }
Ejemplo n.º 55
0
 private void restartWaitState(DateTime now) {
     pluginState = PluginState.wait;
     setStartTime(pluginState, now.AddSeconds(1));
     DebugWrite("^b" + pluginState.ToString() + "^n state re-started " + getStartTime(pluginState).ToString() + "^0", 1);
 }
Ejemplo n.º 56
0
 internal void Enable() {
   if (pluginState != PluginState.Undefined)
     throw new InvalidOperationException("Cannot enable a plugin in state " + pluginState);
   pluginState = PluginState.Enabled;
 }
Ejemplo n.º 57
0
        public void OnLoad()
        {
            plugins.LoadPlugins();

            state = PluginState.Idle;

            // Set hashes
            herohashlist.Clear();
            herohashlist.Add(new HeroHashData(0, "Warrior", "warrior_small.png", 13776678289873991291, 10236917153841177209, 14776501596708557433, 13071189497635732127, 12080542990295427731)); // Garrosh, Garrosh golden small, Garrosh golden big, Magni small, Magni big
            herohashlist.Add(new HeroHashData(1, "Shaman", "shaman_small.png", 18366959783178990451));
            herohashlist.Add(new HeroHashData(2, "Rogue", "rogue_small.png", 5643619427529904809, 11263619176753353643, 10111770795730096827)); // Valeera, Valeera golden small, Valeera golden big
            herohashlist.Add(new HeroHashData(3, "Paladin", "paladin_small.png", 11505795398351105139));
            herohashlist.Add(new HeroHashData(4, "Hunter", "hunter_small.png", 2294799430464257123, 1975465933826505957, 813537221374590197, 12942361696967163803, 17552924014479703963)); // Rexxar, Rexxar golden small, Rexxar golden big, Alleria small, Alleria big
            herohashlist.Add(new HeroHashData(5, "Druid", "druid_small.png", 5433851923975358071));
            herohashlist.Add(new HeroHashData(6, "Warlock", "warlock_small.png", 10186248321710093033));
            herohashlist.Add(new HeroHashData(7, "Mage", "mage_small.png", 15770007155810004267, 8631746754340092973, 8343516378188643373)); // Jaina, Medivh small, Medivh big
            herohashlist.Add(new HeroHashData(8, "Priest", "priest_small.png", 15052908377040876499));

            AddMenuItem();

            stopwatch = Stopwatch.StartNew();

            // Init card list
            List<Card> cards = Database.GetActualCards();
            foreach (var card in cards)
            {
                // Add to the list
                cardlist.Add((Card)card.Clone());
            }

            // Load data
            LoadData();

            // Add log events
            Hearthstone_Deck_Tracker.API.LogEvents.OnArenaLogLine.Add(OnArenaLogLine);
        }
Ejemplo n.º 58
0
 public void Start()
 {
     control.Start();
     pluginState = PluginState.Running;
 }