Commit bdda910d authored by ElderLich's avatar ElderLich

Feature: Add $whitelist mode support in lflist.conf

Implemented $whitelist parsing for both MDPro3 and YGOSharp banlist loaders. In whitelist mode, any card not explicitly listed is treated as banned. Also added support for count=3 as explicit unlimited so whitelist lists can allow cards intentionally.
parent bc6391e9
......@@ -8,6 +8,8 @@ namespace MDPro3.Duel.YGOSharp
public IList<int> BannedIds { get; private set; }
public IList<int> LimitedIds { get; private set; }
public IList<int> SemiLimitedIds { get; private set; }
public IList<int> UnlimitedIds { get; private set; }
public bool WhitelistOnly { get; private set; }
public uint Hash { get; private set; }
public string Name = "";
......@@ -16,6 +18,8 @@ namespace MDPro3.Duel.YGOSharp
BannedIds = new List<int>();
LimitedIds = new List<int>();
SemiLimitedIds = new List<int>();
UnlimitedIds = new List<int>();
WhitelistOnly = false;
Hash = 0x7dfcee6a;
}
......@@ -37,7 +41,9 @@ namespace MDPro3.Duel.YGOSharp
return 1;
if (SemiLimitedIds.Contains(cardId))
return 2;
return 3;
if (UnlimitedIds.Contains(cardId))
return 3;
return WhitelistOnly ? 0 : 3;
}
else
{
......@@ -47,14 +53,24 @@ namespace MDPro3.Duel.YGOSharp
return 1;
if (SemiLimitedIds.Contains(al))
return 2;
return 3;
if (UnlimitedIds.Contains(al))
return 3;
return WhitelistOnly ? 0 : 3;
}
}
public void EnableWhitelistMode()
{
if (WhitelistOnly)
return;
WhitelistOnly = true;
Hash ^= 0x0f0f0f0f;
}
public void Add(int cardId, int quantity)
{
if (quantity < 0 || quantity > 2)
if (quantity < 0 || quantity > 3)
return;
switch (quantity)
{
......@@ -67,9 +83,12 @@ namespace MDPro3.Duel.YGOSharp
case 2:
SemiLimitedIds.Add(cardId);
break;
case 3:
UnlimitedIds.Add(cardId);
break;
}
uint code = (uint)cardId;
Hash = Hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + quantity)) | (code >> (5 - quantity)));
}
}
}
\ No newline at end of file
}
......@@ -182,6 +182,12 @@ namespace MDPro3.Duel.YGOSharp
Banlists.Add(current);
continue;
}
if (line.StartsWith("$"))
{
if (current != null && line.Equals("$whitelist", StringComparison.OrdinalIgnoreCase))
current.EnableWhitelistMode();
continue;
}
if (!line.Contains(" "))
continue;
if (current == null)
......
......@@ -7,6 +7,8 @@ namespace YGOSharp
public IList<int> BannedIds { get; private set; }
public IList<int> LimitedIds { get; private set; }
public IList<int> SemiLimitedIds { get; private set; }
public IList<int> UnlimitedIds { get; private set; }
public bool WhitelistOnly { get; private set; }
public uint Hash { get; private set; }
public Banlist()
......@@ -14,6 +16,8 @@ namespace YGOSharp
BannedIds = new List<int>();
LimitedIds = new List<int>();
SemiLimitedIds = new List<int>();
UnlimitedIds = new List<int>();
WhitelistOnly = false;
Hash = 0x7dfcee6a;
}
......@@ -25,12 +29,22 @@ namespace YGOSharp
return 1;
if (SemiLimitedIds.Contains(cardId))
return 2;
return 3;
if (UnlimitedIds.Contains(cardId))
return 3;
return WhitelistOnly ? 0 : 3;
}
public void EnableWhitelistMode()
{
if (WhitelistOnly)
return;
WhitelistOnly = true;
Hash ^= 0x0f0f0f0f;
}
public void Add(int cardId, int quantity)
{
if (quantity < 0 || quantity > 2)
if (quantity < 0 || quantity > 3)
return;
switch (quantity)
{
......@@ -43,9 +57,12 @@ namespace YGOSharp
case 2:
SemiLimitedIds.Add(cardId);
break;
case 3:
UnlimitedIds.Add(cardId);
break;
}
uint code = (uint)cardId;
Hash = Hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + quantity)) | (code >> (5 - quantity)));
}
}
}
\ No newline at end of file
}
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
namespace YGOSharp
......@@ -25,6 +26,12 @@ namespace YGOSharp
Banlists.Add(current);
continue;
}
if (line.StartsWith("$"))
{
if (current != null && line.Equals("$whitelist", StringComparison.OrdinalIgnoreCase))
current.EnableWhitelistMode();
continue;
}
if (!line.Contains(" "))
continue;
if (current == null)
......@@ -44,4 +51,4 @@ namespace YGOSharp
return 0;
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment