Changes account packets to functional (#284)
- [X] Moved packets from objects to functions - [X] Fixed bug where characters were showing up with their modded names in the character list Bumps release version
This commit is contained in:
parent
90220feb41
commit
0e02cf0821
19 changed files with 866 additions and 631 deletions
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Server.Accounting;
|
||||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
public class MockAccount : IAccount, IComparable<MockAccount>
|
||||
{
|
||||
private readonly Mobile[] m_Mobiles;
|
||||
private string m_Password;
|
||||
|
||||
public MockAccount(Mobile[] mobiles)
|
||||
{
|
||||
m_Mobiles = mobiles;
|
||||
foreach (var mobile in mobiles)
|
||||
{
|
||||
if (mobile != null)
|
||||
{
|
||||
mobile.Account = this;
|
||||
}
|
||||
}
|
||||
|
||||
Length = mobiles.Length;
|
||||
Count = mobiles.Count(t => t != null);
|
||||
Limit = mobiles.Length;
|
||||
}
|
||||
|
||||
public int TotalGold { get; private set; }
|
||||
public int TotalPlat { get; private set; }
|
||||
|
||||
public bool DepositGold(int amount)
|
||||
{
|
||||
TotalGold += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DepositPlat(int amount)
|
||||
{
|
||||
TotalPlat += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WithdrawGold(int amount)
|
||||
{
|
||||
if (TotalGold - amount < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TotalGold -= amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WithdrawPlat(int amount)
|
||||
{
|
||||
if (TotalPlat - amount < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TotalPlat -= amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
public long GetTotalGold() => TotalGold + TotalPlat * 100;
|
||||
|
||||
public int CompareTo(IAccount other) => other == null ? 1 : Username.CompareTo(other.Username);
|
||||
|
||||
public string Username { get; set; }
|
||||
public string Email { get; set; }
|
||||
public AccessLevel AccessLevel { get; set; }
|
||||
public int Length { get; }
|
||||
public int Limit { get; }
|
||||
public int Count { get; }
|
||||
|
||||
public Mobile this[int index]
|
||||
{
|
||||
get => m_Mobiles[index];
|
||||
set => m_Mobiles[index] = value;
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetPassword(string password)
|
||||
{
|
||||
m_Password = password;
|
||||
}
|
||||
|
||||
public bool CheckPassword(string password) => m_Password == password;
|
||||
|
||||
public int CompareTo(MockAccount other) => other == null ? 1 : Username.CompareTo(other.Username);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
public class MockSocket : ISocket
|
||||
{
|
||||
public EndPoint LocalEndPoint { get; set; }
|
||||
public EndPoint RemoteEndPoint { get; set; }
|
||||
public Task<int> SendAsync(IList<ArraySegment<byte>> buffers, SocketFlags flags) => Task.Run(() => 0);
|
||||
|
||||
public Task<int> ReceiveAsync(IList<ArraySegment<byte>> buffers, SocketFlags flags) => Task.Run(() => 0);
|
||||
|
||||
public void Shutdown(SocketShutdown how)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
public static class PacketTestUtilities
|
||||
{
|
||||
public static Span<byte> Compile(this Packet p) =>
|
||||
p.Compile(false, out var length).AsSpan(0, length);
|
||||
|
||||
public static NetState CreateTestNetState() =>
|
||||
new NetState(new MockSocket());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue