sharp-chat/SharpChat/Packet/LegacyCommandResponse.cs

87 lines
3.2 KiB
C#

using System;
using System.Text;
namespace SharpChat.Packet {
public class LegacyCommandResponse : ServerPacket {
private readonly bool IsError;
private readonly string StringId;
private readonly object[] Arguments;
public LegacyCommandResponse(
string stringId,
bool isError = true,
params object[] args
) {
IsError = isError;
StringId = stringId;
Arguments = args;
}
public override string Pack() {
StringBuilder sb = new();
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()
);
sb.AppendFormat(
"{0}\f{1}",
IsError ? 1 : 0,
StringId == LCR.WELCOME ? LCR.BROADCAST : StringId
);
foreach(object arg in Arguments)
sb.AppendFormat("\f{0}", arg);
sb.Append('\t');
if(StringId == LCR.WELCOME)
sb.AppendFormat("{0}\t0", StringId);
else
sb.Append(SequenceId);
sb.Append("\t10010");
return sb.ToString();
}
}
// 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";
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";
}
}