Made the channel event log code similar to the normal event handling code.
This commit is contained in:
parent
5daad52aba
commit
d426df91f0
1 changed files with 14 additions and 28 deletions
|
@ -262,19 +262,12 @@ namespace SharpChat {
|
||||||
|
|
||||||
public void HandleChannelEventLog(string channelName, Action<ISockChatS2CPacket> handler) {
|
public void HandleChannelEventLog(string channelName, Action<ISockChatS2CPacket> handler) {
|
||||||
foreach(ChatEventInfo info in EventStorage.GetChannelEventLog(channelName)) {
|
foreach(ChatEventInfo info in EventStorage.GetChannelEventLog(channelName)) {
|
||||||
ISockChatS2CPacket? packet;
|
|
||||||
|
|
||||||
switch(info.Type) {
|
switch(info.Type) {
|
||||||
case "msg:add":
|
case "msg:add":
|
||||||
string maText = string.Empty;
|
if(info.Data is not MessageAddEventData msgAdd)
|
||||||
bool maAction = false;
|
break;
|
||||||
|
|
||||||
if(info.Data is MessageAddEventData messageAdd) {
|
handler(new MessageAddLogS2CPacket(
|
||||||
maText = messageAdd.Text;
|
|
||||||
maAction = messageAdd.IsAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
packet = new MessageAddLogS2CPacket(
|
|
||||||
info.Id,
|
info.Id,
|
||||||
info.Created,
|
info.Created,
|
||||||
info.SenderId,
|
info.SenderId,
|
||||||
|
@ -282,54 +275,47 @@ namespace SharpChat {
|
||||||
info.SenderColour,
|
info.SenderColour,
|
||||||
info.SenderRank,
|
info.SenderRank,
|
||||||
info.SenderPerms,
|
info.SenderPerms,
|
||||||
maText,
|
msgAdd.Text,
|
||||||
maAction,
|
msgAdd.IsAction,
|
||||||
info.ChannelName.StartsWith('@'),
|
info.ChannelName.StartsWith('@'),
|
||||||
info.IsBroadcast,
|
info.IsBroadcast,
|
||||||
false
|
false
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "user:connect":
|
case "user:connect":
|
||||||
packet = new UserConnectLogS2CPacket(
|
handler(new UserConnectLogS2CPacket(
|
||||||
info.Id,
|
info.Id,
|
||||||
info.Created,
|
info.Created,
|
||||||
SockChatUtility.GetUserName(info)
|
SockChatUtility.GetUserName(info)
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "user:disconnect":
|
case "user:disconnect":
|
||||||
packet = new UserDisconnectLogS2CPacket(
|
handler(new UserDisconnectLogS2CPacket(
|
||||||
info.Id,
|
info.Id,
|
||||||
info.Created,
|
info.Created,
|
||||||
SockChatUtility.GetUserName(info),
|
SockChatUtility.GetUserName(info),
|
||||||
info.Data is UserDisconnectEventData userDisconnect ? userDisconnect.Reason : UserDisconnectReason.Leave
|
info.Data is UserDisconnectEventData userDisconnect ? userDisconnect.Reason : UserDisconnectReason.Leave
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "chan:join":
|
case "chan:join":
|
||||||
packet = new UserChannelJoinLogS2CPacket(
|
handler(new UserChannelJoinLogS2CPacket(
|
||||||
info.Id,
|
info.Id,
|
||||||
info.Created,
|
info.Created,
|
||||||
SockChatUtility.GetUserName(info)
|
SockChatUtility.GetUserName(info)
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "chan:leave":
|
case "chan:leave":
|
||||||
packet = new UserChannelLeaveLogS2CPacket(
|
handler(new UserChannelLeaveLogS2CPacket(
|
||||||
info.Id,
|
info.Id,
|
||||||
info.Created,
|
info.Created,
|
||||||
SockChatUtility.GetUserName(info)
|
SockChatUtility.GetUserName(info)
|
||||||
);
|
));
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
packet = null;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(packet != null)
|
|
||||||
handler(packet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue