Compare commits

..

No commits in common. "ad219b095c0be35ee0ebcc0c7ccdbbda3753392c" and "ac57ecb939463174fccbc18ce049c39345551b25" have entirely different histories.

3 changed files with 19 additions and 33 deletions

View File

@ -86,10 +86,6 @@ public static class Table
public static void Load() public static void Load()
{ {
int catchDataCount = 0;
int stcCount = 0;
int textCount = 0;
foreach (PropertyInfo? prop in typeof(Table).GetProperties().Where(x => x.GetCustomAttribute<LoadDataAttribute>() is not null)) foreach (PropertyInfo? prop in typeof(Table).GetProperties().Where(x => x.GetCustomAttribute<LoadDataAttribute>() is not null))
{ {
LoadDataAttribute attr = prop.GetCustomAttribute<LoadDataAttribute>()!; LoadDataAttribute attr = prop.GetCustomAttribute<LoadDataAttribute>()!;
@ -102,21 +98,18 @@ public static class Table
object? value = JsonSerializer.Deserialize(entry.Value.GetRawText(), prop.PropertyType, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); object? value = JsonSerializer.Deserialize(entry.Value.GetRawText(), prop.PropertyType, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
prop.SetValue(null, value); prop.SetValue(null, value);
Log.Information($"Loaded {(prop.GetValue(null) as IList)?.Count} entries from {prop.Name} catchdata table"); Log.Information($"Loaded {(prop.GetValue(null) as IList)?.Count} entries from {prop.Name} catchdata table");
catchDataCount++;
break; break;
case LoadDataType.STC: case LoadDataType.STC:
prop.SetValue(null, typeof(JSON).GetMethod(nameof(JSON.Load))!.MakeGenericMethod(prop.PropertyType).Invoke(null, [Path.Combine(GetPath(attr.DataType), attr.FileName), false])); prop.SetValue(null, typeof(JSON).GetMethod(nameof(JSON.Load))!.MakeGenericMethod(prop.PropertyType).Invoke(null, [Path.Combine(GetPath(attr.DataType), attr.FileName), false]));
Log.Information($"Loaded {(prop.GetValue(null) as IList)?.Count} entries from {prop.Name} stc table"); Log.Information($"Loaded {(prop.GetValue(null) as IList)?.Count} entries from {prop.Name} stc table");
stcCount++;
break; break;
case LoadDataType.Text: case LoadDataType.Text:
// TODO: textdata is just a flat list of key-value pairs that are looked up from stc // TODO: textdata is just a flat list of key-value pairs that are looked up from stc
textCount++;
break; break;
} }
} }
Log.Information($"Finished loading data tables ({catchDataCount} catchdata, {stcCount} stc, {textCount} text)"); Log.Information("All data tables loaded");
} }
public static string GetPath(LoadDataType type) public static string GetPath(LoadDataType type)

View File

@ -28,13 +28,12 @@ public static class GameServer
static async Task HandleRequest(HttpContext context) static async Task HandleRequest(HttpContext context)
{ {
// Is this even necessary?
if (context.Request.Method == "CONNECT") if (context.Request.Method == "CONNECT")
context.Response.StatusCode = StatusCodes.Status200OK; context.Response.StatusCode = StatusCodes.Status200OK;
else else
{ {
context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed; context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed;
await context.Response.WriteAsync("Error 405: Method Not Allowed"); await context.Response.WriteAsync("Method Not Allowed");
} }
} }
} }

View File

@ -7,16 +7,15 @@ namespace Elisa;
public static class Proxy public static class Proxy
{ {
static int port = 9000;
static string serverUrl = "localhost"; static string serverUrl = "localhost";
public static async Task Start() public static async Task Start()
{ {
Log.Information("Starting Proxy"); Log.Information("Starting Proxy");
TcpListener listener = new TcpListener(IPAddress.Any, port); TcpListener listener = new TcpListener(IPAddress.Any, 9000);
listener.Start(); listener.Start();
Log.Information($"Proxy: Listening on port {port}"); Log.Information($"Proxy: Listening on port 9000");
while (true) while (true)
{ {
@ -24,30 +23,25 @@ public static class Proxy
string clientAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(); string clientAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
Log.Information($"Proxy: Accepted client connection from {clientAddress}"); Log.Information($"Proxy: Accepted client connection from {clientAddress}");
using (TcpClient server = new TcpClient()) TcpClient server = new TcpClient();
{
await server.ConnectAsync(serverUrl, 80); await server.ConnectAsync(serverUrl, 80);
Log.Information($"Proxy: Connected to Elisa"); Log.Information($"Proxy: Connected to Elisa");
using (NetworkStream clientStream = client.GetStream()) NetworkStream clientStream = client.GetStream();
using (NetworkStream serverStream = server.GetStream()) NetworkStream serverStream = server.GetStream();
{
byte[] buffer = new byte[256 * 256]; byte[] buffer = new byte[256 * 256];
int bytesRead; int bytesRead;
while ((bytesRead = await clientStream.ReadAsync(buffer, 0, buffer.Length)) > 0) while ((bytesRead = await clientStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{ Log.Information($"Received data from client: {Encoding.UTF8.GetString(buffer, 0, bytesRead).Trim()}");
string data = Encoding.UTF8.GetString(buffer, 0, bytesRead).Trim();
Log.Information($"Received data from client: {data}");
}
Task c2sTask = clientStream.CopyToAsync(serverStream); Task clientToServerTask = clientStream.CopyToAsync(serverStream);
Task s2cTask = serverStream.CopyToAsync(clientStream); Task serverToClientTask = serverStream.CopyToAsync(clientStream);
await Task.WhenAll(c2sTask, s2cTask); await Task.WhenAll(clientToServerTask, serverToClientTask);
}
}
client.Close(); client.Close();
Log.Information($"Proxy: Closed client connection"); server.Close();
Log.Information($"Proxy: Closed client and server connections");
} }
} }
} }