mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-08-28 05:04:16 -05:00
Core of GenV global terminal server
This commit is contained in:
@@ -51,7 +51,11 @@ namespace PkmnFoundations.GlobalTerminalService
|
||||
|
||||
try
|
||||
{
|
||||
// todo: implement each of the request types here
|
||||
// todo: fact check this for GenIV.
|
||||
//int pid = BitConverter.ToInt32(data, 8);
|
||||
//byte version = data[0x0c];
|
||||
//byte language = data[0x0d];
|
||||
|
||||
switch (requestType)
|
||||
{
|
||||
case RequestTypes4.BoxUpload:
|
||||
@@ -105,7 +109,6 @@ namespace PkmnFoundations.GlobalTerminalService
|
||||
}
|
||||
Console.WriteLine("Retrieved {0} boxes.", results.Length);
|
||||
|
||||
|
||||
} break;
|
||||
case RequestTypes4.DressupUpload:
|
||||
{
|
||||
@@ -245,6 +248,9 @@ namespace PkmnFoundations.GlobalTerminalService
|
||||
Console.WriteLine("Retrieved battle video {0}.", BattleVideoHeader4.FormatSerial(serial));
|
||||
|
||||
} break;
|
||||
default:
|
||||
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -260,12 +266,6 @@ namespace PkmnFoundations.GlobalTerminalService
|
||||
return responseData;
|
||||
}
|
||||
|
||||
private void WriteLength(byte[] message)
|
||||
{
|
||||
byte[] data = BitConverter.GetBytes(message.Length);
|
||||
Array.Copy(data, 0, message, 0, 4);
|
||||
}
|
||||
|
||||
private void CryptMessage(byte[] message)
|
||||
{
|
||||
if (message.Length < 5) return;
|
||||
|
||||
105
GlobalTerminalService/GTServer5.cs
Normal file
105
GlobalTerminalService/GTServer5.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
using System.IO;
|
||||
|
||||
namespace PkmnFoundations.GlobalTerminalService
|
||||
{
|
||||
public class GTServer5 : GTServerBase
|
||||
{
|
||||
public GTServer5()
|
||||
: base(12401, true)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GTServer5(int threads)
|
||||
: base(12401, true, threads)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override byte[] ProcessRequest(byte[] data)
|
||||
{
|
||||
int length = BitConverter.ToInt32(data, 0);
|
||||
AssertHelper.Equals(length, data.Length);
|
||||
|
||||
RequestTypes5 requestType = (RequestTypes5)data[4];
|
||||
Console.WriteLine("Handling Generation V {0} request.", requestType);
|
||||
|
||||
MemoryStream response = new MemoryStream();
|
||||
response.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4); // placeholder for length
|
||||
response.WriteByte((byte)requestType);
|
||||
response.WriteByte(Byte6(requestType));
|
||||
|
||||
try
|
||||
{
|
||||
int pid = BitConverter.ToInt32(data, 8);
|
||||
byte version = data[0x0c];
|
||||
byte language = data[0x0d];
|
||||
|
||||
switch (requestType)
|
||||
{
|
||||
case RequestTypes5.MusicalUpload:
|
||||
{
|
||||
|
||||
} break;
|
||||
default:
|
||||
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
response.Write(new byte[] { 0x02, 0x00 }, 0, 2);
|
||||
}
|
||||
|
||||
response.Flush();
|
||||
byte[] responseData = response.ToArray();
|
||||
WriteLength(responseData);
|
||||
return responseData;
|
||||
}
|
||||
|
||||
private byte Byte6(RequestTypes5 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case RequestTypes5.MusicalUpload:
|
||||
case RequestTypes5.MusicalSearch:
|
||||
return 0x52;
|
||||
case RequestTypes5.BattleVideoUpload:
|
||||
case RequestTypes5.BattleVideoSearch:
|
||||
case RequestTypes5.BattleVideoWatch:
|
||||
return 0x55;
|
||||
default:
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Generation V Global Terminal";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal enum RequestTypes5 : byte
|
||||
{
|
||||
MusicalUpload = 0x08,
|
||||
MusicalSearch = 0x09,
|
||||
|
||||
BattleVideoUpload = 0xf0,
|
||||
BattleVideoSearch = 0xf1,
|
||||
BattleVideoWatch = 0xf2
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,7 @@ namespace PkmnFoundations.GlobalTerminalService
|
||||
Threads = threads;
|
||||
UseSsl = useSsl;
|
||||
m_workers = new List<Thread>(threads);
|
||||
// todo: enumerate nic bindings
|
||||
m_listener = new TcpListener(port);
|
||||
m_listener = new TcpListener(IPAddress.Any, port);
|
||||
if (UseSsl)
|
||||
{
|
||||
Certificate = new X509Certificate2("cert.pfx", "letmein");
|
||||
@@ -138,5 +137,11 @@ namespace PkmnFoundations.GlobalTerminalService
|
||||
protected abstract byte[] ProcessRequest(byte[] data);
|
||||
|
||||
public abstract String Title { get; }
|
||||
|
||||
protected void WriteLength(byte[] message)
|
||||
{
|
||||
byte[] data = BitConverter.GetBytes(message.Length);
|
||||
Array.Copy(data, 0, message, 0, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GTServer4.cs" />
|
||||
<Compile Include="GTServer5.cs" />
|
||||
<Compile Include="GTServerBase.cs" />
|
||||
<Compile Include="Service1.cs">
|
||||
<SubType>Component</SubType>
|
||||
|
||||
@@ -32,7 +32,9 @@ namespace PkmnFoundations.Structures
|
||||
Pearl = 0x0b,
|
||||
Platinum = 0x0c,
|
||||
HeartGold = 0x07,
|
||||
SoulSilver = 0x08
|
||||
SoulSilver = 0x08,
|
||||
White = 0x14,
|
||||
Black = 0x15,
|
||||
}
|
||||
|
||||
public enum EvolutionTriggers
|
||||
|
||||
Reference in New Issue
Block a user