public bool Add(Channel c) { if (!Contains(c.Name)) { Channels.Add(c); return true; } return false; }
protected void ChannelCommand(CommandArgs args) { TPPlayer player = args.Player; if (args.Parameters.Count > 1) { if ((player.Group.ContainsGroup("admin") || player.Group.ContainsGroup("superadmin")) && player.IsLoggedIn) { string pram = args.Parameters[0]; if (pram == "add") { //adding channel string cname = args.Parameters[1]; if (Manager.Contains(cname)) { player.SendErrorMessage(String.Format("Channels: {0} already exists!")); } else { Channel c; if (args.Parameters.Count == 5) { //with custom color byte r = 0; byte g = 0; byte b = 0; byte.TryParse(args.Parameters[2], out r); byte.TryParse(args.Parameters[3], out g); byte.TryParse(args.Parameters[4], out b); c = new Channel(cname, r, g, b); } else { c = new Channel(cname); } Manager.Add(c); Channels.Add(c); player.SendInfoMessage(String.Format("Channels: {0} channel added with success!", cname)); } } else if (pram == "del") { //deleting channel string cname = args.Parameters[1]; Channel c = RemoveChannel(cname); if (c != null) { Manager.Remove(cname); player.SendInfoMessage(String.Format("Channels: {0} channel removed!", cname)); } else { player.SendErrorMessage("Channels: This channel doesn't exists!"); } } else { player.SendErrorMessage("Channels: Invalid command!"); } } else { player.SendErrorMessage("Channels: You don't have the right to do this!"); } } else if (args.Parameters.Count == 1 && args.Parameters[0] == "list") { //listing channels player.SendInfoMessage("Channels: Listing channels"); foreach (Channel c in Channels) { player.SendInfoMessage(String.Format("{0} : {1}", c.Name, c.Count)); } player.SendInfoMessage(String.Format("{0} channel(s)", Channels.Count)); } else { player.SendErrorMessage("Channels: Invalid command"); } }
private void LoadChannelsFile() { if (File.Exists(ChannelsFile)) { StreamReader reader = new StreamReader(ChannelsFile); string data = reader.ReadToEnd(); reader.Close(); string[] lines = data.Split('\n'); int i = 1; foreach (string line in lines) { string tline = line.TrimEnd(new char[] { '\n', '\r' }); if (!tline.StartsWith("#")) { Match m = reChannel.Match(tline); if (m.Success) { string cname = m.Groups["name"].Value; byte r = byte.Parse(m.Groups["r"].Value); byte g = byte.Parse(m.Groups["g"].Value); byte b = byte.Parse(m.Groups["b"].Value); Channel c = new Channel(cname, r, g, b); Channels.Add(c); } else if(tline.Length > 0) { //Need to write this into a LogFile //IMPORTANT Console.WriteLine(String.Format("Channels: Invalid line ({1}) into {0};", ChannelsFile, i)); } } i++; } if (DefaultChannel == null && Channels.Count >= 1) { DefaultChannel = Channels[0]; } } else { //Create default file StreamWriter writer = new StreamWriter(ChannelsFile); writer.WriteLine("#TChatChannels Configuration files"); writer.WriteLine("#You can specify the wanted channels here"); writer.WriteLine("#First channel defined is the default one"); writer.WriteLine("#[ChannelName] r:[red] g:[green] b:[blue]"); writer.WriteLine("General r:175 g:224 b:27"); writer.Flush(); writer.Close(); Channels.Add(new Channel("General", 175, 224, 27)); } }