mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-09-30 13:16:36 -05:00
Enforce species, level, and gender requirements serverside.
This commit is contained in:
@@ -349,6 +349,13 @@ namespace PokeFoundations.GTS
|
||||
int targetPid = BitConverter.ToInt32(data, 296);
|
||||
GtsDatagram4 result = DataAbstract.Instance.GtsDataForUser4(targetPid);
|
||||
|
||||
// enforce request requirements server side
|
||||
if (!upload.CanTrade(result))
|
||||
{
|
||||
Error400(context);
|
||||
return;
|
||||
}
|
||||
|
||||
// todo: maybe strong type this
|
||||
object[] tag = new object[2];
|
||||
tag[0] = upload;
|
||||
|
||||
@@ -150,6 +150,19 @@ namespace PokeFoundations.Structures
|
||||
return new GtsDatagram4(Save());
|
||||
}
|
||||
|
||||
public bool CanTrade(GtsDatagram4 other)
|
||||
{
|
||||
if (Species != other.RequestedSpecies) return false;
|
||||
if (other.RequestedGender != Genders.Either && Gender != other.RequestedGender) return false;
|
||||
if (CheckLevels(other.RequestedMinLevel, other.RequestedMaxLevel, Level)) return false;
|
||||
|
||||
if (RequestedSpecies != other.Species) return false;
|
||||
if (RequestedGender != Genders.Either && other.Gender != RequestedGender) return false;
|
||||
if (CheckLevels(RequestedMinLevel, RequestedMaxLevel, other.Level)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void FlagTraded(GtsDatagram4 other)
|
||||
{
|
||||
Species = other.Species;
|
||||
@@ -165,6 +178,12 @@ namespace PokeFoundations.Structures
|
||||
IsExchanged = 0x01;
|
||||
}
|
||||
|
||||
public static bool CheckLevels(byte min, byte max, byte other)
|
||||
{
|
||||
if (max == 0) max = 255;
|
||||
return other >= min && other <= max;
|
||||
}
|
||||
|
||||
public static DateTime ? TimestampToDate(ulong timestamp)
|
||||
{
|
||||
if (timestamp == 0) return null;
|
||||
|
||||
Reference in New Issue
Block a user