Esempio n. 1
0
        void ReplyGroupMessage(MessageUserToken userToken, ChatMessage cm)
        {
            ReplyBase(userToken, new ChatMessage(ChatMessageType.GroupMessageAnswer, ""));

            var groupMsg = cm.GetIMessage <GroupMessage>();

            if (groupMsg != null && !string.IsNullOrEmpty(groupMsg.Name))
            {
                groupMsg.Sender = userToken.ID;

                groupMsg.Sended = DateTimeHelper.ToString();

                var group = _groupList.Get(groupMsg.Name);

                if (group != null && group.Members != null)
                {
                    lock (_groupList.SyncLocker)
                    {
                        var ccm  = new ChatMessage(ChatMessageType.GroupMessage, groupMsg);
                        var data = SerializeHelper.PBSerialize(cm);
                        var sp   = BaseSocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes();

                        Parallel.ForEach(group.Members, (m) =>
                        {
                            if (m.ID != userToken.ID)
                            {
                                _server.SendAsync(m.ID, sp);
                            }
                        });
                    }
                }
            }
        }
Esempio n. 2
0
        void ReplyGroupMessage(MessageUserToken userToken, ChatMessage cm)
        {
            ReplyBase(userToken, new ChatMessage(ChatMessageType.GroupMessageAnswer, ""));

            var groupMsg = cm.GetIMessage <GroupMessage>();

            if (groupMsg != null && !string.IsNullOrEmpty(groupMsg.Name))
            {
                groupMsg.Sender = userToken.ID;

                groupMsg.Sended = DateTimeHelper.ToString();

                var group = _groupList.Get(groupMsg.Name);

                if (group != null && group.Members != null)
                {
                    lock (_groupList.SyncLocker)
                    {
                        foreach (var m in group.Members)
                        {
                            try
                            {
                                if (m.ID != userToken.ID)
                                {
                                    var r = SessionManager.Get(m.ID);
                                    if (r != null)
                                    {
                                        ReplyBase(r, new ChatMessage(ChatMessageType.GroupMessage, groupMsg));
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonGroupRequestMessage jsonRequestMessage = JsonGroupRequestMessage.Parse(jsonRequest.Message);

            // Data
            Entity         entity   = session.Owner;
            GroupComponent group    = entity.Get <GroupComponent>();
            EntityList     entities = GroupList.Get(group.Id);

            if (entities == null)
            {
                channel.SendNotFound();
                return;
            }

            List <JsonClient> jsonClients = new List <JsonClient>();

            lock (entities)
            {
                foreach (Entity e in entities)
                {
#if !DEBUG
                    if (entity.Id.Equals(e.Id))
                    {
                        continue;
                    }
#endif
                    ClientComponent c          = e.Get <ClientComponent>();
                    JsonClient      jsonClient = (JsonClient)c;
                    jsonClients.Add(jsonClient);
                }
            }

            if (jsonClients.Count == 0)
            {
                channel.SendNotFound();
                return;
            }

            jsonClients.Sort();

            // Response
            JsonGroupResponseMessage jsonResponseMessage = new JsonGroupResponseMessage()
            {
                Clients = jsonClients
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };
            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Esempio n. 4
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonSearchRequestMessage jsonRequestMessage = JsonSearchRequestMessage.Parse(jsonRequest.Message);

            // Data
            Entity         entity   = session.Owner;
            GroupComponent group    = entity.Get <GroupComponent>();
            EntityList     entities = GroupList.Get(group.Id);

            if (entities == null)
            {
                channel.SendNotFound();
                return;
            }

            // Response
            string jsonId = SecurityUtil.CreateKeyString();
            JsonSearchResponseMessage jsonResponseMessage = new JsonSearchResponseMessage(jsonId);
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);

            // Optimization: Keep track of the search list for faster downloads
            SearchListComponent download = entity.Get <SearchListComponent>();

            download.Clear();

            // Command
            lock (entities)
            {
                foreach (Entity e in entities)
                {
                    // Do not search yourself
                    if (entity.Id.Equals(e.Id))
                    {
                        continue;
                    }

                    TunnelComponent tunnel = e.Get <TunnelComponent>();
                    if (!tunnel.Connected)
                    {
                        continue;
                    }

                    CommandState state = new CommandState()
                    {
                        Id     = jsonId,
                        Data   = jsonRequest.Data,
                        Source = entity,
                        Target = e
                    };

                    Thread thread = new Thread(new ParameterizedThreadStart(ExecuteThread))
                    {
                        Priority = ThreadPriority.BelowNormal, IsBackground = true
                    };
                    thread.Start(state);
                }
            }
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }