コード例 #1
0
        private async Task BeginSignupProcess(ISessionContext context)
        {
            context.Session.Properties.Set(SessionConstants.SignupStatus, "username");
            await context.Response.Append(AnsiBuilder.Parse("[[action.cls]][[attr.bold]][[fg.yellow]]Welcome newcomer!\r\n\r\n[[attr.normal]][[fg.green]]Some welcome text should go here.\r\n"));

            await ShowUsernamePrompt(context);
        }
コード例 #2
0
        private async Task Broadcast(string message, string roomName, params Guid[] exclusions)
        {
            var room = m_Rooms.Get(roomName);

            if (room == null)
            {
                return;
            }

            var query = from a in m_SessionManager.Sessions
                        where room.Users.Contains(a.ClientId)
                        select a;

            if (exclusions.Length > 0)
            {
                foreach (var exclusion in exclusions)
                {
                    query = query.Where(a => a.ClientId != exclusion);
                }
            }

            var clientList = query.ToList();

            foreach (var client in clientList)
            {
                await client.Notify("[[attr.bold]][[fg.green]]***\r\n");

                await client.Notify(message);

                await client.Notify(AnsiBuilder.Parse("[[attr.bold]][[fg.green]]:"));
            }
        }
コード例 #3
0
        private async Task ShowUsernamePrompt(ISessionContext context)
        {
            await context.Response.Append(AnsiBuilder.Parse("\r\n\r\n[[bg.black]][[fg.green]]Please enter the username you would like to use.\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[bg.white]]                                               \r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[action.moveup]][[bg.white]][[fg.black]]"));
        }
コード例 #4
0
        private async Task ProcessPassword(ISessionContext context)
        {
            var value = Encoding.ASCII.GetString(await context.Request.Body.GetBytes());

            if (string.IsNullOrWhiteSpace(value))
            {
                await ShowError(context, "You must specify a password to continue.");
                await ShowPasswordPrompt(context);

                return;
            }

            if (value.Length < 6)
            {
                await ShowError(context, "Your password must be at least 6 characters.");
                await ShowPasswordPrompt(context);

                return;
            }

            var username     = context.Session.Properties.Get("signup.username").ToString();
            var seed         = Guid.NewGuid();
            var passwordHash = m_CryptoProvider.Hash(value, seed.ToByteArray());
            var userId       = Guid.NewGuid();
            var user         = new User
            {
                Id             = userId,
                Username       = username,
                Password       = passwordHash,
                Seed           = seed,
                DateAdded      = DateTime.Now,
                IpAddress      = context.Session.ClientAddress.ToString(),
                PropertiesBlob = "{ }"
            };

            try
            {
                using (var userEngine = context.Session.GetDependency <IUserEngine>())
                {
                    userEngine.CreateUser(user);
                }
            }
            catch (Exception ex)
            {
                await ShowError(context, "There was an unknown error processing your request.  This has been logged, and the system operator has been notified.  Please try your request again later.");

                context.Session.IsLoggingOff = true;
                // Log Exception
                return;
            }

            await context.Response.Append(AnsiBuilder.Parse($"\r\n[[bg.black]][[fg.white]]Welcome {username}!\r\n"));

            context.Session.Properties.Set(SessionConstants.IsAuthenticated, true);
            context.User = user;
            await Next.OnDataReceived(context);
        }
コード例 #5
0
        private async Task ShowPasswordPrompt(ISessionContext context)
        {
            await context.Response.Append(AnsiBuilder.Parse("\r\n\r\n[[bg.black]][[fg.green]]Please enter the password you will use to login to the system.\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[bg.white]]                                               \r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[action.moveup]][[bg.white]][[fg.black]]"));

            context.Session.Properties.Set(SessionConstants.MaskNextInput, true);
        }
コード例 #6
0
        public async Task Activate(ISessionContext context)
        {
            Guid?  userRoomId = null;
            string userRoom   = null; // TODO: = GetDatabaseCallToAccessUsersLastRoom

            if (string.IsNullOrWhiteSpace(userRoom))
            {
                userRoomId = Guid.Empty;
                userRoom   = "MAIN";
            }

            var room = m_Rooms.Get(userRoom);

            if (room == null)
            {
                room = new ChatRoom(userRoomId.Value);
                m_Rooms.Add(userRoom, room);
            }

            room.Users.Add(context.Session.ClientId);
            var userCount = room.Users.Count;

            var templateName = "template.teleconference.welcome";
            var template     = m_TemplateProvider.BuildTemplate(templateName);

            try
            {
                var templateBody = template.Render(new
                {
                    username = context.Session.Username,
                    room     = userRoom,
                    count    = userCount - 1,  // Exclude Self
                    isEmpty  = userCount == 1, // 1 = only you
                    isFull   = userCount > 2   // > 2 = More than 1
                });
                await Broadcast(AnsiBuilder.Parse($"[[attr.bold]][[fg.yellow]]{context.Session.Username} has entered the room.\r\n"), "MAIN", context.Session.ClientId);

                await context.Response.Append(templateBody);
            }
            catch (KeyNotFoundException ex)
            {
                Console.WriteLine($"Template {templateName} is invalid : {ex.Message}");
            }
            await ShowPrompt(context);
        }
コード例 #7
0
ファイル: MenuProvider.cs プロジェクト: jsheldon/OldSchool
        private void ShowMenu(ISessionContext context)
        {
            var sb = new StringBuilder();

            sb.Append(AnsiBuilder.Parse("[[action.cls]][[fg.green]][[attr.bold]][[bg.black]]Please select from one of the following choices.\r\n"));


            sb.Append(AnsiBuilder.Parse("[[action.cls]]"));
            sb.Append(AnsiBuilder.Parse("\r\n\r\n[[attr.bold]][[fg.cyan]][[bg.black]]MAIN MENU\r\n\r\n"));

            for (var x = 0; x < m_Modules.Count; x++)
            {
                sb.Append(AnsiBuilder.Parse($"[[attr.bold]][[fg.green]]{x + 1} [[fg.white]]- [[fg.green]]{m_Modules[x].Name}\r\n"));
            }

            sb.Append(AnsiBuilder.Parse("[[attr.bold]][[fg.green]]X [[fg.white]]- [[attr.normal]][[fg.green]]Log Off\r\n\r\n"));
            sb.Append(AnsiBuilder.Parse("\r\n\r\n[[attr.bold]][[fg.yellow]]Your Selection? [[bg.white]][[fg.black]] [[bg.black]][[action.moveback]]"));
            context.Response.Append(sb.ToString());
        }
コード例 #8
0
        public async Task OnDataReceived(ISessionContext context)
        {
            var data = await context.Request.Body.GetBytes();

            var text = Encoding.ASCII.GetString(data);

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            if (text.StartsWith("/"))
            {
                HandleSlashCommand(context, text);
                return;
            }

            if (text.StartsWith("?"))
            {
                await ShowHelp(context);

                return;
            }

            if (text.ToLower() == "x")
            {
                await Broadcast(AnsiBuilder.Parse($"[[attr.bold]][[fg.cyan]]{context.Session.Username} [[fg.cyan]]has left the channel!"), "MAIN", context.Session.ClientId);

                context.Session.ActiveModule = null;
                return;
            }

            var message = AnsiBuilder.Parse($"[[attr.bold]][[fg.white]]From [[fg.cyan]]{context.Session.Username}[[fg.yellow]]: [[fg.white]]{text}\r\n");
            await context.Response.Append(message);

            await Broadcast(message, "MAIN", context.Session.ClientId);
            await ShowPrompt(context);
        }
コード例 #9
0
        // TODO: Make this a constant or static if it's going to be variable
        // Also, if we could find a way to make this more readable, that'd be great.
        private async Task ShowHelp(ISessionContext context)
        {
            await context.Response.Append(AnsiBuilder.Parse("[[action.reset]]\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[attr.bold]][[fg.cyan]]In Teleconference, anything you type is broadcast to everyone on the same\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("\"[[fg.white]]channel[[fg.cyan]]\" with you[[fg.white]].  [[fg.cyan]]Also[[fg.white]], [[fg.cyan]]use these special commands[[fg.white]]:         [[fg.cyan]]--[[fg.white]]SHORTHAND[[fg.cyan]]--\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("PAGE [[fg.white]]<[[fg.cyan]]who[[fg.white]]> ...        [[fg.yellow]]\"pages\" the user with a message           [[fg.cyan]]/P [[fg.white]]<[[fg.cyan]]who[[fg.white]]> [[fg.cyan]]...\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("PAGE ON[[fg.white]]/[[fg.cyan]]OFF[[fg.white]]/[[fg.cyan]]OK        [[fg.yellow]]allows/prevents/encourages others to page [[fg.cyan]]/P ON[[fg.white]]/[[fg.cyan]]OFF[[fg.white]]/[[fg.cyan]]OK\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("WHISPER TO [[fg.white]]<[[fg.cyan]]who[[fg.white]]> ...  [[fg.yellow]]sends a private message to another user   [[fg.cyan]]/[[fg.white]]<[[fg.cyan]]who[[fg.white]]> ...\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]CHAT [[fg.white]]<[[fg.cyan]]who[[fg.white]]>            [[fg.yellow]]request or join in a \"chat\" with someone  [[fg.cyan]]/C [[fg.white]]<[[fg.cyan]]who[[fg.white]]>\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]SCAN                  [[fg.yellow]]shows where everyone is in Teleconference [[fg.cyan]]/S\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("LIST                  [[fg.yellow]]lists all public channels you can join\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]USERS                 [[fg.yellow]]shows where everyone is on the system     [[fg.cyan]]#\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("EDIT                  [[fg.yellow]]edit your Teleconference profile          [[fg.cyan]]/E\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("JOIN[[fg.white]]/[[fg.cyan]]JOIN [[fg.white]]<[[fg.cyan]]who[[fg.white]]>       [[fg.yellow]]join a private, public, or forum channel  [[fg.cyan]]/J [[fg.white]]<[[fg.cyan]]who[[fg.white]]>\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]INVITE [[fg.white]]<[[fg.cyan]]who[[fg.white]]>          [[fg.yellow]]invites a user to your private channel    [[fg.cyan]]/I [[fg.white]]<[[fg.cyan]]who[[fg.white]]>\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]UNINVITE [[fg.white]]<[[fg.cyan]]who[[fg.white]]>        [[fg.yellow]]uninvites a user from your channel        [[fg.cyan]]/U [[fg.white]]<[[fg.cyan]]who[[fg.white]]>\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]TOPIC [[fg.white]]...             [[fg.yellow]]list a topic for your private channel     [[fg.cyan]]/T [[fg.white]]...\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("FORGET/REMEMBER [[fg.white]]<[[fg.cyan]]who[[fg.white]]> [[fg.yellow]]\"forget\" (ignore) a user annoying you     [[fg.cyan]]/F or /REM [[fg.white]]<[[fg.cyan]]who[[fg.white]]>\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]IGNORE/NOTICE [[fg.white]]<[[fg.cyan]]who[[fg.white]]>   [[fg.yellow]]ignore or notice a user's action words    [[fg.cyan]]/G or /N [[fg.white]]<[[fg.cyan]]who[[fg.white]]>\r\n"));

            await context.Response.Append(AnsiBuilder.Parse("[[fg.cyan]]%c[[fg.white]]<[[fg.cyan]]who[[fg.white]]> <[[fg.cyan]]message[[fg.white]]>      [[fg.yellow]]direct a message to a user\r\n"));
        }
コード例 #10
0
 private async Task ShowError(ISessionContext context, string errorMessage)
 {
     await context.Response.Append(AnsiBuilder.Parse($"\r\n[[bg.black]][[attr.bold]][[fg.red]]{errorMessage}\r\n"));
 }
コード例 #11
0
 // TODO: Make this a constant or static if it's going to be variable
 private async Task ShowPrompt(ISessionContext context)
 {
     await context.Response.Append(AnsiBuilder.Parse("[[attr.bold]][[fg.green]]:"));
 }
コード例 #12
0
 public async Task OnSessionDisconnecting(ISessionContext context)
 {
     await Broadcast(AnsiBuilder.Parse($"[[fg.cyan]]{context.Session.Username} just hung up!"), "MAIN", context.Session.ClientId);
 }