示例#1
0
        /// <summary>
        /// Loads user's inventory List
        /// </summary>
        /// <returns></returns>
        internal bool LoadInventory()
        {
            this.Inventory = new Dictionary <uint, Item>();

            Database db = new Database(Server.UserDbConString);

            MySqlDataReader reader =
                db.ReaderQuery(
                    "SELECT `id`, `code`, `count`, `equip` " +
                    "FROM `item` " +
                    "WHERE `char_id` = @charId",
                    new string[] { "charId" },
                    new object[] { this.CharId }
                    );

            while (reader.Read())
            {
                Item i = GObjectManager.GetNewItem();
                i.UId      = (long)reader["id"];
                i.Code     = (int)reader["code"];
                i.Count    = (long)reader["count"];
                i.WearInfo = (Item.WearType)(int) reader["equip"];

                if (i.WearInfo != Item.WearType.None)
                {
                    this.Equip[(int)i.WearInfo] = i.Handle;
                }

                this.Inventory.Add(i.Handle, i);
            }

            return(true);
        }
示例#2
0
        public static void Init()
        {
            ConsoleUtils.Write(ConsoleMsgType.Status, "Loading NPC Database...\n");

            Database        db     = new Database(Server.GameDbConString);
            MySqlDataReader reader =
                db.ReaderQuery(
                    "SELECT `id`, `x`, `y`, `face`, `script` " +
                    "FROM `npc_db`", null, null
                    );

            while (reader.Read())
            {
                Npc npc = GObjectManager.GetNewNpc();

                npc.Id            = (int)reader["id"];
                npc.Position      = new Point((int)reader["x"], (int)reader["y"]);
                npc.Face          = (sbyte)reader["face"];
                npc.ContactScript = (string)reader["script"];

                RegionMngr.AddNpcToRegion(npc);
            }

            ConsoleUtils.Write(ConsoleMsgType.Status, "NPC Database Loaded.\n");
        }
示例#3
0
        public static void SpawnMonster(int mobId, Point position)
        {
            Monster mob = GObjectManager.GetNewMob();

            mob.Id       = mobId;
            mob.MaxHp    = MonsterDb.DB[mobId].Hp;
            mob.MaxMp    = MonsterDb.DB[mobId].Mp;
            mob.Hp       = mob.MaxHp;
            mob.Mp       = mob.MaxMp;
            mob.Position = position;

            RegionMngr.AddMobToRegion(mob);
        }
示例#4
0
        private void AcceptCallback(IAsyncResult ar)
        {
            allDone.Set();

            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);

            Player p = GObjectManager.GetNewPlayer();

            p.NetData.ClSocket = handler;
            p.NetData.Encoder  = new XRC4Cipher(Globals.RC4Key);
            p.NetData.Decoder  = new XRC4Cipher(Globals.RC4Key);
            p.NetData.Buffer   = new byte[Globals.MaxBuffer];
            p.NetData.Data     = new PacketStream();

            handler.BeginReceive(p.NetData.Buffer, 0, Globals.MaxBuffer, 0,
                                 new AsyncCallback(ReadCallback), p);
        }
示例#5
0
        private void Start()
        {
            GameDbConString = "Server=" + Settings.GameSqlIp + "; Database=" + Settings.GameSqlDatabase + "; Uid=" + Settings.GameSqlUsername + "; Pwd=" + Settings.GameSqlPassword + ";";
            UserDbConString = "Server=" + Settings.UserSqlIp + "; Database=" + Settings.UserSqlDatabase + "; Uid=" + Settings.UserSqlUsername + "; Pwd=" + Settings.UserSqlPassword + ";";

            // TODO : Put this in settings

            /* Urls
             * guild.url : http://guild.gamepower7.com/client/guild/login.aspx
             * guild_test_download.url : upload/client/guild/
             * web_download : guild.gamepower7.com
             * web_download_port : 0
             * shop.url : http://khroos.gamepower7.com/khroos/
             * ghelp_url : http://help.gamepower7.com/help/help-page/help-page.html
             * guild_icon_upload.ip : 95.211.112.10
             * guild_icon_upload.port : 4617
             * guild_icon_upload.url : http://guild.gamepower7.com/client/guild//iconupload.aspx
             */
            string[] urls = new string[]
            {
                "guild.url", "http://guild.gamepower7.com/client/guild/login.aspx",
                "guild_test_download.url", "upload/client/guild/",
                "web_download", "guild.gamepower7.com",
                "web_download_port", "0",
                "shop.url", "http://khroos.gamepower7.com/khroos/",
                "ghelp_url", "http://help.gamepower7.com/help/help-page/help-page.html",
                "guild_icon_upload.ip", "95.211.112.10",
                "guild_icon_upload.port", "4617",
                "guild_icon_upload.url", "http://guild.gamepower7.com/client/guild//iconupload.aspx"
            };
            UrlList = String.Join("|", urls);

            /* ************************* *
            * Test database connection
            * ************************* */
            ConsoleUtils.Write(ConsoleMsgType.Status, "Testing MySQL Connections...\n");
            Database db = new Database(GameDbConString);

            if (!db.Test())
            {
                ConsoleUtils.Write(ConsoleMsgType.Info, "Fix the errors and restart the server. Press any key to exit.\n");
                Console.ReadKey();
                return;
            }
            ConsoleUtils.Write(ConsoleMsgType.Status, "MySQL Connections Test OK\n");

            /* ************************* *
            * Load Game Data
            * ************************* */
            // Start Game Object Manager
            GObjectManager.Start();

            RegionMngr.Start();

            Script.LuaMain.Start();
            ItemDb.Start();
            StatsDb.Start();
            SkillDb.Start();
            MonsterDb.Start();
            Player.Start();
            Npc.Init();
            QuestDb.Start();

            /* ************************* *
            * Server Internal Timer
            * ************************* */
            // Server Timer
            this.GameTimer          = new Timer();
            this.GameTimer.Interval = 5000;             //ms
            this.GameTimer.Elapsed += (o, x) =>
            {
                GObjectManager.Update();
            };
            this.GameTimer.Start();

            /* ************************* *
            * Start Network Manager
            * ************************* */
            ConsoleUtils.Write(ConsoleMsgType.Status, "Initializing Network\n");

            UserJoinPool = new Dictionary <string, UserJoinData>();
            UserIds      = new Dictionary <string, int>();

            Network = new NetworkManager();
            Network.ConnectToAuthServer();
            Network.InitClientListener();

            ConsoleUtils.Write(ConsoleMsgType.Status, "Network Initialized\n");
        }