Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Code style changes #134

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions HermesProxy/Auth/AuthClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Net;
Expand All @@ -25,14 +24,13 @@ public partial class AuthClient
// Debugger.Log(0, "TraceMe", $"{b}");
#endif
};

GlobalSessionData _globalSession;
readonly GlobalSessionData _globalSession;
Socket _clientSocket;
TaskCompletionSource<AuthResult> _response;
TaskCompletionSource _hasRealmlist;
byte[] _passwordHash;
BigInteger _key;
byte[] _m2;
byte[] _m2;
string _username;
string _locale;

Expand Down Expand Up @@ -104,7 +102,7 @@ private void SetAuthResponse(AuthResult response)
{
_response.TrySetResult(response);
}

public void Disconnect()
{
if (!IsConnected())
Expand Down Expand Up @@ -202,7 +200,7 @@ private void SendPacket(ByteBuffer packet)

private void HandlePacket(byte[] buffer, int size)
{
ByteBuffer packet = new ByteBuffer(buffer);
ByteBuffer packet = new(buffer);
AuthCommand opcode = (AuthCommand)packet.ReadUInt8();
Log.PrintNet(LogType.Debug, LogNetDir.S2P, $"Received opcode {opcode} size {size}.");

Expand All @@ -226,10 +224,10 @@ private void HandlePacket(byte[] buffer, int size)

private void SendLogonChallenge()
{
ByteBuffer buffer = new ByteBuffer();
ByteBuffer buffer = new();
buffer.WriteUInt8((byte)AuthCommand.LOGON_CHALLENGE);
buffer.WriteUInt8((byte)(LegacyVersion.ExpansionVersion > 1 ? 8 : 3));
buffer.WriteUInt16((UInt16)(_username.Length + 30));
buffer.WriteUInt16((ushort)(_username.Length + 30));
buffer.WriteBytes(Encoding.ASCII.GetBytes("WoW"));
buffer.WriteUInt8(0);
buffer.WriteUInt8(LegacyVersion.ExpansionVersion);
Expand Down Expand Up @@ -407,7 +405,7 @@ private void HandleLogonChallenge(ByteBuffer packet)

private void SendLogonProof(byte[] A, byte[] M1, byte[] crc)
{
ByteBuffer buffer = new ByteBuffer();
ByteBuffer buffer = new();
buffer.WriteUInt8((byte)AuthCommand.LOGON_PROOF);
buffer.WriteBytes(A);
buffer.WriteBytes(M1);
Expand Down Expand Up @@ -470,7 +468,7 @@ private void HandleLogonProof(ByteBuffer packet)

public void RequestRealmListUpdate()
{
ByteBuffer buffer = new ByteBuffer();
ByteBuffer buffer = new();
buffer.WriteUInt8((byte)AuthCommand.REALM_LIST);
for (int i = 0; i < 4; i++)
buffer.WriteUInt8(0);
Expand All @@ -493,12 +491,14 @@ private void HandleRealmList(ByteBuffer packet)
}

Log.Print(LogType.Network, $"Received {realmsCount} realms.");
List<RealmInfo> realmList = new List<RealmInfo>();
List<RealmInfo> realmList = new();

for (ushort i = 0; i < realmsCount; i++)
{
RealmInfo realmInfo = new RealmInfo();
realmInfo.ID = i;
RealmInfo realmInfo = new()
{
ID = i
};

if (Settings.ServerBuild < ClientVersionBuild.V2_0_3_6299)
{
Expand All @@ -515,7 +515,7 @@ private void HandleRealmList(ByteBuffer packet)
string addressAndPort = packet.ReadCString();
string[] strArr = addressAndPort.Split(':');
realmInfo.Address = Dns.GetHostAddresses(strArr[0]).First().ToString();
realmInfo.Port = UInt16.Parse(strArr[1]);
realmInfo.Port = ushort.Parse(strArr[1]);
realmInfo.Population = packet.ReadFloat();
realmInfo.CharacterCount = packet.ReadUInt8();
realmInfo.Timezone = packet.ReadUInt8();
Expand Down
8 changes: 1 addition & 7 deletions HermesProxy/Auth/AuthCommand.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HermesProxy.Auth
namespace HermesProxy.Auth
{
// ReSharper disable InconsistentNaming
public enum AuthCommand : byte
Expand Down
2 changes: 1 addition & 1 deletion HermesProxy/Auth/AuthResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public enum AuthResult : byte
FAIL_UNLOCKABLE_LOCK = 0x19, // Your account has been locked but can be unlocked.
FAIL_CONVERSION_REQUIRE = 0x20, // This account needs to be converted to a Battle.net account. Please [Click Here] or go to: <site> to begin conversion.
FAIL_DISCONNECTED = 0xFF,

// HermesProxy internal variables
FAIL_INTERNAL_ERROR = 0xFE, // Internal error
FAIL_WRONG_MODERN_VER = 0xFD, // Modern client is using unsupported version
Expand Down
5 changes: 0 additions & 5 deletions HermesProxy/Auth/RealmInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Framework.Constants;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HermesProxy.Auth
{
Expand Down
47 changes: 24 additions & 23 deletions HermesProxy/BnetServer/Managers/LoginServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
using Framework.Logging;
using Framework.Web;
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;

namespace BNetServer
{
public class LoginServiceManager : Singleton<LoginServiceManager>
{
FormInputs formInputs;
readonly FormInputs formInputs;
IPEndPoint externalAddress;
IPEndPoint localAddress;
X509Certificate2 certificate;

LoginServiceManager()
LoginServiceManager()
{
formInputs = new FormInputs();
}
Expand All @@ -34,8 +30,7 @@ public void Initialize()
}

string configuredAddress = Framework.Settings.ExternalAddress;
IPAddress address;
if (!IPAddress.TryParse(configuredAddress, out address))
if (!IPAddress.TryParse(configuredAddress, out IPAddress address))
{
Log.Print(LogType.Error, $"Could not resolve LoginREST.ExternalAddress {configuredAddress}");
return;
Expand All @@ -50,27 +45,33 @@ public void Initialize()
}
localAddress = new IPEndPoint(address, port);

// set up form inputs
// set up form inputs
formInputs.Type = "LOGIN_FORM";

var input = new FormInput();
input.Id = "account_name";
input.Type = "text";
input.Label = "E-mail";
input.MaxLength = 320;
var input = new FormInput
{
Id = "account_name",
Type = "text",
Label = "E-mail",
MaxLength = 320
};
formInputs.Inputs.Add(input);

input = new FormInput();
input.Id = "password";
input.Type = "password";
input.Label = "Password";
input.MaxLength = 16;
input = new FormInput
{
Id = "password",
Type = "password",
Label = "Password",
MaxLength = 16
};
formInputs.Inputs.Add(input);

input = new FormInput();
input.Id = "log_in_submit";
input.Type = "submit";
input.Label = "Log In";
input = new FormInput
{
Id = "log_in_submit",
Type = "submit",
Label = "Log In"
};
formInputs.Inputs.Add(input);
}

Expand Down
18 changes: 8 additions & 10 deletions HermesProxy/BnetServer/Networking/BnetRestApiSession.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.

using Framework.Constants;
using Framework.Networking;
using Framework.Serialization;
using Framework.Web;
using System;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using HermesProxy.Auth;
using HermesProxy.Enums;
Expand Down Expand Up @@ -52,7 +49,7 @@ public bool RequestRouter(HttpHeader httpRequest)
string path = httpRequest.Path.Substring(BNET_SERVER_BASE_PATH.Length);
string[] pathElements = path.Split('/');

switch (pathElements[0], httpRequest.Method)
switch (pathElements[0], httpRequest.Method)
{
case ("login", "GET"):
SendResponse(HttpCode.Ok, LoginServiceManager.Instance.GetFormInput());
Expand All @@ -72,12 +69,13 @@ public Task HandleLoginRequest(string[] pathElements, HttpHeader request)
if (loginForm == null)
return SendEmptyResponse(HttpCode.InternalServerError);

HermesProxy.GlobalSessionData globalSession = new();

// Format: "login/$platform/$build/$locale/"
globalSession.OS = pathElements[1];
globalSession.Build = uint.Parse(pathElements[2]);
globalSession.Locale = pathElements[3];
HermesProxy.GlobalSessionData globalSession = new()
{
// Format: "login/$platform/$build/$locale/"
OS = pathElements[1],
Build = uint.Parse(pathElements[2]),
Locale = pathElements[3]
};

// Should never happen. Session.HandleLogon checks version already
if (Framework.Settings.ClientBuild != (ClientVersionBuild) globalSession.Build)
Expand Down
2 changes: 1 addition & 1 deletion HermesProxy/BnetServer/Networking/BnetServerCertificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ static BnetServerCertificate()
byte[] bytes = ms.ToArray();
Certificate = new X509Certificate2(bytes);
}
}
}
}
}
23 changes: 12 additions & 11 deletions HermesProxy/BnetServer/Networking/BnetTcpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -44,13 +43,13 @@ public override bool Update()
return true;
}

private List<byte> _currentBuffer = new List<byte>();
private readonly List<byte> _currentBuffer = new();

public override async Task ReadHandler(byte[] data, int receivedLength)
{
if (!IsOpen())
return;

_currentBuffer.AddRange(data.Take(receivedLength));

await ProcessCurrentBuffer();
Expand Down Expand Up @@ -93,12 +92,14 @@ private Task ProcessCurrentBuffer()

public void SendRpcMessage(uint serviceId, OriginalHash service, uint methodId, uint token, BattlenetRpcErrorCode status, IMessage? message)
{
Header header = new();
header.Token = token;
header.Status = (uint)status;
header.ServiceId = serviceId;
header.ServiceHash = (uint)service;
header.MethodId = methodId;
Header header = new()
{
Token = token,
Status = (uint)status,
ServiceId = serviceId,
ServiceHash = (uint)service,
MethodId = methodId
};
if (message != null)
header.Size = (uint)message.CalculateSize();

Expand Down Expand Up @@ -126,7 +127,7 @@ public byte[] GetHeaderSize(Header header)
}

public class AccountInfo
{
{
public uint Id;
public WowGuid128 BnetAccountGuid => WowGuid128.Create(HighGuidType703.BNetAccount, Id);
public string Login;
Expand Down
10 changes: 4 additions & 6 deletions HermesProxy/BnetServer/Services/BnetServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
using BNetServer.Networking;
using Framework.Constants;
using Framework.Logging;
using Google.Protobuf;
Expand All @@ -16,7 +14,7 @@ namespace BNetServer.Services
public partial class BnetServices
{
private static uint _serverInvokedRequestToken = 0;
private Dictionary<uint /*requestId*/, Action<CodedInputStream> /*callbackHandler*/> _callbackHandlers = new();
private readonly Dictionary<uint /*requestId*/, Action<CodedInputStream> /*callbackHandler*/> _callbackHandlers = new();

private GlobalSessionData _globalSession;
private readonly byte[] _clientSecret = new byte[32];
Expand Down Expand Up @@ -58,10 +56,10 @@ private IPEndPoint GetRemoteIpEndPoint()

private void ServiceLog(LogType type, string message)
{
StringBuilder prefix = new StringBuilder();
StringBuilder prefix = new();
prefix.Append($"[{_connectionPath}]");
prefix.Append($"[{GetRemoteIpEndPoint()}");

if (GetSession() != null)
{
if (GetSession().AccountInfo != null && !GetSession().AccountInfo.Login.IsEmpty())
Expand All @@ -70,7 +68,7 @@ private void ServiceLog(LogType type, string message)
if (GetSession().GameAccountInfo != null)
prefix.Append(", Game account: " + GetSession().GameAccountInfo.Name);
}

prefix.Append(']');

Log.Print(type, $"{prefix} {message}");
Expand Down
Loading