From 265e629e5bc5ad8f9d2a8e94dce864ebe995bcef Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sat, 7 Sep 2013 19:34:34 +0700 Subject: onJuickPM --- src/com/juick/jabber/ws/XMPPConnection.java | 48 ++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/com/juick/jabber/ws/XMPPConnection.java b/src/com/juick/jabber/ws/XMPPConnection.java index 0eef26bf..a8af8c44 100644 --- a/src/com/juick/jabber/ws/XMPPConnection.java +++ b/src/com/juick/jabber/ws/XMPPConnection.java @@ -62,7 +62,16 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS); if (jmsg != null) { System.err.println("MID=" + jmsg.MID + "; RID=" + jmsg.RID); - if (jmsg.RID == 0) { + if (jmsg.MID == 0) { + int uid_to = 0; + try { + uid_to = Integer.parseInt(msg.to.Username); + } catch (Exception e) { + } + if (uid_to > 0) { + onJuickPM(uid_to, jmsg); + } + } else if (jmsg.RID == 0) { onJuickMessagePost(jmsg); } else { onJuickMessageReply(jmsg); @@ -70,6 +79,43 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. } } + private void onJuickPM(int uid_to, com.juick.Message jmsg) { + String json = com.juick.json.Message.toJSON(jmsg).toString(); + ByteBuffer jsonbytes = Charset.forName("UTF-8").encode(json); + ByteBuffer bbMsg = ByteBuffer.allocate(10240); + bbMsg.put((byte) 0x81); + if (jsonbytes.limit() <= 125) { + bbMsg.put((byte) jsonbytes.limit()); + } else { + bbMsg.put((byte) 126); + bbMsg.putShort((short) jsonbytes.limit()); + } + bbMsg.put(jsonbytes); + bbMsg.flip(); + + synchronized (Main.clients) { + for (Iterator i = Main.clients.iterator(); i.hasNext();) { + SocketSubscribed s = i.next(); + if (s.VUID == uid_to) { + bbMsg.rewind(); + try { + s.sock.write(bbMsg); + } catch (Exception e) { + try { + s.sock.socket().close(); + } catch (Exception ex) { + } + try { + s.sock.close(); + } catch (Exception ex) { + } + i.remove(); + } + } + } + } + } + private void onJuickMessagePost(com.juick.Message jmsg) { String json = com.juick.json.Message.toJSON(jmsg).toString(); ByteBuffer jsonbytes = Charset.forName("UTF-8").encode(json); -- cgit v1.2.3