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()
{
int catchDataCount = 0;
int stcCount = 0;
int textCount = 0;
foreach (PropertyInfo? prop in typeof(Table).GetProperties().Where(x => x.GetCustomAttribute<LoadDataAttribute>() is not null))
{
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 });
prop.SetValue(null, value);
Log.Information($"Loaded {(prop.GetValue(null) as IList)?.Count} entries from {prop.Name} catchdata table");
catchDataCount++;
break;
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]));
Log.Information($"Loaded {(prop.GetValue(null) as IList)?.Count} entries from {prop.Name} stc table");
stcCount++;
break;
case LoadDataType.Text:
// TODO: textdata is just a flat list of key-value pairs that are looked up from stc
textCount++;
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)

View File

@ -28,13 +28,12 @@ public static class GameServer
static async Task HandleRequest(HttpContext context)
{
// Is this even necessary?
if (context.Request.Method == "CONNECT")
context.Response.StatusCode = StatusCodes.Status200OK;
else
{
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
{
static int port = 9000;
static string serverUrl = "localhost";
public static async Task Start()
{
Log.Information("Starting Proxy");
TcpListener listener = new TcpListener(IPAddress.Any, port);
TcpListener listener = new TcpListener(IPAddress.Any, 9000);
listener.Start();
Log.Information($"Proxy: Listening on port {port}");
Log.Information($"Proxy: Listening on port 9000");
while (true)
{
@ -24,30 +23,25 @@ public static class Proxy
string clientAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
Log.Information($"Proxy: Accepted client connection from {clientAddress}");
using (TcpClient server = new TcpClient())
{
await server.ConnectAsync(serverUrl, 80);
Log.Information($"Proxy: Connected to Elisa");
TcpClient server = new TcpClient();
await server.ConnectAsync(serverUrl, 80);
Log.Information($"Proxy: Connected to Elisa");
using (NetworkStream clientStream = client.GetStream())
using (NetworkStream serverStream = server.GetStream())
{
byte[] buffer = new byte[256 * 256];
int bytesRead;
while ((bytesRead = await clientStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
string data = Encoding.UTF8.GetString(buffer, 0, bytesRead).Trim();
Log.Information($"Received data from client: {data}");
}
NetworkStream clientStream = client.GetStream();
NetworkStream serverStream = server.GetStream();
Task c2sTask = clientStream.CopyToAsync(serverStream);
Task s2cTask = serverStream.CopyToAsync(clientStream);
await Task.WhenAll(c2sTask, s2cTask);
}
}
byte[] buffer = new byte[256 * 256];
int bytesRead;
while ((bytesRead = await clientStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
Log.Information($"Received data from client: {Encoding.UTF8.GetString(buffer, 0, bytesRead).Trim()}");
Task clientToServerTask = clientStream.CopyToAsync(serverStream);
Task serverToClientTask = serverStream.CopyToAsync(clientStream);
await Task.WhenAll(clientToServerTask, serverToClientTask);
client.Close();
Log.Information($"Proxy: Closed client connection");
server.Close();
Log.Information($"Proxy: Closed client and server connections");
}
}
}