private void ChatroomMemberList(EventPacket eventPacket, PluginContext context) { string chatroom = eventPacket.ChatRoom; var room = context.ChatRooms[chatroom]; if (room == null) { context.Logger.ErrorFormat("Error: member list for a chatroom which doesn't exist."); return; } // iterate through each user string[] subPackets = eventPacket.Packet.body.Split(new string[] { "\n\n" }, StringSplitOptions.None); foreach (string subPacket in subPackets) { if (subPacket == "") continue; // get subpacket Packet p = new Packet(subPacket); Member member = room.GetMember(p.param); if (member == null) { // get the bot user if they exist var user = context.Authorizer.GetUser(p.param); room.AddMember(new Member { UserName = p.param, RealName = p.args.ContainsKey("realname") ? p.args["realname"] : string.Empty, Description = p.args.ContainsKey("typename") ? p.args["typename"] : string.Empty, PrivClass = p.args.ContainsKey("pc") ? p.args["pc"] : string.Empty, //ServerPrivClass = p.args["gpc"], Symbol = p.args.ContainsKey("symbol") ? p.args["symbol"] : string.Empty, Role = user == null ? context.Authorizer.DefaultRole : user.Role }); } else { member.UserName = p.param; member.RealName = p.args.ContainsKey("realname") ? p.args["realname"] : string.Empty; member.Description = p.args.ContainsKey("typename") ? p.args["typename"] : string.Empty; member.PrivClass = p.args.ContainsKey("pc") ? p.args["pc"] : string.Empty; //user.ServerPrivClass = p.args["gpc"]; member.Symbol = p.args.ContainsKey("symbol") ? p.args["symbol"] : string.Empty; member.Count++; } } }
/// <summary> /// Send a say packet. /// </summary> /// <param name="ns">Channel to send to.</param> /// <param name="message">Message to say.</param> public void Say(string ns, string message) { // determine message type string type = "msg"; if (message.StartsWith("/me")) { type = "action"; message = message.Substring("/me ".Length); // strip /me from the string } else if (message.StartsWith("/npmsg")) { type = "npmsg"; message = message.Substring("/npmsg ".Length); // strip /npmsg from the string } // replace illegal characters message = message.Replace("<", "<"); message = message.Replace(">", ">"); message = message.Trim(); // get chatroom name ns = FormatChat(ns); // send packet Packet packet = new Packet { cmd = "send", param = ns, body = type + " main\n\n" + message }; Send(packet); }
/// <summary> /// Method that sends the packets to the dAmn server. /// </summary> /// <param name="packet">Packet to send.</param> public void Send(Packet packet) { Send(packet.ToString()); }
/// <summary> /// Gets the details. /// </summary> /// <returns>Details for this packet.</returns> public PacketDetails GetDetails() { PacketDetails details = new PacketDetails(); switch (PacketType) { case PacketType.Handshake: // nothing to do break; case PacketType.Login: details.EventResponse = this.args["e"]; break; case PacketType.Join: case PacketType.Part: details.EventResponse = this.args["e"]; if (this.args.ContainsKey("r")) details.Message = this.args["r"]; break; case PacketType.Topic: case PacketType.Title: case PacketType.PrivClasses: case PacketType.MemberList: details.EventResponse = this.args["p"]; if (this.args.ContainsKey("by")) details.From = this.args["by"]; break; case PacketType.Chat: case PacketType.MemberJoin: case PacketType.MemberPart: case PacketType.MemberKick: case PacketType.PrivChange: case PacketType.AdminCreate: case PacketType.AdminError: case PacketType.AdminMove: case PacketType.AdminRemove: case PacketType.AdminRename: case PacketType.AdminShow: case PacketType.AdminUpdate: // get sub packet Packet subPacket = new Packet(this.body); switch (subPacket.cmd) { case "msg": case "action": details.From = subPacket.args["from"]; details.Message = subPacket.body; break; case "join": case "part": details.From = subPacket.param; if (subPacket.args.ContainsKey("r")) details.Message = subPacket.args["r"]; break; case "privchg": case "kicked": details.From = subPacket.param; details.Target = subPacket.args["by"]; if (subPacket.cmd == "privchg") details.Message = subPacket.args["pc"]; if (!string.IsNullOrEmpty(subPacket.cmd)) details.Message = subPacket.body; break; case "admin": // TODO! break; } break; case PacketType.Kicked: details.From = this.args["by"]; if (!string.IsNullOrEmpty(this.body)) details.Message = this.body; break; case PacketType.Ping: // nothing to do break; case PacketType.Disconnect: details.EventResponse = this.args["e"]; break; case PacketType.ErrorSend: case PacketType.ErrorKick: case PacketType.ErrorGet: case PacketType.ErrorSet: // TODO! break; case PacketType.ErrorKill: details.EventResponse = this.args["e"]; break; } return details; }