This commit is contained in:
lhodges1 2023-09-12 01:34:44 +10:00
parent fc8db4bf6d
commit e475d49bf0
5 changed files with 39 additions and 13 deletions

View file

@ -29,13 +29,6 @@ namespace server.Database.Entity
h.IsBanned);
}
public bool CheckIfHardwareExists()
{
return _modelContext.HardwareConfiguration.Any(
h => h.MotherboardSerial == MotherboardSerial &&
h.DeviceDrive0Serial == DeviceDrive0Serial);
}
public void InsertHardwareConfiguration()
{
_modelContext.HardwareConfiguration.Add(this);

View file

@ -27,6 +27,14 @@ namespace server.Database.Entity
return _modelContext.Users.Any(u => u.Steam64Id == Steam64Id && u.IsBanned);
}
public bool CheckIfUsersHardwareExists()
{
List<HardwareConfiguration> hardwareConfigurations = _modelContext.HardwareConfiguration
.Where(h => h.User.Steam64Id == Steam64Id).ToList();
return hardwareConfigurations.Count > 0;
}
public void InsertUser()
{
_modelContext.Users.Add(this);

View file

@ -43,7 +43,7 @@ namespace server.Message
public int success;
}
public ClientReport(ILogger logger, byte[] buffer, int bufferSize, PACKET_HEADER packetHeader)
public ClientReport(ILogger logger, ref byte[] buffer, int bufferSize, PACKET_HEADER packetHeader)
{
this._logger = logger;
this._buffer = buffer;
@ -64,6 +64,11 @@ namespace server.Message
return Helper.StructureToBytes<CLIENT_REPORT_PACKET_RESPONSE>(ref this._responsePacket);
}
private void SetResponsePacketData(int success)
{
this._responsePacket.success = success;
}
public bool HandleMessage()
{
if (this._clientReportPacketHeader.reportCode == 0)
@ -109,6 +114,7 @@ namespace server.Message
break;
}
SetResponsePacketData(1);
return true;
}
}

View file

@ -40,7 +40,7 @@ namespace server.Message
public int reason;
}
public ClientSend(ILogger logger, byte[] buffer, int bufferSize, PACKET_HEADER packetHeader)
public ClientSend(ILogger logger, ref byte[] buffer, int bufferSize, PACKET_HEADER packetHeader)
{
this._logger = logger;
this._buffer = buffer;
@ -92,6 +92,25 @@ namespace server.Message
info.MotherboardSerialNumber,
info.DeviceDriver0Serial);
/*
* When a client connects to the server, we will perform the following.
*
* 1. Check if the user exists,
* - if the user doesn't exist we instert them into the database.
* - if the user does exist, check if they're banned
* - if the user is banned, return a response packet stating the
* client may not proceed
* 2. Next we check if the hardware is banned. We don't care if the hardware doesn't exist
* at this point because if it doesn't exist it can't be banned.
* - If the hardware is banned, return a cannot proceed packet.
* 3. Then we check if the users hardware already exists in the database, and the foreign
* UserId references the user by checking if the Steam64Id matches.
* - If a hardware configuration already exists, we send a response packet
* allowing the client to continue.
* 4. If we make it to here, the user is new and the hardware is not banned, so we then create
* a new user and a new hardware configuration and insert it into the database and then
* return a packet notifying the client can continue.
*/
using (var context = new ModelContext())
{
context.Database.EnsureCreated();
@ -127,9 +146,9 @@ namespace server.Message
return;
}
if (hardwareConfiguration.CheckIfHardwareExists())
if (user.CheckIfUsersHardwareExists())
{
_logger.Information("Users hardware already exists.");
_logger.Information("Users hardware already references the user.");
SetResponsePacketData(1, sendPacketHeader.RequestId, 0);
return;
}

View file

@ -70,7 +70,7 @@ namespace server.Message
private void HandleClientSendReport()
{
ClientReport report = new ClientReport(_logger, _buffer, _bufferSize, _header);
ClientReport report = new ClientReport(_logger, ref _buffer, _bufferSize, _header);
if (report.HandleMessage())
{
@ -84,7 +84,7 @@ namespace server.Message
private void HandleClientSendMessage()
{
ClientSend send = new ClientSend(_logger, _buffer, _bufferSize, _header);
ClientSend send = new ClientSend(_logger, ref _buffer, _bufferSize, _header);
if (send.HandleMessage())
{