ace/Source/ACE.Common/Extensions/BinaryReaderExtensions.cs
Mogwai-TheFurry 610c2d0573 Authentication overhaul and API start (#543)
* WIP

* WIP - MVC app for weenie editor with auth overhaul in place

* removed redundant project

* more WIP.  commiting to rebase

* WIP.  API works, auth partially tied in, swagger works, api host works

* moved auth to a post with a body instead of get

* WIP.  auth fully works.  swagger UI supports auth model.

* added easier auth attribute, updated existing methods for consistency.  should PR this after a couple more hours

* stylecop cleanups

* WIP. commiting to get help with session and connection issues

* forgot to save some changes to a sql script

* got all the login issues squared away.  new auth system is done.

* WIP. getting an out of memory exception i cant track down

* WIP.  PacketInboundLoginRequets reads the JwtToken with 2 bonus (invalid) prepended characters

* updated ReadString32L to suck a little less.  i dont think this is 100% correct though.

* Authentication overhaul complete, APIs begun to support content editing

* appveyor cleanup

* appveyor cleanup, take 2

* appveyor cleanup, take 3

* appveyor cleanup, take 4

* Rename 2017-10-20-auth-overhaul.sql to 2017-10-20-00-auth-overhaul.sql

* Rename 2017-10-20-auth-overhaul-shard.sql to 2017-10-20-00-auth-overhaul-shard.sql

* Rename 2017-10-20-auth-overhaul-world.sql to 2017-10-20-00-auth-overhaul-world.sql

* Update MySqlInstall.bat
2017-10-21 13:32:06 -04:00

53 lines
1.9 KiB
C#

using System.IO;
namespace ACE.Common.Extensions
{
public static class BinaryReaderExtensions
{
private static uint CalculatePadMultiple(uint length, uint multiple)
{
return multiple * ((length + multiple - 1u) / multiple) - length;
}
public static string ReadString32L(this BinaryReader reader)
{
uint length = reader.ReadUInt32();
// 32L strings are crazy. the only place this is known as of time of writing this is in the
// Login header packet. it's a DWORD of the data length, followed by a packed word of the
// string length. for most cases, this means the string comes out with a 1 or 2 character
// prefix that just needs to get tossed.
if (length == 0)
return "";
reader.Skip(1);
length--;
if (length > 255)
{
reader.Skip(1);
length--;
}
string rdrStr = (length != 0 ? new string(reader.ReadChars((int)length)) : string.Empty);
// in the login header, this is completely unnecessary as it's the end of the packet. if
// we find this is ever used somewhere else, we would need to validate it.
reader.Skip(CalculatePadMultiple(sizeof(uint) + length, 4u));
return rdrStr;
}
public static string ReadString16L(this BinaryReader reader)
{
ushort length = reader.ReadUInt16();
string rdrStr = (length != 0 ? new string(reader.ReadChars(length)) : string.Empty);
// client pads string length to be a multiple of 4 including the 2 bytes for length
reader.Skip(CalculatePadMultiple(sizeof(ushort) + (uint)length, 4u));
return rdrStr;
}
public static void Skip(this BinaryReader reader, uint length) { reader.BaseStream.Position += length; }
}
}