public static void KillScript(UserObject userobj, String args) { if (userobj.Level < Settings.ScriptLevel) return; ScriptManager.Items.Remove(args); }
public static String PrepareUserName(UserObject userobj) { String str = userobj.OrgName; foreach (String i in Illegal) str = Regex.Replace(str, Regex.Escape(i), String.Empty, RegexOptions.IgnoreCase); str = str.Replace("_", " "); while (Encoding.UTF8.GetByteCount(str) > 20) str = str.Substring(0, str.Length - 1); if (Encoding.UTF8.GetByteCount(str) < 2) return "anon " + userobj.Cookie; if (str == Settings.BotName) return null; if (Users.Find(x => x.LoggedIn && (x.Name == str || x.OrgName == str)) != null) // name in use { UserObject u = Users.Find(x => x.LoggedIn && (x.Name == str || x.OrgName == str) && (x.ExternalIP.Equals(userobj.ExternalIP) || x.Guid.Equals(userobj.Guid))); if (u == null) return null; else { u.LoggedIn = u.Vroom != 0; u.Expired = true; userobj.Ghost = true; return str; } } return str; }
public static void ListBans(UserObject userobj) { if (userobj.Level < Settings.BanLevel) return; Bans.ListBans(userobj); }
public static void LoadScript(UserObject userobj, String args) { if (userobj.Level < Settings.ScriptLevel) return; string scriptDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); scriptDir = System.IO.Path.Combine(scriptDir, "Arca4", "Scripts"); if (!Directory.Exists(scriptDir)) Directory.CreateDirectory(scriptDir); // Not a javascript script if (!args.EndsWith(".js")) { // TODO: Localizaton support userobj.SendPacket(AresTCPPackets.NoSuch("File is not a javascript script")); return; } // file doesnt exist return false string filePath = Path.Combine(scriptDir, args); if (!File.Exists(filePath)) { // TODO: Localizaton support userobj.SendPacket(AresTCPPackets.NoSuch("File does not exist")); return; } ScriptManager.Items.Remove(args); ScriptManager.Items.Add(args, File.ReadAllText(filePath, Encoding.UTF8)); }
public static void ListBans(UserObject userobj) { int i = 0; Items.ForEach(x => userobj.SendPacket(AresTCPPackets.NoSuch((i++) + " - " + x.Name + " [" + x.ExternalIP + "]"))); if (i == 0) userobj.SendPacket(AresTCPPackets.NoSuch("no banned users")); }
public static void ListScripts(UserObject userobj) { if (userobj.Level < Settings.ScriptLevel) return; foreach (var script in ScriptManager.Items) { userobj.SendPacket(AresTCPPackets.NoSuch(script.ScriptName)); } }
public static byte[] CustomEmoteDelete(UserObject userobj, String shortcut) { AresTCPPacketWriter packet = new AresTCPPacketWriter(); packet.WriteString(userobj.Name); packet.WriteString(shortcut); byte[] buf = packet.ToAresPacket(ProtoMessage.MSG_CHAT_SERVER_CUSTOM_EMOTE_DELETE); packet = new AresTCPPacketWriter(); packet.WriteBytes(buf); return packet.ToAresPacket(ProtoMessage.MSG_CHAT_ADVANCED_FEATURES_PROTOCOL); }
public static void Kill(UserObject userobj, UserObject target) { if (userobj.Level < Settings.KillLevel || target == null) return; if (target.Level < userobj.Level) { target.Expired = true; DebugLog.WriteLine(target.Name + " killed by " + userobj.Name); } }
public static void BroadcastVoiceClip(UserObject sender, byte[] packet) { Users.ForEach(x => { if (x.LoggedIn) if (x.ID != sender.ID) if (x.CanVCPublic) if (!x.VCIgnores.Contains(sender.Name)) x.SendPacket(packet); }); }
public static void Ban(UserObject userobj, UserObject target) { if (userobj.Level < Settings.BanLevel || target == null) return; if (target.Level < userobj.Level) { target.Expired = true; Bans.AddBan(target); DebugLog.WriteLine(target.Name + " banned by " + userobj.Name); } }
public static void Eval(UserObject userobj, ProtoMessage msg, AresTCPPacketReader packet) { switch (msg) { case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_ADD_TAGS: ProcessAddCustomTag(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_REM_TAGS: ProcessRemCustomTag(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_FONT: ProcessCustomFont(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_SUPPORTED: ProcessVCSupported(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_FIRST: ProcessVCFirst(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_FIRST_TO: ProcessVCFirstTo(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_CHUNK: ProcessVCChunk(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_CHUNK_TO: ProcessVCChunkTo(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_IGNORE: ProcessVCIgnore(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_SUPPORTS_CUSTOM_EMOTES: ProcessSupportsCustomEmotes(userobj); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_EMOTES_UPLOAD_ITEM: ProcessCustomEmoteUpload(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_EMOTE_DELETE: ProcessCustomEmoteDelete(userobj, packet); break; } }
public static byte[] CustomEmoteItem(UserObject userobj, CustomEmoticon item) { AresTCPPacketWriter packet = new AresTCPPacketWriter(); packet.WriteString(userobj.Name); packet.WriteString(item.Shortcut); packet.WriteByte(item.Size); packet.WriteBytes(item.Image); byte[] buf = packet.ToAresPacket(ProtoMessage.MSG_CHAT_SERVER_CUSTOM_EMOTES_ITEM); packet = new AresTCPPacketWriter(); packet.WriteBytes(buf); return packet.ToAresPacket(ProtoMessage.MSG_CHAT_ADVANCED_FEATURES_PROTOCOL); }
public static byte[] CustomFontDefault(UserObject userobj) { AresTCPPacketWriter packet = new AresTCPPacketWriter(); packet.WriteString(userobj.Name); // user's name + null packet.WriteByte(10); // limited to between 8 to 16 packet.WriteString("Verdana"); // null terminated packet.WriteByte(255); packet.WriteByte(255); byte[] buf = packet.ToAresPacket(ProtoMessage.MSG_CHAT_SERVER_CUSTOM_FONT); // id = 204 packet = new AresTCPPacketWriter(); packet.WriteBytes(buf); return packet.ToAresPacket(ProtoMessage.MSG_CHAT_ADVANCED_FEATURES_PROTOCOL); }
private static void ProcessCustomEmoteDelete(UserObject userobj, AresTCPPacketReader packet) { if (!Settings.CanCustomEmotes) return; String text = packet.ReadString(); userobj.CustomEmoticons.RemoveAll(x => x.Shortcut == text); byte[] buf = CustomPackets.CustomEmoteDelete(userobj, text); UserPool.Users.ForEach(x => { if (x.LoggedIn && x.Vroom == userobj.Vroom) if (x.SupportsCustomEmoticons) x.SendPacket(buf); }); }
public static bool CanChangeName(UserObject userobj, String name) { foreach (String i in Illegal) if (Regex.IsMatch(name, Regex.Escape(i), RegexOptions.IgnoreCase)) return false; if (Encoding.UTF8.GetByteCount(name) > 20) return false; if (Encoding.UTF8.GetByteCount(name) < 2) return false; if (name == Settings.BotName) return false; return Users.Find(x => (x.LoggedIn && x.ID != userobj.ID) && (x.Name == name || x.OrgName == name)) == null; }
public static void SendMOTD(UserObject userobj) { List<byte> buf = new List<byte>(); motd.ForEach(x => { buf.AddRange(AresTCPPackets.NoSuch(x.Replace("+n", userobj.Name))); if (buf.Count > 800) { userobj.SendPacket(AresTCPPackets.ClientCompressed(buf.ToArray())); buf.Clear(); } }); if (buf.Count > 0) userobj.SendPacket(AresTCPPackets.ClientCompressed(buf.ToArray())); }
private static void ProcessAddCustomTag(UserObject userobj, AresTCPPacketReader packet) { while (packet.Remaining > 0) userobj.CustomTags.Add(packet.ReadString()); }
private static void ProcessSupportsCustomEmotes(UserObject userobj) { if (!Settings.CanCustomEmotes) return; if (!userobj.SupportsCustomEmoticons) { userobj.SupportsCustomEmoticons = true; userobj.CustomEmoticons.Clear(); UserPool.SendCustomEmotesToUser(userobj); } }
private static void ProcessRemCustomTag(UserObject userobj, AresTCPPacketReader packet) { while (packet.Remaining > 0) { String str = packet.ReadString(); userobj.CustomTags.Remove(str); } }
private static void ProcessVCFirstTo(UserObject userobj, AresTCPPacketReader packet) { if (Settings.CanVoiceChat) { String name = packet.ReadString(); UserObject target = UserPool.Users.Find(x => x.LoggedIn && x.Name == name); if (target != null) if (!target.VCIgnores.Contains(userobj.Name)) if (target.CanVCPrivate) { byte[] buffer = CustomPackets.VoiceChatFirstTo(userobj.Name, packet.ReadBytes()); target.SendPacket(buffer); } else userobj.SendPacket(CustomPackets.VoiceChatNoPrivate(target.Name)); else userobj.SendPacket(CustomPackets.VoiceChatIgnored(target.Name)); else userobj.SendPacket(AresTCPPackets.OfflineUser(name)); } }
private static void ProcessVCFirst(UserObject userobj, AresTCPPacketReader packet) { if (Settings.CanVoiceChat) { byte[] buffer = CustomPackets.VoiceChatFirst(userobj.Name, packet.ReadBytes()); UserPool.BroadcastVoiceClip(userobj, buffer); } }
private static void ProcessVCIgnore(UserObject userobj, AresTCPPacketReader packet) { if (Settings.CanVoiceChat) { String name = packet.ReadString(); if (userobj.VCIgnores.Contains(name)) { userobj.SendPacket(AresTCPPackets.NoSuch(name + " is voice chat unignored")); userobj.VCIgnores.RemoveAll(x => x == name); } else { userobj.SendPacket(AresTCPPackets.NoSuch(name + " is voice chat ignored")); userobj.VCIgnores.Add(name); } } }
public static void Info(UserObject userobj) { UserPool.Users.ForEach(x => { if (x.LoggedIn) userobj.SendPacket(AresTCPPackets.NoSuch(x.ID + " - " + x.Name + " -> " + x.Vroom)); }); }
public static void Unban(UserObject userobj, String args) { if (userobj.Level < Settings.BanLevel) return; int index; String name = null; if (int.TryParse(args, out index)) name = Bans.RemoveBan(index); else if (args.Length > 2) if ((args.StartsWith("\"") && args.EndsWith("\"")) || (args.StartsWith("'") && args.EndsWith("'"))) name = Bans.RemoveBan(args.Substring(1, args.Length - 2)); if (name != null) DebugLog.WriteLine(name + " unbanned by " + userobj.Name); }
public static void Unmuzzle(UserObject userobj, UserObject target) { if (userobj.Level < Settings.MuzzleLevel || target == null) return; if (target.Muzzled) { target.Muzzled = false; Muzzles.RemoveMuzzle(target); DebugLog.WriteLine(target.Name + " unmuzzled by " + userobj.Name); } }
public static void SetUserLevel(UserObject userobj, UserObject target, String args) { if (userobj.Level < 3 || target == null) return; byte b = 0; if (byte.TryParse(args, out b)) { byte old_level = target.Level; target.Level = b; if (target.Registered) UserAccounts.UpdateAdminLevel(target); DebugLog.WriteLine(target.Name + " set admin level " + b + " by " + userobj.Name); if (b > old_level) ServerEvents.OnLoginGranted(target); } }
public static void Muzzle(UserObject userobj, UserObject target) { if (userobj.Level < Settings.MuzzleLevel || target == null) return; if (target.Level < userobj.Level && !target.Muzzled) { target.Muzzled = true; Muzzles.AddMuzzle(target); DebugLog.WriteLine(target.Name + " muzzled by " + userobj.Name); } }
public static CommandObject TextToCommand(UserObject userobj, String text) { CommandObject cmd = new CommandObject(); String str = text; int i = str.IndexOf(" "); if (i > -1) { str = str.Substring(i + 1); if (str.Length > 0) { cmd.target = UserPool.Users.Find(x => x.LoggedIn && x.Name == str); if (cmd.target != null) // right click command return cmd; else if (str[0] == '\'' || str[0] == '"') { char c = str[0]; str = str.Substring(1); i = str.IndexOf(c); if (i > 0) { cmd.target = UserPool.Users.Find(x => x.LoggedIn && x.Name.StartsWith(str.Substring(0, i))); if (cmd.target != null) { str = str.Substring(i + 1); if (str.Length > 1) cmd.args = str.Substring(1); return cmd; } } } else { i = str.IndexOf(" "); if (i > 0) { if (int.TryParse(str.Substring(0, i), out i)) if (i > -1) { cmd.target = UserPool.Users.Find(x => x.LoggedIn && x.ID == i); if (cmd.target != null) { cmd.args = str.Substring(str.IndexOf(" ") + 1); return cmd; } } } else if (int.TryParse(str, out i)) if (i > -1) { cmd.target = UserPool.Users.Find(x => x.LoggedIn && x.ID == i); return cmd; } } } } cmd.target = null; cmd.args = String.Empty; return cmd; }
private static void ProcessCustomEmoteUpload(UserObject userobj, AresTCPPacketReader packet) { if (!Settings.CanCustomEmotes) return; ProcessSupportsCustomEmotes(userobj); CustomEmoticon emoticon = new CustomEmoticon { Shortcut = packet.ReadString(), Size = packet.ReadByte(), Image = packet.ReadBytes() }; userobj.CustomEmoticons.Add(emoticon); if (userobj.CustomEmoticons.Count > 16) throw new Exception("exceeded custom emoticon maximum"); byte[] buf = CustomPackets.CustomEmoteItem(userobj, emoticon); UserPool.Users.ForEach(x => { if (x.LoggedIn && x.Vroom == userobj.Vroom) if (x.SupportsCustomEmoticons) x.SendPacket(buf); }); }
private static void ProcessVCSupported(UserObject userobj, AresTCPPacketReader packet) { if (Settings.CanVoiceChat) { userobj.CanVCPublic = packet.ReadByte() == 1; userobj.CanVCPrivate = packet.ReadByte() == 1; UserPool.BroadcastToVroom(userobj.Vroom, CustomPackets.VoiceChatUserSupport(userobj)); } }