mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-17 22:39:37 -05:00
Added stub hax validations.
This commit is contained in:
parent
098c9434ba
commit
0e0226db20
|
|
@ -253,6 +253,7 @@ namespace PkmnFoundations.GTS
|
|||
return;
|
||||
}
|
||||
|
||||
// todo: add transaction
|
||||
if (DataAbstract.Instance.GtsDataForUser4(pid) != null)
|
||||
{
|
||||
// there's already a pokemon inside
|
||||
|
|
@ -265,6 +266,14 @@ namespace PkmnFoundations.GTS
|
|||
byte[] recordBinary = new byte[292];
|
||||
Array.Copy(data, 4, recordBinary, 0, 292);
|
||||
GtsRecord4 record = new GtsRecord4(recordBinary);
|
||||
if (!record.Validate())
|
||||
{
|
||||
// hack check failed
|
||||
sessions.Remove(session.Hash);
|
||||
context.Response.OutputStream.Write(new byte[] { 0x00, 0x00 }, 0, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
// the following two fields are blank in the uploaded record.
|
||||
// The server must provide them instead.
|
||||
record.TimeDeposited = DateTime.UtcNow;
|
||||
|
|
@ -350,14 +359,13 @@ namespace PkmnFoundations.GTS
|
|||
GtsRecord4 result = DataAbstract.Instance.GtsDataForUser4(targetPid);
|
||||
|
||||
// enforce request requirements server side
|
||||
if (!upload.CanTrade(result))
|
||||
if (!upload.Validate() || !upload.CanTrade(result))
|
||||
{
|
||||
Error400(context);
|
||||
return;
|
||||
}
|
||||
|
||||
// todo: maybe strong type this
|
||||
object[] tag = new object[2];
|
||||
object[] tag = new GtsRecord4[2];
|
||||
tag[0] = upload;
|
||||
tag[1] = result;
|
||||
session.Tag = tag;
|
||||
|
|
@ -365,6 +373,17 @@ namespace PkmnFoundations.GTS
|
|||
GtsRecord4 tradedResult = result.Clone();
|
||||
tradedResult.FlagTraded(upload); // only real purpose is to generate a proper response
|
||||
|
||||
// todo: we need a mechanism to "reserve" a pokemon being traded at this
|
||||
// point in the process, but be able to relinquish it if exchange_finish
|
||||
// never happens.
|
||||
// Currently, if two people try to take the same pokemon, it will appear
|
||||
// to work for both but then fail for the second after they've saved
|
||||
// their game. This causes a hard crash and a "save file is corrupt,
|
||||
// "previous will be loaded" error when restarting.
|
||||
// the reservation can be done in application state and has no reason
|
||||
// to touch the database. (exchange_finish won't work anyway if application
|
||||
// state is lost.)
|
||||
|
||||
context.Response.OutputStream.Write(result.Save(), 0, 292);
|
||||
|
||||
} break;
|
||||
|
|
@ -383,8 +402,8 @@ namespace PkmnFoundations.GTS
|
|||
GtsSession4 prevSession = FindSession(sessions, pid, "/worldexchange/exchange.asp");
|
||||
|
||||
sessions.Remove(prevSession.Hash);
|
||||
AssertHelper.Assert(prevSession.Tag is object[]);
|
||||
object[] tag = (object[])prevSession.Tag;
|
||||
AssertHelper.Assert(prevSession.Tag is GtsRecord4[]);
|
||||
GtsRecord4[] tag = (GtsRecord4[])prevSession.Tag;
|
||||
AssertHelper.Assert(tag.Length == 2);
|
||||
AssertHelper.Assert(tag[0] is GtsRecord4);
|
||||
AssertHelper.Assert(tag[0] is GtsRecord4);
|
||||
|
|
|
|||
|
|
@ -150,6 +150,12 @@ namespace PkmnFoundations.Structures
|
|||
return new GtsRecord4(Save());
|
||||
}
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
// todo: a. legitimacy check, and b. check that pkm data matches metadata
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanTrade(GtsRecord4 other)
|
||||
{
|
||||
if (Species != other.RequestedSpecies) return false;
|
||||
|
|
@ -194,7 +200,7 @@ namespace PkmnFoundations.Structures
|
|||
byte hour = (byte)((timestamp >> 0x18) & 0xff);
|
||||
byte minute = (byte)((timestamp >> 0x10) & 0xff);
|
||||
byte second = (byte)((timestamp >> 0x08) & 0xff);
|
||||
//byte fractional = (byte)(timestamp & 0xff);
|
||||
//byte fractional = (byte)(timestamp & 0xff); // always 0
|
||||
|
||||
// allow ArgumentOutOfRangeExceptions to escape
|
||||
return new DateTime(year, month, day, hour, minute, second);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user