Compare commits

...

2 commits

Author SHA1 Message Date
09d5bfef82 Fixed excessive sending of user update packets.
the funny inverted if condition
2024-05-24 13:19:04 +00:00
d426df91f0 Made the channel event log code similar to the normal event handling code. 2024-05-24 13:11:21 +00:00

View file

@ -197,7 +197,7 @@ namespace SharpChat {
hasChanged = true;
}
if(colour.HasValue && user.Colour.Equals(colour.Value)) {
if(colour.HasValue && !user.Colour.Equals(colour.Value)) {
user.Colour = colour.Value;
hasChanged = true;
}
@ -222,7 +222,7 @@ namespace SharpChat {
hasChanged = true;
}
if(isSuper.HasValue) {
if(isSuper.HasValue && user.IsSuper != isSuper) {
user.IsSuper = isSuper.Value;
hasChanged = true;
}
@ -262,19 +262,12 @@ namespace SharpChat {
public void HandleChannelEventLog(string channelName, Action<ISockChatS2CPacket> handler) {
foreach(ChatEventInfo info in EventStorage.GetChannelEventLog(channelName)) {
ISockChatS2CPacket? packet;
switch(info.Type) {
case "msg:add":
string maText = string.Empty;
bool maAction = false;
if(info.Data is not MessageAddEventData msgAdd)
break;
if(info.Data is MessageAddEventData messageAdd) {
maText = messageAdd.Text;
maAction = messageAdd.IsAction;
}
packet = new MessageAddLogS2CPacket(
handler(new MessageAddLogS2CPacket(
info.Id,
info.Created,
info.SenderId,
@ -282,54 +275,47 @@ namespace SharpChat {
info.SenderColour,
info.SenderRank,
info.SenderPerms,
maText,
maAction,
msgAdd.Text,
msgAdd.IsAction,
info.ChannelName.StartsWith('@'),
info.IsBroadcast,
false
);
));
break;
case "user:connect":
packet = new UserConnectLogS2CPacket(
handler(new UserConnectLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info)
);
));
break;
case "user:disconnect":
packet = new UserDisconnectLogS2CPacket(
handler(new UserDisconnectLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info),
info.Data is UserDisconnectEventData userDisconnect ? userDisconnect.Reason : UserDisconnectReason.Leave
);
));
break;
case "chan:join":
packet = new UserChannelJoinLogS2CPacket(
handler(new UserChannelJoinLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info)
);
));
break;
case "chan:leave":
packet = new UserChannelLeaveLogS2CPacket(
handler(new UserChannelLeaveLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info)
);
break;
default:
packet = null;
));
break;
}
if(packet != null)
handler(packet);
}
}