From 392f9952cd596b899719a9990079c92d34f8fea3 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Mon, 28 Apr 2014 02:54:01 -0400 Subject: [PATCH] Enforce species, level, and gender requirements serverside. --- gts/pokemondpds.ashx.cs | 7 +++++++ library/Structures/GtsDatagram4.cs | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/gts/pokemondpds.ashx.cs b/gts/pokemondpds.ashx.cs index 61795577..6c08bc08 100644 --- a/gts/pokemondpds.ashx.cs +++ b/gts/pokemondpds.ashx.cs @@ -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; diff --git a/library/Structures/GtsDatagram4.cs b/library/Structures/GtsDatagram4.cs index b75d9a62..337afb1a 100644 --- a/library/Structures/GtsDatagram4.cs +++ b/library/Structures/GtsDatagram4.cs @@ -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;