129 lines
4.2 KiB
C#
129 lines
4.2 KiB
C#
|
|
using System.Text;
|
|
|
|
|
|
using RabbitMQ.Client;
|
|
using RabbitMQ.Client.Events;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
|
|
|
|
using SESSION_ID = System.Int32;
|
|
using META_ID = System.UInt32;
|
|
using ENTITY_GUID = System.String;
|
|
using ACCOUNT_ID = System.String;
|
|
using OWNER_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
using CHARACTER_GUID = System.String;
|
|
using ITEM_GUID = System.String;
|
|
|
|
|
|
namespace GameServer;
|
|
|
|
|
|
public class RabbitMQ4Game : RabbitMqConnector, IWithPacketNamespaceVerifier
|
|
{
|
|
public readonly string EXCHANGE_ALL_GAME_NAME = ServerCommon.Constant.EXCHANGE_ALL_GAME_NAME;
|
|
|
|
|
|
private IModel? m_exchange_all_game_channel = null;
|
|
|
|
|
|
public RabbitMQ4Game(ModuleContext moduleContext) :
|
|
base(moduleContext)
|
|
{
|
|
}
|
|
|
|
protected override Result onCreateExchangeChannel()
|
|
{
|
|
var result = new Result();
|
|
|
|
m_exchange_all_game_channel = createExchangeChannel(EXCHANGE_ALL_GAME_NAME, ExchangeType.Fanout);
|
|
|
|
return result;
|
|
}
|
|
|
|
public void sendChat(string chatMessage, string sender, ChatType chatType)
|
|
{
|
|
var message = new ServerMessage();
|
|
message.MessageTime = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow);
|
|
message.Chat = new ServerMessage.Types.Chat();
|
|
message.Chat.SenderNickName = sender;
|
|
message.Chat.Message = chatMessage;
|
|
message.Chat.ReceiverGuid = string.Empty;
|
|
message.Chat.Receiverstate = 0;
|
|
message.Chat.Type = chatType;
|
|
|
|
string messageJson = Google.Protobuf.JsonFormatter.Default.Format(message);
|
|
|
|
var body = Encoding.UTF8.GetBytes(messageJson);
|
|
if (null == m_exchange_all_game_channel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_exchange_all_game_channel.BasicPublish( exchange: EXCHANGE_ALL_GAME_NAME
|
|
, routingKey: ""
|
|
, basicProperties: null
|
|
, body: body );
|
|
}
|
|
|
|
public void sendExchangeMannequinDisplayItemNoti(string anchorGuid, List<int> displayItmeIds)
|
|
{
|
|
var message = new ServerMessage();
|
|
message.MessageTime = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow);
|
|
message.ExchangeMannequinDisplayItemNoti = new();
|
|
message.ExchangeMannequinDisplayItemNoti.AnchorGuid = anchorGuid;
|
|
message.ExchangeMannequinDisplayItemNoti.DisplayItemIds.AddRange(displayItmeIds);
|
|
|
|
string messageJson = Google.Protobuf.JsonFormatter.Default.Format(message);
|
|
var body = Encoding.UTF8.GetBytes(messageJson);
|
|
|
|
if (null == m_exchange_all_game_channel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_exchange_all_game_channel.BasicPublish( exchange: EXCHANGE_ALL_GAME_NAME
|
|
, routingKey: ""
|
|
, basicProperties: null
|
|
, body: body );
|
|
}
|
|
|
|
public void sendMessageToExchangeAllGame(ServerMessage message)
|
|
{
|
|
message.MessageTime = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow);
|
|
|
|
string messageJson = Google.Protobuf.JsonFormatter.Default.Format(message);
|
|
var body = Encoding.UTF8.GetBytes(messageJson);
|
|
|
|
if (null == m_exchange_all_game_channel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_exchange_all_game_channel.BasicPublish( exchange: EXCHANGE_ALL_GAME_NAME
|
|
, routingKey: ""
|
|
, basicProperties: null
|
|
, body: body );
|
|
}
|
|
|
|
protected override bool onCheckByExchangeType<T>(BasicDeliverEventArgs ea, T recvProtocol)
|
|
{
|
|
var msg = recvProtocol as ServerMessage;
|
|
if (msg is null) return false;
|
|
|
|
if (true == ea.Exchange.Equals(EXCHANGE_ALL_GAME_NAME, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
// 10초 전에 생성된 메시지는 드랍
|
|
if (msg.MessageTime.ToDateTime() < DateTime.UtcNow.AddSeconds(-10))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
} |