80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using AutoMapper;
|
||
|
|
using Common.Utils;
|
||
|
|
using CommonDomain;
|
||
|
|
using CommonDomain.BaseModel;
|
||
|
|
using CommonService;
|
||
|
|
using DotNetCore.CAP;
|
||
|
|
using FishRoomService.Hubs;
|
||
|
|
using FishRoomService.RoomSend;
|
||
|
|
using Microsoft.Extensions.Logging;
|
||
|
|
using MongoRepository;
|
||
|
|
using RedisService.Param;
|
||
|
|
using RedisService;
|
||
|
|
using UserDomain.Entity;
|
||
|
|
using UserService;
|
||
|
|
using UserService.Param;
|
||
|
|
using UserService.User;
|
||
|
|
|
||
|
|
namespace FishRoomService.MQ
|
||
|
|
{
|
||
|
|
|
||
|
|
public class RoomMQService : IRoomMQService, ICapSubscribe
|
||
|
|
{
|
||
|
|
private readonly IFishingRoomSendService _service;
|
||
|
|
private readonly IHubSend<FishRoomHub> _hubSend;
|
||
|
|
private readonly IRedisService _redisService;
|
||
|
|
private readonly ILogger<RoomMQService> _logger;
|
||
|
|
|
||
|
|
public RoomMQService(IFishingRoomSendService service, IHubSend<FishRoomHub> hubSend, IRedisService redisService, ILogger<RoomMQService> logger)
|
||
|
|
{
|
||
|
|
_service = service;
|
||
|
|
_hubSend = hubSend;
|
||
|
|
_redisService = redisService;
|
||
|
|
_logger = logger;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
[CapSubscribe(TopicKeys.房间变化)]
|
||
|
|
public async Task RoomChange(RedisGameRoom room)
|
||
|
|
{
|
||
|
|
|
||
|
|
_service.RoomChange(room);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
[CapSubscribe(TopicKeys.用户资产同步前端)]
|
||
|
|
public async Task UserAssetSync(UserAssetSyncParam param)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var session = _redisService.GetRedisUserCId(param.UserId);
|
||
|
|
var cid = session?.FishRoomCId;
|
||
|
|
if (string.IsNullOrWhiteSpace(cid) && string.IsNullOrWhiteSpace(session?.RoomId))
|
||
|
|
cid = session?.CId;
|
||
|
|
if (string.IsNullOrWhiteSpace(cid))
|
||
|
|
return;
|
||
|
|
await _hubSend.SendUserCIdAsync(cid, "AssetUpdated", new
|
||
|
|
{
|
||
|
|
param.CurrencyType,
|
||
|
|
param.ChangeType,
|
||
|
|
param.Amount,
|
||
|
|
param.NewGold,
|
||
|
|
param.NewDiamond,
|
||
|
|
param.Source,
|
||
|
|
param.Remark
|
||
|
|
});
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
_logger.LogError(ex, "房间AssetUpdated推送失败 userId={UserId}", param?.UserId);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|