fix: Cleans up core code (#1187)

**Only one functional change**
* Fixes a bug in LogFactory where `Warning` is being logged as `Information`

Non-functional changes:
* Updates/Fixes copyright headers
* Removes namespace scopes for core files.

View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
Kamron Batman 2022-10-10 21:47:08 -07:00 committed by GitHub
parent 0138d40bda
commit f268d5d4e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
262 changed files with 28527 additions and 28646 deletions

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: MapLoader.cs *
* *
@ -22,125 +22,124 @@ using System.Text.Json.Serialization;
using Server.Json;
using Server.Logging;
namespace Server
namespace Server;
public static class MapLoader
{
public static class MapLoader
private static readonly ILogger logger = LogFactory.GetLogger(typeof(MapLoader));
/* Here we configure all maps. Some notes:
*
* 1) The first 32 maps are reserved for core use.
* 2) Map 127 is reserved for core use.
* 3) Map 255 is reserved for core use.
* 4) Changing or removing any predefined maps may cause server instability.
*
* Map definitions are modified in Data/Map Definitions/<expansion>.json:
* - <index> : An unreserved unique index for this map
* - <id> : An identification number used in client communications. For any visible maps, this value must be from 0-5
* - <fileIndex> : A file identification number. For any visible maps, this value must be from 0-5
* - <width>, <height> : Size of the map (in tiles)
* - <season> : Season of the map. 0 = Spring, 1 = Summer, 2 = Fall, 3 = Winter, 4 = Desolation
* - <name> : Reference name for the map, used in props gump, get/set commands, region loading, etc
* - <rules> : Rules and restrictions associated with the map. See documentation for details
*/
[CallPriority(2)]
public static void Configure()
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(MapLoader));
var failures = new List<string>();
var count = 0;
/* Here we configure all maps. Some notes:
*
* 1) The first 32 maps are reserved for core use.
* 2) Map 127 is reserved for core use.
* 3) Map 255 is reserved for core use.
* 4) Changing or removing any predefined maps may cause server instability.
*
* Map definitions are modified in Data/Map Definitions/<expansion>.json:
* - <index> : An unreserved unique index for this map
* - <id> : An identification number used in client communications. For any visible maps, this value must be from 0-5
* - <fileIndex> : A file identification number. For any visible maps, this value must be from 0-5
* - <width>, <height> : Size of the map (in tiles)
* - <season> : Season of the map. 0 = Spring, 1 = Summer, 2 = Fall, 3 = Winter, 4 = Desolation
* - <name> : Reference name for the map, used in props gump, get/set commands, region loading, etc
* - <rules> : Rules and restrictions associated with the map. See documentation for details
*/
[CallPriority(2)]
public static void Configure()
var path = Path.Combine(Core.BaseDirectory, "Data/map-definitions.json");
logger.Information("Loading Map Definitions");
var stopwatch = Stopwatch.StartNew();
var maps = JsonConfig.Deserialize<List<MapDefinition>>(path);
if (maps == null)
{
var failures = new List<string>();
var count = 0;
throw new JsonException($"Failed to deserialize {path}.");
}
var path = Path.Combine(Core.BaseDirectory, "Data/map-definitions.json");
logger.Information("Loading Map Definitions");
var stopwatch = Stopwatch.StartNew();
var maps = JsonConfig.Deserialize<List<MapDefinition>>(path);
if (maps == null)
foreach (var def in maps)
{
try
{
throw new JsonException($"Failed to deserialize {path}.");
RegisterMap(def);
count++;
}
foreach (var def in maps)
catch (Exception ex)
{
try
{
RegisterMap(def);
count++;
}
catch (Exception ex)
{
logger.Debug(ex, "Failed to load map definition {MapDefName} ({MapDefId})", def.Name, def.Id);
failures.Add($"\tInvalid map definition {def.Name} ({def.Id})");
}
}
stopwatch.Stop();
if (failures.Count > 0)
{
logger.Warning(
"Map Definitions loaded with failures ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
logger.Warning("Map load failures: {Failure}", failures);
}
else
{
logger.Information(
"Map Definitions loaded successfully ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
logger.Debug(ex, "Failed to load map definition {MapDefName} ({MapDefId})", def.Name, def.Id);
failures.Add($"\tInvalid map definition {def.Name} ({def.Id})");
}
}
private static void RegisterMap(MapDefinition mapDefinition)
stopwatch.Stop();
if (failures.Count > 0)
{
var newMap = new Map(
mapDefinition.Id,
mapDefinition.Index,
mapDefinition.FileIndex,
Math.Max(mapDefinition.Width, Map.SectorSize),
Math.Max(mapDefinition.Height, Map.SectorSize),
mapDefinition.Season,
mapDefinition.Name,
mapDefinition.Rules
logger.Warning(
"Map Definitions loaded with failures ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
Map.Maps[mapDefinition.Index] = newMap;
Map.AllMaps.Add(newMap);
logger.Warning("Map load failures: {Failure}", failures);
}
internal class MapDefinition
else
{
[JsonPropertyName("index")]
public int Index { get; set; }
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("fileIndex")]
public int FileIndex { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("width")]
public int Width { get; set; }
[JsonPropertyName("height")]
public int Height { get; set; }
[JsonPropertyName("season")]
public int Season { get; set; }
[JsonPropertyName("rules")]
public MapRules Rules { get; set; }
logger.Information(
"Map Definitions loaded successfully ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
}
}
private static void RegisterMap(MapDefinition mapDefinition)
{
var newMap = new Map(
mapDefinition.Id,
mapDefinition.Index,
mapDefinition.FileIndex,
Math.Max(mapDefinition.Width, Map.SectorSize),
Math.Max(mapDefinition.Height, Map.SectorSize),
mapDefinition.Season,
mapDefinition.Name,
mapDefinition.Rules
);
Map.Maps[mapDefinition.Index] = newMap;
Map.AllMaps.Add(newMap);
}
internal class MapDefinition
{
[JsonPropertyName("index")]
public int Index { get; set; }
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("fileIndex")]
public int FileIndex { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("width")]
public int Width { get; set; }
[JsonPropertyName("height")]
public int Height { get; set; }
[JsonPropertyName("season")]
public int Season { get; set; }
[JsonPropertyName("rules")]
public MapRules Rules { get; set; }
}
}