mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-08-01 23:53:39 -05:00
Added page to insert box upload captures into the database.
This commit is contained in:
parent
5b775ed32b
commit
4f8376ec3e
15
gts/admin/AddBoxes.aspx
Normal file
15
gts/admin/AddBoxes.aspx
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="AddBoxes.aspx.cs" Inherits="PkmnFoundations.GTS.admin.AddBoxes" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="cpHead" runat="server">
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="cpMain" runat="server">
|
||||
<form id="theForm" runat="server">
|
||||
<div>
|
||||
<p>Upload a wiresharked box search response here to add it to the database:</p>
|
||||
<asp:FileUpload ID="fuBox" runat="server" />
|
||||
<asp:Button ID="btnSend" Text="Send" OnClick="btnSend_Click" runat="server" />
|
||||
</div>
|
||||
<asp:Literal ID="litMessage" runat="server" />
|
||||
</form>
|
||||
</asp:Content>
|
||||
71
gts/admin/AddBoxes.aspx.cs
Normal file
71
gts/admin/AddBoxes.aspx.cs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Data;
|
||||
|
||||
namespace PkmnFoundations.GTS.admin
|
||||
{
|
||||
public partial class AddBoxes : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Init(object sender, EventArgs e)
|
||||
{
|
||||
litMessage.Text = "";
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void btnSend_Click(object sender, EventArgs e)
|
||||
{
|
||||
byte[] data = fuBox.FileBytes;
|
||||
if (data.Length < 0xf8)
|
||||
{
|
||||
Fail(); return;
|
||||
}
|
||||
|
||||
Common.CryptMessage(data);
|
||||
if (data[0x04] != 0x21 ||
|
||||
data[0x05] != 0x52 ||
|
||||
data[0x06] != 0x00 ||
|
||||
data[0x07] != 0x00)
|
||||
{
|
||||
Fail(); return;
|
||||
}
|
||||
|
||||
int results = BitConverter.ToInt32(data, 0x08);
|
||||
if (data.Length != 12 + 556 * results)
|
||||
{
|
||||
Fail(); return;
|
||||
}
|
||||
|
||||
int added = 0;
|
||||
|
||||
for (int x = 0; x < results; x++)
|
||||
{
|
||||
int pid = BitConverter.ToInt32(data, 12 + 556 * x);
|
||||
BoxLabels4 label = (BoxLabels4)BitConverter.ToInt32(data, 16 + 556 * x);
|
||||
long serial = BitConverter.ToInt64(data, 20 + 556 * x);
|
||||
if (serial == 0) continue;
|
||||
|
||||
byte[] result = new byte[540];
|
||||
Array.Copy(data, 28 + 556 * x, result, 0, 540);
|
||||
|
||||
BoxRecord4 record = new BoxRecord4(pid, label, serial, result);
|
||||
if (DataAbstract.Instance.BoxUpload4(record) != 0) added++;
|
||||
}
|
||||
|
||||
litMessage.Text = "Added " + added.ToString() + " boxes to the database.";
|
||||
}
|
||||
|
||||
private void Fail()
|
||||
{
|
||||
litMessage.Text = "There was an error with the data.";
|
||||
}
|
||||
}
|
||||
}
|
||||
51
gts/admin/AddBoxes.aspx.designer.cs
generated
Normal file
51
gts/admin/AddBoxes.aspx.designer.cs
generated
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace PkmnFoundations.GTS.admin {
|
||||
|
||||
|
||||
public partial class AddBoxes {
|
||||
|
||||
/// <summary>
|
||||
/// theForm control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlForm theForm;
|
||||
|
||||
/// <summary>
|
||||
/// fuBox control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.FileUpload fuBox;
|
||||
|
||||
/// <summary>
|
||||
/// btnSend control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Button btnSend;
|
||||
|
||||
/// <summary>
|
||||
/// litMessage control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Literal litMessage;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,8 +22,6 @@ namespace PkmnFoundations.GTS.test
|
|||
|
||||
}
|
||||
|
||||
private static byte[] m_pad = new byte[256];
|
||||
|
||||
protected void btnSend_Click(object sender, EventArgs e)
|
||||
{
|
||||
byte[] data = fuBox.FileBytes;
|
||||
|
|
@ -32,11 +30,7 @@ namespace PkmnFoundations.GTS.test
|
|||
Fail(); return;
|
||||
}
|
||||
|
||||
FileStream s = File.Open(Server.MapPath("~/pad.bin"), FileMode.Open);
|
||||
s.Read(m_pad, 0, m_pad.Length);
|
||||
s.Close();
|
||||
|
||||
CryptMessage(data);
|
||||
Common.CryptMessage(data);
|
||||
if (data[0x04] != 0x21 ||
|
||||
data[0x05] != 0x4e ||
|
||||
data[0x06] != 0x00 ||
|
||||
|
|
@ -69,16 +63,6 @@ namespace PkmnFoundations.GTS.test
|
|||
litMessage.Text = "Added " + added.ToString() + " dressup photos to the database.";
|
||||
}
|
||||
|
||||
private void CryptMessage(byte[] message)
|
||||
{
|
||||
if (message.Length < 5) return;
|
||||
byte padOffset = (byte)(message[0] + message[4]);
|
||||
|
||||
// encrypt and decrypt are the same operation...
|
||||
for (int x = 5; x < message.Length; x++)
|
||||
message[x] ^= m_pad[(x + padOffset) & 0xff];
|
||||
}
|
||||
|
||||
private void Fail()
|
||||
{
|
||||
litMessage.Text = "There was an error with the data.";
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@
|
|||
<Reference Include="System.Web.ApplicationServices" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="admin\AddBoxes.aspx" />
|
||||
<Content Include="AllPokemon.aspx" />
|
||||
<Content Include="BattleVideo.aspx" />
|
||||
<Content Include="css\main.css" />
|
||||
|
|
@ -81,6 +82,13 @@
|
|||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="admin\AddBoxes.aspx.cs">
|
||||
<DependentUpon>AddBoxes.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="admin\AddBoxes.aspx.designer.cs">
|
||||
<DependentUpon>AddBoxes.aspx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="AllPokemon.aspx.cs">
|
||||
<DependentUpon>AllPokemon.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.IO;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
|
@ -76,5 +77,25 @@ namespace PkmnFoundations.GTS
|
|||
{
|
||||
return HttpUtility.HtmlEncode(s);
|
||||
}
|
||||
|
||||
private static byte[] m_pad = null;
|
||||
|
||||
public static void CryptMessage(byte[] message)
|
||||
{
|
||||
if (m_pad == null)
|
||||
{
|
||||
m_pad = new byte[256];
|
||||
FileStream s = File.Open(HttpContext.Current.Server.MapPath("~/pad.bin"), FileMode.Open);
|
||||
s.Read(m_pad, 0, m_pad.Length);
|
||||
s.Close();
|
||||
}
|
||||
|
||||
if (message.Length < 5) return;
|
||||
byte padOffset = (byte)(message[0] + message[4]);
|
||||
|
||||
// encrypt and decrypt are the same operation...
|
||||
for (int x = 5; x < message.Length; x++)
|
||||
message[x] ^= m_pad[(x + padOffset) & 0xff];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user