UUID IGroupSelectInterface.this[UGUI requestingAgent, UGI group, UGUI principal]
 {
     get
     {
         UUID id;
         if (!ActiveGroup.TryGetValue(requestingAgent, group, principal, out id))
         {
             throw new KeyNotFoundException();
         }
         return(id);
     }
     set
     {
         MemoryGroupInfo   info;
         MemoryGroupMember mem;
         if (m_Groups.TryGetValue(group.ID, out info) && info.Members.TryGetValue(principal, out mem))
         {
             mem.ActiveRoleID = value;
         }
         else
         {
             throw new KeyNotFoundException();
         }
     }
 }
Example #2
0
        public virtual void OnEnterDungeon(Mobile m)
        {
            if (m == null || m.Deleted)
            {
                return;
            }

            if (m is PlayerMobile)
            {
                var pm = (PlayerMobile)m;

                ActiveGroup.AddOrReplace(pm);

                if (ActiveGroup.Count > 0 && ActiveLeader == null)
                {
                    ActiveLeader = pm;
                }

                DungeonUI.DisplayTo(pm, false, this);
            }

            if (m.Player)
            {
                CheckDismount(m);

                if (!Options.Rules.AllowPets && m is PlayerMobile)
                {
                    StablePets((PlayerMobile)m);
                }
            }

            m.Delta(MobileDelta.Noto);
        }
        /* get/set active role id */
        UUID IGroupSelectInterface.this[UGUI requestingAgent, UGI group, UGUI principal]
        {
            get
            {
                UUID id;
                if (!ActiveGroup.TryGetValue(requestingAgent, group, principal, out id))
                {
                    id = UUID.Zero;
                }
                return(id);
            }

            set
            {
                using (var conn = new NpgsqlConnection(m_ConnectionString))
                {
                    conn.Open();
                    using (var cmd = new NpgsqlCommand("UPDATE groupmemberships SET \"SelectedRoleID\"=@roleid WHERE \"PrincipalID\" = @principalid AND \"GroupID\" = @groupid", conn))
                    {
                        cmd.Parameters.AddParameter("@roleid", value);
                        cmd.Parameters.AddParameter("@groupid", group.ID);
                        cmd.Parameters.AddParameter("@principalid", principal.ID);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
Example #4
0
    static int SelectByUid(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        ActiveGroup obj  = (ActiveGroup)LuaScriptMgr.GetUnityObjectSelf(L, 1, "ActiveGroup");
        int         arg0 = (int)LuaScriptMgr.GetNumber(L, 2);

        obj.SelectByUid(arg0);
        return(0);
    }
Example #5
0
    static int SetChangeCallback(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        ActiveGroup obj  = (ActiveGroup)LuaScriptMgr.GetUnityObjectSelf(L, 1, "ActiveGroup");
        LuaFunction arg0 = LuaScriptMgr.GetLuaFunction(L, 2);

        obj.SetChangeCallback(arg0);
        return(0);
    }
Example #6
0
    static int AddActiveButton(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        ActiveGroup  obj  = (ActiveGroup)LuaScriptMgr.GetUnityObjectSelf(L, 1, "ActiveGroup");
        ActiveButton arg0 = (ActiveButton)LuaScriptMgr.GetUnityObject(L, 2, typeof(ActiveButton));

        obj.AddActiveButton(arg0);
        return(0);
    }
Example #7
0
 static void MarkButton(Listing_Toggles view, string group)
 {
     if (ActiveGroup.Equals(group))
     {
         GUI.color = ClickedColor;
     }
     if (view.ButtonText(group.Translate()))
     {
         ActiveGroup = group;
     }
     GUI.color = DefaultColor;
 }
Example #8
0
 // Middle view
 static void DoMiddle(Rect middleRect)
 {
     if (!ActiveGroup.NullOrEmpty())
     {
         if (ActiveGroup.Equals(ButtonCat.MetaModSettings))
         {
             DoMetaSettingsView(middleRect);
         }
         else
         {
             DoToggleView(middleRect);
         }
     }
 }
Example #9
0
        public void ExecuteDelayedScripts()
        {
            lock (ListDelayedOnlineCommand)
            {
                foreach (DelayedExecutableOnlineScript ActiveCommand in ListDelayedOnlineCommand)
                {
                    ActiveCommand.ExecuteOnMainThread();
                }

                ListDelayedOnlineCommand.Clear();
            }

            foreach (CommunicationClient ActiveGroup in DicCrossServerCommunicationByGroupID.Values)
            {
                ActiveGroup.ExecuteDelayedScripts();
            }
        }
        protected virtual void GenerateLoot(BaseCreature m, List <Item> loot, double scale)
        {
            double c;

            if (ActiveGroup.Count <= 0)
            {
                c = Utility.RandomDouble() * (Math.Log10(m.RawStatTotal) / 10.0);
            }
            else
            {
                c = ActiveGroup.Average(o => ComputeLootChance(o, m));
            }

            var count = Math.Max(1, ActiveGroup.Count);

            Item item;

            while (--count >= 0)
            {
                if (Utility.RandomDouble() > c)
                {
                    continue;
                }

                item = GenerateLootItem(m);

                if (item == null || item.Deleted)
                {
                    continue;
                }

                MutateLootItem(item);

                if (item.Deleted)
                {
                    continue;
                }

                ScaleItem(item, scale);

                if (!item.Deleted)
                {
                    loot.Add(item);
                }
            }
        }
Example #11
0
        private void Slice()
        {
            if (Deleted || Initializing || Generating)
            {
                return;
            }

            ActiveGroup.ForEachReverse(
                m =>
            {
                if (m == null)
                {
                    return;
                }

                if (m.Map == Map && Zones.Any(m.InRegion))
                {
                    CheckDismount(m);

                    if (!Options.Rules.AllowPets)
                    {
                        StablePets(m);
                    }
                }
                else
                {
                    OnExitDungeon(m);
                }
            });

            OnSlice();

            if (DateTime.UtcNow > Deadline)
            {
                OnDeadline();
            }

            if (Core.TickCount < _NextDefragment)
            {
                return;
            }

            _NextDefragment = Core.TickCount + 60000;

            Defragment();
        }
        UGI IGroupSelectInterface.this[UGUI requestingAgent, UGUI principal]
        {
            get
            {
                UGI ugi;
                if (!ActiveGroup.TryGetValue(requestingAgent, principal, out ugi))
                {
                    throw new KeyNotFoundException();
                }
                return(ugi);
            }

            set
            {
                m_ActiveGroups[principal] = value.ID;
            }
        }
Example #13
0
        public void Update()
        {
            foreach (OnlineScript ActiveScript in Host.ReadScripts())
            {
                ActiveScript.Execute(Host);
            }

            foreach (CommunicationClient ActiveGroup in DicCrossServerCommunicationByGroupID.Values)
            {
                ActiveGroup.Update();
            }

            if (!Host.IsConnected())
            {
                OnConnectionLost();
            }
        }
 void CheckGroup(string id, ActiveGroup item)
 {
     if (string.IsNullOrEmpty(groupID))
     {
         Debug.LogError("Group ID for the ActiveGroup on " + gameObject.name + " is empty!", this);
     }
     else if (id == groupID)
     {
         if (item != this)
         {
             gameObject.SetActive(false);
         }
         else
         {
             gameObject.SetActive(true);
         }
     }
 }
Example #15
0
        public virtual void OnExitDungeon(Mobile m)
        {
            if (m == null)
            {
                return;
            }

            if (MobileSpawns.Remove(m))
            {
                OnSpawnDeactivate(m);
            }

            if (m.Deleted)
            {
                return;
            }

            if (m is PlayerMobile)
            {
                var pm = (PlayerMobile)m;

                ActiveGroup.Remove(pm);

                if (ActiveGroup.Count > 0 && ActiveLeader == pm)
                {
                    ActiveLeader = ActiveGroup[0];
                }

                pm.CloseGump(typeof(DungeonUI));
                pm.CloseGump(typeof(DungeonLootUI));

                if (pm.Map == null || pm.Map == Server.Map.Internal)
                {
                    StablePets(pm);
                }
                else
                {
                    SummonPets(pm);
                }
            }

            m.Delta(MobileDelta.Noto);
            m.ProcessDelta();
        }
Example #16
0
    static int set_Select(IntPtr L)
    {
        object      o   = LuaScriptMgr.GetLuaObject(L, 1);
        ActiveGroup obj = (ActiveGroup)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name Select");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index Select on a nil value");
            }
        }

        obj.Select = (ActiveButton)LuaScriptMgr.GetUnityObject(L, 3, typeof(ActiveButton));
        return(0);
    }
Example #17
0
        // Right view
        static void DoRight(Rect rightRect)
        {
            // Logged letters
            if (ActiveGroup.Equals(ButtonCat.Letters))
            {
                List <string> loggedLetters = Letter_Patch.LoggedLetters;
                float         rightY        = (loggedLetters.Count() + 2) * 25f;
                var           rightView     = new Listing_Toggles();
                rightView.BeginListing(rightRect, ref scrollPositionRight, rightY);
                rightView.CustomLabel("LoggedLetters".Translate(), -1, "LoggedLettersDesc".Translate());

                foreach (string letter in loggedLetters)
                {
                    if (rightView.CustomButtonText(letter))
                    {
                        Letter_Patch.AddRawLetter(letter);
                    }
                }

                rightView.EndListing();
            }

            // Alert me later
            if (ActiveGroup.Equals(ButtonCat.Alerts))
            {
                float rightY    = 10 * 25f;
                var   rightView = new Listing_Toggles();
                rightView.BeginListing(rightRect, ref scrollPositionRight, rightY);

                int alertSleepHours = AlertsReadout_Patch.hourMultiplier;
                rightView.CustomLabel("AlertMeLater".Translate(), -1, "AlertMeLaterDesc".Translate(alertSleepHours));
                rightView.GapLine();

                rightView.CustomLabel("AlertSleepCount".Translate(alertSleepHours));
                AlertsReadout_Patch.hourMultiplier = Mathf.RoundToInt(rightView.Slider((float)alertSleepHours, 1f, 24f));;
                rightView.EndListing();
            }
        }
        bool IActiveGroupMembershipInterface.TryGetValue(UGUI requestingAgent, UGUI principal, out GroupActiveMembership gam)
        {
            gam = default(GroupActiveMembership);
            UGI activegroup;

            if (!ActiveGroup.TryGetValue(requestingAgent, principal, out activegroup))
            {
                return(false);
            }
            GroupInfo group;

            if (!Groups.TryGetValue(requestingAgent, activegroup, out group))
            {
                return(false);
            }

            GroupMember gmem;

            if (!Members.TryGetValue(requestingAgent, activegroup, principal, out gmem))
            {
                return(false);
            }

            GroupRole role;

            if (!Roles.TryGetValue(requestingAgent, activegroup, gmem.SelectedRoleID, out role))
            {
                return(false);
            }

            gam = new GroupActiveMembership
            {
                Group          = group.ID,
                SelectedRoleID = gmem.SelectedRoleID,
                User           = gmem.Principal
            };
            return(true);
        }
Example #19
0
        protected override void OnSlice()
        {
            base.OnSlice();

            for (var i = 0; i < Bosses.Length; i++)
            {
                var o = Bosses[i];

                if (o != null && !o.Deleted && o.Alive)
                {
                    var players = 0;

                    foreach (var m in Circles[i].FindEntities <PlayerMobile>(Map))
                    {
                        if (ActiveGroup.Contains(m))
                        {
                            ++players;
                        }

                        if (m.Z < 0)
                        {
                            Teleport(m, TeleportersFrom[i].PointDest, Map);
                        }
                    }

                    if (players <= 0)
                    {
                        o.Combatant = null;
                    }

                    if (o.InCombat(TimeSpan.FromSeconds(5)))
                    {
                        DropFloor(i, false);
                    }
                }
            }
        }
Example #20
0
        public void UpdatePlayers()
        {
            Parallel.ForEach(ListPlayer, (ActivePlayer, loopState) =>
            {
                if (!ActivePlayer.IsConnected())
                {
                    if (ActivePlayer.HasLeftServer())
                    {
                        ListPlayerToRemove.Add(ActivePlayer);
                        Database.RemovePlayer(ActivePlayer);
                    }
                }
                else
                {
                    lock (ActivePlayer.ListAsyncOnlineScript)
                    {
                        foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                        {
                            ActiveScript.Execute(ActivePlayer);
                        }

                        ActivePlayer.ListAsyncOnlineScript.Clear();
                    }
                }
            });

            while (ListPlayerToRemove.Count > 0)
            {
                ListPlayer.Remove(ListPlayerToRemove[0]);
                ListPlayerToRemove.RemoveAt(0);
            }

            Parallel.ForEach(DicLocalRoom.Values, (ActiveGroup, loopState) =>
            {
                if (ActiveGroup.IsRunningSlow())
                {
                    //Send Room to another Server
                }

                if (ActiveGroup.CurrentGame != null)
                {
                    ActiveGroup.CurrentGame.Update(DeltaTime);
                }

                for (int P = ActiveGroup.Room.ListOnlinePlayer.Count - 1; P >= 0; --P)
                {
                    IOnlineConnection ActivePlayer = ActiveGroup.Room.ListOnlinePlayer[P];

                    if (!ActivePlayer.IsConnected())
                    {
                        if (ActivePlayer.HasLeftServer())
                        {
                            string PlayerID = ActiveGroup.Room.ListOnlinePlayer[P].ID;
                            ActiveGroup.Room.RemoveOnlinePlayer(P);
                            Database.UpdatePlayerCountInRoom(ActiveGroup.Room.RoomID, (byte)ActiveGroup.Room.ListOnlinePlayer.Count);

                            if (ActiveGroup.Room.ListOnlinePlayer.Count == 0)
                            {
                                ListLocalRoomToRemove.Add(ActiveGroup.Room.RoomID);
                            }

                            if (ActiveGroup.CurrentGame == null)
                            {
                                foreach (IOnlineConnection OtherPlayer in ActiveGroup.Room.ListOnlinePlayer)
                                {
                                    OtherPlayer.Send(new PlayerLeftScriptServer(PlayerID, 0));
                                }
                            }
                            else
                            {
                                ActiveGroup.CurrentGame.RemoveOnlinePlayer(PlayerID, ActivePlayer);
                            }

                            ActivePlayer.StopReadingScriptAsync();
                        }
                    }
                    else
                    {
                        lock (ActivePlayer.ListAsyncOnlineScript)
                        {
                            foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                            {
                                ActiveScript.Execute(ActivePlayer);
                            }

                            ActivePlayer.ListAsyncOnlineScript.Clear();
                        }
                    }
                }
            });

            while (ListLocalRoomToRemove.Count > 0)
            {
                DicLocalRoom.Remove(ListLocalRoomToRemove[0]);
                DicAllRoom.Remove(ListLocalRoomToRemove[0]);
                Database.RemoveRoom(ListLocalRoomToRemove[0]);
                ListLocalRoomToRemove.RemoveAt(0);
            }

            foreach (GameClientGroup ActiveGroup in DicTransferingRoom.Values)
            {
                foreach (IOnlineConnection ActivePlayer in ActiveGroup.Room.ListOnlinePlayer)
                {
                    lock (ActivePlayer.ListAsyncOnlineScript)
                    {
                        foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                        {
                            ActiveScript.Execute(ActivePlayer);
                        }

                        ActivePlayer.ListAsyncOnlineScript.Clear();
                    }
                }

                if (ActiveGroup.Room.ListOnlinePlayer.Count == ActiveGroup.Room.CurrentPlayerCount && ActiveGroup.CurrentGame != null)
                {
                    ListTransferingRoomToRemove.Add(ActiveGroup.Room.RoomID);
                }
            }

            while (ListTransferingRoomToRemove.Count > 0)
            {
                DicLocalRoom.Add(ListTransferingRoomToRemove[0], DicTransferingRoom[ListTransferingRoomToRemove[0]]);
                DicTransferingRoom.Remove(ListTransferingRoomToRemove[0]);
                ListTransferingRoomToRemove.RemoveAt(0);
            }

            //TODO: Run task in background
            if (DateTimeOffset.Now > NextRoomUpdateTime)
            {
                NextRoomUpdateTime = NextRoomUpdateTime.AddSeconds(10);

                List <IRoomInformations> ListRoomUpdates = Database.GetAllRoomUpdatesSinceLastTimeChecked(ServerVersion);

                if (ListRoomUpdates != null)
                {
                    foreach (IRoomInformations ActiveRoomUpdate in ListRoomUpdates)
                    {
                        if (ActiveRoomUpdate.IsDead)
                        {
                            DicAllRoom.Remove(ActiveRoomUpdate.RoomID);
                        }
                        else
                        {
                            if (DicAllRoom.ContainsKey(ActiveRoomUpdate.RoomID))
                            {
                                DicAllRoom[ActiveRoomUpdate.RoomID] = ActiveRoomUpdate;
                            }
                            else
                            {
                                DicAllRoom.Add(ActiveRoomUpdate.RoomID, ActiveRoomUpdate);
                            }
                        }
                    }

                    SharedWriteBuffer.ClearWriteBuffer();
                    SharedWriteBuffer.WriteScript(new RoomListScriptServer(this, ListRoomUpdates));
                    Parallel.ForEach(ListPlayer, (ActivePlayer, loopState) =>
                    {
                        ActivePlayer.SendWriteBuffer();
                    });
                }
            }
        }
        /// <summary>
        /// Changes the active group to the group specified.
        /// </summary>
        /// <param name="localSummit">Summit System</param>
        /// <param name="groupToChangeTo">Medtronic Active Group Format to change to</param>
        /// <param name="localSenseModel">Sense Model that uses the streaming parameters for turning stream on and off</param>
        /// <returns>Tuple with bool true if success or false if not. string give error message</returns>
        public async Task <Tuple <bool, string> > ChangeActiveGroup(SummitSystem localSummit, ActiveGroup groupToChangeTo, SenseModel localSenseModel)
        {
            if (localSummit == null || localSummit.IsDisposed)
            {
                return(Tuple.Create(false, "Error: Summit null or disposed."));
            }
            APIReturnInfo bufferReturnInfo;

            try
            {
                int counter = 5;
                summitSensing.StopStreaming(localSummit, true);
                do
                {
                    bufferReturnInfo = await Task.Run(() => localSummit.StimChangeActiveGroup(groupToChangeTo));

                    if (counter < 5)
                    {
                        Thread.Sleep(400);
                    }
                    counter--;
                } while ((bufferReturnInfo.RejectCode != 0) && counter > 0);
                //Start streaming
                summitSensing.StartStreaming(localSummit, localSenseModel, true);
                if ((bufferReturnInfo.RejectCode != 0) && counter == 0)
                {
                    _log.Warn(":: Error: Medtronic API return error changing active group: " + bufferReturnInfo.Descriptor + ". Reject Code: " + bufferReturnInfo.RejectCode);

                    return(Tuple.Create(false, "Error: Medtronic API return error changing active group: " + bufferReturnInfo.Descriptor + ". Reject Code: " + bufferReturnInfo.RejectCode));
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
                return(Tuple.Create(false, "Error: Could not change groups"));
            }
            return(Tuple.Create(true, "Successfully changed groups"));
        }
Example #22
0
        public void Delete()
        {
            if (Deleted || _Deleting)
            {
                return;
            }

            _Deleting = true;

            OnBeforeDelete();

            KickAll();

            EventSink.Shutdown -= InternalServerShutdown;
            EventSink.Logout   -= InternalLogout;
            EventSink.Login    -= InternalLogin;

            if (CoreTimer != null)
            {
                CoreTimer.Dispose();
                CoreTimer = null;
            }

            Instances.Dungeons.Remove(Serial);

            OnDelete();

            if (ExitPortal1 != null)
            {
                ExitPortal1.Delete();
                ExitPortal1 = null;
            }

            if (ExitPortal2 != null)
            {
                ExitPortal2.Delete();
                ExitPortal2 = null;
            }

            if (Loot != null)
            {
                Loot.ForEach(l => l.Free());
                Loot.Free(true);
            }

            if (Zones != null)
            {
                Zones.ForEachReverse(
                    z =>
                {
                    if (z != null)
                    {
                        z.Dungeon = null;
                        z.Delete();
                    }
                });
                Zones.Free(true);
            }

            if (MobileSpawns != null)
            {
                MobileSpawns.Where(m => m != null && !m.Deleted && !m.Player && m.Map == Map).ForEach(m => m.Delete());
                MobileSpawns.Free(true);
            }

            if (ItemSpawns != null)
            {
                ItemSpawns.Where(m => m != null && !m.Deleted && m.Map == Map && m.Parent == null).ForEach(i => i.Delete());
                ItemSpawns.Free(true);
            }

            if (Map != null)
            {
                if (Map.InstanceRegions.All(z => z == null || z.Deleted))
                {
                    Map.Delete();
                }

                Map = null;
            }

            if (Logs != null)
            {
                Logs.Values.Free(true);
                Logs.Clear();
            }

            if (ActiveGroup != null)
            {
                ActiveGroup.Free(true);
            }

            if (Group != null)
            {
                Group.Free(true);
            }

            if (SubCommands != null)
            {
                SubCommands.Clear();
            }

            if (Options != null)
            {
                Options.Clear();
            }

            Deleted = true;

            OnAfterDelete();

            _Deleting = false;

            /*
             * Loot = null;
             * Zones = null;
             * MobileSpawns = null;
             * ItemSpawns = null;
             * Map = null;
             * Logs = null;
             * ActiveGroup = null;
             * Group = null;
             * SubCommands = null;
             * Options = null;
             */
        }
Example #23
0
        // View of standard toggles, with multipicker.
        static void DoToggleView(Rect middleRect)
        {
            List <Toggle> groupToggles = ToggleManager.Toggles.Where(x => x.Group.Equals(ActiveGroup)).ToList();
            float         middleY      = (groupToggles.Count() + 5) * 25f;
            var           middleView   = new Listing_Toggles();

            middleView.BeginListing(middleRect, ref scrollPositionMiddle, middleY);

            // Establishes references for checking if Option buttons are disabled further down.
            string optionsEntryButton = $"{ButtonCat.ButtonsEntry}_Options";
            string optionsPlayButton  = $"{ButtonCat.ButtonsPlay}_Options";
            bool   optionsEntryFlag   = ToggleManager.IsActive(optionsEntryButton);
            bool   optionsPlayFlag    = ToggleManager.IsActive(optionsPlayButton);

            // Draw multi picker.
            // Only show if any button has been clicked at start.
            if (!ActiveGroup.NullOrEmpty())
            {
                bool wasPartial = false;

                if (groupToggles.All(x => x.active))
                {
                    state = MultiCheckboxState.On;
                }
                else if (groupToggles.All(x => !x.active))
                {
                    state = MultiCheckboxState.Off;
                }
                else
                {
                    state      = MultiCheckboxState.Partial;
                    wasPartial = true;
                }

                state = middleView.MultiCheckBoxLabel(state, GetHotkeyFloatOptions(groupToggles), "Hotkey".Translate(), ActiveGroup.Translate(), $"{ActiveGroup}Desc".Translate());

                // If partial is clicked, it defaults to off. This workaround turns all on instead, by checking if it was partial before clicking.
                if (state == MultiCheckboxState.On || (wasPartial && state == MultiCheckboxState.Off))
                {
                    groupToggles.ForEach(x => x.active = true);
                }
                else if (state == MultiCheckboxState.Off)
                {
                    groupToggles.ForEach(x => x.active = false);
                }
            }

            middleView.GapLine();

            // Draw toggles in middle view depending on what button is active in left view.
            foreach (Toggle toggle in groupToggles.OrderBy(x => x.PrettyLabel))
            {
                middleView.CheckboxLabeled(toggle.PrettyLabel, toggle.PrettyHotkey, ref toggle.active, GetHotkeyFloatOptions(toggle));
            }

            // Opens confirmation window if user has deactivated the Options button.
            CheckOptionsActive(optionsEntryButton, optionsEntryFlag);
            CheckOptionsActive(optionsPlayButton, optionsPlayFlag);

            middleView.EndListing();
        }
Example #24
0
        public void UpdatePlayers()
        {
            Parallel.ForEach(ListPlayerConnection, (ActivePlayer, loopState) =>
            {
                if (!ActivePlayer.IsConnected())
                {
                    if (ActivePlayer.HasLeftServer())
                    {
                        ListPlayerToRemove.Add(new KeyValuePair <IOnlineConnection, string>(ActivePlayer, null));
                        Database.RemovePlayer(ActivePlayer);
                    }
                }
                else
                {
                    lock (ActivePlayer.ListAsyncOnlineScript)
                    {
                        foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                        {
                            ActiveScript.Execute(ActivePlayer);
                        }

                        ActivePlayer.ListAsyncOnlineScript.Clear();
                    }
                }
            });

            while (ListPlayerToRemove.Count > 0)
            {
                DicCommunicationGroup[ListPlayerToRemove[0].Value].ListGroupMember.Remove(ListPlayerToRemove[0].Key);
                DicPlayerInfoByName.Remove(ListPlayerToRemove[0].Key.ID);
                DicPlayerByID.Remove(ListPlayerToRemove[0].Key.ID);
                ListPlayerToRemove.RemoveAt(0);
            }

            Parallel.ForEach(DicCommunicationGroup.Values, (ActiveGroup, loopState) =>
            {
                if (ActiveGroup.IsRunningSlow())
                {
                    //Send Room to another Server
                }

                for (int P = ActiveGroup.ListGroupMember.Count - 1; P >= 0; --P)
                {
                    IOnlineConnection ActivePlayer = ActiveGroup.ListGroupMember[P];

                    if (!ActivePlayer.IsConnected())
                    {
                        if (ActivePlayer.HasLeftServer())
                        {
                            string PlayerID = ActiveGroup.ListGroupMember[P].ID;
                            ActiveGroup.RemoveOnlinePlayer(P);

                            if (ActiveGroup.ListGroupMember.Count == 0)
                            {
                                ListGroupToRemove.Add(ActiveGroup.GroupID);
                            }

                            ActivePlayer.StopReadingScriptAsync();
                        }
                    }
                }
            });

            while (ListGroupToRemove.Count > 0)
            {
                DicCommunicationGroup.Remove(ListGroupToRemove[0]);

                ListGroupToRemove.RemoveAt(0);
            }

            if (DateTimeOffset.Now > NextPlayerUpdateTime)
            {
                NextPlayerUpdateTime = NextPlayerUpdateTime.AddSeconds(10);

                SharedWriteBuffer.ClearWriteBuffer();
                SharedWriteBuffer.WriteScript(new PlayerListScriptServer(GetPlayerNames()));

                Parallel.ForEach(DicCommunicationGroup["Global"].ListGroupMember, (ActiveMember, loopState) =>
                {
                    ActiveMember.SendWriteBuffer();
                });
            }
        }
        /// <summary>
        /// Updates the Breadcrumb list and resets all the leaves (including the active one).
        /// </summary>
        /// <param name="group">The group to activate.</param>
        public void SetGroup(IKeePassGroup group)
        {
            // If this is an effective no-op, do nothing.
            if (group == ActiveGroup)
            {
                return;
            }

            int originalChildCount = 0;

            // Remove the children changed handler from the current group.
            if (ActiveGroup != null)
            {
                ((INotifyCollectionChanged)ActiveGroup.Children).CollectionChanged -= ChildrenChangedHandler;
                originalChildCount = ActiveGroup.Children.Count;
            }

            // Are we clearing everything?
            if (group == null)
            {
                this.breadcrumbs.Clear();
            }
            else
            {
                // Are we navigating upwards from the current tree?
                if (ActiveGroup != null && ActiveGroup.HasAncestor(group))
                {
                    int breadcrumbLastIndex = this.breadcrumbs.Count - 1;
                    // Pop off breadcrumbs until we're done
                    while (this.breadcrumbs[breadcrumbLastIndex].Group != group)
                    {
                        this.breadcrumbs.RemoveAt(breadcrumbLastIndex--);
                    }
                }
                // Are we navigating down a level to a new child of the current Group?
                else if (group.Parent != null && group.Parent.Equals(ActiveGroup))
                {
                    this.breadcrumbs.Add(new Breadcrumb(group));
                }
                // Something more catastrophic is happened, so just reset the list
                else
                {
                    this.breadcrumbs.Clear();

                    while (group != null)
                    {
                        this.breadcrumbs.Insert(0, new Breadcrumb(group, (group.Parent == null)));
                        group = group.Parent;
                    }
                }

                ((INotifyCollectionChanged)ActiveGroup.Children).CollectionChanged += ChildrenChangedHandler;
            }

            if (ActiveLeaf != null && group != ActiveLeaf.Parent)
            {
                // Remove the ActiveLeaf if we're changing the ActiveGroup
                ActiveLeaf = null;
            }

            OnPropertyChanged(nameof(ActiveGroup));

            if (originalChildCount != 0 || (ActiveGroup != null && ActiveGroup.Children.Count != 0))
            {
                RaiseLeavesChanged();
            }
        }