Exemple #1
0
        protected void WriteToOutputBuffer(NetworkMessage msg)
        {
            OutputMessage @out = GetOutputBuffer(msg.Length);

            if (@out != null)
            {
                @out.Append(msg);
            }
            NetworkMessagePool.ReleaseMessage(msg);
        }
Exemple #2
0
        internal static void Main()
        {
            NativeMethods.SetConsoleCtrlHandler(ConsoleCtrlOperationHandler, true);

            Game.Initialize();
            Tools.Initialize();
            OutputMessagePool.Initialize();
            NetworkMessagePool.Initialize();

            Console.Title = Constants.ServerName;
            Console.Clear();
            Console.WriteLine("Welcome to {0} - Version {1}", Constants.ServerName, Constants.ServerVersion);
            Console.WriteLine("Developed by {0}", Constants.ServerDevelopers);
            Console.WriteLine();

            // Start Threads
            DispatcherManager.Start();

            // Loading config.lua
            if (!ConfigManager.Load("config.lua"))
            {
                ExitApplication();
            }

            if (!Enum.TryParse(ConfigManager.Instance[ConfigStr.MinConsoleLogLevel], true, out Logger.MinConsoleLogLevel))
            {
                Console.WriteLine("LOGGER LOG LEVEL COULD NOT BE PARSED! PLEASE FIX!");
                ExitApplication();
            }

            // Setting up process priority
            switch (ConfigManager.Instance[ConfigStr.DefaultPriority])
            {
            case "realtime":
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
                break;

            case "high":
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
                break;

            case "higher":
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
                break;
            }

            // Setting up RSA cyrpto
            if (!Rsa.SetKey(RsaP, RsaQ))
            {
                ExitApplication();
            }

            // Initializing Database connection
            if (!Database.Initialize())
            {
                ExitApplication();
            }
            //DATABASE MANAGER UPDATE DATABASE
            //DATABASE TASKS START

            // Loading vocations
            if (!Vocation.LoadVocations())
            {
                ExitApplication();
            }

            // Loading items
            if (!ItemManager.Load())
            {
                ExitApplication();
            }

            // Loading Chat Channels
            if (!Chat.Load())
            {
                ExitApplication();
            }

            // Loading scripts
            if (!ScriptManager.LoadCsScripts() || !ScriptManager.LoadLuaScripts())
            {
                ExitApplication();
            }

            // Loading Command Line Operations
            if (!ScriptManager.LoadCommandLineOperations())
            {
                ExitApplication();
            }

            // LOAD CREATURES HERE

            // Loading outfits
            if (!OutfitManager.Load())
            {
                ExitApplication();
            }

            // Loading map
            if (!Map.Load())
            {
                ExitApplication();
            }

            // Setting game world type
            switch (ConfigManager.Instance[ConfigStr.WorldType])
            {
            case "pvp":
                Game.WorldType = GameWorldTypes.Pvp;
                break;

            case "no-pvp":
                Game.WorldType = GameWorldTypes.NoPvp;
                break;

            case "pvp-enforced":
                Game.WorldType = GameWorldTypes.PvpEnforced;
                break;

            default:
                Logger.Log(LogLevels.Error, "Invalid game world type: " + ConfigManager.Instance[ConfigStr.WorldType]);
                ExitApplication();
                break;
            }
            Logger.Log(LogLevels.Operation, "Setting Game World Type: " + Game.WorldType);

            // Initialize Game State
            Game.GameState = GameStates.Init;

            //TODO: HOUSE RENTS
            //TODO: MARKET CHECK OFFERS
            //TODO: MARKET STATISTICS

            if (ConfigManager.Instance[ConfigBool.UseExternalLoginServer])
            {
                //Create secret communication channel with login server if login server is external
                if (!SecretServerConnection.Initialize())
                {
                    ExitApplication();
                }

                // Create signal waiting system to get authentication response from external login server
            }
            else
            {
                _loginServer = new LoginServer.LoginServer();
                _loginServer.Start();
            }

            GameServer.Start();
            Game.GameState = GameStates.Normal;
            Game.StartJobs();
            //TODO: FIRE SERVER RUNNING EVENT

            while (true)
            {
                string input = Console.ReadLine();

                if (input == null)
                {
                    continue;
                }

                string[]      firstPass  = input.Split('"');
                List <string> secondPass = firstPass[0].Trim().Split(' ').ToList();

                if (firstPass.Length > 1)
                {
                    for (int i = 1; i < firstPass.Length; i++)
                    {
                        if (i % 2 == 1)
                        {
                            secondPass.Add(firstPass[i]);
                        }
                        else
                        {
                            secondPass.AddRange(firstPass[i].Trim().Split(' '));
                        }
                    }
                }
                string[] command = secondPass.ToArray();

                if (ScriptManager.CommandLineOperations.ContainsKey(command[0]))
                {
                    try
                    {
                        ScriptManager.CommandLineOperations[command[0]].Invoke(command);
                    }
                    catch (Exception)
                    {
                        Logger.Log(LogLevels.Warning, "Command '" + command[0] + "' could not be executed in this environment!");
                    }
                }
                else
                {
                    Logger.Log(LogLevels.Warning, "Command is unknown!");
                }
            }
            // ReSharper disable FunctionNeverReturns
        }