void Session_Data(RudpSession session, byte[] data) { G2Header root = new G2Header(data); if (G2Protocol.ReadPacket(root)) { switch (root.Name) { case ChatPacket.Data: ReceiveMessage(ChatText.Decode(root), session); break; case ChatPacket.Status: ReceiveStatus(ChatStatus.Decode(root), session); break; case ChatPacket.Invite: ReceiveInvite(ChatInvite.Decode(root), session); break; case ChatPacket.Who: ReceiveWho(ChatWho.Decode(root), session); break; } } }
private void ReceiveMessage(ChatText message, RudpSession session) { if (Core.Buddies.IgnoreList.SafeContainsKey(session.UserID)) { return; } // remote's command low, is my command high // do here otherwise have to send custom roomID packets to selfs/lowers/highers if (Trust != null && session.UserID != Core.UserID) { // if check fails then it is loop node sending data, keep it unchanged if (message.Kind == RoomKind.Command_High && Trust.IsLowerDirect(session.UserID, message.ProjectID)) { message.Kind = RoomKind.Command_Low; } else if (message.Kind == RoomKind.Command_Low && Trust.IsHigher(session.UserID, message.ProjectID)) { message.Kind = RoomKind.Command_High; } else if (message.Kind == RoomKind.Live_High) { message.Kind = RoomKind.Live_Low; } else if (message.Kind == RoomKind.Live_Low) { message.Kind = RoomKind.Live_High; } } ulong id = IsCommandRoom(message.Kind) ? GetRoomID(message.ProjectID, message.Kind) : message.RoomID; ChatRoom room = null; // if not in room let remote user know if (!RoomMap.TryGetValue(id, out room) || !room.Active) { SendStatus(session); return; } // if sender not in room if (!room.Members.SafeContains(session.UserID)) { return; } if (!ChatNewsUpdate) { ChatNewsUpdate = true; Core.MakeNews(ServiceIDs.Chat, Core.GetName(session.UserID) + " is chatting", session.UserID, 0, false); } ProcessMessage(room, new ChatMessage(Core, session, message)); }
public ChatMessage(OpCore core, RudpSession session, ChatText text) { UserID = session.UserID; ClientID = session.ClientID; TimeStamp = core.TimeNow; Text = text.Text; Format = text.Format; }
public void SendMessage(ChatRoom room, string text, TextFormat format) { if (Core.InvokeRequired) { Core.RunInCoreAsync(delegate() { SendMessage(room, text, format); }); return; } bool sent = false; if (room.Active) { ChatText message = new ChatText(); message.ProjectID = room.ProjectID; message.Kind = room.Kind; message.RoomID = room.RoomID; message.Text = text; message.Format = format; room.Members.LockReading(delegate() { // also sends to other instances of self foreach (ulong member in room.Members) { foreach (RudpSession session in Network.RudpControl.GetActiveSessions(member)) { sent = true; session.SendData(ServiceID, 0, message); } } }); } ProcessMessage(room, new ChatMessage(Core, text, format) { Sent = sent }); //if (!sent) // ProcessMessage(room, "Could not send message, not connected to anyone"); }
public static ChatText Decode(G2Header root) { ChatText chat = new ChatText(); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_ID: chat.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Kind: chat.Kind = (RoomKind)BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Text: chat.Text = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Format: chat.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_RoomID: chat.RoomID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; } } return(chat); }
public static ChatText Decode(G2Header root) { ChatText chat = new ChatText(); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_ID: chat.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Kind: chat.Kind = (RoomKind) BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Text: chat.Text = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Format: chat.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_RoomID: chat.RoomID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; } } return chat; }