85 lines
3 KiB
C#
85 lines
3 KiB
C#
using System.Text;
|
|
|
|
namespace SharpChat.SockChat.S2CPackets;
|
|
|
|
public class CommandResponseS2CPacket(
|
|
long msgId,
|
|
string stringId,
|
|
bool isError = true,
|
|
params object[] args
|
|
) : S2CPacket {
|
|
public string Pack() {
|
|
StringBuilder sb = new();
|
|
|
|
if(stringId == LCR.WELCOME) {
|
|
sb.Append("7\t1\t");
|
|
sb.Append(DateTimeOffset.Now.ToUnixTimeSeconds());
|
|
sb.Append("\t-1\tChatBot\tinherit\t\t");
|
|
} else {
|
|
sb.Append("2\t");
|
|
sb.Append(DateTimeOffset.Now.ToUnixTimeSeconds());
|
|
sb.Append("\t-1\t");
|
|
}
|
|
|
|
sb.Append(isError ? '1' : '0');
|
|
sb.Append('\f');
|
|
sb.Append(stringId == LCR.WELCOME ? LCR.BROADCAST : stringId);
|
|
|
|
if(args.Length > 0)
|
|
foreach(object arg in args) {
|
|
sb.Append('\f');
|
|
sb.Append(arg);
|
|
}
|
|
|
|
sb.Append('\t');
|
|
|
|
if(stringId == LCR.WELCOME) {
|
|
sb.Append(stringId);
|
|
sb.Append("\t0");
|
|
} else
|
|
sb.Append(msgId);
|
|
|
|
sb.Append("\t10010");
|
|
/*sb.AppendFormat(
|
|
"\t1{0}0{1}{2}",
|
|
Flags.HasFlag(ChatMessageFlags.Action) ? '1' : '0',
|
|
Flags.HasFlag(ChatMessageFlags.Action) ? '0' : '1',
|
|
Flags.HasFlag(ChatMessageFlags.Private) ? '1' : '0'
|
|
);*/
|
|
|
|
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";
|
|
public const string NICKNAME_CHANGE = "nick";
|
|
}
|