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; hasChanged = true;
} }
if(colour.HasValue && user.Colour.Equals(colour.Value)) { if(colour.HasValue && !user.Colour.Equals(colour.Value)) {
user.Colour = colour.Value; user.Colour = colour.Value;
hasChanged = true; hasChanged = true;
} }
@ -222,7 +222,7 @@ namespace SharpChat {
hasChanged = true; hasChanged = true;
} }
if(isSuper.HasValue) { if(isSuper.HasValue && user.IsSuper != isSuper) {
user.IsSuper = isSuper.Value; user.IsSuper = isSuper.Value;
hasChanged = true; hasChanged = true;
} }
@ -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);
} }
} }