Enforce species, level, and gender requirements serverside.

This commit is contained in:
Greg Edwards
2014-04-28 02:54:01 -04:00
parent 007c15b78b
commit 392f9952cd
2 changed files with 26 additions and 0 deletions

View File

@@ -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;

View File

@@ -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;