コード例 #1
0
        private void ProcessException(Exception ex, Node node, XmppStream stream)
        {
            if (ex is JabberException)
            {
                var je    = (JabberException)ex;
                var error = je.ToElement();

                if (je.ErrorCode != ErrorCode.Forbidden)
                {
                    log.Error("JabberError", ex);
                }
                if (je.StreamError)
                {
                    ((Error)error).Text = je.Message;
                    sender.SendTo(stream, error);
                }
                else
                {
                    if (node is Stanza && error is StanzaError)
                    {
                        sender.SendTo(stream, XmppStanzaError.ToErrorStanza((Stanza)node, (StanzaError)error));
                    }
                    else
                    {
                        var streamError = XmppStreamError.InternalServerError;
                        streamError.Text = "Stanza error in stream.";
                        sender.SendToAndClose(stream, streamError);
                    }
                }

                if (je.CloseStream)
                {
                    sender.CloseStream(stream);
                }
            }
            else
            {
                log.Error("InternalServerError", ex);
                var error = XmppStreamError.InternalServerError;
                error.Text = ex.Message;
                sender.SendToAndClose(stream, error);
            }
        }
コード例 #2
0
        public void AdminCommand(IQ iq, MucRoomMember member)
        {
            Admin admin       = iq.Query as Admin;
            Admin returnAdmin = new Admin();

            if (admin != null)
            {
                if (iq.Type == IqType.get)
                {
                    foreach (Core.protocol.x.muc.iq.admin.Item item in admin.GetItems())
                    {
                        if (item.Actor == null && item.Affiliation != Affiliation.none)
                        {
                            foreach (MucRoomMemberInfo mucRoomMember in RoomSettings.Members)
                            {
                                if (mucRoomMember.Affiliation == item.Affiliation)
                                {
                                    returnAdmin.AddItem(
                                        new Core.protocol.x.muc.iq.admin.Item(mucRoomMember.Affiliation,
                                                                              mucRoomMember.Role,
                                                                              mucRoomMember.Jid));
                                }
                            }
                        }
                    }
                    iq.Query = returnAdmin;
                    iq.Type  = IqType.result;
                }
                else if (iq.Type == IqType.set)
                {
                    // Change affilation
                    foreach (Core.protocol.x.muc.iq.admin.Item item in admin.GetItems())
                    {
                        if (item.Actor == null)
                        {
                            Actor actor = new Actor()
                            {
                                Jid = iq.From
                            };
                            MucRoomMemberInfo memberToModify = FindMemberInfo(item);
                            if (memberToModify != null)
                            {
                                //Get member
                                if ((int)item.Affiliation != -1)
                                {
                                    if (RoomSettings.CanChangeAffilation(memberToModify.Affiliation,
                                                                         item.Affiliation,
                                                                         member.Affiliation))
                                    {
                                        memberToModify.Affiliation = item.Affiliation;
                                        //Try notify online
                                        MucRoomMember onlineMember = members.FindByBareJid(memberToModify.Jid);
                                        if (onlineMember != null)
                                        {
                                            onlineMember.Affiliation = item.Affiliation;
                                        }
                                    }
                                    else
                                    {
                                        // Error!
                                        XmppStanzaError.ToErrorStanza(iq, new Error(ErrorCondition.NotAllowed));
                                        return;
                                    }
                                }

                                if ((int)item.Role != -1)
                                {
                                    if (RoomSettings.CanChangeRole(memberToModify.Role,
                                                                   item.Role,
                                                                   member.Role,
                                                                   member.Affiliation))
                                    {
                                        memberToModify.Role = item.Role;
                                        MucRoomMember onlineMember = members.FindByBareJid(memberToModify.Jid);
                                        if (onlineMember != null)
                                        {
                                            if (item.Role != Role.none)
                                            {
                                                onlineMember.Role = item.Role;
                                            }
                                            else
                                            {
                                                //Role == none it's a kick
                                                onlineMember.Kick(actor, item.Reason);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // Error!
                                        XmppStanzaError.ToErrorStanza(iq, new Error(ErrorCondition.NotAllowed));
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    SettingsSave();
                    iq.RemoveAllChildNodes();
                    iq.Type = IqType.result;
                }
            }
        }