public static MessageData Decode(G2Header root) { MessageData msg = new MessageData(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_Text: msg.Text = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Format: msg.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_TargetID: msg.TargetID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; } } return msg; }
public InstantMessage(OpCore core, RudpSession session, MessageData message) { UserID = session.UserID; ClientID = session.ClientID; TimeStamp = core.TimeNow; Text = message.Text; Format = message.Format; }
public void SendMessage(ulong key, string text, TextFormat format) { if (Core.InvokeRequired) { Core.RunInCoreAsync(delegate() { SendMessage(key, text, format); }); return; } if (text == "***debug***") { Core.DebugWindowsActive = true; text = "activated"; } IMStatus status = null; if (!IMMap.SafeTryGetValue(key, out status)) return; bool sent = false; MessageData message = new MessageData(text, format); foreach (RudpSession session in Network.RudpControl.GetActiveSessions(key)) { sent = true; // only sent if target receies session.SendData(ServiceID, 0, message); } // send copies to other selves running message.TargetID = key; foreach (RudpSession session in Network.RudpControl.GetActiveSessions(Core.UserID)) session.SendData(ServiceID, 0, message); ProcessMessage(status, new InstantMessage(Core, text, format) { Sent = sent }); }