Added base class for packets with timestamp.

This commit is contained in:
flash 2024-05-20 02:16:38 +00:00
parent 042b6ddbd6
commit 1d781bd72c
56 changed files with 265 additions and 334 deletions

View file

@ -200,7 +200,7 @@ namespace SharpChat {
HandleDisconnect(user, reason);
}
public void HandleChannelEventLog(string channelName, Action<ServerPacket> handler) {
public void HandleChannelEventLog(string channelName, Action<SockChatS2CPacket> handler) {
foreach(StoredEventInfo msg in Events.GetChannelEventLog(channelName))
handler(msg.Type switch {
"msg:add" => new MessageAddLogPacket(
@ -218,19 +218,23 @@ namespace SharpChat {
false
),
"user:connect" => new UserConnectLogPacket(
msg.Id,
msg.Created,
msg.Sender == null ? string.Empty : SockChatUtility.GetUserName(msg.Sender)
),
"user:disconnect" => new UserDisconnectLogPacket(
msg.Id,
msg.Created,
msg.Sender == null ? string.Empty : SockChatUtility.GetUserNameWithStatus(msg.Sender),
(UserDisconnectReason)msg.Data.RootElement.GetProperty("reason").GetByte()
),
"chan:join" => new UserChannelJoinLogPacket(
msg.Id,
msg.Created,
msg.Sender == null ? string.Empty : SockChatUtility.GetUserName(msg.Sender)
),
"chan:leave" => new UserChannelLeaveLogPacket(
msg.Id,
msg.Created,
msg.Sender == null ? string.Empty : SockChatUtility.GetUserName(msg.Sender)
),
@ -241,7 +245,6 @@ namespace SharpChat {
public void HandleJoin(UserInfo user, ChannelInfo chan, ConnectionInfo conn, int maxMsgLength) {
if(!ChannelsUsers.Has(chan, user)) {
SendTo(chan, new UserConnectPacket(
DateTimeOffset.Now,
user.UserId,
SockChatUtility.GetUserNameWithStatus(user),
user.Colour,
@ -292,7 +295,6 @@ namespace SharpChat {
foreach(ChannelInfo chan in channels) {
SendTo(chan, new UserDisconnectPacket(
DateTimeOffset.Now,
user.UserId,
SockChatUtility.GetUserNameWithStatus(user),
reason
@ -369,26 +371,26 @@ namespace SharpChat {
RemoveChannel(oldChan);
}
public void Send(ServerPacket packet) {
public void Send(SockChatS2CPacket packet) {
foreach(ConnectionInfo conn in Connections)
if(conn.IsAuthed)
conn.Send(packet);
}
public void SendTo(UserInfo user, ServerPacket packet) {
public void SendTo(UserInfo user, SockChatS2CPacket packet) {
foreach(ConnectionInfo conn in Connections)
if(conn.IsAuthed && conn.User!.UserId == user.UserId)
conn.Send(packet);
}
public void SendTo(ChannelInfo channel, ServerPacket packet) {
public void SendTo(ChannelInfo channel, SockChatS2CPacket packet) {
long[] userIds = ChannelsUsers.GetChannelUserIds(channel);
foreach(ConnectionInfo conn in Connections)
if(conn.IsAuthed && userIds.Contains(conn.User!.UserId))
conn.Send(packet);
}
public void SendToUserChannels(UserInfo user, ServerPacket packet) {
public void SendToUserChannels(UserInfo user, SockChatS2CPacket packet) {
ChannelInfo[] chans = GetUserChannels(user);
foreach(ChannelInfo chan in chans)
SendTo(chan, packet);

View file

@ -44,7 +44,7 @@ namespace SharpChat {
RemotePort = (ushort)sock.ConnectionInfo.ClientPort;
}
public void Send(ServerPacket packet) {
public void Send(SockChatS2CPacket packet) {
if(!Socket.IsAvailable)
return;

View file

@ -1,12 +0,0 @@
namespace SharpChat {
public abstract class ServerPacket {
public long SequenceId { get; }
public ServerPacket(long sequenceId = 0) {
// Allow sequence id to be manually set for potential message repeats
SequenceId = sequenceId > 0 ? sequenceId : SharpId.Next();
}
public abstract string Pack();
}
}

View file

@ -1,7 +1,7 @@
using System;
namespace SharpChat.Packet {
public class AuthFailPacket : ServerPacket {
public class AuthFailPacket : SockChatS2CPacket {
public enum FailReason {
AuthInvalid,
MaxSessions,

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class AuthSuccessPacket : ServerPacket {
public class AuthSuccessPacket : SockChatS2CPacket {
private readonly long UserId;
private readonly string UserName;
private readonly Colour UserColour;

View file

@ -1,20 +1,17 @@
using System;
using System.Text;
using System.Text;
namespace SharpChat.Packet {
public class BanListResponsePacket : ServerPacket {
private readonly long Timestamp;
public class BanListResponsePacket : SockChatTimedS2CPacket {
private readonly string[] Bans;
public BanListResponsePacket(string[] bans) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
Bans = bans;
}
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat("2\t{0}\t-1\t0\fbanlist\f", Timestamp);
sb.AppendFormat("2\t{0}\t-1\t0\fbanlist\f", TimeStamp.ToUnixTimeSeconds());
foreach(string ban in Bans)
sb.AppendFormat(@"<a href=""javascript:void(0);"" onclick=""Chat.SendMessageWrapper('/unban '+ this.innerHTML);"">{0}</a>, ", ban);
@ -22,7 +19,7 @@ namespace SharpChat.Packet {
if(Bans.Length > 0)
sb.Length -= 2;
sb.AppendFormat("\t{0}\t10010", SequenceId);
sb.AppendFormat("\t{0}\t10010", MessageId);
return sb.ToString();
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class ChannelCreatePacket : ServerPacket {
public class ChannelCreatePacket : SockChatS2CPacket {
private readonly string ChannelName;
private readonly bool ChannelHasPassword;
private readonly bool ChannelIsTemporary;

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelCreateResponsePacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelCreateResponsePacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelCreateResponsePacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t0\fcrchan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelDeleteNotAllowedErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelDeleteNotAllowedErrorPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelDeleteNotAllowedErrorPacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fndchan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class ChannelDeletePacket : ServerPacket {
public class ChannelDeletePacket : SockChatS2CPacket {
private readonly string ChannelName;
public ChannelDeletePacket(string channelName) {

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelDeleteResponsePacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelDeleteResponsePacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelDeleteResponsePacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t0\fdelchan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class ChannelNameFormatErrorPacket : ServerPacket {
private readonly long Timestamp;
public ChannelNameFormatErrorPacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class ChannelNameFormatErrorPacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\finchan\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\finchan\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelNameInUseErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelNameInUseErrorPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelNameInUseErrorPacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fnischan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelNotFoundErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelNotFoundErrorPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelNotFoundErrorPacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fnochan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class ChannelPasswordChangedResponsePacket : ServerPacket {
private readonly long Timestamp;
public ChannelPasswordChangedResponsePacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class ChannelPasswordChangedResponsePacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t0\fcpwdchan\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t0\fcpwdchan\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelPasswordWrongErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelPasswordWrongErrorPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelPasswordWrongErrorPacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fipwchan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class ChannelRankChangedResponsePacket : ServerPacket {
private readonly long Timestamp;
public ChannelRankChangedResponsePacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class ChannelRankChangedResponsePacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t0\fcprivchan\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t0\fcprivchan\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class ChannelRankTooHighErrorPacket : ServerPacket {
private readonly long Timestamp;
public ChannelRankTooHighErrorPacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class ChannelRankTooHighErrorPacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\frankerr\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\frankerr\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class ChannelRankTooLowErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class ChannelRankTooLowErrorPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public ChannelRankTooLowErrorPacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fipchan\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class ChannelUpdatePacket : ServerPacket {
public class ChannelUpdatePacket : SockChatS2CPacket {
private readonly string ChannelNamePrevious;
private readonly string ChannelNameNew;
private readonly bool ChannelHasPassword;

View file

@ -1,7 +1,7 @@
using System.Text;
namespace SharpChat.Packet {
public class ChannelsPopulatePacket : ServerPacket {
public class ChannelsPopulatePacket : SockChatS2CPacket {
public record ListEntry(string Name, bool HasPassword, bool IsTemporary);
private readonly ListEntry[] Entries;

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class CommandFormatErrorPacket : ServerPacket {
private readonly long Timestamp;
public CommandFormatErrorPacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class CommandFormatErrorPacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\fcmdna\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\fcmdna\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class CommandNotAllowedErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class CommandNotAllowedErrorPacket : SockChatTimedS2CPacket {
private readonly string CommandName;
public CommandNotAllowedErrorPacket(string commandName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
CommandName = commandName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fcmdna\f/{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
CommandName,
SequenceId
MessageId
);
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class ContextClearPacket : ServerPacket {
public class ContextClearPacket : SockChatS2CPacket {
public enum ClearMode {
Messages = 0,
Users = 1,

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class FloodWarningPacket : ServerPacket {
private readonly long Timestamp;
public FloodWarningPacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class FloodWarningPacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t0\fflwarn\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t0\fflwarn\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,7 +1,7 @@
using System;
namespace SharpChat.Packet {
public class ForceDisconnectPacket : ServerPacket {
public class ForceDisconnectPacket : SockChatS2CPacket {
private readonly long Expires;
public ForceDisconnectPacket() {}

View file

@ -1,17 +1,18 @@
using System;
namespace SharpChat.Packet {
public class KickBanNoRecordErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class KickBanNoRecordErrorPacket : SockChatTimedS2CPacket {
private readonly string TargetName;
public KickBanNoRecordErrorPacket(string targetName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
TargetName = targetName;
}
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\fnotban\f{1}\t{2}\t10010", Timestamp, TargetName, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\fnotban\f{1}\t{2}\t10010",
TimeStamp.ToUnixTimeSeconds(),
TargetName,
MessageId
);
}
}
}

View file

@ -1,17 +1,18 @@
using System;
namespace SharpChat.Packet {
public class KickBanNotAllowedErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class KickBanNotAllowedErrorPacket : SockChatTimedS2CPacket {
private readonly string UserName;
public KickBanNotAllowedErrorPacket(string userName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
UserName = userName;
}
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\fkickna\f{1}\t{2}\t10010", Timestamp, UserName, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\fkickna\f{1}\t{2}\t10010",
TimeStamp.ToUnixTimeSeconds(),
UserName,
MessageId
);
}
}
}

View file

@ -1,19 +1,16 @@
using System;
namespace SharpChat.Packet {
public class MOTDPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class MOTDPacket : SockChatTimedS2CPacket {
private readonly string Body;
public MOTDPacket(string body) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
Body = body;
}
public override string Pack() {
return string.Format(
"7\t1\t{0}\t-1\tChatBot\tinherit\t\t0\fsay\f{1}\twelcome\t0\t10010",
Timestamp, SockChatUtility.SanitiseMessageBody(Body)
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseMessageBody(Body)
);
}
}

View file

@ -1,8 +1,7 @@
using System;
namespace SharpChat.Packet {
public class MessageAddLogPacket : ServerPacket {
private readonly long Created;
public class MessageAddLogPacket : SockChatTimedS2CPacket {
private readonly long UserId;
private readonly string UserName;
private readonly Colour UserColour;
@ -15,8 +14,8 @@ namespace SharpChat.Packet {
private readonly bool Notify;
public MessageAddLogPacket(
long msgId,
DateTimeOffset created,
long messageId,
DateTimeOffset timeStamp,
long userId,
string userName,
Colour userColour,
@ -27,8 +26,7 @@ namespace SharpChat.Packet {
bool isPrivate,
bool isBroadcast,
bool notify
) : base(msgId) {
Created = created.ToUnixTimeSeconds();
) : base(messageId, timeStamp) {
UserId = userId < 0 ? -1 : userId;
UserName = userName;
UserColour = userColour;
@ -62,13 +60,13 @@ namespace SharpChat.Packet {
return string.Format(
"7\t1\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}{9}{10}{11}{12}",
Created,
TimeStamp.ToUnixTimeSeconds(),
UserId,
UserName,
UserColour,
userPerms,
body,
SequenceId,
MessageId,
Notify ? 1 : 0,
1,
IsAction ? 1 : 0,

View file

@ -1,22 +1,20 @@
using System;
namespace SharpChat.Packet {
public class MessageAddPacket : ServerPacket {
private readonly long Created;
public class MessageAddPacket : SockChatTimedS2CPacket {
private readonly long UserId;
private readonly string Body;
private readonly bool IsAction;
private readonly bool IsPrivate;
public MessageAddPacket(
long msgId,
DateTimeOffset created,
long messageId,
DateTimeOffset timeStamp,
long userId,
string body,
bool isAction,
bool isPrivate
) : base(msgId) {
Created = created.ToUnixTimeSeconds();
) : base(messageId, timeStamp) {
UserId = userId < 0 ? -1 : userId;
Body = body;
IsAction = isAction;
@ -30,10 +28,10 @@ namespace SharpChat.Packet {
return string.Format(
"2\t{0}\t{1}\t{2}\t{3}\t{4}{5}{6}{7}{8}",
Created,
TimeStamp.ToUnixTimeSeconds(),
UserId,
body,
SequenceId,
MessageId,
1,
IsAction ? 1 : 0,
0,

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class MessageBroadcastPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class MessageBroadcastPacket : SockChatTimedS2CPacket {
private readonly string Body;
public MessageBroadcastPacket(string body) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
Body = body;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t0\fsay\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseMessageBody(Body),
SequenceId
MessageId
);
}
}

View file

@ -1,15 +1,11 @@
using System;
namespace SharpChat.Packet {
public class MessageDeleteNotAllowedErrorPacket : ServerPacket {
private readonly long Timestamp;
public MessageDeleteNotAllowedErrorPacket() {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
namespace SharpChat.Packet {
public class MessageDeleteNotAllowedErrorPacket : SockChatTimedS2CPacket {
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\fdelerr\t{1}\t10010", Timestamp, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\fdelerr\t{1}\t10010",
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}
}

View file

@ -1,13 +1,13 @@
namespace SharpChat.Packet {
public class MessageDeletePacket : ServerPacket {
private readonly long MessageId;
public class MessageDeletePacket : SockChatS2CPacket {
private readonly long DeletedMessageId;
public MessageDeletePacket(long msgId) {
MessageId = msgId;
public MessageDeletePacket(long deletedMessageId) {
DeletedMessageId = deletedMessageId;
}
public override string Pack() {
return string.Format("6\t{0}", MessageId);
return string.Format("6\t{0}", DeletedMessageId);
}
}
}

View file

@ -1,17 +1,18 @@
using System;
namespace SharpChat.Packet {
public class PardonResponsePacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class PardonResponsePacket : SockChatTimedS2CPacket {
private readonly string Subject;
public PardonResponsePacket(string subject) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
Subject = subject;
}
public override string Pack() {
return string.Format("2\t{0}\t-1\t0\funban\f{1}\t{2}\t10010", Timestamp, Subject, SequenceId);
return string.Format(
"2\t{0}\t-1\t0\funban\f{1}\t{2}\t10010",
TimeStamp.ToUnixTimeSeconds(),
Subject,
MessageId
);
}
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class PongPacket : ServerPacket {
public class PongPacket : SockChatS2CPacket {
public override string Pack() {
return "0\tpong";
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class UserChannelForceJoinPacket : ServerPacket {
public class UserChannelForceJoinPacket : SockChatS2CPacket {
private readonly string ChannelName;
public UserChannelForceJoinPacket(string channelName) {

View file

@ -1,24 +1,23 @@
using System;
namespace SharpChat.Packet {
public class UserChannelJoinLogPacket : ServerPacket {
private readonly long Timestamp;
public class UserChannelJoinLogPacket : SockChatTimedS2CPacket {
private readonly string UserName;
public UserChannelJoinLogPacket(
DateTimeOffset timestamp,
long messageId,
DateTimeOffset timeStamp,
string userName
) {
Timestamp = timestamp.ToUnixTimeSeconds();
) : base(messageId, timeStamp) {
UserName = userName;
}
public override string Pack() {
return string.Format(
"7\t1\t{0}\t-1\tChatBot\tinherit\t\t0\fjchan\f{1}\t{2}\t0\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
UserName,
SequenceId
MessageId
);
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class UserChannelJoinPacket : ServerPacket {
public class UserChannelJoinPacket : SockChatS2CPacket {
private readonly long UserId;
private readonly string UserName;
private readonly Colour UserColour;
@ -33,7 +33,7 @@
UserPerms.HasFlag(UserPermissions.CreateChannel) ? (
UserPerms.HasFlag(UserPermissions.SetChannelPermanent) ? 2 : 1
) : 0,
SequenceId
MessageId
);
}
}

View file

@ -1,24 +1,23 @@
using System;
namespace SharpChat.Packet {
public class UserChannelLeaveLogPacket : ServerPacket {
private readonly long Timestamp;
public class UserChannelLeaveLogPacket : SockChatTimedS2CPacket {
private readonly string UserName;
public UserChannelLeaveLogPacket(
DateTimeOffset timestamp,
long messageId,
DateTimeOffset timeStamp,
string userName
) {
Timestamp = timestamp.ToUnixTimeSeconds();
) : base(messageId, timeStamp) {
UserName = userName;
}
public override string Pack() {
return string.Format(
"7\t1\t{0}\t-1\tChatBot\tinherit\t\t0\flchan\f{1}\t{2}\t0\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
UserName,
SequenceId
MessageId
);
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class UserChannelLeavePacket : ServerPacket {
public class UserChannelLeavePacket : SockChatS2CPacket {
private readonly long UserId;
public UserChannelLeavePacket(long userId) {
@ -7,7 +7,11 @@
}
public override string Pack() {
return string.Format("5\t1\t{0}\t{1}", UserId, SequenceId);
return string.Format(
"5\t1\t{0}\t{1}",
UserId,
MessageId
);
}
}
}

View file

@ -1,24 +1,23 @@
using System;
namespace SharpChat.Packet {
public class UserConnectLogPacket : ServerPacket {
private readonly long Timestamp;
public class UserConnectLogPacket : SockChatTimedS2CPacket {
private readonly string UserName;
public UserConnectLogPacket(
DateTimeOffset timestamp,
long messageId,
DateTimeOffset timeStamp,
string userName
) {
Timestamp = timestamp.ToUnixTimeSeconds();
) : base(messageId, timeStamp) {
UserName = userName;
}
public override string Pack() {
return string.Format(
"7\t1\t{0}\t-1\tChatBot\tinherit\t\t0\fjoin\f{1}\t{2}\t0\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
UserName,
SequenceId
MessageId
);
}
}

View file

@ -1,8 +1,5 @@
using System;
namespace SharpChat.Packet {
public class UserConnectPacket : ServerPacket {
private readonly DateTimeOffset Joined;
namespace SharpChat.Packet {
public class UserConnectPacket : SockChatTimedS2CPacket {
private readonly long UserId;
private readonly string UserName;
private readonly Colour UserColour;
@ -10,14 +7,12 @@ namespace SharpChat.Packet {
private readonly UserPermissions UserPerms;
public UserConnectPacket(
DateTimeOffset joined,
long userId,
string userName,
Colour userColour,
int userRank,
UserPermissions userPerms
) {
Joined = joined;
UserId = userId;
UserName = userName;
UserColour = userColour;
@ -28,7 +23,7 @@ namespace SharpChat.Packet {
public override string Pack() {
return string.Format(
"1\t{0}\t{1}\t{2}\t{3}\t{4} {5} {6} {7} {8}\t{9}",
Joined.ToUnixTimeSeconds(),
TimeStamp.ToUnixTimeSeconds(),
UserId,
UserName,
UserColour,
@ -39,7 +34,7 @@ namespace SharpChat.Packet {
UserPerms.HasFlag(UserPermissions.CreateChannel) ? (
UserPerms.HasFlag(UserPermissions.SetChannelPermanent) ? 2 : 1
) : 0,
SequenceId
MessageId
);
}
}

View file

@ -1,17 +1,16 @@
using System;
namespace SharpChat.Packet {
public class UserDisconnectLogPacket : ServerPacket {
private readonly long Timestamp;
public class UserDisconnectLogPacket : SockChatTimedS2CPacket {
private readonly string UserName;
private readonly UserDisconnectReason Reason;
public UserDisconnectLogPacket(
DateTimeOffset timestamp,
long messageId,
DateTimeOffset timeStamp,
string userName,
UserDisconnectReason reason
) {
Timestamp = timestamp.ToUnixTimeSeconds();
) : base(messageId, timeStamp) {
UserName = userName;
Reason = reason;
}
@ -19,7 +18,7 @@ namespace SharpChat.Packet {
public override string Pack() {
return string.Format(
"7\t1\t{0}\t-1\tChatBot\tinherit\t\t0\f{1}\f{2}\t{3}\t0\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
Reason switch {
UserDisconnectReason.Leave => "leave",
UserDisconnectReason.TimeOut => "timeout",
@ -28,7 +27,7 @@ namespace SharpChat.Packet {
_ => "leave",
},
UserName,
SequenceId
MessageId
);
}
}

View file

@ -1,19 +1,14 @@
using System;
namespace SharpChat.Packet {
public class UserDisconnectPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class UserDisconnectPacket : SockChatTimedS2CPacket {
private readonly long UserId;
private readonly string UserName;
private readonly UserDisconnectReason Reason;
public UserDisconnectPacket(
DateTimeOffset timestamp,
long userId,
string userName,
UserDisconnectReason reason
) {
Timestamp = timestamp.ToUnixTimeSeconds();
UserId = userId;
UserName = userName;
Reason = reason;
@ -31,8 +26,8 @@ namespace SharpChat.Packet {
UserDisconnectReason.Flood => "flood",
_ => "leave",
},
Timestamp,
SequenceId
TimeStamp.ToUnixTimeSeconds(),
MessageId
);
}
}

View file

@ -1,17 +1,18 @@
using System;
namespace SharpChat.Packet {
public class UserNameInUseErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class UserNameInUseErrorPacket : SockChatTimedS2CPacket {
private readonly string UserName;
public UserNameInUseErrorPacket(string userName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
UserName = userName;
}
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\fnameinuse\f{1}\t{2}\t10010", Timestamp, UserName, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\fnameinuse\f{1}\t{2}\t10010",
TimeStamp.ToUnixTimeSeconds(),
UserName,
MessageId
);
}
}
}

View file

@ -1,17 +1,18 @@
using System;
namespace SharpChat.Packet {
public class UserNotFoundErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class UserNotFoundErrorPacket : SockChatTimedS2CPacket {
private readonly string UserName;
public UserNotFoundErrorPacket(string userName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
UserName = userName;
}
public override string Pack() {
return string.Format("2\t{0}\t-1\t1\fusernf\f{1}\t{2}\t10010", Timestamp, UserName, SequenceId);
return string.Format(
"2\t{0}\t-1\t1\fusernf\f{1}\t{2}\t10010",
TimeStamp.ToUnixTimeSeconds(),
UserName,
MessageId
);
}
}
}

View file

@ -1,24 +1,20 @@
using System;
namespace SharpChat.Packet {
public class UserUpdateNotificationPacket : ServerPacket {
namespace SharpChat.Packet {
public class UserUpdateNotificationPacket : SockChatTimedS2CPacket {
private readonly string PreviousName;
private readonly string NewName;
private readonly long Timestamp;
public UserUpdateNotificationPacket(string previousName, string newName) {
PreviousName = previousName;
NewName = newName;
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t0\fnick\f{1}\f{2}\t{3}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
PreviousName,
NewName,
SequenceId
MessageId
);
}
}

View file

@ -1,5 +1,5 @@
namespace SharpChat.Packet {
public class UserUpdatePacket : ServerPacket {
public class UserUpdatePacket : SockChatS2CPacket {
private readonly long UserId;
private readonly string UserName;
private readonly Colour UserColour;

View file

@ -1,7 +1,7 @@
using System.Text;
namespace SharpChat.Packet {
public class UsersPopulatePacket : ServerPacket {
public class UsersPopulatePacket : SockChatS2CPacket {
public record ListEntry(long Id, string Name, Colour Colour, int Rank, UserPermissions Perms, bool Visible);
private readonly ListEntry[] Entries;

View file

@ -1,21 +1,17 @@
using System;
namespace SharpChat.Packet {
public class WhoChannelNotFoundErrorPacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class WhoChannelNotFoundErrorPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
public WhoChannelNotFoundErrorPacket(string channelName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
}
public override string Pack() {
return string.Format(
"2\t{0}\t-1\t1\fwhoerr\f{1}\t{2}\t10010",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName),
SequenceId
MessageId
);
}
}

View file

@ -2,14 +2,12 @@
using System.Text;
namespace SharpChat.Packet {
public class WhoChannelResponsePacket : ServerPacket {
private readonly long Timestamp;
public class WhoChannelResponsePacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
private readonly string[] Users;
private readonly string SelfName;
public WhoChannelResponsePacket(string channelName, string[] users, string selfName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
ChannelName = channelName;
Users = users;
SelfName = selfName;
@ -20,7 +18,7 @@ namespace SharpChat.Packet {
sb.AppendFormat(
"2\t{0}\t-1\t0\fwhochan\f{1}\f",
Timestamp,
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName)
);
@ -36,7 +34,7 @@ namespace SharpChat.Packet {
if(Users.Length > 0)
sb.Length -= 2;
sb.AppendFormat("\t{0}\t10010", SequenceId);
sb.AppendFormat("\t{0}\t10010", MessageId);
return sb.ToString();
}

View file

@ -2,13 +2,11 @@
using System.Text;
namespace SharpChat.Packet {
public class WhoServerResponsePacket : ServerPacket {
private readonly long Timestamp;
public class WhoServerResponsePacket : SockChatTimedS2CPacket {
private readonly string[] Users;
private readonly string SelfName;
public WhoServerResponsePacket(string[] users, string selfName) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
Users = users;
SelfName = selfName;
}
@ -16,7 +14,7 @@ namespace SharpChat.Packet {
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat("2\t{0}\t-1\t0\fwho\f", Timestamp);
sb.AppendFormat("2\t{0}\t-1\t0\fwho\f", TimeStamp.ToUnixTimeSeconds());
foreach(string userName in Users) {
sb.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
@ -30,7 +28,7 @@ namespace SharpChat.Packet {
if(Users.Length > 0)
sb.Length -= 2;
sb.AppendFormat("\t{0}\t10010", SequenceId);
sb.AppendFormat("\t{0}\t10010", MessageId);
return sb.ToString();
}

View file

@ -1,19 +1,21 @@
using System;
namespace SharpChat.Packet {
public class WhoisResponsePacket : ServerPacket {
private readonly long Timestamp;
namespace SharpChat.Packet {
public class WhoisResponsePacket : SockChatTimedS2CPacket {
private readonly string UserName;
private readonly string RemoteAddress;
public WhoisResponsePacket(string userName, string remoteAddress) {
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
UserName = userName;
RemoteAddress = remoteAddress;
}
public override string Pack() {
return string.Format("2\t{0}\t-1\t0\fipaddr\f{1}\f{2}\t{3}\t10010", Timestamp, UserName, RemoteAddress, SequenceId);
return string.Format(
"2\t{0}\t-1\t0\fipaddr\f{1}\f{2}\t{3}\t10010",
TimeStamp.ToUnixTimeSeconds(),
UserName,
RemoteAddress,
MessageId
);
}
}
}

View file

@ -0,0 +1,15 @@
namespace SharpChat {
public abstract class SockChatS2CPacket {
protected readonly long MessageId;
public SockChatS2CPacket() {
MessageId = SharpId.Next();
}
public SockChatS2CPacket(long messageId) {
MessageId = messageId;
}
public abstract string Pack();
}
}

View file

@ -0,0 +1,15 @@
using System;
namespace SharpChat {
public abstract class SockChatTimedS2CPacket : SockChatS2CPacket {
protected readonly DateTimeOffset TimeStamp;
public SockChatTimedS2CPacket() : base() {
TimeStamp = DateTimeOffset.UtcNow;
}
public SockChatTimedS2CPacket(long messageId, DateTimeOffset timeStamp) : base(messageId) {
TimeStamp = timeStamp;
}
}
}