Ejemplo n.º 1
0
        public void Stop()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Stopping Realm Manager...");
            }
            Terminating = true;
            var saveAccountUnlock = new List <Client>();

            foreach (var c in Clients.Values)
            {
                saveAccountUnlock.Add(c);
                c.Disconnect(Client.DisconnectReason.STOPPING_SERVER);
            }
            //To prevent a buggy Account in use.
            using (var db = new Database())
            {
                foreach (var c in saveAccountUnlock)
                {
                    db.UnlockAccount(c.Account);
                }
            }
            GameData.Dispose();
            logic.Join();
            network.Join();
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Realm Manager stopped.");
            }
        }
Ejemplo n.º 2
0
 public void Run()
 {
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Starting Realm Manager...");
     }
     Network  = new NetworkTicker(this);
     Logic    = new LogicTicker(this);
     Database = new DatabaseTicker();
     network  = new Thread(Network.TickLoop)
     {
         Name           = "Network",
         CurrentCulture = CultureInfo.InvariantCulture
     };
     logic = new Thread(Logic.TickLoop)
     {
         Name           = "Logic",
         CurrentCulture = CultureInfo.InvariantCulture
     };
     //Start logic loop first
     logic.Start();
     network.Start();
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Realm Manager started.");
     }
 }
Ejemplo n.º 3
0
 private void OnWorldRemoved(World world)
 {
     world.Manager = null;
     if (world is GameWorld)
     {
         Monitor.WorldRemoved(world);
     }
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("World {0}({1}) removed.", world.Id, world.Name);
     }
 }
Ejemplo n.º 4
0
 private void OnWorldAdded(World world)
 {
     if (world.Manager == null)
     {
         world.Manager = this;
     }
     if (world is GameWorld)
     {
         Monitor.WorldAdded(world);
         CurrentWorldId = world.Id;
     }
     if (world is CourtOfBereavement)
     {
         CurrentCourtId = world.Id;
     }
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("World {0}({1}) added.", world.Id, world.Name);
     }
 }
Ejemplo n.º 5
0
        public BehaviorDb(RealmManager manager)
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Initializing Behavior Database...");
            }

            Manager = manager;

            Definitions = new Dictionary <ushort, Tuple <State, Loot> >();

            if (Interlocked.Exchange(ref initializing, 1) == 1)
            {
                Console.WriteLine("Attempted to initialize multiple BehaviorDb at the same time.");
                throw new InvalidOperationException("Attempted to initialize multiple BehaviorDb at the same time.");
            }
            InitDb = this;

            FieldInfo[] fields = GetType()
                                 .GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
                                 .Where(field => field.FieldType == typeof(_))
                                 .ToArray();
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo field = fields[i];
                if (CheckConfig.IsDebugOn())
                {
                    Console.WriteLine("Loading behavior for '{0}'({1}/{2})...", field.Name, i + 1, fields.Length);
                }
                ((_)field.GetValue(this))();
                field.SetValue(this, null);
            }

            InitDb       = null;
            initializing = 0;

            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Behavior Database initialized...");
            }
        }
Ejemplo n.º 6
0
 public void Initialize()
 {
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Initializing Realm Manager...");
     }
     GameData  = new XmlData();
     Behaviors = new BehaviorDb(this);
     GeneratorCache.Init();
     MerchantLists.InitMerchatLists(GameData);
     AddWorld(World.NEXUS_ID, Worlds[0] = new Nexus());
     AddWorld(World.MARKET, new ClothBazaar());
     AddWorld(World.TUT_ID, new Tutorial(true));
     AddWorld(World.FMARKET, new Market());
     Monitor = new RealmPortalMonitor(this);
     Task.Factory.StartNew(() => GameWorld.AutoName(1, true))
     .ContinueWith(_ => AddWorld(_.Result), TaskScheduler.Default);
     Chat     = new ChatManager(this);
     Commands = new CommandManager(this);
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Realm Manager initialized.");
     }
 }