Implemented battle video saved request type.

This commit is contained in:
Greg Edwards 2014-09-15 12:21:13 -04:00
parent f5d41b8756
commit ab16eb46d3
5 changed files with 100 additions and 3 deletions

View File

@ -70,6 +70,7 @@ namespace PkmnFoundations.GlobalTerminalService
switch (requestType)
{
#region Box upload
case RequestTypes4.BoxUpload:
{
if (data.Length != 0x360)
@ -130,6 +131,9 @@ namespace PkmnFoundations.GlobalTerminalService
logEntry.AppendLine();
} break;
#endregion
#region Dressup
case RequestTypes4.DressupUpload:
{
if (data.Length != 0x220)
@ -187,6 +191,9 @@ namespace PkmnFoundations.GlobalTerminalService
logEntry.AppendLine();
} break;
#endregion
#region Battle videos
case RequestTypes4.BattleVideoUpload:
{
if (data.Length != 0x1e8c)
@ -291,6 +298,35 @@ namespace PkmnFoundations.GlobalTerminalService
logEntry.AppendLine();
} break;
case RequestTypes4.BattleVideoSaved:
{
if (data.Length != 0x148)
{
logEntry.AppendLine("Length did not validate.");
type = EventLogEntryType.FailureAudit;
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
break;
}
ulong serial = BitConverter.ToUInt64(data, 0x140);
if (DataAbstract.Instance.BattleVideoFlagSaved4(serial))
{
response.Write(new byte[] { 0x00, 0x00 }, 0, 2); // result code (0 for OK)
logEntry.AppendFormat("Battle video {0} flagged saved.", BattleVideoHeader4.FormatSerial(serial));
logEntry.AppendLine();
}
else
{
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
logEntry.AppendFormat("Requested battle video {0} was missing.", BattleVideoHeader4.FormatSerial(serial));
logEntry.AppendLine();
}
} break;
#endregion
// todo: A mysterious 0xdb request type is appearing in my logs. Implement.
default:
logEntry.AppendLine("Unrecognized request type.");
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
@ -337,6 +373,7 @@ namespace PkmnFoundations.GlobalTerminalService
case RequestTypes4.BattleVideoUpload:
case RequestTypes4.BattleVideoSearch:
case RequestTypes4.BattleVideoWatch:
case RequestTypes4.BattleVideoSaved:
return 0x59;
case RequestTypes4.TopTrainersHead:
case RequestTypes4.TopTrainersSearch:
@ -368,6 +405,7 @@ namespace PkmnFoundations.GlobalTerminalService
BattleVideoUpload = 0xd8,
BattleVideoSearch = 0xd9,
BattleVideoWatch = 0xda,
BattleVideoSaved = 0xdb,
TopTrainersHead = 0xf0,
TopTrainersSearch = 0xf1

View File

@ -69,6 +69,7 @@ namespace PkmnFoundations.GlobalTerminalService
switch (requestType)
{
#region Musicals
case RequestTypes5.MusicalUpload:
{
if (data.Length != 0x370)
@ -123,11 +124,13 @@ namespace PkmnFoundations.GlobalTerminalService
response.Write(BitConverter.GetBytes(result.SerialNumber), 0, 8);
response.Write(result.Data, 0, 0x230);
}
logEntry.AppendFormat("Retrieved {0} dressup results.", results.Length);
logEntry.AppendFormat("Retrieved {0} musical results.", results.Length);
logEntry.AppendLine();
} break;
#endregion
#region Battle videos
case RequestTypes5.BattleVideoUpload:
{
if (data.Length != 0x1ae8)
@ -249,8 +252,32 @@ namespace PkmnFoundations.GlobalTerminalService
logEntry.AppendLine();
} break;
case RequestTypes5.BattleVideoSaved:
{
if (data.Length != 0x148)
{
logEntry.AppendLine("Length did not validate.");
type = EventLogEntryType.FailureAudit;
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
break;
}
// todo: A mysterious 0xf3 request type is appearing in my logs. Implement.
ulong serial = BitConverter.ToUInt64(data, 0x140);
if (DataAbstract.Instance.BattleVideoFlagSaved5(serial))
{
response.Write(new byte[] { 0x00, 0x00 }, 0, 2); // result code (0 for OK)
logEntry.AppendFormat("Battle video {0} flagged saved.", BattleVideoHeader4.FormatSerial(serial));
logEntry.AppendLine();
}
else
{
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
logEntry.AppendFormat("Requested battle video {0} was missing.", BattleVideoHeader4.FormatSerial(serial));
logEntry.AppendLine();
}
} break;
#endregion
default:
logEntry.AppendLine("Unrecognized request type.");

View File

@ -118,6 +118,7 @@ namespace PkmnFoundations.Data
public abstract ulong BattleVideoUpload4(BattleVideoRecord4 record);
public abstract BattleVideoHeader4[] BattleVideoSearch4(ushort species, BattleVideoRankings4 ranking, BattleVideoMetagames4 metagame, byte country, byte region, int count);
public abstract BattleVideoRecord4 BattleVideoGet4(ulong serial, bool incrementViews = false);
public abstract bool BattleVideoFlagSaved4(ulong serial);
public abstract ulong BattleVideoCount4();
#endregion
@ -132,6 +133,7 @@ namespace PkmnFoundations.Data
public abstract ulong BattleVideoUpload5(BattleVideoRecord5 record);
public abstract BattleVideoHeader5[] BattleVideoSearch5(ushort species, BattleVideoRankings5 ranking, BattleVideoMetagames5 metagame, byte country, byte region, int count);
public abstract BattleVideoRecord5 BattleVideoGet5(ulong serial, bool incrementViews = false);
public abstract bool BattleVideoFlagSaved5(ulong serial);
public abstract ulong BattleVideoCount5();
#endregion

View File

@ -2114,6 +2114,20 @@ namespace PkmnFoundations.Data
return new BattleVideoRecord4(header.PID, header.SerialNumber, header, data);
}
public override bool BattleVideoFlagSaved4(ulong serial)
{
using (MySqlConnection db = CreateConnection())
{
db.Open();
int results = db.ExecuteNonQuery("UPDATE TerminalBattleVideos4 " +
"SET Saves = Saves + 1 WHERE SerialNumber = @serial",
new MySqlParameter("@serial", serial));
db.Close();
return results > 0;
}
}
public override ulong BattleVideoCount4()
{
using (MySqlConnection db = CreateConnection())
@ -2473,6 +2487,20 @@ namespace PkmnFoundations.Data
return new BattleVideoRecord5(header.PID, header.SerialNumber, header, data);
}
public override bool BattleVideoFlagSaved5(ulong serial)
{
using (MySqlConnection db = CreateConnection())
{
db.Open();
int results = db.ExecuteNonQuery("UPDATE TerminalBattleVideos5 " +
"SET Saves = Saves + 1 WHERE SerialNumber = @serial",
new MySqlParameter("@serial", serial));
db.Close();
return results > 0;
}
}
public override ulong BattleVideoCount5()
{
using (MySqlConnection db = CreateConnection())

View File

@ -7,7 +7,7 @@
#
# Host: 127.0.0.1 (MySQL 5.5.27)
# Database: gts
# Generation Time: 2014-08-29 23:13:12 +0000
# Generation Time: 2014-09-15 16:20:29 +0000
# ************************************************************
@ -681,6 +681,7 @@ CREATE TABLE `TerminalBattleVideos4` (
`Country` tinyint(3) unsigned NOT NULL,
`Region` tinyint(3) unsigned NOT NULL,
`Views` int(10) unsigned NOT NULL DEFAULT '0',
`Saves` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `SerialNumber` (`SerialNumber`),
KEY `TimeAdded` (`TimeAdded`),
@ -712,6 +713,7 @@ CREATE TABLE `TerminalBattleVideos5` (
`Country` tinyint(3) unsigned NOT NULL,
`Region` tinyint(3) unsigned NOT NULL,
`Views` int(10) unsigned NOT NULL DEFAULT '0',
`Saves` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `SerialNumber` (`SerialNumber`),
KEY `TimeAdded` (`TimeAdded`),