Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/cypher_proxy' into cypher_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
coolzoom committed Aug 3, 2022
2 parents a4e8ae4 + ebcdd7f commit 4b3972d
Show file tree
Hide file tree
Showing 59 changed files with 25,726 additions and 350 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/Build_Proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build Proxy

on: ['push']

env:
DOTNET_VERSION: '6.0.x'

jobs:
build:
strategy:
matrix:
os: ['windows', 'ubuntu']
runs-on: ${{ matrix.os }}-latest

steps:
- name: Checkout repository content
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Publish
run: dotnet publish --configuration Release --self-contained true --use-current-runtime

- name: Copy files
run: cp -r ./HermesProxy/bin/*/Release/*/*/publish/ publish

- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: HermesProxy-${{ matrix.os }}-${{ runner.arch }}-${{ github.sha }}
path: publish
if-no-files-found: error
23 changes: 4 additions & 19 deletions Framework/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,11 @@ private static KeyValueConfigurationCollection GetConfiguration()
}
++i;
}
// load different config file
if (configFile != null)
{
string configPath = Path.Combine(Environment.CurrentDirectory, configFile);

try
{
// Get the mapped configuration file
var config = ConfigurationManager.OpenExeConfiguration(configPath);


settings = ((AppSettingsSection)config.GetSection("appSettings")).Settings;
}
catch (Exception ex)
{
Console.WriteLine("Could not load config file {0}, reason: {1}", configPath, ex.Message);
}
}

ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = "HermesProxy.dll.config" };
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
if (settings == null)
settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings;
settings = config.AppSettings.Settings;

// override config options with options from command line
foreach (var pair in opts)
Expand Down
8 changes: 5 additions & 3 deletions Framework/Configuration/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Framework
{
Expand All @@ -12,15 +13,16 @@ public static class Settings
public static readonly string ClientSeed = Conf.GetString("ClientSeed", "179D3DC3235629D07113A9B3867F97A7");
public static readonly ClientVersionBuild ClientBuild = Conf.GetEnum("ClientBuild", ClientVersionBuild.V2_5_2_40892);
public static readonly ClientVersionBuild ServerBuild = Conf.GetEnum("ServerBuild", ClientVersionBuild.V2_4_3_8606);
public static readonly string ServerAddress = Conf.GetString("ServerAddress", "127.0.0.1");
public static readonly string ServerAddress = Dns.GetHostAddresses(Conf.GetString("ServerAddress", "127.0.0.1")).GetValue(0).ToString();
public static readonly int ServerPort = Conf.GetInt("ServerPort", 3724);
public static readonly string ReportedOS = Conf.GetString("ReportedOS", "OSX");
public static readonly string ReportedPlatform = Conf.GetString("ReportedPlatform", "PPC");
public static readonly string ReportedPlatform = Conf.GetString("ReportedPlatform", "x86");
public static readonly string ExternalAddress = Conf.GetString("ExternalAddress", "127.0.0.1");
public static readonly int RestPort = Conf.GetInt("RestPort", 8081);
public static readonly int BNetPort = Conf.GetInt("BNetPort", 1119);
public static readonly int RealmPort = Conf.GetInt("RealmPort", 8085);
public static readonly int RealmPort = Conf.GetInt("RealmPort", 8084);
public static readonly int InstancePort = Conf.GetInt("InstancePort", 8086);
public static readonly bool DebugOutput = Conf.GetBoolean("DebugOutput", false);
public static readonly bool PacketsLog = Conf.GetBoolean("PacketsLog", true);
}
}
40 changes: 18 additions & 22 deletions Framework/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,36 @@ public static class Log
};

static BlockingCollection<(LogType Type, string Message)> logQueue = new();

public static bool IsLogging;
private static Thread? _logOutputThread = null;
public static bool IsLogging => _logOutputThread != null && !logQueue.IsCompleted;

/// <summary>
/// Start the logging Thread and take logs out of the <see cref="BlockingCollection{T}"/>
/// </summary>
public static void Start()
{
var logThread = new Thread(() =>
if (_logOutputThread == null)
{
IsLogging = true;

while (IsLogging)
_logOutputThread = new Thread(() =>
{
Thread.Sleep(1);
foreach (var msg in logQueue.GetConsumingEnumerable())
{
if (msg.Type == LogType.Debug && !Framework.Settings.DebugOutput)
continue;

if (!logQueue.TryTake(out var msg))
continue;
Console.Write($"{DateTime.Now:HH:mm:ss} |");

if (msg.Type == LogType.Debug && !Framework.Settings.DebugOutput)
continue;
Console.ForegroundColor = LogToColorType[msg.Type].Color;
Console.Write($"{LogToColorType[msg.Type].Type}");
Console.ResetColor();

Console.Write($"{DateTime.Now:H:mm:ss} |");
Console.WriteLine($"| {msg.Message}");
}
});

Console.ForegroundColor = LogToColorType[msg.Type].Color;
Console.Write($"{LogToColorType[msg.Type].Type}");
Console.ResetColor();

Console.WriteLine($"| {msg.Message}");
}
});
IsLogging = true;
logThread.IsBackground = true;
logThread.Start();
_logOutputThread.IsBackground = true;
_logOutputThread.Start();
}
}

public static void Print(LogType type, object text, [CallerMemberName] string method = "", [CallerFilePath] string path = "")
Expand Down
19 changes: 14 additions & 5 deletions HermesProxy/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Option: ClientBuild
Description: The version of the client you will play with.
Default: "40618" (1.14.0)
"40892" (2.5.2)
-->
<add key="ClientBuild" value="40618" />
<!--
Expand All @@ -17,6 +18,7 @@
Option: ServerBuild
Description: The version of the server you want to connect to.
Default: "5875" (1.12.1)
"8606" (2.4.3)
-->
<add key="ServerBuild" value="5875" />
<!--
Expand All @@ -40,9 +42,9 @@
<!--
Option: ReportedPlatform
Description: The platform identifier that will be sent to the remote server.
Default: "PPC"
Default: "x86"
-->
<add key="ReportedPlatform" value="PPC" />
<add key="ReportedPlatform" value="x86" />
<!--
Option: ExternalAddress
Description: Your real IP address on which others can connect.
Expand All @@ -57,14 +59,15 @@
<add key="RestPort" value="8081" />
<!--
Option: BNetPort
Description: The port on which the BNet server will listen.
Description: The port on which the BNet(/Portal) server will listen.
This is the port that you have to use in your Config.wtf file.
Default: "1119"
-->
<add key="BNetPort" value="1119" />
<!--
Option: RealmPort
Description: The port on which the Realm server will listen.
Default: "8085"
Default: "8084"
-->
<add key="RealmPort" value="8086" />
<!--
Expand All @@ -79,5 +82,11 @@
Default: "false"
-->
<add key="DebugOutput" value="false" />
<!--
Option: PacketsLog
Description: Save each session's packets to a single file in PacketsLog directory.
Default: "true"
-->
<add key="PacketsLog" value="true" />
</appSettings>
</configuration>
</configuration>
59 changes: 36 additions & 23 deletions HermesProxy/Auth/AuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Sockets;
using HermesProxy.Enums;
using System.Numerics;
using System.Threading.Tasks;
using Framework.Constants;
using Framework.Cryptography;
using Framework;
Expand All @@ -15,26 +16,35 @@ namespace HermesProxy.Auth
{
public class AuthClient
{
GlobalSessionData _globalSession;
Socket _clientSocket;
bool? _isSuccessful = null;
TaskCompletionSource<AuthResult> _response;
byte[] _passwordHash;
BigInteger _key;
byte[] _m2;
bool _hasRealmList;
string _username;
string _password;
string _locale;

public bool ConnectToAuthServer(string username, string password, string locale)
public AuthClient(GlobalSessionData globalSession)
{
_globalSession = globalSession;
}

public GlobalSessionData GetSession()
{
return _globalSession;
}

public AuthResult ConnectToAuthServer(string username, string password, string locale)
{
_username = username;
_password = password;
_locale = locale;

_isSuccessful = null;
_response = new ();
_hasRealmList = false;

string authstring = $"{_username.ToUpper()}:{_password}";
string authstring = $"{_username.ToUpper()}:{password}";
_passwordHash = HashAlgorithm.SHA1.Hash(Encoding.ASCII.GetBytes(authstring.ToUpper()));

try
Expand All @@ -48,15 +58,19 @@ public bool ConnectToAuthServer(string username, string password, string locale)
catch (Exception ex)
{
Log.Print(LogType.Error, $"Socket Error: {ex.Message}");
_isSuccessful = false;
_response.SetResult(AuthResult.FAIL_INTERNAL_ERROR);
}

while (_isSuccessful == null)
{ }
_response.Task.Wait();

return (bool)_isSuccessful;
return _response.Task.Result;
}

private void SetAuthResponse(AuthResult response)
{
_response.TrySetResult(response);
}

public void Disconnect()
{
if (!IsConnected())
Expand Down Expand Up @@ -89,7 +103,7 @@ private void ConnectCallback(IAsyncResult AR)
catch (Exception ex)
{
Log.Print(LogType.Error, $"Connect Error: {ex.Message}");
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);
}
}

Expand All @@ -101,8 +115,7 @@ private void ReceiveCallback(IAsyncResult AR)

if (received == 0)
{
if (_isSuccessful == null)
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);

Log.Print(LogType.Error, "Socket Closed By Server");
return;
Expand All @@ -122,7 +135,7 @@ private void ReceiveCallback(IAsyncResult AR)
catch (Exception ex)
{
Log.Print(LogType.Error, $"Packet Read Error: {ex.Message}");
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);
}
}

Expand All @@ -135,7 +148,7 @@ private void SendCallback(IAsyncResult AR)
catch (Exception ex)
{
Log.Print(LogType.Error, $"Packet Send Error: {ex.Message}");
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);
}
}

Expand All @@ -148,7 +161,7 @@ private void SendPacket(ByteBuffer packet)
catch (Exception ex)
{
Log.Print(LogType.Error, $"Packet Write Error: {ex.Message}");
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);
}
}

Expand All @@ -171,7 +184,7 @@ private void HandlePacket(byte[] buffer, int size)
break;
default:
Log.Print(LogType.Error, $"No handler for opcode {opcode}!");
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);
break;
}
}
Expand Down Expand Up @@ -207,7 +220,7 @@ private void HandleLogonChallenge(ByteBuffer packet)
if (error != AuthResult.SUCCESS)
{
Log.Print(LogType.Error, $"Login failed. Reason: {error}");
_isSuccessful = false;
SetAuthResponse(error);
return;
}

Expand Down Expand Up @@ -375,7 +388,7 @@ private void HandleLogonProof(ByteBuffer packet)
if (error != AuthResult.SUCCESS)
{
Log.Print(LogType.Error, $"Login failed. Reason: {error}");
_isSuccessful = false;
SetAuthResponse(error);
return;
}

Expand Down Expand Up @@ -408,12 +421,12 @@ private void HandleLogonProof(ByteBuffer packet)
if (!equal)
{
Log.Print(LogType.Error, "Authentication failed!");
_isSuccessful = false;
SetAuthResponse(AuthResult.FAIL_INTERNAL_ERROR);
}
else
{
Log.Print(LogType.Network, "Authentication succeeded!");
_isSuccessful = true;
SetAuthResponse(AuthResult.SUCCESS);
}
}

Expand Down Expand Up @@ -471,7 +484,7 @@ private void HandleRealmList(ByteBuffer packet)
realmInfo.Name = packet.ReadCString();
string addressAndPort = packet.ReadCString();
string[] strArr = addressAndPort.Split(':');
realmInfo.Address = strArr[0];
realmInfo.Address = Dns.GetHostAddresses(strArr[0]).GetValue(0).ToString();
realmInfo.Port = UInt16.Parse(strArr[1]);
realmInfo.Population = packet.ReadFloat();
realmInfo.CharacterCount = packet.ReadUInt8();
Expand All @@ -488,7 +501,7 @@ private void HandleRealmList(ByteBuffer packet)
realmList.Add(realmInfo);
}

RealmManager.Instance.UpdateRealms(realmList);
GetSession().RealmManager.UpdateRealms(realmList);
_hasRealmList = true;
}
}
Expand Down
Loading

0 comments on commit 4b3972d

Please sign in to comment.