Exemplo n.º 1
0
        void Core_SecondTimer()
        {
            // send status upates once per second so we're not sending multiple updates to the same client more than
            // once per second

            foreach (ulong key in StatusUpdate.Keys)
            {
                foreach (RudpSession session in Network.RudpControl.GetActiveSessions(key))
                {
                    SendStatus(session);
                }
            }

            StatusUpdate.Clear();


            // publish room location for public rooms hourly
            RoomMap.LockReading(delegate()
            {
                foreach (ChatRoom room in RoomMap.Values)
                {
                    if (room.Active && room.PublishRoom && Core.TimeNow > room.NextPublish)
                    {
                        TempLocation.Publish(room.RoomID, Core.Locations.LocalClient.Data.EncodeLight(Network.Protocol));
                        room.NextPublish = Core.TimeNow.AddHours(1);
                    }
                }
            });


            // for sim test write random msg ever 10 secs
            if (Core.Sim != null && SimTextActive && Core.RndGen.Next(10) == 0)
            {
                List <ChatRoom> rooms = new List <ChatRoom>();
                RoomMap.LockReading(delegate()
                {
                    foreach (ChatRoom room in RoomMap.Values)
                    {
                        if (room.Active)
                        {
                            rooms.Add(room);
                        }
                    }
                });

                if (rooms.Count > 0)
                {
                    SendMessage(rooms[Core.RndGen.Next(rooms.Count)], Core.TextGen.GenerateSentences(1, Sentence.Short)[0], TextFormat.Plain);
                }
            }
        }
Exemplo n.º 2
0
        void Core_SecondTimer()
        {
            if (RunSave)
            {
                SaveHeaders();
                RunSave = false;
            }

            // interface has its own timer that updates automatically
            // done because transfers isnt multi-threaded

            Local.Files.LockReading(() =>
            {
                foreach (SharedFile file in Local.Files)
                {
                    if (file.Hash == null) // still processing
                    {
                        continue;
                    }

                    file.TransferStatus = "";

                    if (Core.Transfers.Pending.Any(t => t.FileID == file.FileID))
                    {
                        file.TransferStatus = "Download Pending";
                    }

                    bool active = false;

                    OpTransfer transfer;
                    if (Core.Transfers.Transfers.TryGetValue(file.FileID, out transfer))
                    {
                        if (transfer.Searching)
                        {
                            file.TransferStatus = "Searching..."; // allow to be re-assigned
                        }
                        if (transfer.Status != TransferStatus.Complete)
                        {
                            long progress = transfer.GetProgress() * 100 / transfer.Details.Size;

                            file.TransferStatus = "Downloading " + progress + "% at " + Utilities.ByteSizetoString((long)transfer.Bandwidth.InAvg()) + "/s";

                            if (progress > 0)
                            {
                                active = true;
                            }
                        }

                        else if (transfer.Verifying)
                        {
                            file.TransferStatus = "Verifying...";
                        }

                        else if (Core.Transfers.UploadPeers.Values.Where(u => u.Active != null && u.Active.Transfer.FileID == file.FileID).Count() > 0)
                        {
                            file.TransferStatus = "Uploading at " + Utilities.ByteSizetoString((long)transfer.Bandwidth.OutAvg()) + "/s";
                            active = true;
                        }
                    }

                    file.TransferActive = active;

                    if (active && Core.TimeNow > file.NextPublish)
                    {
                        TempLocation.Publish(file.FileID, Core.Locations.LocalClient.Data.EncodeLight(Network.Protocol));
                        file.NextPublish = Core.TimeNow.AddHours(1);
                    }
                }
            });
        }