mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-24 15:26:48 -05:00
Implemented dressup uploading. (probably)
This commit is contained in:
parent
dcf397cbbc
commit
aeb7f3fb3d
|
|
@ -62,10 +62,36 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
} break;
|
||||
case RequestTypes4.DressupUpload:
|
||||
{
|
||||
if (data.Length != 0x220)
|
||||
{
|
||||
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
int pid = BitConverter.ToInt32(data, 8);
|
||||
byte[] dressupData = new byte[0xe0];
|
||||
Array.Copy(data, 0x140, dressupData, 0, 0xe0);
|
||||
DressupRecord4 record = new DressupRecord4(pid, 0, dressupData);
|
||||
long serial = DataAbstract.Instance.DressupUpload4(record);
|
||||
|
||||
if (serial == 0)
|
||||
{
|
||||
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
response.Write(new byte[] { 0x00, 0x00 }, 0, 2); // result code (0 for OK)
|
||||
response.Write(BitConverter.GetBytes(serial), 0, 8);
|
||||
|
||||
} break;
|
||||
case RequestTypes4.DressupSearch:
|
||||
{
|
||||
if (data.Length != 0x14c)
|
||||
{
|
||||
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
// todo: validate or log some of this?
|
||||
ushort species = BitConverter.ToUInt16(data, 0x144);
|
||||
|
||||
|
|
@ -77,7 +103,7 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
{
|
||||
response.Write(BitConverter.GetBytes(result.PID), 0, 4);
|
||||
response.Write(BitConverter.GetBytes(result.SerialNumber), 0, 8);
|
||||
response.Write(result.Data, 0, 224);
|
||||
response.Write(result.Data, 0, 0xe0);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
data = new byte[length];
|
||||
BitConverter.GetBytes(length).CopyTo(data, 0);
|
||||
s.Read(data, 4, length - 4); // todo: stop DoS by timing out blocking requests
|
||||
// todo after that: ban IPs that make lots of blocking requests
|
||||
|
||||
byte[] response = ProcessRequest(data);
|
||||
s.Write(response, 0, response.Length);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ namespace PkmnFoundations.Data
|
|||
#endregion
|
||||
|
||||
#region GTS 4
|
||||
public readonly const int GTS_VERSION_4 = 0;
|
||||
|
||||
public abstract GtsRecord4 GtsDataForUser4(int pid);
|
||||
|
||||
public abstract bool GtsDepositPokemon4(GtsRecord4 record);
|
||||
|
|
@ -61,6 +63,8 @@ namespace PkmnFoundations.Data
|
|||
#endregion
|
||||
|
||||
#region GTS 5
|
||||
public readonly const int GTS_VERSION_5 = 0;
|
||||
|
||||
public abstract GtsRecord5 GtsDataForUser5(int pid);
|
||||
|
||||
public abstract bool GtsDepositPokemon5(GtsRecord5 record);
|
||||
|
|
@ -75,10 +79,14 @@ namespace PkmnFoundations.Data
|
|||
#endregion
|
||||
|
||||
#region Global Terminal 4
|
||||
public abstract long DressupUpload4(int pid, byte[] data);
|
||||
public readonly const int DRESSUP_VERSION_4 = 1;
|
||||
|
||||
public abstract long DressupUpload4(DressupRecord4 record);
|
||||
public abstract DressupRecord4[] DressupSearch4(ushort species, int count);
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Data;
|
|||
using MySql.Data.MySqlClient;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace PkmnFoundations.Data
|
||||
{
|
||||
|
|
@ -713,9 +714,27 @@ namespace PkmnFoundations.Data
|
|||
#endregion
|
||||
|
||||
#region Global Terminal 4
|
||||
public override long DressupUpload4(int pid, byte[] data)
|
||||
public override long DressupUpload4(DressupRecord4 record)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (record.Data.Length != 224) throw new ArgumentException("Dressup data must be 224 bytes.");
|
||||
using (MySqlConnection db = CreateConnection())
|
||||
{
|
||||
db.Open();
|
||||
using (MySqlTransaction tran = db.BeginTransaction())
|
||||
{
|
||||
byte exists = (byte)tran.ExecuteScalar("SELECT EXISTS(SELECT * FROM TerminalDressup4 WHERE Data = @data)", new MySqlParameter("@data", record.Data));
|
||||
if (exists != 0) return 0;
|
||||
|
||||
long serial = (long)tran.ExecuteScalar("INSERT INTO TerminalDressup4 (pid, " +
|
||||
"Data, TimeAdded, ParseVersion, Species) VALUES (@pid, @data, " +
|
||||
"GETUTCDATE(), 1, @species); SELECT LAST_INSERT_ID()",
|
||||
new MySqlParameter("@pid", record.PID),
|
||||
new MySqlParameter("@data", record.Data),
|
||||
new MySqlParameter("@species", record.Species));
|
||||
tran.Commit();
|
||||
return serial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override DressupRecord4[] DressupSearch4(ushort species, int count)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace PkmnFoundations.Structures
|
|||
|
||||
public DressupRecord4(int pid, long serial_number, byte[] data)
|
||||
{
|
||||
if (data.Length != 224) throw new ArgumentException("data");
|
||||
if (data.Length != 224) throw new ArgumentException("Dressup data must be 224 bytes.");
|
||||
|
||||
PID = pid;
|
||||
SerialNumber = serial_number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user