惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
T
Threatpost
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
Project Zero
Project Zero
H
Heimdal Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
S
Securelist
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
NISL@THU
NISL@THU
N
News and Events Feed by Topic
S
Security Affairs
The Last Watchdog
The Last Watchdog
T
Tor Project blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security

博客园 - 追梦华仔

Openfire服务器MySQL优化 放开Linux内核对用户进程可打开文件数和TCP连接的限制 SSL 握手协议 非对称密码学(Asymmetric Cryptography)- 转载 Visual Studio 2008下载 Visual Studio 2008 提示“无法识别工具版本4.0” Openfire S2S 经验分享 注册Jmail组件的三种方法 读取excel文件的时候 出错提示:外部表不是预期的格式 - 追梦华仔 - 博客园 System.Runtime.InteropServices.COMException: 服务器出现意外情况 Excel表格导入出错,提示“拒绝访问”的错误,ExcelObj = new Excel.Application(); 在 ASP.NET 中执行 URL 重写 XP下如何解决“ASP.NET 未被授权访问所请求的资源”的问题 - 追梦华仔 - 博客园 无法在web服务器上启动调试 您不具备调试此应用程序的权限 - 追梦华仔 - 博客园 Server Application Error ---Http 500错误解决方法 用Lucene实现在检索结果中再检索 [转载]Ruby on Rails:开源技术将深入企业 Lucene.Net中按时间范围查询,结果没有查到数据 Lucene.Net.Search.Highlight.FragmentQueue 中的派生方法 LessThan 不能减少访问
改造MUC实现Openfire群
追梦华仔 · 2011-12-31 · via 博客园 - 追梦华仔

我的Openfire群实现思路:

1、群和群成员,要保存到表中。

2、拉取群列表和群成员列表,均从DB中查询返回。

3、抛弃老外的“进房间,要发Presence ”。只要此人一上线,就模似一个Presence进行joinRoom,进入他的各群房间。

     多了解LocalMUCRoom 类中:public LocalMUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest, LocalMUCUser user, Presence presence)

    我的模似代码如下:

View Code

 1 /**
 2      * 模似用户进群(含呢称、含Precense、初始化角色LocalMUCRole)
 3      * @param roomId
 4      * @param packet
 5      * @return
 6      */
 7     public MUCRole getRolesByRoomId(long roomId, Packet packet)
 8     {
 9         MUCRole role = null;
10         try {
11             // Get or create the room  获取该群
12             MUCRoom room = server.getChatRoom(roomId, packet.getFrom());
13             
14             //从数据库中查询他的姓名作为昵称(得自己实现)
15             String nickname = new MUCRoomServiceDao().getUserNickname(packet.getFrom().getNode());
16             if(nickname == null)
17             {
18                 if(packet.getFrom().getResource() != null)
19                 {
20                     nickname = packet.getFrom().getResource();
21                 }
22                 else 
23                 {
24                     nickname = packet.getFrom().getNode();
25                 }
26             }
27             
28             HistoryRequest historyRequest = null;
29             String password = null;
30             
31             //构建成员进入群的Presence
32             Presence presence = new Presence();
33             presence.setTo(room.getJID().toBareJID() + "/" + nickname);    
34             presence.setFrom(packet.getFrom());
35             PacketExtension extension = new PacketExtension("x", http://jabber.org/protocol/muc);
36             presence.addExtension(extension);
37             
38             // The user joins the room 用户进入群
39             role = room.joinRoom(nickname,
40                     password,
41                     historyRequest,
42                     this,
43                     presence);
44             
45             // If the client that created the room is non-MUC compliant then
46             // unlock the room thus creating an "instant" room
47             //if (mucInfo == null && room.isLocked() && !room.isManuallyLocked()) {
48             if (room.isLocked() && !room.isManuallyLocked()) {
49                 room.unlock(role);
50                 //server.chatRoomAdded((LocalMUCRoom)room);
51             }
52             
53             addRole(roomId, (LocalMUCRole)role);//添加“用户在某个群中的角色”
54             
55         }
56         catch (UnauthorizedException e) {
57             sendErrorPacket(packet, PacketError.Condition.not_authorized);
58         }
59         catch (ServiceUnavailableException e) {
60             sendErrorPacket(packet, PacketError.Condition.service_unavailable);
61         }
62         catch (UserAlreadyExistsException e) {
63             sendErrorPacket(packet, PacketError.Condition.conflict);
64         }
65         catch (RoomLockedException e) {
66             sendErrorPacket(packet, PacketError.Condition.recipient_unavailable);
67         }
68         catch (ForbiddenException e) {
69             sendErrorPacket(packet, PacketError.Condition.forbidden);
70         }
71         catch (RegistrationRequiredException e) {
72             sendErrorPacket(packet, PacketError.Condition.registration_required);
73         }
74         catch (ConflictException e) {
75             sendErrorPacket(packet, PacketError.Condition.conflict);
76         }
77         catch (NotAcceptableException e) {
78             sendErrorPacket(packet, PacketError.Condition.not_acceptable);
79         }
80         catch (NotAllowedException e) {
81             sendErrorPacket(packet, PacketError.Condition.not_allowed);
82         }        
83         return role;
84     }

 4、抛弃老外的“以昵称为Key 缓存群成员”。改为以帐号为Key。

     多了解 LocalMUCRoom 类中:private Map<String,MUCRole> occupants = new ConcurrentHashMap<String, MUCRole>();

     在joinRoom办法中:    

View Code

1 //以JID作为缓存的key
2         JID userJid = user.getAddress();
3         if (userJid != null) {
4             occupants.put(userJid.toBareJID(), joinRole);
5         }

 5、详细了解 LocalMUCRoom、LocalMUCUser、LocalMUCRole这三个类,各类中的数据成员、方法。