Пример #1
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();
        }
Пример #2
0
 public static void HandleTimeOfDayChanged(ref Time source)
 {
     SendTimeToAll();
     modDatabase.ClearAllMapNpcs();
     S_Npc.SpawnAllMapNpcs();
 }
Пример #3
0
        public static void NpcMoveAlongPath(int MapNum, int MapNpcNum)
        {
            int x, y;

            // make sure we're not at end of path
            if (modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc >= 1)
            {
                x = modTypes.MapNpc[MapNum].Npc[MapNpcNum].arPath[modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc - 1].x;
                y = modTypes.MapNpc[MapNum].Npc[MapNpcNum].arPath[modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc - 1].y;

                // Do 8 Directional First
                // up Left
                if (y < modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x < modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.UpLeft))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.UpLeft, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // Up Right
                else if (y < modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x > modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.UpRight))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.UpRight, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // Down Left
                else if (y > modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x < modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.DownLeft))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.DownLeft, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // Down Right
                else if (y > modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x > modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.DownRight))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.DownRight, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }

                // up
                else if (y < modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Up))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Up, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // down
                if (y > modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Down))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Down, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // left
                if (x < modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Left))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Left, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // right
                if (x > modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Right))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Right, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
            }
        }