Пример #1
0
 private static void LoadGameData()
 {
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.WriteLine("Loading Classes..."); modDatabase.LoadClasses();
     Console.WriteLine("Loading Maps..."); modDatabase.LoadMaps();
     Console.WriteLine("Creating Map Matrices...");
     for (int i = 1; i < Constants.MAX_MAPS; i++)
     {
         modPathfinding.CreatePathMatrix(i);
     }
     Console.WriteLine("Loading Items..."); S_Items.LoadItems();
     Console.WriteLine("Loading Npc's..."); modDatabase.LoadNpcs();
     Console.WriteLine("Loading Resources..."); S_Resources.LoadResources();
     Console.WriteLine("Loading Shops..."); modDatabase.LoadShops();
     Console.WriteLine("Loading Skills..."); modDatabase.LoadSkills();
     Console.WriteLine("Loading Animations..."); S_Animations.LoadAnimations();
     Console.WriteLine("Loading Quests..."); S_Quest.LoadQuests();
     Console.WriteLine("Loading House Configurations..."); S_Housing.LoadHouses();
     Console.WriteLine("Loading Switches..."); S_Events.LoadSwitches();
     Console.WriteLine("Loading Variables..."); S_Events.LoadVariables();
     Console.WriteLine("Spawning global events..."); S_EventLogic.SpawnAllMapGlobalEvents();
     Console.WriteLine("Loading projectiles..."); S_Projectiles.LoadProjectiles();
     Console.WriteLine("Loading Recipes..."); modCrafting.LoadRecipes();
     Console.WriteLine("Loading Pets..."); S_Pets.LoadPets();
     Console.ResetColor();
 }
Пример #2
0
 internal static void ClearGameData()
 {
     Console.WriteLine("Clearing temp tile fields..."); modDatabase.ClearTempTiles();
     Console.WriteLine("Clearing Maps..."); modDatabase.ClearMaps();
     Console.WriteLine("Clearing Map Items..."); modDatabase.ClearMapItems();
     Console.WriteLine("Clearing Map Npc's..."); modDatabase.ClearAllMapNpcs();
     Console.WriteLine("Clearing Npc's..."); modDatabase.ClearNpcs();
     Console.WriteLine("Clearing Resources..."); S_Resources.ClearResources();
     Console.WriteLine("Clearing Items..."); S_Items.ClearItems();
     Console.WriteLine("Clearing Shops..."); modDatabase.ClearShops();
     Console.WriteLine("Clearing Skills..."); modDatabase.ClearSkills();
     Console.WriteLine("Clearing Animations..."); S_Animations.ClearAnimations();
     Console.WriteLine("Clearing Quests..."); S_Quest.ClearQuests();
     Console.WriteLine("Clearing map projectiles..."); S_Projectiles.ClearMapProjectiles();
     Console.WriteLine("Clearing projectiles..."); S_Projectiles.ClearProjectiles();
     Console.WriteLine("Clearing Recipes..."); modCrafting.ClearRecipes();
     Console.WriteLine("Clearing pets..."); S_Pets.ClearPets();
 }
Пример #3
0
 private static void LoadGameData()
 {
     Console.WriteLine("Loading Classes..."); modDatabase.LoadClasses();
     Console.WriteLine("Loading Maps..."); modDatabase.LoadMaps();
     Console.WriteLine("Loading Items..."); S_Items.LoadItems();
     Console.WriteLine("Loading Npc's..."); modDatabase.LoadNpcs();
     Console.WriteLine("Loading Resources..."); S_Resources.LoadResources();
     Console.WriteLine("Loading Shops..."); modDatabase.LoadShops();
     Console.WriteLine("Loading Skills..."); modDatabase.LoadSkills();
     Console.WriteLine("Loading Animations..."); S_Animations.LoadAnimations();
     Console.WriteLine("Loading Quests..."); S_Quest.LoadQuests();
     Console.WriteLine("Loading House Configurations..."); S_Housing.LoadHouses();
     Console.WriteLine("Loading Switches..."); S_Events.LoadSwitches();
     Console.WriteLine("Loading Variables..."); S_Events.LoadVariables();
     Console.WriteLine("Spawning global events..."); S_EventLogic.SpawnAllMapGlobalEvents();
     Console.WriteLine("Loading projectiles..."); S_Projectiles.LoadProjectiles();
     Console.WriteLine("Loading Recipes..."); modCrafting.LoadRecipes();
     Console.WriteLine("Loading Pets..."); S_Pets.LoadPets();
 }
Пример #4
0
        public static void InitServer()
        {
            int i;
            int F;
            int x;
            int time1;
            int time2;

            myStopWatch.Start();

            if (Debugger.IsAttached)
            {
                // Since there is a debugger attached,
                // assume we are running from the IDE
                S_Globals.Debugging = true;
            }
            else
            {
                // Assume we aren't running from the IDE
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += ErrorHandler;
            }

            Console.Title = "Orion+# Server";
            Console.SetWindowSize(120, 20);

            time1 = GetTimeMs();

            // Initialize the random-number generator
            VBMath.Randomize();

            // LOAD ENCRYPTION
            var fi = Application.StartupPath + @"\AsyncKeys.xml";

            if (!File.Exists(fi))
            {
                S_Globals.EKeyPair.GenerateKeys();
                S_Globals.EKeyPair.ExportKey(fi, true); // True exports private key too.
            }
            else
            {
                S_Globals.EKeyPair.ImportKey(fi);
            }
            // END LOAD ENCRYPTION

            modTypes.Map = new MapRec[601];

            modTypes.MapNpc = new MapDataRec[601];
            for (i = 0; i <= S_Instances.MAX_CACHED_MAPS; i++)
            {
                modTypes.MapNpc[i].Npc = new MapNpcRec[Constants.MAX_MAP_NPCS + 1];
                modTypes.Map[i].Npc    = new int[Constants.MAX_MAP_NPCS + 1];
            }

            // quests
            S_Quest.Quest = new QuestRec[251];
            S_Quest.ClearQuests();

            // event
            S_Events.Switches     = new string[501];
            S_Events.Variables    = new string[501];
            S_Events.TempEventMap = new GlobalEventsStruct[601];

            // Housing
            S_Housing.HouseConfig = new HouseRec[S_Housing.MAX_HOUSES + 1];

            for (i = 0; i <= S_Instances.MAX_CACHED_MAPS; i++)
            {
                for (x = 0; x <= Constants.MAX_MAP_NPCS; x++)
                {
                    modTypes.MapNpc[i].Npc[x].Vital = new int[(int)Enums.VitalType.Count + 1];
                }
            }

            modTypes.Bank = new BankRec[71];

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                modTypes.Bank[i].Item     = new PlayerInvRec[Constants.MAX_BANK + 1];
                modTypes.Bank[i].ItemRand = new RandInvRec[Constants.MAX_BANK + 1];
                for (x = 1; x <= Constants.MAX_BANK; x++)
                {
                    modTypes.Bank[i].ItemRand[x].Stat = new int[7];
                }
            }

            modTypes.Player = new PlayerRec[71];

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                // multi char
                modTypes.Player[i].Character = new CharacterRec[S_Constants.MAX_CHARS + 1];
                for (x = 1; x <= S_Constants.MAX_CHARS; x++)
                {
                    modTypes.Player[i].Character[x].Switches    = new byte[501];
                    modTypes.Player[i].Character[x].Variables   = new int[501];
                    modTypes.Player[i].Character[x].Vital       = new int[4];
                    modTypes.Player[i].Character[x].Stat        = new int[7];
                    modTypes.Player[i].Character[x].Equipment   = new int[7];
                    modTypes.Player[i].Character[x].Inv         = new PlayerInvRec[Constants.MAX_INV + 1];
                    modTypes.Player[i].Character[x].Skill       = new int[Constants.MAX_PLAYER_SKILLS + 1];
                    modTypes.Player[i].Character[x].PlayerQuest = new PlayerQuestRec[251];

                    modTypes.Player[i].Character[x].RandEquip = new RandInvRec[7];
                    modTypes.Player[i].Character[x].RandInv   = new RandInvRec[Constants.MAX_INV + 1];
                    for (var y = 1; y <= (int)Enums.EquipmentType.Count - 1; y++)
                    {
                        modTypes.Player[i].Character[x].RandEquip[y].Stat = new int[7];
                    }
                    for (int y = 1; y <= Constants.MAX_INV; y++)
                    {
                        modTypes.Player[i].Character[x].RandInv[y].Stat = new int[7];
                    }
                }
            }

            modTypes.TempPlayer = new TempPlayerRec[71];

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                modTypes.TempPlayer[i].SkillCd    = new int[Constants.MAX_PLAYER_SKILLS + 1];
                modTypes.TempPlayer[i].PetSkillCd = new int[5];
            }

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                modTypes.TempPlayer[i].TradeOffer = new PlayerInvRec[Constants.MAX_INV + 1];
            }

            S_AutoMap.LoadTilePrefab();

            Types.Classes = new ClassRec[S_Globals.Max_Classes + 1];
            var loopTo = S_Globals.Max_Classes;

            for (i = 0; i <= loopTo; i++)
            {
                Types.Classes[i].Stat       = new byte[7];
                Types.Classes[i].StartItem  = new int[6];
                Types.Classes[i].StartValue = new int[6];
            }

            for (i = 0; i <= Constants.MAX_ITEMS; i++)
            {
                Types.Item[i].Add_Stat        = new byte[7];
                Types.Item[i].Stat_Req        = new byte[7];
                Types.Item[i].FurnitureBlocks = new int[4, 4];
                Types.Item[i].FurnitureFringe = new int[4, 4];
            }
            Types.Npc[Constants.MAX_NPCS].Stat = new byte[7];

            Types.Shop[Constants.MAX_SHOPS].TradeItem = new TradeItemRec[Constants.MAX_TRADES + 1];

            Types.Animation[Constants.MAX_ANIMATIONS].Sprite    = new int[2];
            Types.Animation[Constants.MAX_ANIMATIONS].Frames    = new int[2];
            Types.Animation[Constants.MAX_ANIMATIONS].LoopCount = new int[2];
            Types.Animation[Constants.MAX_ANIMATIONS].LoopTime  = new int[2];

            S_Projectiles.MapProjectiles = new MapProjectileRec[601, 256];
            S_Projectiles.Projectiles    = new ProjectileRec[256];

            // parties
            S_Parties.ClearParties();

            // pets
            S_Pets.Pet = new PetRec[101];
            S_Pets.ClearPets();

            // Check if the directory is there, if its not make it
            CheckDir(Path.Combine(Application.StartupPath, "data"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "items"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "maps"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "npcs"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "shops"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "skills"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "accounts"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "resources"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "animations"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "logs"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "quests"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "recipes"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "pets"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "projectiles"));

            // load options, set if they dont exist
            if (!File.Exists(Path.Combine(Application.StartupPath, "Data", "Config.xml")))
            {
                modTypes.Options.GameName = "Orion+#";
                modTypes.Options.Port     = 7001;
                modTypes.Options.Motd     = "Welcome to the Orion+# Engine";
                modTypes.Options.Website  = "http://ascensiongamedev.com/index.php";
                modTypes.Options.StartMap = 1;
                modTypes.Options.StartX   = 13;
                modTypes.Options.StartY   = 7;
                modDatabase.SaveOptions();
            }
            else
            {
                modDatabase.LoadOptions();
            }

            // Get that network READY SUN! ~ SpiceyWOlf
            S_NetworkConfig.InitNetwork();

            // Init all the player sockets
            Console.WriteLine("Initializing player array...");

            for (x = 1; x <= Constants.MAX_PLAYERS; x++)
            {
                modDatabase.ClearPlayer(x);
            }

            // Serves as a constructor
            ClearGameData();
            LoadGameData();
            Console.WriteLine("Spawning map items...");
            S_Items.SpawnAllMapsItems();
            Console.WriteLine("Spawning map npcs...");
            S_Npc.SpawnAllMapNpcs();

            // Check if the master charlist file exists for checking duplicate names, and if it doesnt make it
            if (!File.Exists(@"data\accounts\charlist.txt"))
            {
                F = FileSystem.FreeFile();
            }

            // resource system
            S_Resources.LoadSkillExp();

            modTime.InitTime();

            UpdateCaption();
            time2 = GetTimeMs();

            Console.Clear();
            Console.WriteLine("   ____       _                   _  _   ");
            Console.WriteLine(@"  / __ \     (_)             _  _| || |_ ");
            Console.WriteLine(" | |  | |_ __ _  ___  _ __ _| ||_  __  _|");
            Console.WriteLine(@" | |  | | '__| |/ _ \| '_ \_   _|| || |_ ");
            Console.WriteLine(@" | |__| | |  | | (_) | | | ||_||_  __  _|");
            Console.WriteLine(@"  \____/|_|  |_|\___/|_| |_|     |_||_|  ");

            Console.WriteLine("");

            Console.WriteLine("Initialization complete. Server loaded in " + (time2 - time1).ToString() + "ms.");
            Console.WriteLine("");
            Console.WriteLine("Use /help for the available commands.");

            MyIPAddress = S_NetworkConfig.GetIP();

            UpdateCaption();

            // reset shutdown value
            S_Globals.isShuttingDown = false;

            // Start listener now that everything is loaded
            S_NetworkConfig.Socket.StartListening(modTypes.Options.Port, 5, 1);

            // Starts the server loop
            modLoop.ServerLoop();
        }