mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-24 15:26:48 -05:00
Pass a Pokedex instance to the GtsRecord ctors
This commit is contained in:
parent
4c7e46bcdb
commit
8d8d0e44cc
|
|
@ -14,7 +14,7 @@ namespace PkmnFoundations.GTS
|
|||
void Application_Start(object sender, EventArgs e)
|
||||
{
|
||||
// Code that runs on application startup
|
||||
Application["pkmncfPokedex"] = new Pokedex.Pokedex(Database.Instance, false);
|
||||
AppStateHelper.Pokedex(Application);
|
||||
}
|
||||
|
||||
void Application_End(object sender, EventArgs e)
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@
|
|||
<Compile Include="pokemondpds_web.ashx.cs">
|
||||
<DependentUpon>pokemondpds_web.ashx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="src\AppStateHelper.cs" />
|
||||
<Compile Include="src\FakeOpponentGenerator4.cs" />
|
||||
<Compile Include="syachi2ds.ashx.cs">
|
||||
<DependentUpon>syachi2ds.ashx</DependentUpon>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
public override void ProcessGamestatsRequest(byte[] data, MemoryStream response, string url, int pid, HttpContext context, GamestatsSession session)
|
||||
{
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(context.Application);
|
||||
|
||||
switch (url)
|
||||
{
|
||||
default:
|
||||
|
|
@ -93,7 +95,7 @@ namespace PkmnFoundations.GTS
|
|||
* in the GTS, it responds with 0x0004; if not, it responds
|
||||
* with 0x0005. */
|
||||
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pid);
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pokedex, pid);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
@ -125,7 +127,7 @@ namespace PkmnFoundations.GTS
|
|||
// this is only called if result.asp returned 4.
|
||||
// todo: what does this do if the contained pokemon is traded??
|
||||
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pid);
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pokedex, pid);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
@ -146,7 +148,7 @@ namespace PkmnFoundations.GTS
|
|||
{
|
||||
SessionManager.Remove(session);
|
||||
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pid);
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pokedex, pid);
|
||||
if (record == null)
|
||||
{
|
||||
response.Write(new byte[] { 0x00, 0x00 }, 0, 2);
|
||||
|
|
@ -175,7 +177,7 @@ namespace PkmnFoundations.GTS
|
|||
{
|
||||
SessionManager.Remove(session);
|
||||
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pid);
|
||||
GtsRecord4 record = Database.Instance.GtsDataForUser4(pokedex, pid);
|
||||
if (record == null)
|
||||
{
|
||||
response.Write(new byte[] { 0x00, 0x00 }, 0, 2);
|
||||
|
|
@ -212,7 +214,7 @@ namespace PkmnFoundations.GTS
|
|||
}
|
||||
|
||||
// todo: add transaction
|
||||
if (Database.Instance.GtsDataForUser4(pid) != null)
|
||||
if (Database.Instance.GtsDataForUser4(pokedex, pid) != null)
|
||||
{
|
||||
// there's already a pokemon inside
|
||||
SessionManager.Remove(session);
|
||||
|
|
@ -223,7 +225,7 @@ namespace PkmnFoundations.GTS
|
|||
// keep the record in memory while we wait for post_finish.asp request
|
||||
byte[] recordBinary = new byte[292];
|
||||
Array.Copy(data, 0, recordBinary, 0, 292);
|
||||
GtsRecord4 record = new GtsRecord4(recordBinary);
|
||||
GtsRecord4 record = new GtsRecord4(pokedex, recordBinary);
|
||||
if (!record.Validate())
|
||||
{
|
||||
// hack check failed
|
||||
|
|
@ -315,7 +317,7 @@ namespace PkmnFoundations.GTS
|
|||
if (data.Length > 7) country = data[7];
|
||||
|
||||
if (resultsCount > 7) resultsCount = 7; // stop DDOS
|
||||
GtsRecord4[] records = Database.Instance.GtsSearch4(pid, species, gender, minLevel, maxLevel, country, resultsCount);
|
||||
GtsRecord4[] records = Database.Instance.GtsSearch4(pokedex, pid, species, gender, minLevel, maxLevel, country, resultsCount);
|
||||
foreach (GtsRecord4 record in records)
|
||||
{
|
||||
response.Write(record.Save(), 0, 292);
|
||||
|
|
@ -338,10 +340,10 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
byte[] uploadData = new byte[292];
|
||||
Array.Copy(data, 0, uploadData, 0, 292);
|
||||
GtsRecord4 upload = new GtsRecord4(uploadData);
|
||||
GtsRecord4 upload = new GtsRecord4(pokedex, uploadData);
|
||||
upload.IsExchanged = 0;
|
||||
int targetPid = BitConverter.ToInt32(data, 292);
|
||||
GtsRecord4 result = Database.Instance.GtsDataForUser4(targetPid);
|
||||
GtsRecord4 result = Database.Instance.GtsDataForUser4(pokedex, targetPid);
|
||||
DateTime ? searchTime = Database.Instance.GtsGetLastSearch4(pid);
|
||||
|
||||
if (result == null || searchTime == null ||
|
||||
|
|
|
|||
30
gts/src/AppStateHelper.cs
Normal file
30
gts/src/AppStateHelper.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using PkmnFoundations.Data;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
public static class AppStateHelper
|
||||
{
|
||||
public static Pokedex.Pokedex Pokedex(HttpApplicationState application)
|
||||
{
|
||||
return GetTypedApplicationObject(application, "pkmncfPokedex", () => new Pokedex.Pokedex(Database.Instance, false));
|
||||
}
|
||||
|
||||
public static T GetTypedApplicationObject<T>(HttpApplicationState application, String key, Func<T> initializer) where T : class
|
||||
{
|
||||
object o = application[key];
|
||||
T t = o as T;
|
||||
|
||||
if (t == null)
|
||||
{
|
||||
t = initializer();
|
||||
application.Add(key, t);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,8 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
public override void ProcessGamestatsRequest(byte[] request, MemoryStream response, string url, int pid, HttpContext context, GamestatsSession session)
|
||||
{
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(context.Application);
|
||||
|
||||
switch (url)
|
||||
{
|
||||
default:
|
||||
|
|
@ -83,7 +85,7 @@ namespace PkmnFoundations.GTS
|
|||
// my guess is that it's trainer profile info like setProfile.asp
|
||||
// There's a long string of 0s which could be a trainer card signature raster
|
||||
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pid);
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pokedex, pid);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
@ -112,7 +114,7 @@ namespace PkmnFoundations.GTS
|
|||
// todo: what does this do if the contained pokemon is traded??
|
||||
// todo: the same big blob of stuff from result.asp is sent here too.
|
||||
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pid);
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pokedex, pid);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
@ -135,7 +137,7 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
// todo: the same big blob of stuff from result.asp is sent here too.
|
||||
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pid);
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pokedex, pid);
|
||||
if (record == null)
|
||||
{
|
||||
response.Write(new byte[] { 0x00, 0x00 }, 0, 2);
|
||||
|
|
@ -164,7 +166,7 @@ namespace PkmnFoundations.GTS
|
|||
{
|
||||
SessionManager.Remove(session);
|
||||
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pid);
|
||||
GtsRecord5 record = Database.Instance.GtsDataForUser5(pokedex, pid);
|
||||
if (record == null)
|
||||
{
|
||||
response.Write(new byte[] { 0x00, 0x00 }, 0, 2);
|
||||
|
|
@ -203,7 +205,7 @@ namespace PkmnFoundations.GTS
|
|||
}
|
||||
|
||||
// todo: add transaction
|
||||
if (Database.Instance.GtsDataForUser5(pid) != null)
|
||||
if (Database.Instance.GtsDataForUser5(pokedex, pid) != null)
|
||||
{
|
||||
// there's already a pokemon inside
|
||||
SessionManager.Remove(session);
|
||||
|
|
@ -214,7 +216,7 @@ namespace PkmnFoundations.GTS
|
|||
// keep the record in memory while we wait for post_finish.asp request
|
||||
byte[] recordBinary = new byte[296];
|
||||
Array.Copy(request, 0, recordBinary, 0, 296);
|
||||
GtsRecord5 record = new GtsRecord5(recordBinary);
|
||||
GtsRecord5 record = new GtsRecord5(pokedex, recordBinary);
|
||||
|
||||
// todo: figure out what bytes 296-431 do:
|
||||
// appears to be 4 bytes of 00, 128 bytes of stuff, 4 bytes of 80 00 00 00
|
||||
|
|
@ -314,7 +316,7 @@ namespace PkmnFoundations.GTS
|
|||
if (request.Length > 7) country = request[7];
|
||||
|
||||
if (resultsCount > 7) resultsCount = 7; // stop DDOS
|
||||
GtsRecord5[] records = Database.Instance.GtsSearch5(pid, species, gender, minLevel, maxLevel, country, resultsCount);
|
||||
GtsRecord5[] records = Database.Instance.GtsSearch5(pokedex, pid, species, gender, minLevel, maxLevel, country, resultsCount);
|
||||
foreach (GtsRecord5 record in records)
|
||||
{
|
||||
response.Write(record.Save(), 0, 296);
|
||||
|
|
@ -337,10 +339,10 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
byte[] uploadData = new byte[296];
|
||||
Array.Copy(request, 0, uploadData, 0, 296);
|
||||
GtsRecord5 upload = new GtsRecord5(uploadData);
|
||||
GtsRecord5 upload = new GtsRecord5(pokedex, uploadData);
|
||||
upload.IsExchanged = 0;
|
||||
int targetPid = BitConverter.ToInt32(request, 296);
|
||||
GtsRecord5 result = Database.Instance.GtsDataForUser5(targetPid);
|
||||
GtsRecord5 result = Database.Instance.GtsDataForUser5(pokedex, targetPid);
|
||||
DateTime ? searchTime = Database.Instance.GtsGetLastSearch5(pid);
|
||||
|
||||
if (result == null || searchTime == null ||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ namespace PkmnFoundations.Data
|
|||
#endregion
|
||||
|
||||
#region GTS 4
|
||||
public GtsRecord4 GtsDataForUser4(MySqlTransaction tran, int pid)
|
||||
public GtsRecord4 GtsDataForUser4(MySqlTransaction tran, Pokedex.Pokedex pokedex, int pid)
|
||||
{
|
||||
using (MySqlDataReader reader = (MySqlDataReader)tran.ExecuteReader("SELECT Data, Species, Gender, Level, " +
|
||||
"RequestedSpecies, RequestedGender, RequestedMinLevel, RequestedMaxLevel, " +
|
||||
|
|
@ -145,7 +145,7 @@ namespace PkmnFoundations.Data
|
|||
reader.Close();
|
||||
return null;
|
||||
}
|
||||
GtsRecord4 result = Record4FromReader(reader);
|
||||
GtsRecord4 result = Record4FromReader(pokedex, reader);
|
||||
#if DEBUG
|
||||
AssertHelper.Equals(result.PID, pid);
|
||||
#endif
|
||||
|
|
@ -154,12 +154,12 @@ namespace PkmnFoundations.Data
|
|||
}
|
||||
}
|
||||
|
||||
public override GtsRecord4 GtsDataForUser4(int pid)
|
||||
public override GtsRecord4 GtsDataForUser4(Pokedex.Pokedex pokedex, int pid)
|
||||
{
|
||||
return WithTransaction(tran => GtsDataForUser4(tran, pid));
|
||||
return WithTransaction(tran => GtsDataForUser4(tran, pokedex, pid));
|
||||
}
|
||||
|
||||
public GtsRecord4 GtsGetRecord4(MySqlTransaction tran, long tradeId, bool isExchanged, bool allowHistory)
|
||||
public GtsRecord4 GtsGetRecord4(MySqlTransaction tran, Pokedex.Pokedex pokedex, long tradeId, bool isExchanged, bool allowHistory)
|
||||
{
|
||||
using (MySqlDataReader reader = (MySqlDataReader)tran.ExecuteReader("SELECT Data, Species, Gender, Level, " +
|
||||
"RequestedSpecies, RequestedGender, RequestedMinLevel, RequestedMaxLevel, " +
|
||||
|
|
@ -172,7 +172,7 @@ namespace PkmnFoundations.Data
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
GtsRecord4 result = Record4FromReader(reader);
|
||||
GtsRecord4 result = Record4FromReader(pokedex, reader);
|
||||
reader.Close();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ namespace PkmnFoundations.Data
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
GtsRecord4 result = Record4FromReader(reader);
|
||||
GtsRecord4 result = Record4FromReader(pokedex, reader);
|
||||
reader.Close();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -202,9 +202,9 @@ namespace PkmnFoundations.Data
|
|||
return null;
|
||||
}
|
||||
|
||||
public override GtsRecord4 GtsGetRecord4(long tradeId, bool isExchanged, bool allowHistory)
|
||||
public override GtsRecord4 GtsGetRecord4(Pokedex.Pokedex pokedex, long tradeId, bool isExchanged, bool allowHistory)
|
||||
{
|
||||
return WithTransaction(tran => GtsGetRecord4(tran, tradeId, isExchanged, allowHistory));
|
||||
return WithTransaction(tran => GtsGetRecord4(tran, pokedex, tradeId, isExchanged, allowHistory));
|
||||
}
|
||||
|
||||
public bool GtsDepositPokemon4(MySqlTransaction tran, GtsRecord4 record)
|
||||
|
|
@ -312,7 +312,7 @@ namespace PkmnFoundations.Data
|
|||
traded.FlagTraded(result);
|
||||
|
||||
ulong? trade_id = GtsGetDepositId4(tran, result.PID);
|
||||
GtsRecord4 resultOrig = GtsDataForUser4(tran, result.PID);
|
||||
GtsRecord4 resultOrig = GtsDataForUser4(tran, result.Pokedex, result.PID);
|
||||
if (resultOrig == null || resultOrig != result)
|
||||
// looks like the pokemon was ninja'd between the Exchange and Exchange_finish
|
||||
return false;
|
||||
|
|
@ -341,7 +341,7 @@ namespace PkmnFoundations.Data
|
|||
return WithTransactionSuccessful(tran => GtsTradePokemon4(tran, upload, result, partner_pid));
|
||||
}
|
||||
|
||||
public GtsRecord4[] GtsSearch4(MySqlTransaction tran, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
public GtsRecord4[] GtsSearch4(MySqlTransaction tran, Pokedex.Pokedex pokedex, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
{
|
||||
List<MySqlParameter> _params = new List<MySqlParameter>();
|
||||
String where = "WHERE pid != @pid AND IsExchanged = 0";
|
||||
|
|
@ -403,21 +403,21 @@ namespace PkmnFoundations.Data
|
|||
else records = new List<GtsRecord4>();
|
||||
|
||||
while (reader.Read())
|
||||
records.Add(Record4FromReader(reader));
|
||||
records.Add(Record4FromReader(pokedex, reader));
|
||||
|
||||
reader.Close();
|
||||
return records.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override GtsRecord4[] GtsSearch4(int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
public override GtsRecord4[] GtsSearch4(Pokedex.Pokedex pokedex, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
{
|
||||
return WithTransaction(tran => GtsSearch4(tran, pid, species, gender, minLevel, maxLevel, country, count));
|
||||
return WithTransaction(tran => GtsSearch4(tran, pokedex, pid, species, gender, minLevel, maxLevel, country, count));
|
||||
}
|
||||
|
||||
private static GtsRecord4 Record4FromReader(MySqlDataReader reader)
|
||||
private static GtsRecord4 Record4FromReader(Pokedex.Pokedex pokedex, MySqlDataReader reader)
|
||||
{
|
||||
GtsRecord4 result = new GtsRecord4();
|
||||
GtsRecord4 result = new GtsRecord4(pokedex);
|
||||
|
||||
byte[] data = new byte[236];
|
||||
reader.GetBytes(0, 0, data, 0, 236);
|
||||
|
|
@ -1108,7 +1108,7 @@ namespace PkmnFoundations.Data
|
|||
#endregion
|
||||
|
||||
#region GTS 5
|
||||
public GtsRecord5 GtsDataForUser5(MySqlTransaction tran, int pid)
|
||||
public GtsRecord5 GtsDataForUser5(MySqlTransaction tran, Pokedex.Pokedex pokedex, int pid)
|
||||
{
|
||||
using (MySqlDataReader reader = (MySqlDataReader)tran.ExecuteReader("SELECT Data, Unknown0, " +
|
||||
"Species, Gender, Level, " +
|
||||
|
|
@ -1124,7 +1124,7 @@ namespace PkmnFoundations.Data
|
|||
reader.Close();
|
||||
return null;
|
||||
}
|
||||
GtsRecord5 result = Record5FromReader(reader);
|
||||
GtsRecord5 result = Record5FromReader(pokedex, reader);
|
||||
#if DEBUG
|
||||
AssertHelper.Equals(result.PID, pid);
|
||||
#endif
|
||||
|
|
@ -1133,12 +1133,12 @@ namespace PkmnFoundations.Data
|
|||
}
|
||||
}
|
||||
|
||||
public override GtsRecord5 GtsDataForUser5(int pid)
|
||||
public override GtsRecord5 GtsDataForUser5(Pokedex.Pokedex pokedex, int pid)
|
||||
{
|
||||
return WithTransaction(tran => GtsDataForUser5(tran, pid));
|
||||
return WithTransaction(tran => GtsDataForUser5(tran, pokedex, pid));
|
||||
}
|
||||
|
||||
public GtsRecord5 GtsGetRecord5(MySqlTransaction tran, long tradeId, bool isExchanged, bool allowHistory)
|
||||
public GtsRecord5 GtsGetRecord5(MySqlTransaction tran, Pokedex.Pokedex pokedex, long tradeId, bool isExchanged, bool allowHistory)
|
||||
{
|
||||
using (MySqlDataReader reader = (MySqlDataReader)tran.ExecuteReader("SELECT Data, Unknown0, " +
|
||||
"Species, Gender, Level, " +
|
||||
|
|
@ -1152,7 +1152,7 @@ namespace PkmnFoundations.Data
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
GtsRecord5 result = Record5FromReader(reader);
|
||||
GtsRecord5 result = Record5FromReader(pokedex, reader);
|
||||
reader.Close();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1173,7 +1173,7 @@ namespace PkmnFoundations.Data
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
GtsRecord5 result = Record5FromReader(reader);
|
||||
GtsRecord5 result = Record5FromReader(pokedex, reader);
|
||||
reader.Close();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1183,9 +1183,9 @@ namespace PkmnFoundations.Data
|
|||
return null;
|
||||
}
|
||||
|
||||
public override GtsRecord5 GtsGetRecord5(long tradeId, bool isExchanged, bool allowHistory)
|
||||
public override GtsRecord5 GtsGetRecord5(Pokedex.Pokedex pokedex, long tradeId, bool isExchanged, bool allowHistory)
|
||||
{
|
||||
return WithTransaction(tran => GtsGetRecord5(tran, tradeId, isExchanged, allowHistory));
|
||||
return WithTransaction(tran => GtsGetRecord5(tran, pokedex, tradeId, isExchanged, allowHistory));
|
||||
}
|
||||
|
||||
public bool GtsDepositPokemon5(MySqlTransaction tran, GtsRecord5 record)
|
||||
|
|
@ -1295,7 +1295,7 @@ namespace PkmnFoundations.Data
|
|||
traded.FlagTraded(result);
|
||||
|
||||
ulong? trade_id = GtsGetDepositId5(tran, result.PID);
|
||||
GtsRecord5 resultOrig = GtsDataForUser5(tran, result.PID);
|
||||
GtsRecord5 resultOrig = GtsDataForUser5(tran, result.Pokedex, result.PID);
|
||||
if (resultOrig == null || resultOrig != result)
|
||||
// looks like the pokemon was ninja'd between the Exchange and Exchange_finish
|
||||
return false;
|
||||
|
|
@ -1324,12 +1324,12 @@ namespace PkmnFoundations.Data
|
|||
return WithTransactionSuccessful(tran => GtsTradePokemon5(tran, upload, result, partner_pid));
|
||||
}
|
||||
|
||||
public override GtsRecord5[] GtsSearch5(int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
public override GtsRecord5[] GtsSearch5(Pokedex.Pokedex pokedex, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
{
|
||||
return WithTransaction(tran => GtsSearch5(tran, pid, species, gender, minLevel, maxLevel, country, count));
|
||||
return WithTransaction(tran => GtsSearch5(tran, pokedex, pid, species, gender, minLevel, maxLevel, country, count));
|
||||
}
|
||||
|
||||
public GtsRecord5[] GtsSearch5(MySqlTransaction tran, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
|
||||
public GtsRecord5[] GtsSearch5(MySqlTransaction tran, Pokedex.Pokedex pokedex, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count)
|
||||
{
|
||||
List<MySqlParameter> _params = new List<MySqlParameter>();
|
||||
String where = "WHERE pid != @pid AND IsExchanged = 0";
|
||||
|
|
@ -1393,17 +1393,17 @@ namespace PkmnFoundations.Data
|
|||
else records = new List<GtsRecord5>();
|
||||
|
||||
while (reader.Read())
|
||||
records.Add(Record5FromReader(reader));
|
||||
records.Add(Record5FromReader(pokedex, reader));
|
||||
|
||||
reader.Close();
|
||||
return records.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private static GtsRecord5 Record5FromReader(MySqlDataReader reader)
|
||||
private static GtsRecord5 Record5FromReader(Pokedex.Pokedex pokedex, MySqlDataReader reader)
|
||||
{
|
||||
// xxx: Don't use ordinals here
|
||||
GtsRecord5 result = new GtsRecord5();
|
||||
GtsRecord5 result = new GtsRecord5(pokedex);
|
||||
|
||||
// xxx: Data and Unknown0 should share a database field.
|
||||
// (This requires migrating a lot of existing data)
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ namespace PkmnFoundations.Data
|
|||
#region GTS 4
|
||||
public const int GTS_VERSION_4 = 0;
|
||||
|
||||
public abstract GtsRecord4 GtsDataForUser4(int pid);
|
||||
public abstract GtsRecord4 GtsGetRecord4(long tradeId, bool isExchanged, bool allowHistory);
|
||||
public abstract GtsRecord4 GtsDataForUser4(Pokedex.Pokedex pokedex, int pid);
|
||||
public abstract GtsRecord4 GtsGetRecord4(Pokedex.Pokedex pokedex, long tradeId, bool isExchanged, bool allowHistory);
|
||||
|
||||
public abstract bool GtsDepositPokemon4(GtsRecord4 record);
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ namespace PkmnFoundations.Data
|
|||
public abstract bool GtsTradePokemon4(int pidSrc, int pidDest);
|
||||
public abstract bool GtsTradePokemon4(GtsRecord4 upload, GtsRecord4 result, int partner_pid);
|
||||
|
||||
public abstract GtsRecord4[] GtsSearch4(int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count);
|
||||
public abstract GtsRecord4[] GtsSearch4(Pokedex.Pokedex pokedex, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count);
|
||||
public abstract int GtsAvailablePokemon4();
|
||||
|
||||
public abstract void GtsSetLastSearch4(int pid);
|
||||
|
|
@ -100,8 +100,8 @@ namespace PkmnFoundations.Data
|
|||
#region GTS 5
|
||||
public const int GTS_VERSION_5 = 0;
|
||||
|
||||
public abstract GtsRecord5 GtsDataForUser5(int pid);
|
||||
public abstract GtsRecord5 GtsGetRecord5(long tradeId, bool isExchanged, bool allowHistory);
|
||||
public abstract GtsRecord5 GtsDataForUser5(Pokedex.Pokedex pokedex, int pid);
|
||||
public abstract GtsRecord5 GtsGetRecord5(Pokedex.Pokedex pokedex, long tradeId, bool isExchanged, bool allowHistory);
|
||||
|
||||
public abstract bool GtsDepositPokemon5(GtsRecord5 record);
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ namespace PkmnFoundations.Data
|
|||
public abstract bool GtsTradePokemon5(int pidSrc, int pidDest);
|
||||
public abstract bool GtsTradePokemon5(GtsRecord5 upload, GtsRecord5 result, int partner_pid);
|
||||
|
||||
public abstract GtsRecord5[] GtsSearch5(int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count);
|
||||
public abstract GtsRecord5[] GtsSearch5(Pokedex.Pokedex pokedex, int pid, ushort species, Genders gender, byte minLevel, byte maxLevel, byte country, int count);
|
||||
public abstract int GtsAvailablePokemon5();
|
||||
|
||||
public abstract void GtsSetLastSearch5(int pid);
|
||||
|
|
|
|||
|
|
@ -15,17 +15,33 @@ namespace PkmnFoundations.Structures
|
|||
/// </summary>
|
||||
public class GtsRecord4 : GtsRecordBase, IEquatable<GtsRecord4>
|
||||
{
|
||||
public GtsRecord4() : base()
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GtsRecord4(byte[] data) : base()
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, BinaryReader data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, byte[] data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, byte[] data, int offset)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data, offset);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
|
|
@ -152,7 +168,7 @@ namespace PkmnFoundations.Structures
|
|||
public GtsRecord4 Clone()
|
||||
{
|
||||
// todo: I am not very efficient
|
||||
return new GtsRecord4(Save());
|
||||
return new GtsRecord4(m_pokedex, Save());
|
||||
}
|
||||
|
||||
public bool Validate()
|
||||
|
|
|
|||
|
|
@ -15,17 +15,33 @@ namespace PkmnFoundations.Structures
|
|||
/// </summary>
|
||||
public class GtsRecord5 : GtsRecordBase, IEquatable<GtsRecord5>
|
||||
{
|
||||
public GtsRecord5()
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GtsRecord5(byte[] data)
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, BinaryReader data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, byte[] data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, byte[] data, int offset)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data, offset);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
|
|
@ -161,7 +177,7 @@ namespace PkmnFoundations.Structures
|
|||
public GtsRecord5 Clone()
|
||||
{
|
||||
// todo: I am not very efficient
|
||||
return new GtsRecord5(Save());
|
||||
return new GtsRecord5(m_pokedex, Save());
|
||||
}
|
||||
|
||||
public bool Validate()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,23 @@ namespace PkmnFoundations.Structures
|
|||
{
|
||||
public abstract class GtsRecordBase : BinarySerializableBase
|
||||
{
|
||||
public GtsRecordBase(Pokedex.Pokedex pokedex) : base()
|
||||
{
|
||||
m_pokedex = pokedex;
|
||||
}
|
||||
|
||||
protected Pokedex.Pokedex m_pokedex;
|
||||
public Pokedex.Pokedex Pokedex
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_pokedex;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_pokedex = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckLevels(byte min, byte max, byte other)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<%@ Application Codebehind="Global.asax.cs" Inherits="PkmnFoundations.GTS.Global" Language="C#" %>
|
||||
<%@ Application Codebehind="Global.asax.cs" Inherits="PkmnFoundations.Web.Global" Language="C#" %>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Web.Security;
|
|||
using System.Web.SessionState;
|
||||
using PkmnFoundations.Data;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
namespace PkmnFoundations.Web
|
||||
{
|
||||
public class Global : System.Web.HttpApplication
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace PkmnFoundations.GTS
|
|||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
m_pokedex = (Pokedex.Pokedex)Application["pkmncfPokedex"];
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
|
||||
|
||||
int species; Int32.TryParse(ppSpecies.Value, out species);
|
||||
int minLevel = Convert.ToInt32(txtLevelMin.Text);
|
||||
|
|
@ -27,7 +27,7 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
if (rbGen4.Checked)
|
||||
{
|
||||
GtsRecord4[] records4 = Database.Instance.GtsSearch4(0, (ushort)species, gender, (byte)minLevel, (byte)maxLevel, 0, -1);
|
||||
GtsRecord4[] records4 = Database.Instance.GtsSearch4(pokedex, 0, (ushort)species, gender, (byte)minLevel, (byte)maxLevel, 0, -1);
|
||||
rptPokemon4.DataSource = records4;
|
||||
rptPokemon4.DataBind();
|
||||
rptPokemon4.Visible = true;
|
||||
|
|
@ -35,7 +35,7 @@ namespace PkmnFoundations.GTS
|
|||
}
|
||||
else if (rbGen5.Checked)
|
||||
{
|
||||
GtsRecord5[] records5 = Database.Instance.GtsSearch5(0, (ushort)species, gender, (byte)minLevel, (byte)maxLevel, 0, -1);
|
||||
GtsRecord5[] records5 = Database.Instance.GtsSearch5(pokedex, 0, (ushort)species, gender, (byte)minLevel, (byte)maxLevel, 0, -1);
|
||||
rptPokemon5.DataSource = records5;
|
||||
rptPokemon5.DataBind();
|
||||
rptPokemon4.Visible = false;
|
||||
|
|
@ -43,8 +43,6 @@ namespace PkmnFoundations.GTS
|
|||
}
|
||||
}
|
||||
|
||||
private Pokedex.Pokedex m_pokedex;
|
||||
|
||||
private String FormatLevels(byte min, byte max)
|
||||
{
|
||||
if (min == 0 && max == 0)
|
||||
|
|
@ -106,8 +104,9 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
protected String CreateSpecies(object DataItem)
|
||||
{
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
|
||||
GtsRecord4 record = (GtsRecord4)DataItem;
|
||||
return m_pokedex.Species(record.Species).Name.ToString();
|
||||
return pokedex.Species(record.Species).Name.ToString();
|
||||
}
|
||||
|
||||
protected String CreatePokedex(object DataItem)
|
||||
|
|
@ -139,9 +138,10 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
protected String CreateWantedSpecies(object DataItem)
|
||||
{
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
|
||||
GtsRecord4 record = (GtsRecord4)DataItem;
|
||||
return String.Format("{0} (#{1})",
|
||||
m_pokedex.Species(record.RequestedSpecies).Name,
|
||||
pokedex.Species(record.RequestedSpecies).Name,
|
||||
record.RequestedSpecies);
|
||||
}
|
||||
|
||||
|
|
@ -163,22 +163,24 @@ namespace PkmnFoundations.GTS
|
|||
|
||||
protected String CreateOffer5(object DataItem)
|
||||
{
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
|
||||
GtsRecord5 record = (GtsRecord5)DataItem;
|
||||
return String.Format("{3} (#{0})<br />{1}<br />Lv {2}",
|
||||
record.Species,
|
||||
record.Gender,
|
||||
record.Level,
|
||||
m_pokedex.Species(record.Species).Name);
|
||||
pokedex.Species(record.Species).Name);
|
||||
}
|
||||
|
||||
protected String CreateWanted5(object DataItem)
|
||||
{
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
|
||||
GtsRecord5 record = (GtsRecord5)DataItem;
|
||||
return String.Format("{3} (#{0})<br />{1}<br />{2}",
|
||||
record.RequestedSpecies,
|
||||
record.RequestedGender,
|
||||
FormatLevels(record.RequestedMinLevel, record.RequestedMaxLevel),
|
||||
m_pokedex.Species(record.RequestedSpecies).Name);
|
||||
pokedex.Species(record.RequestedSpecies).Name);
|
||||
}
|
||||
|
||||
protected String CreateTrainer5(object DataItem)
|
||||
|
|
|
|||
|
|
@ -14,11 +14,9 @@ namespace PkmnFoundations.Web.gts
|
|||
{
|
||||
public partial class Pokemon : System.Web.UI.Page
|
||||
{
|
||||
private Pokedex.Pokedex m_pokedex;
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
m_pokedex = (Pokedex.Pokedex)Application["pkmncfPokedex"];
|
||||
Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
|
||||
PokemonParty4 pkmn = null;
|
||||
|
||||
if (Request.QueryString.Count == 0 || Request.QueryString.Count > 2) throw new WebException(400);
|
||||
|
|
@ -54,14 +52,14 @@ namespace PkmnFoundations.Web.gts
|
|||
{
|
||||
case "4":
|
||||
{
|
||||
GtsRecord4 record = Database.Instance.GtsGetRecord4(tradeId, isExchanged, true);
|
||||
if (record != null) pkmn = new PokemonParty4(m_pokedex, record.Data);
|
||||
GtsRecord4 record = Database.Instance.GtsGetRecord4(pokedex, tradeId, isExchanged, true);
|
||||
if (record != null) pkmn = new PokemonParty4(pokedex, record.Data);
|
||||
|
||||
} break;
|
||||
case "5":
|
||||
{
|
||||
GtsRecord5 record = Database.Instance.GtsGetRecord5(tradeId, isExchanged, true);
|
||||
if (record != null) pkmn = new PokemonParty4(m_pokedex, record.Data);
|
||||
GtsRecord5 record = Database.Instance.GtsGetRecord5(pokedex, tradeId, isExchanged, true);
|
||||
if (record != null) pkmn = new PokemonParty4(pokedex, record.Data);
|
||||
|
||||
} break;
|
||||
default:
|
||||
|
|
|
|||
30
web/src/AppStateHelper.cs
Normal file
30
web/src/AppStateHelper.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using PkmnFoundations.Data;
|
||||
|
||||
namespace PkmnFoundations.Web
|
||||
{
|
||||
public static class AppStateHelper
|
||||
{
|
||||
public static Pokedex.Pokedex Pokedex(HttpApplicationState application)
|
||||
{
|
||||
return GetTypedApplicationObject(application, "pkmncfPokedex", () => new Pokedex.Pokedex(Database.Instance, false));
|
||||
}
|
||||
|
||||
public static T GetTypedApplicationObject<T>(HttpApplicationState application, String key, Func<T> initializer) where T : class
|
||||
{
|
||||
object o = application[key];
|
||||
T t = o as T;
|
||||
|
||||
if (t == null)
|
||||
{
|
||||
t = initializer();
|
||||
application.Add(key, t);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3577,6 +3577,7 @@
|
|||
<Compile Include="RoomLeaders.aspx.designer.cs">
|
||||
<DependentUpon>RoomLeaders.aspx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="src\AppStateHelper.cs" />
|
||||
<Compile Include="src\Common.cs" />
|
||||
<Compile Include="src\DependencyNode.cs" />
|
||||
<Compile Include="src\HeaderColour.cs" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user