Esempio n. 1
0
        private Dictionary <int, Zone> BuildZones(INPCRepository npcRepository)
        {
            Dictionary <int, Zone> zones = new Dictionary <int, Zone>();

            for (int i = 0; i < 1; i++)
            {
                MapData mapData = MapData.LoadFromFile(i.ToString() + ".map");
                zones.Add(i, new Zone(i, m_npcRepository, m_npcFactory, mapData));
            }
            return(zones);
        }
Esempio n. 2
0
        public World(IAccountRepository accountRepository, INPCRepository npcRepository, IPlayerRepository playerRepository, IServerStatsRepository statsRepository, IAbilityRepository abilityRepository)
        {
            m_accountRepository = accountRepository;
            m_npcRepository     = npcRepository;
            m_playerRepository  = playerRepository;
            m_statsRepository   = statsRepository;
            m_abilityRepository = abilityRepository;

            m_npcFactory = new NPCFactory(npcRepository);

            m_zones = BuildZones(m_npcRepository);

            m_cpuCounter.CategoryName = "Processor";
            m_cpuCounter.CounterName  = "% Processor Time";
            m_cpuCounter.InstanceName = "_Total";

            m_fiber.Enqueue(Update, false);
            //m_fiber.Enqueue(StatsUpdate, false);
        }
Esempio n. 3
0
        public Zone(int zoneID, INPCRepository npcRepository, NPCFactory npcFactory, MapData mapData)
        {
            ID = zoneID;

            m_npcRepository = npcRepository;
            m_npcFactory    = npcFactory;

            m_mapData = mapData;

            m_npcSpawns = LoadZoneNPCSpawns();
            m_npcArray  = new NPCInstance[m_npcSpawns.Count];
            for (int i = 0; i < m_npcSpawns.Count; i++)
            {
                NPCInstance npcInstance = npcFactory.CreateNPC(m_fiber, m_npcSpawns[i], mapData);
                m_npcs.Add(npcInstance.ID, npcInstance);
                m_npcArray[i] = npcInstance;
            }

            m_playerArray = Enumerable.Empty <PlayerPeer>().ToArray();

            m_fiber.Enqueue(Update);
        }
Esempio n. 4
0
 public NPCFactory(INPCRepository npcRepository)
 {
     m_npcRepository = npcRepository;
     LoadBehaviourTypes();
 }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

            ServerConfiguration config = (ServerConfiguration)ConfigurationManager.GetSection("server");

            s_log.Info("Creating repositories...");
            UnityContainer repositoryResolver = new UnityContainer();

            repositoryResolver.LoadConfiguration();

            IAccountRepository     accountRepository = repositoryResolver.Resolve <IAccountRepository>();
            INPCRepository         npcRepository     = repositoryResolver.Resolve <INPCRepository>();
            IPlayerRepository      playerRepository  = repositoryResolver.Resolve <IPlayerRepository>();
            IAbilityRepository     abilityRepository = repositoryResolver.Resolve <IAbilityRepository>();
            IServerStatsRepository statsRepository   = new NullServerStatsRepository();

            try
            {
                statsRepository = repositoryResolver.Resolve <IServerStatsRepository>();
            }
            catch
            {
                s_log.Warn("Failed to create stats repository. Stats will be disabled.");
            }

            s_log.Info("Precaching NPCs...");
            var npcs = npcRepository.GetNPCs();

            s_log.Info("Precaching NPC Spawns...");
            npcRepository.GetNPCSpawns();

            s_log.Info("Precaching NPC Behaviours...");
            var npcBehaviours = npcRepository.GetNPCBehaviours();

            foreach (NPCModel npc in npcs)
            {
                npcRepository.GetNPCBehavioursByNPCID(npc.NPCID);
            }

            s_log.Info("Precaching NPC Behaviour Vars...");
            npcRepository.GetNPCBehaviourVars();
            foreach (NPCBehaviourModel npcBehaviour in npcBehaviours)
            {
                npcRepository.GetNPCBehaviourVarsByNPCBehaviourID(npcBehaviour.NPCBehaviourID);
            }

            s_log.Info("Precaching NPC Stats...");
            npcRepository.GetNPCStats();
            foreach (NPCModel npc in npcs)
            {
                npcRepository.GetNPCStatsByNPCID(npc.NPCID);
            }

            s_log.Info("Precaching abilities...");
            abilityRepository.GetAbilities();

            s_log.Info("Initialising serializer...");
            ProtocolUtility.InitialiseSerializer();

            s_log.Info("Creating world...");
            using (World world = new World(accountRepository, npcRepository, playerRepository, statsRepository, abilityRepository))
            {
                TcpListener listener = new TcpListener(IPAddress.Any, config.Port);
                listener.Start();
                s_log.Info("Listening for connections on " + listener.LocalEndpoint.ToString());

                while (true)
                {
                    Socket socket = listener.AcceptSocket();
                    world.AcceptSocket(socket);
                }
            }
        }