public void WorldServerLogin(string passphrase)
        {
            ServerConsole.InfoLine("World-server successfull connected: {0}", CurrentClient.RemoteEndPoint);
            // @TODO: Validate against config for allowed connections

            _knownServers.Add(CurrentClient);
        }
Example #2
0
        public static string[] GetNpcs()
        {
            int           count = 0;
            List <string> list  = new List <string>();

            ScriptEntry[] entrys = ScriptDatabase.GetType(EScriptContent.Npc);

            for (int i = 0; i < entrys.Length; i++)
            {
                if (entrys[i].Type != EScriptType.Path)
                {
                    continue;
                }
                if (File.Exists(entrys[i].Path) == false)
                {
                    ServerConsole.ErrorLine("Cant find File/Path: \"" + entrys[i].Path + "\"! Skipping...");
                    continue;
                }

                list.Add(Path.Combine(Environment.CurrentDirectory, entrys[i].Path));
                ServerConsole.InfoLine("\t#{0}: \"{1}\"", (++count), entrys[i].Path);
            }

            return(list.ToArray());
        }
Example #3
0
 public static void Initialize()
 {
     ServerConsole.InfoLine("Loading packet structures..");
     if (LoadPacketDefintions() == false)
     {
         return;
     }
 }
Example #4
0
        /// <summary>
        ///     Starts the server loop in a new thread.
        /// </summary>
        /// <returns></returns>
        public override bool Start()
        {
            if (base.Start() == false)
            {
                return(false);
            }

            ServerConsole.InfoLine("Server starts listening on: {0}", _endPoint);
            return(true);
        }
Example #5
0
        public static void Load()
        {
            if (Loaded == true || Loading == true)
            {
                return;
            }

            Loading = true;
            // Trigger events for scripts
            Events.Call("worldLoadStart");

            // Our object manager for world objects (spawned objects)
            Objects = new WorldObjectManager();

            // Delegate for Send() Method
            //mForeachInRangeCallback = new ForeachInRangeVoidDelegate(SendSub);

            mAddQueue = new Queue <WorldObject>();
            mDelQueue = new Queue <WorldObject>();

            // Load globals from config, initialize packets ect
            ServerConsole.InfoLine("Initialize game symantics...");
            Global.Initialize();
            PathHelper.Initialize();

            // Real database loading
            ServerConsole.InfoLine("Begin World loading...");

            DataTable table    = null;
            Stopwatch watchAll = Stopwatch.StartNew();
            Stopwatch watch    = Stopwatch.StartNew();

            //------------- loading start -------------

            #region Mapcache
            ServerConsole.Info("\t# loading Maps from mapcache...");
            watch.Reset();
            watch.Start();
            Mapcache.Initialize();
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Mapcache.Maps.Count + " Maps in " + watch.ElapsedMilliseconds + "ms)");
            #endregion


            // Loading other shit
            // o.o

            //------------- loading end -------------

            // Trigger event for scripts
            Events.Call("worldLoadFinish");

            Loading = false;
            Loaded  = true;

            ProcessSafetyQueues();

            // TODO: Initialize save timer

            ServerConsole.InfoLine("Finished World loading! Needed {0:F2} sec", watchAll.Elapsed.TotalSeconds);

            watch.Stop();
            watch = null;
            watchAll.Stop();
            watchAll = null;
        }
Example #6
0
        private static bool CompileScripts(string AssemblyFile, bool debug, bool cache, out Assembly assembly)
        {
            ServerConsole.InfoLine("Compile Scripts...");

            string[] files = GetNpcs();
            if (files.Length == 0)
            {
                ServerConsole.WriteLine(EConsoleColor.Error, "no Script found oO");
                assembly = null;
                return(true);
            }

            if (File.Exists("Scripts/Output/Scripts.dll"))
            {
                if (cache && File.Exists("Scripts/Output/Scripts.hash"))
                {
                    try {
                        byte[] hashCode = GetHashCode("Scripts/Output/Scripts.dll", files, debug);

                        using (FileStream fs = File.OpenRead("Scripts/Output/Scripts.hash")) {
                            using (BinaryReader bin = new BinaryReader(fs)) {
                                byte[] bytes = bin.ReadBytes(hashCode.Length);

                                if (bytes.Length == hashCode.Length)
                                {
                                    bool valid = true;

                                    for (int i = 0; i < bytes.Length; ++i)
                                    {
                                        if (bytes[i] != hashCode[i])
                                        {
                                            valid = false;
                                            break;
                                        }
                                    }

                                    if (valid)
                                    {
                                        assembly = Assembly.LoadFrom("Scripts/Output/Scripts.dll");

                                        if (!mAdditionalReferences.Contains(assembly.Location))
                                        {
                                            mAdditionalReferences.Add(assembly.Location);
                                        }

                                        ServerConsole.StatusLine("done (cached)");

                                        return(true);
                                    }
                                }
                            }
                        }
                    } catch {
                    }
                }
            }

            DeleteFiles("Scripts*.dll");

            var providerOptions = new Dictionary <string, string>();

            providerOptions.Add("CompilerVersion", "v4.0");

            using (CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions)) {
                string             path    = GetUnusedPath("Scripts");
                CompilerParameters parms   = new CompilerParameters(GetReferenceAssemblies(AssemblyFile), path, debug);
                string             defines = GetDefines();
                if (defines != null)
                {
                    parms.CompilerOptions = defines;
                }
                parms.CompilerOptions         = string.Format("{0} /debug /nowarn:169,219,414 /recurse:Scripts/*.cs", parms.CompilerOptions);
                parms.IncludeDebugInformation = true;
                parms.WarningLevel            = 4;

                CompilerResults results = provider.CompileAssemblyFromFile(parms, files);
                Display(results);
                foreach (CompilerError e in results.Errors)
                {
                    if (e.IsWarning == false)
                    {
                        assembly = null;
                        return(false);
                    }
                }

                mAdditionalReferences.Add(path);

                if (cache && Path.GetFileName(path) == "Scripts.dll")
                {
                    try {
                        byte[] hashCode = GetHashCode(path, files, debug);

                        using (FileStream fs = File.OpenWrite("Scripts/Output/Scripts.hash")) {
                            using (BinaryWriter bin = new BinaryWriter(fs)) {
                                bin.Write(hashCode, 0, hashCode.Length);
                            }
                        }
                    } catch {
                    }
                }

                assembly = results.CompiledAssembly;
                return(true);
            }
        }
Example #7
0
 private static void ServerOnClientDisconnected(object sender, ServiceClientEventArgs args)
 {
     ServerConsole.InfoLine("Client disconnected: {0}", args.Client.RemoteEndPoint);
 }
Example #8
0
 protected override void ServerOnClientConnected(object sender, ServerClientEventArgs args)
 {
     ServerConsole.InfoLine("Client connected: {0}", args.Client.RemoteEndPoint);
     base.ServerOnClientConnected(sender, args);
 }
Example #9
0
 /// <summary>
 ///     Stops the server (listener) and disconnects all clients.
 /// </summary>
 /// <returns></returns>
 public override void Stop()
 {
     ServerConsole.InfoLine("Server stops listening..");
     _server.Stop();
 }
Example #10
0
        public static void Load()
        {
            if (Loaded == true || Loading == true)
            {
                return;
            }

            Loading = true;
            // Trigger events for scripts
            Events.InvokeWorldLoadStart();

            // Our object manager for databsae objects
            Database = new DatabaseObjectManager();
            // Our object manager for world objects (spawned objects)
            Objects = new WorldObjectManager();

            // Delegate for Send() Method
            mForeachInRangeCallback = new ForeachInRangeVoidDelegate(SendSub);

            mAddQueue = new Queue <DatabaseObject>();
            mDelQueue = new Queue <DatabaseObject>();

            // Load globals from config, initialize packets ect
            ServerConsole.InfoLine("Initialize game symantics...");
            Global.Initialize();
            WorldObjectStatus.Initialize();
            ChatHelper.Initialize();
            PlayerCommandHelper.Initialize();
            PathHelper.Initialize();
            SkillTree.Initialize();
            FameListHelper.Initialize();
            CharacterJobBonus.Initialize();
            CharacterJobModifer.Initialize();

            // Real database loading
            ServerConsole.InfoLine("Begin World loading...");

            DataTable table    = null;
            Stopwatch watchAll = Stopwatch.StartNew();
            Stopwatch watch    = Stopwatch.StartNew();

            //------------- loading start -------------

            #region Mapcache
            ServerConsole.Info("\t# loading Maps from mapcache...");
            watch.Reset();
            watch.Start();
            Mapcache.Initialize();
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Mapcache.Maps.Count + " Maps in " + watch.ElapsedMilliseconds + "ms)");
            #endregion


            #region Items
            ServerConsole.Info("\t# loading Items...");
            watch.Reset();
            watch.Start();
            table           = Core.Database.Query("SELECT * FROM dbitem");
            table.TableName = "ItemDB Table";


            if (table == null || table.Rows.Count == 0)
            {
                if (Core.Database.LastError != null)
                {
                    ServerConsole.ErrorLine("failed to load Item Database!");
                    ServerConsole.WriteLine(Core.Database.LastError.ToString());
                }
            }
            else
            {
                ItemDatabaseData item;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    item = ItemDatabaseData.Load(table.Rows[i]);
                    if (item == null)
                    {
                        ServerConsole.WarningLine("Failed to load item {0}: #{1} {2}", i, table.Rows[i].Field <int>("itemID"), table.Rows[i].Field <string>("nameEnglish"));
                        continue;
                    }
                    Database.Add(item);

                    //ServerConsole.DebugLine("\tLoad: #{0} {1}", item.NameID.ToString().PadLeft(5), item.Name);
                }
            }
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Database.Items.Count + " Items in " + watch.ElapsedMilliseconds + "ms)");
            #endregion


            #region Monster
            ServerConsole.Info("\t# loading Mobs...");
            watch.Reset();
            watch.Start();
            table           = Core.Database.Query("SELECT * FROM dbmob");
            table.TableName = "MobDB Table";
            if (table == null || table.Rows.Count == 0)
            {
                if (Core.Database.LastError != null)
                {
                    ServerConsole.ErrorLine("failed to load Monster Database!");
                    ServerConsole.WriteLine(Core.Database.LastError.ToString());
                }
            }
            else
            {
                MonsterDatabaseData mob;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    mob = MonsterDatabaseData.Load(table.Rows[i]);
                    if (mob == null)
                    {
                        ServerConsole.WarningLine("Failed to load mob {0}: #{1} {2}", i, table.Rows[i].Field <int>("mobID"), table.Rows[i].Field <string>("nameInter"));
                        continue;
                    }
                    Database.Add(mob);

                    //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} drops, {3} skills)", mob.ID.ToString().PadLeft(5), mob.NameInter, mob.Drops.Count, mob.Skills.Count);
                }
            }
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Database.Monster.Count + " Mobs in " + watch.ElapsedMilliseconds + "ms)");


            ServerConsole.Info("\t# loading Mob Skills...");
            watch.Reset();
            watch.Start();
            table           = Core.Database.Query("SELECT * FROM dbmob_skill ORDER BY mobID ASC");
            table.TableName = "MobDB Skill Table";
            if (table == null || table.Rows.Count == 0)
            {
                if (Core.Database.LastError != null)
                {
                    ServerConsole.ErrorLine("failed to load Mob Skill Database!");
                    ServerConsole.WriteLine(Core.Database.LastError.ToString());
                }
            }
            else
            {
                MonsterSkill mobSkill;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    mobSkill = MonsterSkill.Load(table.Rows[i]);
                    if (mobSkill == null)
                    {
                        throw new Exception(string.Format("Failed to load mob skill #{0}: {1}", table.Rows[i].Field <int>("mobID"), table.Rows[i].Field <string>("info")));
                    }

                    (Database[EDatabaseType.Mob, mobSkill.MobID] as MonsterDatabaseData).Skills.Add(mobSkill);

                    //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} level)", skill.ID.ToString().PadLeft(5), skill.Name, skill.Level.Count);
                }
            }
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done in " + watch.ElapsedMilliseconds + "ms");


            ServerConsole.Info("\t# loading Mob Drops...");
            watch.Reset();
            watch.Start();
            table           = Core.Database.Query("SELECT * FROM dbmob_drop ORDER BY mobID ASC");
            table.TableName = "MobDB Drop Table";
            if (table == null || table.Rows.Count == 0)
            {
                if (Core.Database.LastError != null)
                {
                    ServerConsole.ErrorLine("failed to load Mob Drop Database!");
                    ServerConsole.WriteLine(Core.Database.LastError.ToString());
                }
            }
            else
            {
                MonsterDrop drop;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    drop = MonsterDrop.Load(table.Rows[i]);

                    (Database[EDatabaseType.Mob, drop.MobID] as MonsterDatabaseData).Drops.Add(drop);

                    //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} level)", skill.ID.ToString().PadLeft(5), skill.Name, skill.Level.Count);
                }
            }
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done in " + watch.ElapsedMilliseconds + "ms");
            #endregion


            #region General Skills
            ServerConsole.Info("\t# loading Skills...");
            watch.Reset();
            watch.Start();
            table           = Core.Database.Query("SELECT * FROM dbskill");
            table.TableName = "SkillDB Table";
            if (table == null || table.Rows.Count == 0)
            {
                if (Core.Database.LastError != null)
                {
                    ServerConsole.ErrorLine("failed to load Skill Database!");
                    ServerConsole.WriteLine(Core.Database.LastError.ToString());
                }
            }
            else
            {
                SkillDatabaseData skill;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    skill = SkillDatabaseData.Load(table.Rows[i]);
                    if (skill == null)
                    {
                        ServerConsole.WarningLine("Failed to load skill {0}: #{1} {2}", i, table.Rows[i].Field <int>("skillID"), table.Rows[i].Field <string>("name"));
                        continue;
                    }
                    Database.Add(skill.Index, skill);

                    //ServerConsole.DebugLine("\tLoad: #{0} {1} ({2} level)", skill.ID.ToString().PadLeft(5), skill.Name, skill.Level.Count);
                }
            }
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done (" + Database.Skill.Count + " Skills in " + watch.ElapsedMilliseconds + "ms)");
            #endregion


            // Loading other shit
            // o.o

            //------------- loading end -------------

            // Trigger event for scripts
            Events.InvokeWorldLoadFinish();

            Loading = false;
            Loaded  = true;

            ProcessSafetyQueues();

            // TODO: Initialize save timer

            ServerConsole.InfoLine("Finished World loading! Needed {0:F2} sec", watchAll.Elapsed.TotalSeconds);

            watch.Stop();
            watch = null;
            watchAll.Stop();
            watchAll = null;
        }