mirror of
https://github.com/donnaskiez/ac.git
synced 2024-11-21 22:24:08 +01:00
bed time c:
This commit is contained in:
parent
bebcce9ac9
commit
fafcc9da1e
6 changed files with 106 additions and 138 deletions
|
@ -1,49 +0,0 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using server.Types.ClientReport;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace server.Database
|
||||
{
|
||||
public class ClientSend
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
private enum ClientSendCodes
|
||||
{
|
||||
MODULE_VERIFICATION_CHECKSUM_FAILURE = 10,
|
||||
}
|
||||
|
||||
public ClientSend(ILogger<ClientSend> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void InsertReport<T>(T report, int reportCode)
|
||||
{
|
||||
if (report == null)
|
||||
{
|
||||
_logger.LogError("Report is null");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reportCode)
|
||||
{
|
||||
/* case (int)ReportCodes.MODULE_VERIFICATION_CHECKSUM_FAILURE:
|
||||
InsertReportWithCode10((MODULE_VERIFICATION_CHECKSUM_FAILURE)Convert.ChangeType(report, typeof(MODULE_VERIFICATION_CHECKSUM_FAILURE)));
|
||||
break;
|
||||
default:
|
||||
_logger.LogError("Unknown report code: {0}", reportCode);
|
||||
break;*/
|
||||
}
|
||||
}
|
||||
|
||||
private void InsertReportWithCode10(MODULE_VERIFICATION_CHECKSUM_FAILURE report)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,9 +21,8 @@ namespace server.Database.Entity
|
|||
|
||||
public bool CheckIfHardwareConfigurationExists()
|
||||
{
|
||||
return _modelContext.HardwareConfiguration.Any(h =>
|
||||
h.MotherboardSerial == MotherboardSerial &&
|
||||
h.DeviceDrive0Serial == DeviceDrive0Serial);
|
||||
return _modelContext.HardwareConfiguration.Any(h => h.MotherboardSerial == MotherboardSerial &&
|
||||
h.DeviceDrive0Serial == DeviceDrive0Serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace server.Database.Model
|
|||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
public bool IsBanned { get; set; }
|
||||
public ulong DeviceDrive0Serial { get; set; }
|
||||
public ulong MotherboardSerial { get; set; }
|
||||
public string DeviceDrive0Serial { get; set; }
|
||||
public string MotherboardSerial { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,24 @@ namespace server
|
|||
}
|
||||
}
|
||||
|
||||
unsafe public static byte[] StructureToBytes<T>(ref T structure)
|
||||
{
|
||||
int typeSize = Marshal.SizeOf(typeof(T));
|
||||
byte[] buffer = new byte[typeSize];
|
||||
IntPtr ptr = Marshal.AllocHGlobal(typeSize);
|
||||
|
||||
try
|
||||
{
|
||||
Marshal.StructureToPtr(structure, ptr, true);
|
||||
Marshal.Copy(ptr, buffer, 0, typeSize);
|
||||
return buffer;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe public static string FixedUnsafeBufferToSafeString(ref byte[] buffer, int bufferSize, int offset, int stringSize)
|
||||
{
|
||||
if (stringSize > bufferSize)
|
||||
|
|
|
@ -12,6 +12,9 @@ using System.Net.Sockets;
|
|||
using server.Types.ClientReport;
|
||||
using server.Types.ClientSend;
|
||||
using System.Runtime.InteropServices;
|
||||
using server.Database.Model;
|
||||
using server.Database.Entity;
|
||||
using Org.BouncyCastle.Asn1.BC;
|
||||
|
||||
namespace server
|
||||
{
|
||||
|
@ -38,14 +41,27 @@ namespace server
|
|||
public struct PACKET_HEADER
|
||||
{
|
||||
public int message_type;
|
||||
public Int64 steam64_id;
|
||||
public ulong steam64_id;
|
||||
};
|
||||
|
||||
struct PACKET_REQUEST_HEADER
|
||||
private struct PACKET_REQUEST_HEADER
|
||||
{
|
||||
public int RequestId;
|
||||
}
|
||||
|
||||
private struct SYSTEM_INFORMATION_REQUEST_RESPONSE
|
||||
{
|
||||
public int RequestId;
|
||||
public int CanUserProceed;
|
||||
public int reason;
|
||||
}
|
||||
|
||||
private enum USER_BAN_REASONS
|
||||
{
|
||||
HARDWARE_BAN = 10,
|
||||
USER_BAN = 20
|
||||
}
|
||||
|
||||
public Message(NetworkStream networkStream, byte[] buffer, int bufferSize, ILogger logger)
|
||||
{
|
||||
_networkStream = networkStream;
|
||||
|
@ -128,7 +144,72 @@ namespace server
|
|||
|
||||
_logger.Information("SteamId: {0}, Mobo Serial: {1}, drive serial: {2}", _header.steam64_id, moboSerial, driveSerial);
|
||||
|
||||
using (var context = new ModelContext())
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
UserEntity user = new UserEntity(_logger, context);
|
||||
|
||||
user.Steam64Id = _header.steam64_id;
|
||||
user.HardwareConfigurationEntity = new HardwareConfigurationEntity(context);
|
||||
user.HardwareConfigurationEntity.MotherboardSerial = moboSerial;
|
||||
user.HardwareConfigurationEntity.DeviceDrive0Serial = driveSerial;
|
||||
|
||||
if (user.IsUsersHardwareBanned())
|
||||
{
|
||||
//return packet saying user is banned
|
||||
_logger.Information("Users hardware is banned");
|
||||
|
||||
BuildSystemVerificationResponseHeader(0, sendPacketHeader.RequestId, (int)USER_BAN_REASONS.HARDWARE_BAN);
|
||||
|
||||
context.SaveChanges();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (user.CheckIfUserExists())
|
||||
{
|
||||
if (user.CheckIfUserIsBanned())
|
||||
{
|
||||
//same here, send packet back saying user is banned
|
||||
_logger.Information("User is banned");
|
||||
|
||||
BuildSystemVerificationResponseHeader(0, sendPacketHeader.RequestId, (int)USER_BAN_REASONS.USER_BAN);
|
||||
|
||||
context.SaveChanges();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//send packet back that the user has successfully been authenticated
|
||||
_logger.Information("User is not banned");
|
||||
|
||||
BuildSystemVerificationResponseHeader(1, sendPacketHeader.RequestId, 0);
|
||||
|
||||
context.SaveChanges();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Information("User does not exist and is on valid hardware, creating new user");
|
||||
|
||||
user.InsertUser();
|
||||
BuildSystemVerificationResponseHeader(1, sendPacketHeader.RequestId, 0);
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildSystemVerificationResponseHeader(int canUserProceed, int requestId, int reason)
|
||||
{
|
||||
SYSTEM_INFORMATION_REQUEST_RESPONSE response = new SYSTEM_INFORMATION_REQUEST_RESPONSE();
|
||||
response.CanUserProceed = canUserProceed;
|
||||
response.RequestId = requestId;
|
||||
response.reason = reason;
|
||||
|
||||
byte[] responseBytes = Helper.StructureToBytes<SYSTEM_INFORMATION_REQUEST_RESPONSE>(ref response);
|
||||
|
||||
_networkStream.Write(responseBytes, 0, Marshal.SizeOf(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,90 +17,9 @@ namespace server
|
|||
using var logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.CreateLogger();
|
||||
|
||||
using (var context = new ModelContext())
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
Database.Entity.UserEntity user = new Database.Entity.UserEntity(logger, context);
|
||||
|
||||
user.IsBanned = false;
|
||||
user.Steam64Id = 123123123;
|
||||
|
||||
user.HardwareConfigurationEntity = new HardwareConfigurationEntity(context);
|
||||
user.HardwareConfigurationEntity.MotherboardSerial = 987654321;
|
||||
user.HardwareConfigurationEntity.DeviceDrive0Serial = 123456789;
|
||||
|
||||
if (user.IsUsersHardwareBanned())
|
||||
{
|
||||
logger.Information("Users hardware is banned");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.CheckIfUserExists())
|
||||
{
|
||||
if (user.CheckIfUserIsBanned())
|
||||
{
|
||||
logger.Information("User is banned");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Information("User is not banned");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Information("User does not exist");
|
||||
|
||||
user.InsertUser();
|
||||
}
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
Server server = new Server(logger);
|
||||
await server.Listen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*namespace server
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
await Program.Listen();
|
||||
}
|
||||
|
||||
public static async Task Listen()
|
||||
{
|
||||
var ipEndPoint = new IPEndPoint(IPAddress.Any, 8888);
|
||||
TcpListener listener = new(ipEndPoint);
|
||||
|
||||
try
|
||||
{
|
||||
listener.Start();
|
||||
|
||||
using TcpClient handler = await listener.AcceptTcpClientAsync();
|
||||
await using NetworkStream stream = handler.GetStream();
|
||||
|
||||
stream.BeginRead(new byte[1024], 0, 1024, Callback, null);
|
||||
|
||||
var message = $"📅 {DateTime.Now} 🕛";
|
||||
var dateTimeBytes = Encoding.UTF8.GetBytes(message);
|
||||
await stream.WriteAsync(dateTimeBytes);
|
||||
}
|
||||
finally
|
||||
{
|
||||
listener.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Callback(IAsyncResult ar)
|
||||
{
|
||||
Console.WriteLine("Is ocmpleted: {0}", ar.IsCompleted);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
Loading…
Reference in a new issue