58 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using DysonNetwork.Shared.Models;
 | 
						|
using DysonNetwork.Shared.Services;
 | 
						|
using MagicOnion.Server;
 | 
						|
using Microsoft.AspNetCore.Http;
 | 
						|
 | 
						|
namespace DysonNetwork.Pass.Account;
 | 
						|
 | 
						|
public class ActionLogService : ServiceBase<IActionLogService>, IActionLogService
 | 
						|
{
 | 
						|
    // private readonly GeoIpService _geo;
 | 
						|
    // private readonly FlushBufferService _fbs;
 | 
						|
 | 
						|
    public ActionLogService(
 | 
						|
        // GeoIpService geo,
 | 
						|
        // FlushBufferService fbs
 | 
						|
    )
 | 
						|
    {
 | 
						|
        // _geo = geo;
 | 
						|
        // _fbs = fbs;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public void CreateActionLog(Guid accountId, string action, Dictionary<string, object> meta)
 | 
						|
    {
 | 
						|
        var log = new ActionLog
 | 
						|
        {
 | 
						|
            Action = action,
 | 
						|
            AccountId = accountId,
 | 
						|
            Meta = meta,
 | 
						|
        };
 | 
						|
 | 
						|
        // fbs.Enqueue(log);
 | 
						|
    }
 | 
						|
 | 
						|
    public async Task<ActionLog> CreateActionLogFromRequest(string type, Dictionary<string, object> meta, string? ipAddress, string? userAgent, Shared.Models.Account? account = null)
 | 
						|
    {
 | 
						|
        var log = new ActionLog
 | 
						|
        {
 | 
						|
            Action = type,
 | 
						|
            Meta = meta,
 | 
						|
            UserAgent = userAgent,
 | 
						|
            IpAddress = ipAddress,
 | 
						|
            // Location = geo.GetPointFromIp(ipAddress)
 | 
						|
        };
 | 
						|
        
 | 
						|
        if (account != null)
 | 
						|
            log.AccountId = account.Id;
 | 
						|
        else
 | 
						|
            throw new ArgumentException("No user context was found");
 | 
						|
        
 | 
						|
        // For MagicOnion, HttpContext.Items["CurrentSession"] is not directly available.
 | 
						|
        // You might need to pass session ID explicitly if needed.
 | 
						|
        // if (request.HttpContext.Items["CurrentSession"] is Session currentSession)
 | 
						|
        //    log.SessionId = currentSession.Id;
 | 
						|
 | 
						|
        // fbs.Enqueue(log);
 | 
						|
        return log;
 | 
						|
    }
 | 
						|
} |