Created TrainerName on GtsRecordBase.

This commit is contained in:
Greg Edwards 2015-04-21 21:32:26 -04:00
parent d582fbc2b5
commit 36edf2d753
4 changed files with 53 additions and 19 deletions

View File

@ -210,7 +210,7 @@ namespace PkmnFoundations.Data
public bool GtsDepositPokemon4(MySqlTransaction tran, GtsRecord4 record)
{
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
// note that IsTraded being true in the record is not an error condition
// since it might have use later on. You should check for this in the upload handler.
@ -243,7 +243,7 @@ namespace PkmnFoundations.Data
public override bool GtsDepositPokemon4(GtsRecord4 record)
{
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
return WithTransactionSuccessful(tran => GtsDepositPokemon4(tran, record));
}
@ -443,7 +443,7 @@ namespace PkmnFoundations.Data
data = new byte[16];
reader.GetBytes(14, 0, data, 0, 16);
result.TrainerName = new EncodedString4(data);
result.TrainerNameEncoded = new EncodedString4(data);
data = null;
result.TrainerOT = reader.GetUInt16(15);
@ -475,7 +475,7 @@ namespace PkmnFoundations.Data
result[11] = new MySqlParameter("@TimeDeposited", record.TimeDeposited);
result[12] = new MySqlParameter("@TimeExchanged", record.TimeExchanged);
result[13] = new MySqlParameter("@pid", record.PID);
result[14] = new MySqlParameter("@TrainerName", record.TrainerName.RawData);
result[14] = new MySqlParameter("@TrainerName", record.TrainerNameEncoded.RawData);
result[15] = new MySqlParameter("@TrainerOT", record.TrainerOT);
result[16] = new MySqlParameter("@TrainerCountry", record.TrainerCountry);
result[17] = new MySqlParameter("@TrainerRegion", record.TrainerRegion);
@ -500,7 +500,7 @@ namespace PkmnFoundations.Data
public void GtsLogTrade4(MySqlTransaction tran, GtsRecord4 record, DateTime? timeWithdrawn, int ? partner_pid, ulong ? trade_id)
{
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
// note that IsTraded being true in the record is not an error condition
// since it might have use later on. You should check for this in the upload handler.
@ -540,7 +540,7 @@ namespace PkmnFoundations.Data
public void GtsLogTrade4(GtsRecord4 record, DateTime? timeWithdrawn, int? partner_pid, ulong ? trade_id)
{
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
WithTransaction(tran => GtsLogTrade4(tran, record, timeWithdrawn, partner_pid, trade_id));
}
@ -1192,7 +1192,7 @@ namespace PkmnFoundations.Data
{
if (record == null) throw new ArgumentNullException("record");
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
// note that IsTraded being true in the record is not an error condition
// since it might have use later on. You should check for this in the upload handler.
@ -1226,7 +1226,7 @@ namespace PkmnFoundations.Data
{
if (record == null) throw new ArgumentNullException("record");
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
return WithTransactionSuccessful(tran => GtsDepositPokemon5(tran, record));
}
@ -1432,7 +1432,7 @@ namespace PkmnFoundations.Data
data = new byte[16];
reader.GetBytes(16, 0, data, 0, 16);
result.TrainerName = new EncodedString5(data);
result.TrainerNameEncoded = new EncodedString5(data);
data = null;
result.TrainerCountry = reader.GetByte(17);
@ -1473,7 +1473,7 @@ namespace PkmnFoundations.Data
result[13] = new MySqlParameter("@TimeExchanged", record.TimeExchanged);
result[14] = new MySqlParameter("@pid", record.PID);
result[15] = new MySqlParameter("@TrainerOT", record.TrainerOT);
result[16] = new MySqlParameter("@TrainerName", record.TrainerName.RawData);
result[16] = new MySqlParameter("@TrainerName", record.TrainerNameEncoded.RawData);
result[17] = new MySqlParameter("@TrainerCountry", record.TrainerCountry);
result[18] = new MySqlParameter("@TrainerRegion", record.TrainerRegion);
result[19] = new MySqlParameter("@TrainerClass", record.TrainerClass);
@ -1506,7 +1506,7 @@ namespace PkmnFoundations.Data
// todo: Bring these out into a ValidateRecord5 method
if (record == null) throw new ArgumentNullException("record");
if (record.Data.Count != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
if (record.TrainerNameEncoded.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes.");
// note that IsTraded being true in the record is not an error condition
// since it might have use later on. You should check for this in the upload handler.

View File

@ -107,14 +107,28 @@ namespace PkmnFoundations.Structures
/// <summary>
/// 16 bytes
/// </summary>
public EncodedString4 TrainerName;
public EncodedString4 TrainerNameEncoded;
public override string TrainerName
{
get
{
if (TrainerNameEncoded == null) return null;
return TrainerNameEncoded.Text;
}
set
{
if (TrainerNameEncoded == null) TrainerNameEncoded = new EncodedString4(value, 16);
else TrainerNameEncoded.Text = value;
}
}
public ushort TrainerOT;
protected override void Save(BinaryWriter writer)
{
// todo: enclose in properties and validate these when assigning.
if (TrainerName.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
if (TrainerNameEncoded.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
writer.Write(DataActual, 0, 0xEC); // 0x0000
writer.Write(Species); // 0x00EC
@ -130,7 +144,7 @@ namespace PkmnFoundations.Structures
writer.Write(DateToTimestamp(TimeDeposited)); // 0x00F8
writer.Write(DateToTimestamp(TimeExchanged)); // 0x0100
writer.Write(PID); // 0x0108
writer.Write(TrainerName.RawData, 0, 0x10); // 0x010C
writer.Write(TrainerNameEncoded.RawData, 0, 0x10); // 0x010C
writer.Write(TrainerOT); // 0x011C
writer.Write(TrainerCountry); // 0x011E
writer.Write(TrainerRegion); // 0x011F
@ -156,7 +170,7 @@ namespace PkmnFoundations.Structures
TimeDeposited = TimestampToDate(reader.ReadUInt64()); // 0x00F8
TimeExchanged = TimestampToDate(reader.ReadUInt64()); // 0x0100
PID = reader.ReadInt32(); // 0x0108
TrainerName = new EncodedString4(reader.ReadBytes(0x10)); // 0x010C
TrainerNameEncoded = new EncodedString4(reader.ReadBytes(0x10)); // 0x010C
TrainerOT = reader.ReadUInt16(); // 0x011C
TrainerCountry = reader.ReadByte(); // 0x011E
TrainerRegion = reader.ReadByte(); // 0x011F

View File

@ -110,7 +110,21 @@ namespace PkmnFoundations.Structures
/// <summary>
/// 16 bytes
/// </summary>
public EncodedString5 TrainerName;
public EncodedString5 TrainerNameEncoded;
public override string TrainerName
{
get
{
if (TrainerNameEncoded == null) return null;
return TrainerNameEncoded.Text;
}
set
{
if (TrainerNameEncoded == null) TrainerNameEncoded = new EncodedString5(value, 16);
else TrainerNameEncoded.Text = value;
}
}
public byte TrainerBadges; // speculative. Usually 8.
public byte TrainerUnityTower;
@ -118,7 +132,7 @@ namespace PkmnFoundations.Structures
protected override void Save(BinaryWriter writer)
{
// todo: enclose in properties and validate these when assigning.
if (TrainerName.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
if (TrainerNameEncoded.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
writer.Write(DataActual, 0, 0xEC); // 0x0000
writer.Write(Species); // 0x00EC
@ -135,7 +149,7 @@ namespace PkmnFoundations.Structures
writer.Write(DateToTimestamp(TimeExchanged)); // 0x0100
writer.Write(PID); // 0x0108
writer.Write(TrainerOT); // 0x010C
writer.Write(TrainerName.RawData, 0, 0x10); // 0x0110
writer.Write(TrainerNameEncoded.RawData, 0, 0x10); // 0x0110
writer.Write(TrainerCountry); // 0x0120
writer.Write(TrainerRegion); // 0x0121
writer.Write(TrainerClass); // 0x0122
@ -163,7 +177,7 @@ namespace PkmnFoundations.Structures
TimeExchanged = TimestampToDate(reader.ReadUInt64()); // 0x0100
PID = reader.ReadInt32(); // 0x0108
TrainerOT = reader.ReadUInt32(); // 0x010C
TrainerName = new EncodedString5(reader.ReadBytes(0x10)); // 0x0110
TrainerNameEncoded = new EncodedString5(reader.ReadBytes(0x10)); // 0x0110
TrainerCountry = reader.ReadByte(); // 0x0120
TrainerRegion = reader.ReadByte(); // 0x0121
TrainerClass = reader.ReadByte(); // 0x0122

View File

@ -69,6 +69,12 @@ namespace PkmnFoundations.Structures
public byte TrainerRegion;
public byte TrainerClass;
public abstract String TrainerName
{
get;
set;
}
public byte IsExchanged;
public byte TrainerVersion;