Example #1
0
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            args.Reverse();
            for (int i = 0; i < args.Length; i++)
            {
                args[i] = args[i].Reverse();
            }

            string msg = String.Join(" ", args).Trim();

            ChatHubMessage chatHubMessage = new ChatHubMessage()
            {
                ChatHubRoomId = callerContext.RoomId,
                ChatHubUserId = caller.UserId,
                User          = caller,
                Content       = msg,
                Type          = ChatHubMessageType.Guest.ToString()
            };

            context.ChatHubRepository.AddChatHubMessage(chatHubMessage);

            ChatHubMessage chatHubMessageClientModel = context.ChatHubService.CreateChatHubMessageClientModel(chatHubMessage);
            var            connectionsIds            = context.ChatHubService.GetAllExceptConnectionIds(caller);
            await context.ChatHub.Clients.GroupExcept(callerContext.RoomId.ToString(), connectionsIds).SendAsync("AddMessage", chatHubMessageClientModel);
        }
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string targetUserName = args[0];

            ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName);

            targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser;

            if (targetUser == null)
            {
                await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (caller.UserId == targetUser.UserId)
            {
                // TODO: Delete the rest of the user data
                context.ChatHubRepository.DeleteChatHubMessages(caller.UserId);
                context.ChatHubRepository.DeleteChatHubConnections(caller.UserId);
                context.ChatHubRepository.DeleteChatHubRooms(caller.UserId, context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId).ModuleId);
                context.ChatHubRepository.DeleteChatHubUser(caller.UserId);

                throw new HubException(string.Format("Successfully deleted all database entries. System do not know an user named {0} anymore.", caller.DisplayName));
            }
        }
Example #3
0
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string messageColor = args[0];

            if (!string.IsNullOrEmpty(messageColor))
            {
                var settings = caller.Settings;
                settings.MessageColor = messageColor;
                context.ChatHubRepository.UpdateChatHubSetting(settings);

                await context.ChatHub.SendClientNotification("Message Color Updated.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);
            }
        }
Example #4
0
        public async Task <bool> TryHandleCommand(string commandName, string[] args)
        {
            if (String.IsNullOrEmpty(commandName))
            {
                return(false);
            }

            commandName = commandName.Trim();
            if (commandName.StartsWith("/"))
            {
                return(false);
            }

            var context = new CommandServicesContext
            {
                ChatHub           = _chatHub,
                ChatHubService    = _chatService,
                ChatHubRepository = _repository,
                UserManager       = _userManager
            };

            var callerContext = new CommandCallerContext
            {
                ConnectionId = _connectionId,
                UserId       = _caller.UserId,
                RoomId       = _roomId
            };

            ICommand command;

            command = MatchCommand(commandName);
            if (command != null)
            {
                await command.Execute(context, callerContext, args, _caller);

                return(true);
            }

            throw new HubException(string.Format("No command found that called like {0}", commandName));
        }
Example #5
0
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string targetUserName = args[0];

            ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName);

            targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser;

            if (targetUser == null)
            {
                await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            await context.ChatHub.UnignoreUser(targetUser.Username);
        }
Example #6
0
 public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
 {
     await context.ChatHub.SendCommandMetaDatas(callerContext.RoomId);
 }
Example #7
0
        public override async Task Execute(CommandServicesContext commandServicesContext, CommandCallerContext commandCallerContext, string[] args, ChatHubUser caller)
        {
            IdentityUser identityUser = await commandServicesContext.UserManager.FindByNameAsync(caller.Username);

            if (!commandServicesContext.UserManager.IsInRoleAsync(identityUser, Oqtane.Shared.Constants.AdminRole).Result)
            {
                return;
            }

            await ExecuteAdminOperation(commandServicesContext, commandCallerContext, args, caller);
        }
Example #8
0
 public abstract Task ExecuteAdminOperation(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller);
 public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
 {
     await context.ChatHub.Clients.Client(callerContext.ConnectionId).SendAsync("ClearHistory", callerContext.RoomId);
 }
Example #10
0
        public override async Task ExecuteModeratorOperation(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string targetUserName = args[0];

            ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName);

            targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser;

            if (targetUser == null)
            {
                await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            foreach (var connection in targetUser.Connections)
            {
                await context.ChatHub.Clients.Client(connection.ConnectionId).SendAsync("Disconnect", context.ChatHubService.CreateChatHubUserClientModel(targetUser));
            }
        }
Example #11
0
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string targetUserName = args[0];

            ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName);

            targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser;

            if (targetUser == null)
            {
                await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (!targetUser.Online())
            {
                await context.ChatHub.SendClientNotification("User not online.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (caller.UserId == targetUser.UserId)
            {
                await context.ChatHub.SendClientNotification("Calling user can not be target user.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string msg = null;

            if (args.Length > 1)
            {
                msg = String.Join(" ", args.Skip(1)).Trim();
            }

            var callerRoom = context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId);

            ChatHubMessage chatHubMessage = new ChatHubMessage()
            {
                ChatHubRoomId = callerContext.RoomId,
                ChatHubUserId = caller.UserId,
                User          = caller,
                Content       = msg ?? string.Empty,
                Type          = Enum.GetName(typeof(ChatHubMessageType), ChatHubMessageType.Whisper)
            };

            context.ChatHubRepository.AddChatHubMessage(chatHubMessage);
            var chatHubMessageClientModel = context.ChatHubService.CreateChatHubMessageClientModel(chatHubMessage);

            var users = new List <ChatHubUser>(); users.Add(caller); users.Add(targetUser);

            foreach (var item in users)
            {
                var rooms       = context.ChatHubRepository.GetChatHubRoomsByUser(item).Public().Active().ToList();
                var connections = item.Connections.Active();

                foreach (var room in rooms)
                {
                    foreach (var connection in connections)
                    {
                        await context.ChatHub.Clients.Client(connection.ConnectionId).SendAsync("AddMessage", chatHubMessageClientModel);
                    }
                }
            }
        }
Example #12
0
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string targetUserName = args[0];

            ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName);

            targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser;

            if (targetUser == null)
            {
                await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (!targetUser.Online())
            {
                await context.ChatHub.SendClientNotification("User not online.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (caller.UserId == targetUser.UserId)
            {
                await context.ChatHub.SendClientNotification("Calling user can not be target user.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string msg = null;

            if (args.Length > 1)
            {
                msg = String.Join(" ", args.Skip(1)).Trim();
            }

            var callerRoom = context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId);

            if (caller.UserId != callerRoom.CreatorId)
            {
                await context.ChatHub.SendClientNotification("Whitelist user command can be executed from room creator only.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (callerRoom.Public() || callerRoom.Protected() || callerRoom.Private())
            {
                ChatHubWhitelistUser chatHubWhitelistUser = context.ChatHubRepository.AddChatHubWhitelistUser(targetUser);

                ChatHubRoomChatHubWhitelistUser room_whitelistuser = new ChatHubRoomChatHubWhitelistUser()
                {
                    ChatHubRoomId          = callerRoom.Id,
                    ChatHubWhitelistUserId = chatHubWhitelistUser.Id,
                };
                context.ChatHubRepository.AddChatHubRoomChatHubWhitelistUser(room_whitelistuser);

                foreach (var connection in caller.Connections.Active())
                {
                    await context.ChatHub.SendClientNotification("Command whitelist user succeeded.", callerContext.RoomId, connection.ConnectionId, caller, ChatHubMessageType.System);
                }
            }
        }
Example #13
0
        public override async Task Execute(CommandServicesContext commandServicesContext, CommandCallerContext commandCallerContext, string[] args, ChatHubUser caller)
        {
            if (!commandServicesContext.ChatHub.Context.User.HasClaim(ClaimTypes.Role, Shared.RoleNames.Admin))
            {
                throw new HubException("You do not have any permissions to run this command");
            }

            await ExecuteAdminOperation(commandServicesContext, commandCallerContext, args, caller);
        }
 public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
 {
     await context.ChatHub.Clients.Client(callerContext.ConnectionId).SendAsync("Disconnect", context.ChatHubService.CreateChatHubUserClientModel(caller));
 }
Example #15
0
 async Task ICommand.Execute(CommandServicesContext commandServiceContext, CommandCallerContext commandCallerContext, string[] args, ChatHubUser user)
 {
     await Execute(commandServiceContext, commandCallerContext, args, user);
 }
Example #16
0
        public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller)
        {
            if (args.Length == 0)
            {
                await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string targetUserName = args[0];

            ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName);

            targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser;

            if (targetUser == null)
            {
                await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (!targetUser.Online())
            {
                await context.ChatHub.SendClientNotification("User not online.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            if (caller.UserId == targetUser.UserId)
            {
                await context.ChatHub.SendClientNotification("Calling user can not be target user.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System);

                return;
            }

            string msg = null;

            if (args.Length > 1)
            {
                msg = String.Join(" ", args.Skip(1)).Trim();
            }

            var callerRoom   = context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId);
            var oneVsOneRoom = context.ChatHubService.GetOneVsOneRoom(caller, targetUser, callerRoom.ModuleId);

            if (oneVsOneRoom != null)
            {
                await context.ChatHub.EnterChatRoom(oneVsOneRoom.Id);

                ChatHubInvitation chatHubInvitation = new ChatHubInvitation()
                {
                    Guid     = Guid.NewGuid(),
                    RoomId   = oneVsOneRoom.Id,
                    Hostname = caller.DisplayName
                };
                foreach (var connection in targetUser.Connections.Active())
                {
                    await context.ChatHub.Clients.Client(connection.ConnectionId).SendAsync("AddInvitation", chatHubInvitation);
                }
            }
        }
Example #17
0
        public override async Task Execute(CommandServicesContext commandServicesContext, CommandCallerContext commandCallerContext, string[] args, ChatHubUser caller)
        {
            var room = commandServicesContext.ChatHubRepository.GetChatHubRoom(commandCallerContext.RoomId);
            var moderator = commandServicesContext.ChatHubRepository.GetChatHubModerator(caller.UserId);
            var chatHubRoomChatHubModerator = commandServicesContext.ChatHubRepository.GetChatHubRoomChatHubModerator(commandCallerContext.RoomId, moderator.Id);

            if(room.CreatorId != caller.UserId && chatHubRoomChatHubModerator == null && !commandServicesContext.ChatHub.Context.User.HasClaim(ClaimTypes.Role, Shared.RoleNames.Admin))
            {
                throw new HubException("You do not have any permissions to run this command.");
            }

            await ExecuteModeratorOperation(commandServicesContext, commandCallerContext, args, caller);
        }