Exemplo n.º 1
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");
        }
        /// [0x0003]  3 -> (GC) Informs that an entitity entered
        ///					player surroundings
        ///	<main type>.B <object handle>.L <x>.L <y>.L <z>.L <layer>.B
        ///	<sub type>.B <extra data>.?B
        ///	Read the full documentation for extra data values
        internal static void send_EntityAck(GameObject objData)
        {
            PacketStream data = new PacketStream(0x0003);

            data.WriteByte((byte)objData.Type);
            data.WriteUInt32(objData.Handle);
            data.WriteFloat(objData.Position.X);
            data.WriteFloat(objData.Position.Y);
            data.WriteFloat(0);             // Z
            data.WriteByte(objData.Layer);
            data.WriteByte((byte)objData.SubType);

            switch (objData.Type)
            {
            case GameObjectType.Creature:
            {
                CreatureObject co = (CreatureObject)objData;
                data.WriteUInt32(co.Status);
                data.WriteFloat(co.FaceDirection);
                data.WriteInt32(co.Hp);
                data.WriteInt32(co.MaxHp);
                data.WriteInt32(co.Mp);
                data.WriteInt32(co.MaxMp);
                data.WriteInt32(co.Level);
                data.WriteByte((byte)co.Race);
                data.WriteUInt32(co.SkinColor);
                data.WriteBool(true);
                data.WriteInt32(co.Energy);

                switch (co.SubType)
                {
                case GameObjectSubType.Player:
                {
                    Player pl = (Player)co;
                    data.WriteByte((byte)pl.Sex);
                    data.WriteInt32(pl.FaceId);
                    data.WriteInt32(0);                                                     // TODO : FaceTextureID
                    data.WriteInt32(pl.HairId);
                    data.WriteString(pl.Name, 19);
                    data.WriteUInt16((ushort)pl.Job);
                    data.WriteUInt32(0);                                                     // TODO : Ride Handle
                    data.WriteInt32(pl.GuildId);
                }
                break;

                case GameObjectSubType.NPC:
                {
                    Npc          n     = (Npc)co;
                    EncryptedInt crInt = new EncryptedInt(n.Id);
                    crInt.WriteToPacket(data);
                }
                break;

                case GameObjectSubType.Mob:
                {
                    Monster      m     = (Monster)co;
                    EncryptedInt crInt = new EncryptedInt(ScrambleMap.bits_scramble(m.Id));
                    crInt.WriteToPacket(data);
                    data.WriteBool(false);                                                     // is Tamed
                }
                break;

                case GameObjectSubType.Summon:
                {
                    //Npc n = (Npc)co;
                    //EncryptedInt crInt = new EncryptedInt(n.Id);
                    //crInt.WriteToPacket(data);
                }
                break;

                case GameObjectSubType.Pet:
                {
                    //Npc n = (Npc)co;
                    //EncryptedInt crInt = new EncryptedInt(n.Id);
                    //crInt.WriteToPacket(data);
                }
                break;

                default:
                    ConsoleUtils.Write(ConsoleMsgType.Error, "Unhandled Entity SubType\n");
                    break;
                }
            }
            break;

            case GameObjectType.StaticObject:
            {
                switch (objData.SubType)
                {
                case GameObjectSubType.Item:
                {
                }
                break;

                case GameObjectSubType.SkillProp:
                {
                }
                break;

                case GameObjectSubType.FieldProp:
                {
                }
                break;

                default:
                    ConsoleUtils.Write(ConsoleMsgType.Error, "Unhandled Entity SubType\n");
                    break;
                }
            }
            break;

            default:
                ConsoleUtils.Write(ConsoleMsgType.Error, "Unhandled Entity SubType\n");
                break;
            }

            ClientManager.Instance.Send(objData, data, ClientManager.SendTarget.Area);
        }
Exemplo n.º 3
0
 public static void AddNpcToRegion(Npc n1)
 {
     GetRegion(n1.Position.X, n1.Position.Y).Npcs.Add(n1.Handle);
 }