Esempio n. 1
0
        private void SendError(HttpStatusCode code, Socket socket)
        {
            var errResponse = new FetchUserListResponsePacket(new FetchUserListResponsePacketData(
                                                                  (int)code,
                                                                  0,
                                                                  null
                                                                  ));

            Zephy.serverSocket.SendPacket(errResponse, socket);
        }
Esempio n. 2
0
        protected override void Handle(FetchUserListRequestPacket packet, Socket sender)
        {
            var data = packet.Data;

            if (data == null)
            {
                return;
            }
            data.search = data.search.ToLower();

            ActiveUser activeUser = ActiveUsers.GetUser(sender);

            if (activeUser == null)
            {
                SendError(HttpStatusCode.Unauthorized, sender);
                return;
            }

            User user = userCrud.ReadOneById(activeUser.userId);

            // Fetch all users that match the search & aren't the requester
            List <ListedUser> users = userCrud.ReadManyListedPaginated(
                data.page, PAGE_SIZE,
                x =>
                (x.identifier.ToLower().Contains(data.search) ||
                 x.fullName.ToLower().Contains(data.search)) &&
                x._id != user._id
                );



            // remove excludes
            if (data.optionalExcludeIds != null)
            {
                users.RemoveAll(x => data.optionalExcludeIds.Contains(x._id));
            }

            var response = new FetchUserListResponsePacket(new FetchUserListResponsePacketData(
                                                               (int)HttpStatusCode.OK,
                                                               data.page,
                                                               users
                                                               ));

            Zephy.serverSocket.SendPacket(response, sender);
        }