sharp-chat/SharpChat/Packet/LegacyCommandResponse.cs

88 lines
3.2 KiB
C#
Raw Normal View History

2022-08-30 15:00:58 +00:00
using System;
using System.Text;
namespace SharpChat.Packet {
public class LegacyCommandResponse : ServerPacket {
private readonly bool IsError;
private readonly string StringId;
private readonly object[] Arguments;
2022-08-30 15:00:58 +00:00
public LegacyCommandResponse(
string stringId,
bool isError = true,
params object[] args
) {
IsError = isError;
StringId = stringId;
Arguments = args;
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
2023-02-07 15:01:56 +00:00
StringBuilder sb = new();
2022-08-30 15:00:58 +00:00
2024-05-10 17:28:52 +00:00
if(StringId == LCR.WELCOME)
sb.AppendFormat(
"7\t1\t{0}\t-1\tChatBot\tinherit\t\t",
DateTimeOffset.Now.ToUnixTimeSeconds()
);
else
sb.AppendFormat(
"2\t{0}\t-1\t",
DateTimeOffset.Now.ToUnixTimeSeconds()
);
2022-08-30 15:00:58 +00:00
2024-05-10 17:28:52 +00:00
sb.AppendFormat(
"{0}\f{1}",
IsError ? 1 : 0,
StringId == LCR.WELCOME ? LCR.BROADCAST : StringId
);
2022-08-30 15:00:58 +00:00
foreach(object arg in Arguments)
sb.AppendFormat("\f{0}", arg);
2022-08-30 15:00:58 +00:00
sb.Append('\t');
2024-05-10 17:28:52 +00:00
if(StringId == LCR.WELCOME)
sb.AppendFormat("{0}\t0", StringId);
else
2022-08-30 15:00:58 +00:00
sb.Append(SequenceId);
sb.Append("\t10010");
2024-05-10 15:24:43 +00:00
return sb.ToString();
2022-08-30 15:00:58 +00:00
}
}
// Abbreviated class name because otherwise shit gets wide
public static class LCR {
public const string GENERIC_ERROR = "generr";
public const string COMMAND_NOT_FOUND = "nocmd";
public const string COMMAND_NOT_ALLOWED = "cmdna";
public const string COMMAND_FORMAT_ERROR = "cmderr";
public const string WELCOME = "welcome";
public const string BROADCAST = "say";
public const string IP_ADDRESS = "ipaddr";
public const string USER_NOT_FOUND = "usernf";
public const string NAME_IN_USE = "nameinuse";
public const string CHANNEL_INSUFFICIENT_HIERARCHY = "ipchan";
public const string CHANNEL_INVALID_PASSWORD = "ipwchan";
public const string CHANNEL_NOT_FOUND = "nochan";
public const string CHANNEL_ALREADY_EXISTS = "nischan";
2022-08-30 15:00:58 +00:00
public const string CHANNEL_NAME_INVALID = "inchan";
public const string CHANNEL_CREATED = "crchan";
public const string CHANNEL_DELETE_FAILED = "ndchan";
public const string CHANNEL_DELETED = "delchan";
public const string CHANNEL_PASSWORD_CHANGED = "cpwdchan";
public const string CHANNEL_HIERARCHY_CHANGED = "cprivchan";
public const string USERS_LISTING_ERROR = "whoerr";
public const string USERS_LISTING_CHANNEL = "whochan";
public const string USERS_LISTING_SERVER = "who";
public const string INSUFFICIENT_HIERARCHY = "rankerr";
public const string MESSAGE_DELETE_ERROR = "delerr";
public const string KICK_NOT_ALLOWED = "kickna";
public const string USER_NOT_BANNED = "notban";
public const string USER_UNBANNED = "unban";
public const string FLOOD_WARN = "flwarn";
2022-08-30 15:00:58 +00:00
}
}