openfire插件最佳实践(三) 用户加入指定群组功能
来源:互联网 发布:许嵩所有歌曲知乎 编辑:程序博客网 时间:2024/06/08 19:31
忽然要实现这样一个功能,完全没头绪还是看一下openfire的源码吧,发现room部分的服务器端可以直接将用户加入群组,只要发送请求
http://jabber.org/protocol/muc
那么我们可以利用这个请求:
依旧是使用一个自定义IQ来获取用户请求
假设我们指定iq如下格式:
<span style="font-size:18px;"><iq id="2uF5u-4" type="set" from="test@888/Smack"><query xmlns="hoo.iq.roommember"><roomJID>1388453982252@conference.888</roomJID><jID>wtf111@888</jID><affiliation>member</affiliation></query></iq></span>
iq 包set请求,包含roomJID、jID、affiliation三个参数,
roomJID是房间的jid,jID是想要操作的用户的jID,affiliation是用户被操作后的类型,
affiliation 设置为owner :拥有者权限
affiliation 设置为admin :管理员权限
affiliation 设置为member:房间成员权限
affiliation 设置为outcast:被排除者权限
通过发送上面的数据将会将wtf111这个人设置为1388453982252的房间成员
用户可通过这个接口重复设置,也就是说:如果用户开始是拥有者,再次设置affiliation 设置为member 则此用户成灰普通房间成员,
但是当拥有者=1时,不允许继续减少拥有者
好的,我们定义好了消息格式,可以开始对消息进行处理了!
重写 handleIQ 方法
@Override public IQ handleIQ(IQ packet) throws UnauthorizedException { System.out.println(packet.toXML()); //iqpackage:(因为麻烦所以,当前只提供单个用户对某房间的某权限添加)。iq包格式如下 //<iq ><query> //<roomJID></><jID></><affiliation></> //</iq><query> IQ reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); try { ClientSession session = sessionManager.getSession(packet.getFrom()); if (session == null) { Log.error("Error during userInfo. Session not found in " + sessionManager.getPreAuthenticatedKeys() + " for key " + packet.getFrom()); // This error packet will probably won't make it through reply.setError(PacketError.Condition.internal_server_error); return reply; } if (IQ.Type.get.equals(packet.getType())) { throw new RuntimeException("no interface to get it ");} else if (IQ.Type.set.equals(packet.getType())) {Element iq = packet.getElement();Element query = iq.element("query");Element roomJIDEle = query.element("roomJID");Element jID = query.element("jID");Element affiliation = query.element("affiliation");if (roomJIDEle == null || jID == null || affiliation == null) {reply.setError(PacketError.Condition.item_not_found);return reply;}WebManager webManager = new WebManager();JID roomJID = new JID(roomJIDEle.getText());String roomName = roomJID.getNode();MUCRoom room = webManager.getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomName);IQ muciq = new IQ(IQ.Type.set);
//下面都是对内部发送IQ请求来功能if ("owner".equals(affiliation.getText())|| "admin".equals(affiliation.getText())) {Element frag = muciq.setChildElement("query","http://jabber.org/protocol/muc#owner");Element item = frag.addElement("item");item.addAttribute("affiliation", affiliation.getText());item.addAttribute("jid", jID.getText());// Send the IQ packet that will modify the room's// configurationroom.getIQOwnerHandler().handleIQ(muciq, room.getRole());} else if ("member".equals(affiliation.getText())|| "outcast".equals(affiliation.getText())) {Element frag = muciq.setChildElement("query","http://jabber.org/protocol/muc#admin");Element item = frag.addElement("item");item.addAttribute("affiliation", affiliation.getText());item.addAttribute("jid", jID.getText());// Send the IQ packet that will modify the room's// configurationroom.getIQAdminHandler().handleIQ(muciq, room.getRole());}} } catch (Exception e) {reply.setError(PacketError.Condition.internal_server_error);return reply;} return reply; }
server.getIQRouter().addHandler(new RoomMemberIQHander());
0 0
- openfire插件最佳实践(三) 用户加入指定群组功能
- openfire插件最佳实践(三) 用户加入指定群组功能
- openfire插件最佳实践(一)简单插件开发
- openfire插件最佳实践(一)简单插件开发
- openfire插件最佳实践(二)基于IQHandler 的Smack+openfire插件
- openfire插件最佳实践(四)离线消息推送ios服务器
- openfire插件最佳实践(四)离线消息推送ios服务器
- openfire插件二次开发(扩展用户注册功能添加了用户省份信息)
- smack+openfire自定义协议获取当前用户加入的群
- 让用户加入到指定的组
- JQuery插件最佳实践
- openfire密码破解和指定用户
- openfire单独编译指定插件的方法
- linux系统吧用户加入指定的组里
- openfire用户/组管理
- ERP功能测试最佳实践
- 给Openfire插件加上WEB访问功能
- openfire开发笔记三-openfire主要插件介绍
- javascript表头固定-2
- xcode : could not load inserted library: /usr/lib/libgmalloc.dylib 的解决
- 视频与图像RGB/YUV格式详解
- 基于WSP/WTP的MMS传输(2)——MMS的传输模型
- mysql 问题汇总
- openfire插件最佳实践(三) 用户加入指定群组功能
- Java IO流
- Linux网络编程基础和一步一步学
- 《CUDA并行程序设计:GPU编程指南》
- linux 命令 losetup
- 基于WSP/WTP的MMS传输(3)——MMS PDU结构
- YUV图像格式
- 程序猿应该知道的学习网站
- 如何在网页标题栏上显示ICO图标