Exemplo n.º 1
0
 public DatabaseTicker(RealmManager manager)
 {
     Manager = manager;
     pendings = new ConcurrentQueue<Action<Database>>[5];
     for (int i = 0; i < 5; i++)
         pendings[i] = new ConcurrentQueue<Action<Database>>();
 }
Exemplo n.º 2
0
 public Client(RealmManager manager, Socket skt)
 {
     this.skt = skt;
     this.Manager = manager;
     ReceiveKey = new RC4(new byte[] { 0x31, 0x1f, 0x80, 0x69, 0x14, 0x51, 0xc7, 0x1b, 0x09, 0xa1, 0x3a, 0x2a, 0x6e });
     SendKey = new RC4(new byte[] { 0x72, 0xc5, 0x58, 0x3c, 0xaf, 0xb6, 0x81, 0x89, 0x95, 0xcb, 0xd7, 0x4b, 0x80 });
 }
Exemplo n.º 3
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat,
     Random rand, IList<LootDef> lootDefs)
 {
     if (playerDat != null) return;
     XmlData dat = manager.GameData;
     lootDefs.Add(new LootDef(dat.Items[dat.IdToObjectType[item]], probability));
 }
Exemplo n.º 4
0
 public AutoSave(RealmManager manager)
 {
     Manager = manager;
     pendings = new ConcurrentQueue<Action<RealmTime>>[5];
     for (var i = 0; i < 5; i++)
         pendings[i] = new ConcurrentQueue<Action<RealmTime>>();
 }
Exemplo n.º 5
0
        public BehaviorDb(RealmManager manager)
        {
            log.Info("Initializing Behavior Database...");

            Manager = manager;

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

            if (Interlocked.Exchange(ref initializing, 1) == 1)
            {
                log.Error("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];
                log.InfoFormat("Loading behavior for '{0}'({1}/{2})...", field.Name, i + 1, fields.Length);
                ((_) field.GetValue(this))();
                field.SetValue(this, null);
            }

            InitDb = null;
            initializing = 0;

            log.Info("Behavior Database initialized...");
        }
Exemplo n.º 6
0
 public LogicTicker(RealmManager manager)
 {
     this.Manager = manager;
     pendings = new ConcurrentQueue<Action<RealmTime>>[5];
     for (int i = 0; i < 5; i++)
         pendings[i] = new ConcurrentQueue<Action<RealmTime>>();
 }
Exemplo n.º 7
0
 public Client(RealmManager manager, Socket skt)
 {
     Socket = skt;
     Manager = manager;
     ReceiveKey =
         new RC4(new byte[] {0x31, 0x1f, 0x80, 0x69, 0x14, 0x51, 0xc7, 0x1d, 0x09, 0xa1, 0x3a, 0x2a, 0x6e});
     SendKey = new RC4(new byte[] {0x72, 0xc5, 0x58, 0x3c, 0xaf, 0xb6, 0x81, 0x89, 0x95, 0xcd, 0xd7, 0x4b, 0x80});
     BeginProcess();
 }
        public LogicTicker(RealmManager manager)
        {
            Manager = manager;
            pendings = new ConcurrentQueue<Action<RealmTime>>[5];
            for (int i = 0; i < 5; i++)
                pendings[i] = new ConcurrentQueue<Action<RealmTime>>();

            TPS = manager.TPS;
            MsPT = 1000 / TPS;
        }
Exemplo n.º 9
0
 public RealmPortalMonitor(RealmManager manager)
 {
     this.nexus = manager.Worlds[World.NEXUS_ID] as Nexus;
     lock (worldLock)
         foreach (var i in manager.Worlds)
         {
             if (i.Value is GameWorld)
                 WorldAdded(i.Value);
         }
 }
 public RealmPortalMonitor(RealmManager manager)
 {
     log.Info("Initalizing Portal Monitor...");
     this.manager = manager;
     nexus = manager.Worlds[World.NEXUS_ID] as Nexus;
     lock (worldLock)
         foreach (var i in manager.Worlds)
         {
             if (i.Value is GameWorld)
                 WorldAdded(i.Value);
         }
     log.Info("Portal Monitor initialized.");
 }
Exemplo n.º 11
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat,
     Random rand, string lootState, IList<LootDef> lootDefs)
 {
     Lootstate = lootState;
     if (playerDat != null) return;
     Item[] candidates = manager.GameData.Items
         .Where(item => item.Value.SlotType == 26)
         .Where(item => item.Value.Tier == (int)rarity)
         .Select(item => item.Value)
         .ToArray();
     foreach (Item i in candidates)
         lootDefs.Add(new LootDef(i, probability / candidates.Length, lootState));
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.Name = "Entry";

            using (Settings = new SimpleSettings("wServer"))
            {
                var db = new Database(Settings.GetValue("conn"));
                RealmManager manager = new RealmManager(
                    Settings.GetValue<int>("maxClient", "100"),
                    Settings.GetValue<int>("tps", "20"),
                    db);

                manager.Initialize();
                manager.Run();

                Server server = new Server(manager, 2050);
                PolicyServer policy = new PolicyServer();

                Console.CancelKeyPress += (sender, e) => e.Cancel = true;

                policy.Start();
                server.Start();
                log.Info("Server initialized.");

                while (Console.ReadKey(true).Key != ConsoleKey.Escape) ;

                log.Info("Terminating...");
                server.Stop();
                policy.Stop();
                manager.Stop();
                db.Dispose();
                log.Info("Server terminated.");
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.Name = "Server Entry Point";

            RealmManager manager = new RealmManager();
            manager.Initialize();

            Server server = new Server(manager, 2050);
            PolicyServer policy = new PolicyServer();

            Console.CancelKeyPress += (sender, e) =>
            {
                Console.WriteLine("Terminating...");
                server.Stop();
                policy.Stop();
                Environment.Exit(0);
            };

            policy.Start();
            server.Start();
            Console.WriteLine("Listening at port 2050...");
            Thread.CurrentThread.Join();
        }
Exemplo n.º 14
0
        /*
         * ArenaGuard,
         * ArenaPortal,
         * CaveWall,
         * Character,
         * CharacterChanger,
         * ClosedGiftChest,
         * ClosedVaultChest,
         * ConnectedWall,
         * Container,
         * DoubleWall,
         * GameObject,
         * GuildBoard,
         * GuildChronicle,
         * GuildHallPortal,
         * GuildMerchant,
         * GuildRegister,
         * Merchant,
         * MoneyChanger,
         * MysteryBoxGround,
         * NameChanger,
         * ReskinVendor,
         * OneWayContainer,
         * Player,
         * Portal,
         * Projectile,
         * Sign,
         * SpiderWeb,
         * Stalagmite,
         * Wall,
         * Pet,
         * PetUpgrader,
         * YardUpgrader
         */

        public static Entity Resolve(RealmManager manager, string name)
        {
            ushort id;

            return(!manager.GameData.IdToObjectType.TryGetValue(name, out id) ? null : Resolve(manager, id));
        }
Exemplo n.º 15
0
        public static Entity Resolve(RealmManager manager, ushort id)
        {
            var node = manager.GameData.ObjectTypeToElement[id];
            var cls  = node.Element("Class");

            if (cls == null)
            {
                throw new ArgumentException("Invalid XML Element, field class is missing");
            }
            var type = cls.Value;

            switch (type)
            {
            case "Projectile":
                throw new Exception("Projectile should not instantiated using Entity.Resolve");

            case "Sign":
                return(new Sign(manager, id));

            case "Wall":
            case "DoubleWall":
                return(new Wall(manager, id, node));

            case "ConnectedWall":
            case "CaveWall":
                return(new ConnectedObject(manager, id));

            case "GameObject":
            case "CharacterChanger":
            case "MoneyChanger":
            case "NameChanger":
                return(new StaticObject(manager, id, StaticObject.GetHP(node), StaticObject.GetStatic(node), false, true));

            case "GuildRegister":
            case "GuildChronicle":
            case "GuildBoard":
                return(new StaticObject(manager, id, null, false, false, false));

            case "Container":
                return(new Container(manager, node));

            case "Player":
                throw new Exception("Player should not instantiated using Entity.Resolve");

            case "Character":     //Other characters means enemy
                return(new Enemy(manager, id));

            case "Portal":
            case "GuildHallPortal":
                return(new Portal(manager, id, null));

            case "ClosedVaultChest":
            case "ClosedVaultChestGold":
            case "ClosedGiftChest":
            case "VaultChest":
            case "Merchant":
                return(new Merchants(manager, id));

            case "GuildMerchant":
                return(new GuildMerchant(manager, id));

            case "ArenaGuard":
            case "ArenaPortal":
            case "MysteryBoxGround":
            case "ReskinVendor":
            case "PetUpgrader":
            case "FortuneTeller":
            case "YardUpgrader":
            case "FortuneGround":
            case "QuestRewards":
                return(new StaticObject(manager, id, null, true, false, false));

            case "Pet":
                throw new Exception("Pets should not instantiated using Entity.Resolve");

            default:
                Log.Warn("Not supported type: " + type);
                return(new Entity(manager, id));
            }
        }
Exemplo n.º 16
0
        private Player playerOwner; //For Drakes

        public Entity(RealmManager manager, ushort objType)
            : this(manager, objType, true, false)
        {
        }
Exemplo n.º 17
0
 public Entity(RealmManager manager, ushort objType, bool interactive)
     : this(manager, objType, interactive, false)
 {
 }
Exemplo n.º 18
0
 public ChatManager(RealmManager manager)
 {
     this.manager = manager;
 }
Exemplo n.º 19
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat,
     Random rand, IList<LootDef> lootDefs)
 {
     if (playerDat != null && playerDat.Item2/(double) enemy.ObjectDesc.MaxHP >= threshold)
     {
         foreach (ILootDef i in children)
             i.Populate(manager, enemy, null, rand, lootDefs);
     }
 }
Exemplo n.º 20
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat, Random rand, string lootState, IList<LootDef> lootDefs)
 {
     foreach (ILootDef i in children)
         i.Populate(manager, enemy, playerDat, rand, Lootstate, lootDefs);
 }
Exemplo n.º 21
0
        public static Entity Resolve(RealmManager manager, ushort id)
        {
            XElement node = manager.GameData.ObjectTypeToElement[id];
            string   type = node.Element("Class").Value;

            switch (type)
            {
            case "Projectile":
                throw new Exception("Projectile should not instantiated using Entity.Resolve");

            case "Sign":
                return(new Sign(manager, id));

            case "Wall":
            case "DoubleWall":
                return(new Wall(manager, id, node));

            case "ConnectedWall":
            case "CaveWall":
                return(new ConnectedObject(manager, id));

            case "GameObject":
            case "CharacterChanger":
            case "MoneyChanger":
            case "NameChanger":
            case "Stalagmite":
                return(new StaticObject(manager, id, StaticObject.GetHP(node), true, false, true));

            case "MarketplaceGround":
            case "GuildRegister":
            case "GuildChronicle":
            case "GuildBoard":
            case "SpiderWeb":
            case "InteractNPC":
                return(new StaticObject(manager, id, null, false, false, false));

            case "Container":
                return(new Container(manager, id));

            case "Reforge":
            case "Forge":
                return(new Container(manager, id, true));

            case "Player":
                throw new Exception("Player should not instantiated using Entity.Resolve");

            case "Character":     //Other characters means enemy
                return(new Enemy(manager, id));

            case "Portal":
                return(new Portal(manager, id, null));

            case "ClosedVaultChest":
            case "Merchant":
                return(new Merchants(manager, id));

            case "GuildHallPortal":
                return(new StaticObject(manager, id, null, false, false, false));

            case "GuildMerchant":
                return(new GuildMerchant(manager, id));

            //case "InteractNPC":
            //return new InteractNPC(manager, id);
            default:
                log.WarnFormat("Not supported type: {0}", type);
                return(new Entity(manager, id));
            }
        }
Exemplo n.º 22
0
 public DatabaseTicker(RealmManager manager)
 {
     Manager     = manager;
     m_databases = new List <KeyValuePair <Database, bool> >();
 }
Exemplo n.º 23
0
 public NetworkTicker(RealmManager manager)
 {
     Manager = manager;
 }
Exemplo n.º 24
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat,
     Random rand, IList<LootDef> lootDefs)
 {
     if (playerDat == null)
         return;
     for (int i = 0; i < 3; i++ )
         playerDat.Item1.Owner.BroadcastPacket(new ShowEffectPacket()
         {
             EffectType = EffectType.Flow,
             Color = new ARGB(0xFF9999FF),
             TargetId = playerDat.Item1.Id,
             PosA = new Position() { X = enemy.X, Y = enemy.Y }
         }, null);
     manager.Data.AddPendingAction(db =>
     {
         playerDat.Item1.Souls =
             playerDat.Item1.Client.Account.Souls =
                 db.UpdateSouls(playerDat.Item1.Client.Account,
                     rand.Next(minSouls, maxSouls + 1));
     });
     playerDat.Item1.UpdateCount++;
 }
Exemplo n.º 25
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat, Random rand, string lootState, IList<LootDef> lootDefs)
 {
     loots[rand.Next(0, loots.Length)].Populate(manager, enemy, playerDat, rand, lootState, lootDefs);
 }
Exemplo n.º 26
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat,
     Random rand, IList<LootDef> lootDefs)
 {
     if (playerDat != null) return;
     Item[] candidates = manager.GameData.Items
         .Where(item => Array.IndexOf(types, item.Value.SlotType) != -1)
         .Where(item => item.Value.Tier == tier)
         .Select(item => item.Value)
         .ToArray();
     foreach (Item i in candidates)
         lootDefs.Add(new LootDef(i, probability/candidates.Length));
 }
Exemplo n.º 27
0
 public NetworkTicker(RealmManager manager)
 {
     this.Manager = manager;
 }
Exemplo n.º 28
0
 public IEnumerable<Entity> InstantiateEntities(RealmManager manager)
 {
     foreach (var i in entities)
     {
         var entity = Entity.Resolve(i.Item2);
         entity.Move(i.Item1.X + 0.5f, i.Item1.Y + 0.5f);
         if (i.Item3 != null)
             foreach (var item in i.Item3.Split(';'))
             {
                 var kv = item.Split(':');
                 switch (kv[0])
                 {
                     case "name":
                         entity.Name = kv[1];
                         break;
                     case "size":
                         entity.Size = Utils.FromString(kv[1]);
                         break;
                     case "eff":
                         entity.ConditionEffects = (ConditionEffects)Utils.FromString(kv[1]);
                         break;
                     case "conn":
                         (entity as ConnectedObject).Connection =
                             ConnectionInfo.Infos[(uint)Utils.FromString(kv[1])];
                         break;
                     case "mtype":
                         (entity as Merchants).custom = true;
                         (entity as Merchants).mType = Utils.FromString(kv[1]);
                         break;
                     //case "mcount":
                     //    entity.Stats[StatsType.MerchantRemainingCount] = Utils.FromString(kv[1]); break;    NOT NEEDED FOR NOW
                     //case "mtime":
                     //    entity.Stats[StatsType.MerchantRemainingMinute] = Utils.FromString(kv[1]); break;
                     case "mcost":
                         (entity as SellableObject).Price = Utils.FromString(kv[1]);
                         break;
                     case "mcur":
                         (entity as SellableObject).Currency = (CurrencyType)Utils.FromString(kv[1]);
                         break;
                     case "stars":
                         (entity as SellableObject).RankReq = Utils.FromString(kv[1]);
                         break;
                         //case "nstar":
                         //    entity.Stats[StatsType.NameChangerStar] = Utils.FromString(kv[1]); break;
                 }
             }
         yield return entity;
     }
 }
Exemplo n.º 29
0
 public ChatManager(RealmManager manager)
 {
     this.manager = manager;
 }
 public DatabaseTicker(RealmManager manager)
 {
     Manager = manager;
 }
Exemplo n.º 31
0
 public DbServerManager(RealmManager manager)
 {
     this.manager = manager;
     manager.InterServer.AddHandler <Message>(Channel.Control, HandleControl);
 }
Exemplo n.º 32
0
        public static Entity Resolve(RealmManager manager, ushort id)
        {
            var    node = manager.Resources.GameData.ObjectTypeToElement[id];
            string type = node.Element("Class").Value;

            switch (type)
            {
            case "Projectile":
                throw new Exception("Projectile should not instantiated using Entity.Resolve");

            case "Sign":
                return(new Sign(manager, id));

            case "Wall":
            case "DoubleWall":
                return(new Wall(manager, id, node));

            case "ConnectedWall":
            case "CaveWall":
                return(new ConnectedObject(manager, id));

            case "GameObject":
            case "CharacterChanger":
            case "MoneyChanger":
            case "NameChanger":
                return(new StaticObject(manager, id, StaticObject.GetHP(node), true, false, true));

            case "GuildRegister":
            case "GuildChronicle":
            case "GuildBoard":
                return(new StaticObject(manager, id, null, false, false, false));

            case "Container":
                return(new Container(manager, id));

            case "Player":
                throw new Exception("Player should not instantiated using Entity.Resolve");

            case "Character":       //Other characters means enemy
                return(new Enemy(manager, id));

            case "ArenaPortal":
            case "Portal":
                return(new Portal(manager, id, null));

            case "GuildHallPortal":
                return(new GuildHallPortal(manager, id, null));

            case "ClosedVaultChest":
                return(new ClosedVaultChest(manager, id));

            case "ClosedVaultChestGold":
            case "ClosedGiftChest":
            case "VaultChest":
            case "Merchant":
                return(new WorldMerchant(manager, id));

            case "GuildMerchant":
                return(new GuildMerchant(manager, id));

            default:
                Log.Warn("Not supported type: {0}", type);
                return(new Entity(manager, id));
            }
        }
Exemplo n.º 33
0
 public Server(RealmManager manager, int port)
 {
     Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     Manager = manager;
 }
Exemplo n.º 34
0
 public void Populate(RealmManager manager, Enemy enemy, Tuple<Player, int> playerDat, Random rand, string lootState, IList<LootDef> lootDefs)
 {
     var data = enemy.DamageCounter.GetPlayerData();
     var mostDamage = GetMostDamage(data);
     foreach (var loot in mostDamage.Where(pl => pl.Equals(playerDat)).SelectMany(pl => loots))
         loot.Populate(manager, enemy, null, rand, lootState, lootDefs);
 }
Exemplo n.º 35
0
 public ChatManager(RealmManager manager)
 {
     this.manager = manager;
     manager.InterServer.AddHandler <Message>(ISManager.CHAT, HandleChat);
 }
Exemplo n.º 36
0
        private static void Main(string[] args)
        {
            Console.Title = "Fabiano Swagger of Doom - World Server";
            try
            {
                XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_wServer.config"));

                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
                Thread.CurrentThread.Name = "Entry";

                Settings = new SimpleSettings("wServer");
                new Database(
                    Settings.GetValue<string>("db_host", "127.0.0.1"),
                    Settings.GetValue<string>("db_database", "rotmgprod"),
                    Settings.GetValue<string>("db_user", "root"),
                    Settings.GetValue<string>("db_auth", ""));

                manager = new RealmManager(
                    Settings.GetValue<int>("maxClients", "100"),
                    Settings.GetValue<int>("tps", "20"));

                WhiteList = Settings.GetValue<bool>("whiteList", "false");
                Verify = Settings.GetValue<bool>("verifyEmail", "false");
                WhiteListTurnOff = Settings.GetValue<DateTime>("whitelistTurnOff");

                manager.Initialize();
                manager.Run();

                Server server = new Server(manager);
                PolicyServer policy = new PolicyServer();

                Console.CancelKeyPress += (sender, e) => e.Cancel = true;

                policy.Start();
                server.Start();
                if(Settings.GetValue<bool>("broadcastNews", "false") && File.Exists("news.txt"))
                    new Thread(autoBroadcastNews).Start();
                log.Info("Server initialized.");

                uint key = 0;
                while ((key = (uint)Console.ReadKey(true).Key) != (uint)ConsoleKey.Escape)
                {
                    if (key == (2 | 80))
                        Settings.Reload();
                }

                log.Info("Terminating...");
                server.Stop();
                policy.Stop();
                manager.Stop();
                log.Info("Server terminated.");
            }
            catch (Exception e)
            {
                log.Fatal(e);

                foreach (var c in manager.Clients)
                {
                    c.Value.Disconnect();
                }
                Console.ReadLine();
            }
        }