﻿using GamestatsBase;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace Sample.pokedngnwii.web.rescue
{
    /// <summary>
    /// Summary description for rescueExist
    /// </summary>
    public class rescueExist : GamestatsHandler
    {

        public rescueExist() : base("zjzrhOVXZKLHNspYpGoR0001c7850000620b0000000820556356pokedngnwii",
            GamestatsRequestVersions.Version2, GamestatsResponseVersions.Version2)
        {

        }

        public override void ProcessGamestatsRequest(byte[] request, MemoryStream response, string url, int pid, HttpContext context, GamestatsSession session)
        {
            if (false)
            {
                // replay response from Invalid Code for Rescue Mission.pcapng
                // request data:
                // 0000: 8b9ca41c0c000000 1ca49c8b00000000
                // 0010: 0001b197
                // note: 1b197 corresponds to the inputted rescue ID of 110999 in big endian.

                response.Write(new byte[] { 0x00, 0x00, 0x00, 0x0a },
                    0, 4);
                StreamWriter sw = new StreamWriter(response, Encoding.UTF8);
                sw.Write(":(unknown error:'pokemonSwarm' is null or not an object.");
                sw.Flush();
            }
            else
            {
                // replay response from CodeNotWorking.pcapng
                // request data:
                // 0000: 8b9ca41c0c000000 1ca49c8b00000000
                // 0010: 0001b142

                response.Write(new byte[]
                {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
                    0xa9, 0x9f, 0x50, 0x07, 0xed, 0xa4, 0x96, 0xf7,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0xdd, 0x30, 0xb1, 0x30, 0xe2, 0x30, 0xf3, 0x30,
                    0xba, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45,
                    0x00, 0x00, 0x00, 0x02, 0x00, 0x0d, 0x48, 0xa0,
                    0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
                    0x30, 0x4c, 0x30, 0x82, 0x30, 0x6f, 0x30, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x6f,
                    0x30, 0x4c, 0x30, 0x00, 0x30, 0x6f, 0x30, 0x6f,
                    0x30, 0x82, 0x30, 0x4c, 0x30, 0x82, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                }, 0, 208);
            }
        }
    }
}
