Exemplo n.º 1
0
        public void BroadcastNhoodState(IDA da, MailHandler mail, DbNeighborhood nhood, DbElectionCycle cycle)
        {
            var all = Sessions.Clone();

            foreach (var session in all.OfType <IVoltronSession>())
            {
                if (session.IsAnonymous)
                {
                    continue;
                }

                var myLotID = da.Roommates.GetAvatarsLots(session.AvatarId).FirstOrDefault();
                var myLot   = (myLotID == null) ? null : da.Lots.Get(myLotID.lot_id);

                var free    = da.Elections.GetFreeVote(session.AvatarId);
                var nhoodID = (int)(myLot?.neighborhood_id ?? 0);
                if (free != null)
                {
                    nhoodID = free.neighborhood_id; //enrolled to a free vote. receive vote mail for that neighborhood
                }

                if (myLot != null && nhoodID == nhood.neighborhood_id)
                {
                    SendStateEmail(da, mail, nhood, cycle, session.AvatarId);
                }
            }
        }
Exemplo n.º 2
0
        public void ActivateEvents(IDA da, List <DbEvent> evts)
        {
            //ensure events that have not started

            int[] activeIDs;
            lock (ActiveEvents) {
                activeIDs = ActiveEvents.Select(x => x.event_id).ToArray();
            }
            bool changed = false;

            try
            {
                changed = da.Tuning.ClearInactiveTuning(activeIDs);
            }
            catch (Exception e)
            {
                LOG.Error(e, "Failed to clear inactive tuning!");
            }

            foreach (var evt in evts)
            {
                switch (evt.type)
                {
                case DbEventType.obj_tuning:
                    try
                    {
                        da.Tuning.ActivatePreset(evt.value, evt.event_id);
                    }
                    catch (Exception e)
                    {
                        LOG.Error(e, $"Failed to activate preset {evt.value}!");
                    }
                    changed = true;
                    break;
                }
            }

            if (changed)
            {
                TuningDomain.BroadcastTuningUpdate(true);
            }

            var all = Sessions.Clone();

            foreach (var session in all.OfType <IVoltronSession>())
            {
                foreach (var evt in evts)
                {
                    if (session.IsAnonymous)
                    {
                        continue;
                    }
                    UserJoinedEvent(session, evt, true);
                }
            }
        }
Exemplo n.º 3
0
        public void ActivateEvents(List <DbEvent> evts)
        {
            var all = Sessions.Clone();

            foreach (var session in all.OfType <IVoltronSession>())
            {
                foreach (var evt in evts)
                {
                    if (session.IsAnonymous)
                    {
                        continue;
                    }
                    UserJoinedEvent(session, evt, true);
                }
            }
        }
Exemplo n.º 4
0
        public void BroadcastNhoodState(IDA da, MailHandler mail, DbNeighborhood nhood, DbElectionCycle cycle)
        {
            var all = Sessions.Clone();

            foreach (var session in all.OfType <IVoltronSession>())
            {
                if (session.IsAnonymous)
                {
                    continue;
                }

                var myLotID = da.Roommates.GetAvatarsLots(session.AvatarId).FirstOrDefault();
                var myLot   = (myLotID == null) ? null : da.Lots.Get(myLotID.lot_id);

                if (myLot != null && myLot.neighborhood_id == nhood.neighborhood_id)
                {
                    SendStateEmail(da, mail, nhood, cycle, session.AvatarId);
                }
            }
        }
Exemplo n.º 5
0
        private void Run()
        {
            while (Alive)
            {
                //run background actions that should not be heavily parallelized.
                List <Action> actionCopy;
                lock (LivenessActions)
                {
                    actionCopy = new List <Action>(LivenessActions);
                    LivenessActions.Clear();
                }

                foreach (var action in actionCopy)
                {
                    action();
                }

                //check connections for inactivity
                //sending a packet to the recipient should close their connection if they are unreachable.

                var sessions = Sessions.Clone();
                var now      = Epoch.Now;
                foreach (var s in sessions)
                {
                    try
                    {
                        if ((now - s.LastRecv) > 60)
                        {
                            s.Write(new KeepAlive());
                            s.LastRecv = now;
                        }
                    }
                    catch { }
                }

                Events.TickEvents();

                OnChange.WaitOne(30000);
            }
        }