Skip to content

Commit

Permalink
Only load mobs from enabled regions
Browse files Browse the repository at this point in the history
Respect DISABLED_REGIONS serverproperty
Add DBColumn.IsNotIn operator
  • Loading branch information
NetDwarf committed Sep 30, 2023
1 parent beac167 commit 37a6288
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions DOLDatabase/WhereClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@ internal DBColumn(string columnName)
public WhereClause IsNull() => new PlainTextExpression(Name, "IS NULL");
public WhereClause IsNotNull() => new PlainTextExpression(Name, "IS NOT NULL");
public WhereClause IsIn<T>(IEnumerable<T> values) => new FilterExpression(Name, "IN", values.Cast<object>());
public WhereClause IsNotIn<T>(IEnumerable<T> values) => new FilterExpression(Name, "NOT IN", values.Cast<object>());
}
}
24 changes: 13 additions & 11 deletions GameServer/world/WorldMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,19 @@ public static bool EarlyInit(out RegionData[] regionsData)
log.Debug("loading mobs from DB...");

var mobList = new List<Mob>();
if (ServerProperties.Properties.DEBUG_LOAD_REGIONS != string.Empty)
{
foreach (string loadRegion in Util.SplitCSV(ServerProperties.Properties.DEBUG_LOAD_REGIONS, true))
{
mobList.AddRange(DOLDB<Mob>.SelectObjects(DB.Column(nameof(Mob.Region)).IsEqualTo(loadRegion)));
}
}
else
{
mobList.AddRange(GameServer.Database.SelectAllObjects<Mob>());
}
var debugLoadRegions = Util.SplitCSV(ServerProperties.Properties.DEBUG_LOAD_REGIONS, true);

if (debugLoadRegions.Count > 0)
{
var whereClause = DB.Column(nameof(Mob.Region)).IsIn(debugLoadRegions);
mobList.AddRange(DOLDB<Mob>.SelectObjects(whereClause));
}
else
{
var disabledRegions = Util.SplitCSV(ServerProperties.Properties.DISABLED_REGIONS, true);
var whereClause = DB.Column(nameof(Mob.Region)).IsNotIn(disabledRegions);
mobList.AddRange(DOLDB<Mob>.SelectObjects(whereClause));
}

var mobsByRegionId = new Dictionary<ushort, List<Mob>>(512);
foreach (Mob mob in mobList)
Expand Down
17 changes: 17 additions & 0 deletions Tests/UnitTests/UT_Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using DOL.GS;
using NUnit.Framework;

namespace DOL.UnitTests;

[TestFixture]
public class UT_Util
{
[Test]
public void SplitCSV_EmptyString_EmptyList()
{
var actual = Util.SplitCSV("");
var expected = new List<string>();
Assert.AreEqual(expected, actual);
}
}

0 comments on commit 37a6288

Please sign in to comment.