From dd13c270b3d5e92a34b13c692b60b2fc1843c2d0 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Wed, 9 Jul 2014 22:18:29 -0400 Subject: [PATCH] Fixed some issues with the GenV Global Terminal while testing. --- GlobalTerminalService/GTServer5.cs | 4 +- library/Data/DataAbstract.cs | 2 +- library/Data/DataMysql.cs | 81 ++++++++++++------------ library/Structures/BattleVideoHeader5.cs | 8 +-- 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/GlobalTerminalService/GTServer5.cs b/GlobalTerminalService/GTServer5.cs index bef66462..4770f1fc 100644 --- a/GlobalTerminalService/GTServer5.cs +++ b/GlobalTerminalService/GTServer5.cs @@ -144,7 +144,7 @@ namespace PkmnFoundations.GlobalTerminalService } // todo: validate or log some of this? - BattleVideoSearchTypes5 type = (BattleVideoSearchTypes5)BitConverter.ToUInt32(data, 0x140); + BattleVideoRankings5 type = (BattleVideoRankings5)BitConverter.ToUInt32(data, 0x140); ushort species = BitConverter.ToUInt16(data, 0x144); BattleVideoMetagames5 meta = (BattleVideoMetagames5)data[0x146]; // Byte 148 contains a magic number related to the searched metagame. @@ -153,7 +153,7 @@ namespace PkmnFoundations.GlobalTerminalService byte region = data[0x14b]; Console.Write("Searching for "); - if (type != BattleVideoSearchTypes5.None) + if (type != BattleVideoRankings5.None) Console.Write("{0}, ", type); if (species != 0xffff) Console.Write("species {0}, ", species); diff --git a/library/Data/DataAbstract.cs b/library/Data/DataAbstract.cs index f6f59b54..7313795e 100644 --- a/library/Data/DataAbstract.cs +++ b/library/Data/DataAbstract.cs @@ -102,7 +102,7 @@ namespace PkmnFoundations.Data public abstract MusicalRecord5[] MusicalSearch5(ushort species, int count); public abstract long BattleVideoUpload5(BattleVideoRecord5 record); - public abstract BattleVideoHeader5[] BattleVideoSearch5(ushort species, BattleVideoSearchTypes5 type, BattleVideoMetagames5 metagame, byte country, byte region, int count); + public abstract BattleVideoHeader5[] BattleVideoSearch5(ushort species, BattleVideoRankings5 type, BattleVideoMetagames5 metagame, byte country, byte region, int count); public abstract BattleVideoRecord5 BattleVideoGet5(long serial); #endregion } diff --git a/library/Data/DataMysql.cs b/library/Data/DataMysql.cs index 4a766e98..095b2d75 100644 --- a/library/Data/DataMysql.cs +++ b/library/Data/DataMysql.cs @@ -1141,7 +1141,7 @@ namespace PkmnFoundations.Data MySqlDataReader reader = (MySqlDataReader)db.ExecuteReader("SELECT pid, " + "SerialNumber, Data FROM TerminalMusicals5 " + "WHERE EXISTS(SELECT * FROM TerminalMusicalPokemon5 " + - "WHERE musical_id = TerminalBattleVideos4.id AND Species = @species) " + + "WHERE musical_id = TerminalMusicals5.SerialNumber AND Species = @species) " + "ORDER BY TimeAdded DESC LIMIT @count", new MySqlParameter("@species", species), new MySqlParameter("@count", count)); @@ -1261,7 +1261,7 @@ namespace PkmnFoundations.Data } } - public override BattleVideoHeader5[] BattleVideoSearch5(ushort species, BattleVideoSearchTypes5 type, BattleVideoMetagames5 metagame, byte country, byte region, int count) + public override BattleVideoHeader5[] BattleVideoSearch5(ushort species, BattleVideoRankings5 ranking, BattleVideoMetagames5 metagame, byte country, byte region, int count) { using (MySqlConnection db = CreateConnection()) { @@ -1269,49 +1269,52 @@ namespace PkmnFoundations.Data String where = ""; bool hasSearch = false; - switch (type) + if (ranking == BattleVideoRankings5.None) { - case BattleVideoSearchTypes5.TopLinkBattles: - break; - case BattleVideoSearchTypes5.TopSubwayBattles: - break; - } + switch (ranking) + { + case BattleVideoRankings5.LinkBattles: + break; + case BattleVideoRankings5.SubwayBattles: + break; + } - if (species != 0xffff) - { - where += (hasSearch ? " AND " : " WHERE ") + - "EXISTS(SELECT * FROM TerminalBattleVideoPokemon5 " + - "WHERE video_id = TerminalBattleVideos5.id AND Species = @species)"; - _params.Add(new MySqlParameter("@species", species)); - hasSearch = true; - } + if (species != 0xffff) + { + where += (hasSearch ? " AND " : " WHERE ") + + "EXISTS(SELECT * FROM TerminalBattleVideoPokemon5 " + + "WHERE video_id = TerminalBattleVideos5.id AND Species = @species)"; + _params.Add(new MySqlParameter("@species", species)); + hasSearch = true; + } - // todo: find out if there are ranged searches on GenV too. - /* - if (metagame == BattleVideoMetagames4.SearchColosseumSingleNoRestrictions) - metagame = BattleVideoMetagames4.ColosseumSingleNoRestrictions; - if (metagame == BattleVideoMetagames4.SearchColosseumDoubleNoRestrictions) - metagame = BattleVideoMetagames4.ColosseumDoubleNoRestrictions; - * */ + // todo: find out if there are ranged searches on GenV too. + /* + if (metagame == BattleVideoMetagames4.SearchColosseumSingleNoRestrictions) + metagame = BattleVideoMetagames4.ColosseumSingleNoRestrictions; + if (metagame == BattleVideoMetagames4.SearchColosseumDoubleNoRestrictions) + metagame = BattleVideoMetagames4.ColosseumDoubleNoRestrictions; + * */ - if (metagame != BattleVideoMetagames5.None) - { - where += (hasSearch ? " AND " : " WHERE ") + "Metagame = @metagame"; - _params.Add(new MySqlParameter("@metagame", (byte)metagame)); - hasSearch = true; - } + if (metagame != BattleVideoMetagames5.None) + { + where += (hasSearch ? " AND " : " WHERE ") + "Metagame = @metagame"; + _params.Add(new MySqlParameter("@metagame", (byte)metagame)); + hasSearch = true; + } - if (country != 0xff) - { - where += (hasSearch ? " AND " : " WHERE ") + "Country = @country"; - _params.Add(new MySqlParameter("@country", country)); - hasSearch = true; - } + if (country != 0xff) + { + where += (hasSearch ? " AND " : " WHERE ") + "Country = @country"; + _params.Add(new MySqlParameter("@country", country)); + hasSearch = true; + } - if (region != 0xff) - { - where += (hasSearch ? " AND " : " WHERE ") + "Region = @region"; - _params.Add(new MySqlParameter("@region", region)); + if (region != 0xff) + { + where += (hasSearch ? " AND " : " WHERE ") + "Region = @region"; + _params.Add(new MySqlParameter("@region", region)); + } } _params.Add(new MySqlParameter("@count", count)); diff --git a/library/Structures/BattleVideoHeader5.cs b/library/Structures/BattleVideoHeader5.cs index 5e914f07..0ffecb5a 100644 --- a/library/Structures/BattleVideoHeader5.cs +++ b/library/Structures/BattleVideoHeader5.cs @@ -106,11 +106,11 @@ namespace PkmnFoundations.Structures BattleCompetition = 0x38, } - public enum BattleVideoSearchTypes5 : uint + public enum BattleVideoRankings5 : uint { None = 0x00000000, - Latest30 = 0x00000001, - TopLinkBattles = 0x00000003, - TopSubwayBattles = 0x00000002, + Newest30 = 0x00000001, + LinkBattles = 0x00000003, + SubwayBattles = 0x00000002, } }