Exemplo n.º 1
0
        /// <summary>
        /// This method should be called in a thread.
        /// It runs over the old messages and sends them once the subspace time matches the message send time.
        /// </summary>
        public static void RelayOldVesselMessages()
        {
            while (ServerContext.ServerRunning)
            {
                foreach (var keyVal in OldVesselMessages.Where(m => !m.Value.IsEmpty))
                {
                    var subspaceTime = WarpSystem.GetCurrentSubspaceTime(keyVal.Key);

                    while (keyVal.Value.TryPeek(out var msg) && subspaceTime >= msg.SentTime)
                    {
                        keyVal.Value.TryDequeue(out msg);
                        MessageQueuer.SendMessageToSubspace <VesselSrvMsg>(msg, keyVal.Key);
                    }
                }

                Thread.Sleep(GeneralSettings.SettingsStore.SendReceiveThreadTickMs);
            }
        }
        /// <summary>
        /// This method should be called in a thread.
        /// It runs over the old messages and sends them once the subspace time matches the message send time.
        /// </summary>
        public static async void RelayOldVesselMessages()
        {
            while (ServerContext.ServerRunning)
            {
                var messagesByGroup = DbCollection.FindAll().GroupBy(m => m.SubspaceId);
                foreach (var subspace in messagesByGroup)
                {
                    var subspaceTime = WarpSystem.GetCurrentSubspaceTime(subspace.Key);
                    var msgToSend    = subspace.Where(m => subspaceTime >= m.Msg.SentTime).ToList();
                    msgToSend.ForEach(m =>
                    {
                        MessageQueuer.SendMessageToSubspace <VesselSrvMsg>(m.Msg, m.SubspaceId);
                        DbCollection.Delete(m.Id);
                    });
                }

                DataBase.Shrink();
                await Task.Delay(IntervalSettings.SettingsStore.SendReceiveThreadTickMs);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method should be called in a thread.
        /// It runs over the old messages and sends them once the subspace time matches the message send time.
        /// </summary>
        public static async void RelayOldVesselMessages()
        {
            while (ServerContext.ServerRunning)
            {
                foreach (var subspaceVessels in OldSubspaceVesselMessages.Where(m => !m.Value.IsEmpty))
                {
                    var subspaceTime = WarpSystem.GetCurrentSubspaceTime(subspaceVessels.Key);

                    foreach (var queue in subspaceVessels.Value)
                    {
                        while (queue.Value.TryPeek(out var relayItem) && subspaceTime >= relayItem.Msg.SentTime)
                        {
                            queue.Value.TryDequeue(out relayItem);
                            MessageQueuer.SendMessageToSubspace <VesselSrvMsg>(relayItem?.Msg, subspaceVessels.Key);
                        }
                    }
                }

                await Task.Delay(GeneralSettings.SettingsStore.SendReceiveThreadTickMs);
            }
        }