Пример #1
0
 public ConnectionController(IContainer c)
 {
     model      = c.Resolve <Model>();
     mserver    = c.Resolve <MulticastServerService>();
     peerFinder = c.Resolve <LANPeerFinderService>();
     setupLocalNetwork();
 }
Пример #2
0
        private bool IsNewServerNeeded()
        {
            if (null == peerFinder)
            {
                peerFinder = container.Resolve <LANPeerFinderService>();
            }

            List <DetectedNode> localOverlords =
                peerFinder.Peers.ToList().Where(p => (DateTime.Now - p.LastAnnounce).TotalSeconds < 60).ToList();


            int overlords            = localOverlords.Count;
            int serversWithFreeSlots = 0;
            int totalUsers           = 0;
            int totalSlots           = 0;

            foreach (DetectedNode overlord in localOverlords)
            {
                totalUsers += overlord.CurrentUsers;
                totalSlots += overlord.MaxUsers;
                if (overlord.MaxUsers - overlord.CurrentUsers > 5)
                {
                    serversWithFreeSlots++;
                }
            }

            //Rule 1: Atleast one server
            if (serversWithFreeSlots == 0)
            {
                return(true);
            }
            else
            {
                //Rule 2: Atleast 1 server per 200 people
                if (totalUsers > serversWithFreeSlots * 200)
                {
                    return(true);
                }
                else
                {
                    if (0 != totalUsers && 0 != totalSlots)
                    {
                        //Rule 3: Atleast 5% free slots
                        if (((double)totalUsers / totalSlots) > 0.95)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Пример #3
0
 public FAPServerHandler(IPAddress host, int port, Model m, MulticastClientService c, LANPeerFinderService p,
                         MulticastServerService ms)
 {
     multicastServer     = ms;
     logger              = LogManager.GetLogger("faplog");
     peerFinder          = p;
     serverNode          = new Overlord();
     serverNode.Nickname = "Overlord";
     serverNode.Host     = host.ToString();
     serverNode.Port     = port;
     serverNode.Online   = true;
     serverNode.ID       = IDService.CreateID();
     model              = m;
     m.PropertyChanged += m_PropertyChanged;
     serverNode.GenerateStrength(m.OverlordPriority);
     network         = new Entities.Network();
     multicastClient = c;
     multicastClient.OnMultiCastRX += multicastClient_OnMultiCastRX;
 }