예제 #1
0
        public bool ReportException(Exception item)
        {
            DbLoaderErrorHandler.HandleLoader(item.Message);
            NumberOfErrors--;

            if (NumberOfErrors < 0)
            {
                DbLoaderErrorHandler.Handle("Failed to read too many items, the db will stop loading.", ErrorLevel.Critical);
                return(false);
            }

            return(true);
        }
예제 #2
0
        public bool ReportException(string item)
        {
            DbLoaderErrorHandler.Handle(item);
            NumberOfErrors--;

            if (NumberOfErrors < 0)
            {
                DbLoaderErrorHandler.Handle("Failed to read too many items, the db [" + DbSource + "] will stop loading.", ErrorLevel.Critical);
                return(false);
            }

            return(true);
        }
예제 #3
0
        public bool ReportIdExceptionWithError(string exception, object item)
        {
            DbLoaderErrorHandler.Handle(exception, item.ToString());
            NumberOfErrors--;

            if (NumberOfErrors < 0)
            {
                DbLoaderErrorHandler.Handle("Failed to read too many items, the db [" + DbSource + "] will stop loading.", ErrorLevel.Critical);
                return(false);
            }

            return(true);
        }
예제 #4
0
        public bool Load(ServerDbs dbSource)
        {
            DbSource = dbSource;
            string path = AllLoaders.DetectPath(DbSource);

            TextFileHelper.LatestFile = path;

            if (String.IsNullOrEmpty(path))
            {
                if (_db.ThrowFileNotFoundException)
                {
                    DbLoaderErrorHandler.Handle("File not found '" + DbSource + "'.", ErrorLevel.NotSpecified);
                }

                return(false);
            }

            FileType = AllLoaders.GetFileType(path);
            FilePath = path;
            AllLoaders.StoreFile(FilePath);
            return(true);
        }
예제 #5
0
        private void _addCustomTables()
        {
            foreach (string file in ProjectConfiguration.CustomTabs)
            {
                if (File.Exists(file))
                {
                    DbMaker maker = new DbMaker(file);

                    if (maker.Init(_holder))
                    {
                        this.Dispatch(() => maker.Add(_mainTabControl, _holder, _tabEngine, this));
                    }
                    else
                    {
                        DbLoaderErrorHandler.Handle("Unable to parse the table for the file '" + file + "'.");
                    }
                }
                else
                {
                    DbLoaderErrorHandler.Handle("Couldn't find the file '" + file + "'.");
                }
            }
        }
예제 #6
0
        private static void _trySetIfRefineable(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, bool defaultValue)
        {
            int  type = tuple.GetValue <int>(ServerItemAttributes.Type);
            bool val  = tuple.GetValue <bool>(attribute);

            if (type != 4 && type != 5)
            {
                if (val)
                {
                    // This is not supposed to be allowed, but... we'll let it slide
                    DbLoaderErrorHandler.Handle("The refineable status on the item ID [" + tuple.GetKey <int>() + "] has been set to true but the item type is not an equipment. This is suspicious.", ErrorLevel.Warning);
                    builder.AppendLineUnix("\t" + attribute.AttributeName + ": true");
                }
                return;
            }

            if (val != defaultValue)
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLineUnix(val.ToString().ToLower());
            }
        }
예제 #7
0
        public override void SetValue(DbAttribute attribute, object value)
        {
            bool sameValue;

            try {
                sameValue = GetValue(attribute.Index).ToString() == value.ToString();
            }
            catch {
                sameValue = false;
            }

            try {
                base.SetValue(attribute, value);
            }
            catch {
                DbLoaderErrorHandler.Handle(("Failed to set or parse the value for [" + GetKey <TKey>() + "] at '" + attribute.DisplayName + "'. Value entered is : " + (value ?? "")).RemoveBreakLines(), ErrorLevel.NotSpecified);
                base.SetValue(attribute, attribute.Default);
            }

            if (!sameValue)
            {
                Modified = true;
            }
        }
예제 #8
0
        /// <summary>
        /// Converts a group from an ItemGroup to a Hercules entry
        /// </summary>
        /// <param name="gdb">The base db.</param>
        /// <param name="groupId">The group id.</param>
        /// <param name="aegisNames">The aegis names.</param>
        /// <param name="names">The names.</param>
        /// <returns>A string for an ItemGroup entry converted to Hercules's format</returns>
        public static string ToHerculesDbEntry(BaseDb gdb, int groupId, List <string> aegisNames, List <string> names)
        {
            StringBuilder builder  = new StringBuilder();
            var           dbItems  = gdb.GetMeta <int>(ServerDbs.Items);
            var           dbGroups = gdb.Get <int>(ServerDbs.ItemGroups);

            if (groupId < 500)
            {
                var    dbConstants = gdb.Get <string>(ServerDbs.Constants);
                string sId         = groupId.ToString(CultureInfo.InvariantCulture);
                // The current db is from rAthena

                var    tuple    = dbConstants.FastItems.FirstOrDefault(p => p.GetValue <string>(1) == sId && p.GetKey <string>().StartsWith("IG_"));
                string constant = null;

                if (tuple != null)
                {
                    constant = tuple.GetKey <string>().Substring(3);
                }
                else
                {
                    var res = DbWriterMethods.Constants.Where(p => p.Value == groupId).ToList();

                    if (res.Count > 0)
                    {
                        constant = res[0].Key;
                    }
                }

                if (constant != null)
                {
                    string originalConstantValue = constant;
                    ReadableTuple <int> tupleItem;

                    // Attempts to retrieve the item based on the script
                    tupleItem = dbItems.FastItems.FirstOrDefault(p => p.GetValue <string>(ServerItemAttributes.Script).IndexOf("getrandgroupitem(IG_" + originalConstantValue + ")", StringComparison.OrdinalIgnoreCase) > -1);

                    if (tupleItem == null)
                    {
                        // Attempts to retrieve the item based on a formatted constant name (with underscore)

                        StringBuilder temp = new StringBuilder();
                        temp.Append(constant[0]);

                        for (int i = 1; i < constant.Length; i++)
                        {
                            if (constant[i] == '_')
                            {
                                i++;

                                if (i < constant.Length)
                                {
                                    temp.Append(constant[i]);
                                }
                            }
                            else if (char.IsUpper(constant[i]))
                            {
                                temp.Append('_');
                                temp.Append(constant[i]);
                            }
                            else
                            {
                                temp.Append(constant[i]);
                            }
                        }

                        constant = temp.ToString();

                        // Attempts to retrieve the item with the Old prefix
                        string oldConstant = "Old_" + constant;

                        // Attempts to retrieve the item without the Old prefix
                        tupleItem = dbItems.FastItems.FirstOrDefault(p => p.GetStringValue(ServerItemAttributes.AegisName.Index) == oldConstant);

                        if (tupleItem == null)
                        {
                            tupleItem = dbItems.FastItems.FirstOrDefault(p => p.GetStringValue(ServerItemAttributes.AegisName.Index) == constant);
                        }
                    }

                    // Retrieve the closest item based on the names in the ItemDb.
                    // It uses the Levenshtein distance algorithm to find the clostest match.
                    // This method 'always' returns a value, but a warning is prompted to the user in the error console.
                    if (tupleItem == null)
                    {
                        List <string> values1 = aegisNames;
                        List <string> values2 = names;

                        string closestMatch1 = Methods.ClosestString(originalConstantValue, values1);
                        string closestMatch2 = Methods.ClosestString(originalConstantValue, values2);

                        int lev1 = Methods.LevenshteinDistance(originalConstantValue, closestMatch1);
                        int lev2 = Methods.LevenshteinDistance(originalConstantValue, closestMatch2);

                        tupleItem = dbItems.FastItems[lev1 < lev2 ? values1.IndexOf(closestMatch1) : values2.IndexOf(closestMatch2)];

                        string closestMatch = tupleItem.GetValue <string>(ServerItemAttributes.AegisName);

                        if (Math.Min(lev1, lev2) != 0 && closestMatch.Replace("_", "") != constant)
                        {
                            DbLoaderErrorHandler.Handle("A suspicious conversion occurred for the item [" + originalConstantValue + "]. The group item name is [" + tupleItem.GetValue <string>(ServerItemAttributes.AegisName) + "].");
                        }
                    }

                    builder.AppendLine(tupleItem.GetValue <string>(ServerItemAttributes.AegisName) + ": (");

                    Dictionary <int, ReadableTuple <int> > table = (Dictionary <int, ReadableTuple <int> >)dbGroups.GetTuple(groupId).GetRawValue(ServerItemGroupAttributes.Table.Index);

                    foreach (var pair in table)
                    {
                        tupleItem = dbItems.TryGetTuple(pair.Key);
                        string name = tupleItem == null ? "ID" + pair.Key : tupleItem.GetValue <string>(ServerItemAttributes.AegisName);

                        if (pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate) == "1")
                        {
                            builder.Append("\t\"");
                            builder.Append(name);
                            builder.AppendLine("\",");
                        }
                        else
                        {
                            builder.Append("\t(\"");
                            builder.Append(name);
                            builder.Append("\",");
                            builder.Append(pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate));
                            builder.AppendLine("),");
                        }
                    }

                    builder.Append(")");
                }
                else
                {
                    DbLoaderErrorHandler.Handle("Failed to find the constant name with the id [" + sId + "].");
                }
            }
            else
            {
                // The current db is from Hercules
                var tuple = dbItems.TryGetTuple(groupId);

                if (tuple != null)
                {
                    builder.AppendLine(tuple.GetValue <string>(ServerItemAttributes.AegisName) + ": (");

                    Dictionary <int, ReadableTuple <int> > table = (Dictionary <int, ReadableTuple <int> >)dbGroups.GetTuple(groupId).GetRawValue(ServerItemGroupAttributes.Table.Index);

                    foreach (var pair in table)
                    {
                        tuple = dbItems.TryGetTuple(pair.Key);
                        string name = tuple == null ? "ID" + pair.Key : tuple.GetValue <string>(ServerItemAttributes.AegisName);

                        if (pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate) == "1")
                        {
                            builder.Append("\t\"");
                            builder.Append(name);
                            builder.AppendLine("\",");
                        }
                        else
                        {
                            builder.Append("\t(\"");
                            builder.Append(name);
                            builder.Append("\",");
                            builder.Append(pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate));
                            builder.AppendLine("),");
                        }
                    }

                    builder.Append(")");
                }
                else
                {
                    DbLoaderErrorHandler.Handle("Failed to retrieve the item ID associated with the group ID.", groupId.ToString(CultureInfo.InvariantCulture), ErrorLevel.Critical);
                }
            }

            return(builder.ToString());
        }
예제 #9
0
 public void ReportIdException(string exception, object item, ErrorLevel errorLevel = ErrorLevel.Warning)
 {
     DbLoaderErrorHandler.Handle(exception, item.ToString(), errorLevel);
 }