1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
This is a repository, containing a console application exercise, made by me, and solution in different languages.
The task should serve as a "final exam" for developers who are learning the basics of a programming language (where possible).
# ctfc
`ctfc` is the "**c**onsole **t**ext **f**ile **c**hat", and the project you're going to work on. As the name suggests, it will be a chatting application, entirely in the console. For data storage, simple text files will be used.
## General structure
### Feature overview
- User registration, login and updating
- Chat rooms with title and details, message history, real time chat updating
- Direct user messaging with message, real time updating
### User accounts
Each user must have the following properties:
- `string UserName`: between 2 and 40 characters (A-z, 0-9, ., \*, \_, -, at least one letter, not already existing)
- `string Password`: between 5 and 40 characters (any character, but at least one number)
- `string Name`: between 2 and 60 characters (A-z, spaces, ', -)
Two users can't have the same UserName. Once set, a UserName cannot be changed.
Passwords must be hashed. You decide on which algorithm to use.
### Chat rooms
Each chat room must have the following properties:
- `string Name`: between 2 and 20 characters (A-z, 0-9, spaces, \_, -, at least one letter, not already existing)
- `string Description`: between 0 and 30 characters (any character)
- `string Owner`: between 2 and 40 characters (must be an existing UserName, it's set automatically)
- `string collection Messages`: a collection containing all messages
Two chat rooms can't have the same Name. Once set, a name cannot be changed.
Once set, an owner cannot be changed (owner is set via code, it's not chosen by user).
### Direct messages chat
Each direct message chat has the following properties:
- `User Author1`: an object (or potentially a string that is just a username) for the first user in the direct messages
- `User Author2`: an object (or potentially a string that is just a username) for the second user in the direct messages
- `string collection Messages`: a collection containing all messages
The name is not chosen by a user. It is in the format `USERNAME USERNAME`, where the "bigger" username is first, and the smaller is second.
### Files
As discussed, files are used for long term storage. The location of all files are up to you, but they should follow this structure:
```
├─ Users
│ ├─ john.txt
│ ├─ robertson94.txt
│ └─ steve.txt
├─ Chat Rooms
│ ├─ Cool Kids Club.txt
│ └─ Computer geeks.txt
└─ Direct Messages
└─ robertson94 steve.txt
```
- Users folder: contains text files for each user, in format `USERNAME.txt`
- Each file is in the format:
```
USERNAME
PASSWORD_HASH
NAME
```
- Chat Rooms folder: contains text files for each chat room, in format `CHAT ROOM NAME.txt`
- Each file is in the format:
```
NAME
DESCRIPTION
OWNER_USERNAME
USERNAME
MESSAGE
USERNAME
MESSAGE
```
- Direct Messages folder: contains text files for each direct message combination, in format `USERNAME USERNAME.txt`
- Each file is in the format:
```
NAME
USERNAME
MESSAGE
USERNAME
MESSAGE
```
## User interface
In this part, you're gonna see the general rules for the UI. You must create a system which implements these rules, and then all pages/windows, defined in the following section, must utilize that system (so for each page, there is just a definition of what's inside it).
Note: the `█` character, represents the location of the cursor
- Errors are always surrounded by a double border:
```
╔════════════════════╗
║ An error occurred! ║
╚════════════════════╝
```
and must be shown at the top of the page.
- Menu items (navigation bar items) are always surrounded by a single border:
```
┌────────┬────────┬────────┐
│ Page 1 │ Page 2 │ Page 3 │
└────────┴────────┴────────┘
```
- At the left side, there is always a "rail" that connects all *fields* to the menu items. Errors are never connected.
```
╔══════════════════╗
║ Invalid message! ║
╚══════════════════╝
┌────────┬────────┬────────┐
│ Page 1 │ Page 2 │ Page 3 │
├────────┴────────┴────────┘
├% steve : This is a test message
├% john : It's true
├% steve : And this is another test
└@ Message : █
```
- Text fields just contain some text, and start with a `%`:
```
├% steve : This is a test message
```
- A notable exception is the page indicator, which is just text, but connects to the "rail", rather than start with a `%`:
```
├─Page 1/5─┘
```
- Input fields take user input and start with a `@`, then have specifications on valid input and finally semicolon and user's cursor:
```
└@ Username : █
```
They're always at the very bottom, unless filled. A filled input field is treated as a text field, but still has the `@` symbol.
```
├@ Username : John
└@ Password : █
```
- The specification can be a normal word (like just `Username`, `Password`, etc.) or a command specification. Command specifications are surrounded in square brackets. Capital letters or symbols mean that you can enter that character for the command, while lowercase word(s) specify what type of value is the command. Capital letter commands are case insensitive, so you could just write the lowercase of the letter.
```
└@ [A/B/C/name/number/H] : █
```
*Here, you can either enter the letter A, B, C or H (case insensitive), and that will execute some command. If you enter some sort of a name or number, those will be seen as commands (case sensitive).*
`H` is the Help command, it shows in a bit more detail the command specifications, it should exist almost everywhere
- Usually there is a "blank" line above the input field, unless it's directly below the menu items:
```
┌───────┐
│ Login │
├───────┘
├% Logging into ctfc
│
└@ Username : █
```
```
┌───────┐
│ Login │
├───────┘
└@ Username : █
```
- Numbered fields are used for navigation purposes. In them, each item starts with with a number and by selecting a number, some action should happen to the selected item:
```
├1 First Option
├2 Second Option
├3 Third Option
```
### Initial window
When launching the application, the user will be prompted to choose between logging in or registering an account:
```
┌───────┬──────────┐
│ Login │ Register │
├───────┴──────────┘
└@ [L/R] : █
```
If an invalid value is given, the error is shown on top and the prompt is below:
```
╔════════════════════════════════╗
║ "asd" is not a valid argument! ║
╚════════════════════════════════╝
┌───────┬──────────┐
│ Login │ Register │
├───────┴──────────┘
└@ [L/R] : █
```
### Login
In the login screen, you should be greeted with a username prompt:
```
┌───────┐
│ Login │
├───────┘
└@ Username : █
```
After input, if the user does not exist, it will show an error and the prompt below it:
```
╔════════════════════════════╗
║ User "asd" does not exist! ║
╚════════════════════════════╝
┌───────┐
│ Login │
├───────┘
└@ Username : █
```
but if the user exists, it should show the password prompt below:
```
┌───────┐
│ Login │
├───────┘
├@ Username : John
└@ Password : █
```
On incorrect password, there should be an error shown and the prompt below:
```
╔═════════════════════╗
║ Incorrect password! ║
╚═════════════════════╝
┌───────┐
│ Login │
├───────┘
├@ Username : John
└@ Password : █
```
On correct password, user should be greeted by the [chats page](#Chats%20page).
Note: You probably got how it looks when there is an error, so I won't show it anymore.
### Register
The user should be prompted with input prompts in this order (if values is correct):
```
┌──────────┐
│ Register │
├──────────┘
└@ Username [A-z, 0-9, *, ., _, -] : █
```
```
┌──────────┐
│ Register │
├──────────┘
├@ Username : John
└@ Password [5-40 characters; at least 1 number] : █
```
```
┌──────────┐
│ Register │
├──────────┘
├@ Username : John
├@ Password : password1
└@ Name [2-60 characters] : █
```
After pressing enter in the name section, the user should be redirected to the [chats page](#Chats%20page) (so, instantly logged in).
### Chats page
The chats page is one of the main pages inside the application. Here you can see all available chats with pagination, and you can also Create your own chat or Edit ones you own.
```
┌─────────────────┬─────────┬────────┐
│ Direct Messages │ Account │ Logout │
├─────────────────┴─────────┴────────┘
├1 Cool Kids Club : A chat room only for those worthy of it B-)
├2 Computer geeks : You like computers? So do we. Join us for the nerdy experience
├─Page 1/1─┘
│
└@ [D/A/L/</>/C/E/name/number/H] : █
```
With Help message:
```
┌─────────────────┬─────────┬────────┐
│ Direct Messages │ Account │ Logout │
├─────────────────┴─────────┴────────┘
├1 Cool Kids Club : A chat room only for those worthy of it B)
├2 Computer geeks : You like computers? So do we. Join us for the nerdy experience
├─Page 1/1─┘
│
├% Chats page options : [(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(C) for create chat/(E) for edit chats/(name) for go to chat room by name/(number) for go to chat room by number/(H)elp]
└@ [D/A/L/</>/C/E/name/number/H] : █
```
### Create chat page
```
┌─────────────────────┐
│ Creating a new chat │
├─────────────────────┘
└@ Name [2-20 characters; A-z, 0-9, spaces, _, -] or [B/H] : █
```
```
┌─────────────────────┐
│ Creating a new chat │
├─────────────────────┘
├% Creating a new chat options : [(B)ack to chats page/(H)elp]
└@ Name [2-20 characters; A-z, 0-9, spaces, _, -] or [B/H] : █
```
```
┌─────────────────────┐
│ Creating a new chat │
├─────────────────────┘
├@ Name : Computer geeks
└@ Description [0-30 characters] : █
```
### Edit chat page
```
┌───────────────┐
│ Edit own chat │
├───────────────┘
├1 Cool Kids Club : A chat room only for those worthy of it B-)
├─Page 1/1─┘
│
└@ [B/</>/name/number/H] : █
```
```
┌───────────────┐
│ Edit own chat │
├───────────────┘
├1 Cool Kids Club : A chat room only for those worthy of it B-)
├─Page 1/1─┘
│
├% Edit own chat options : [(B)ack to chats page/(<) for previous page/(>) for next page/(name) to edit chat room with name/(number) to edit chat room with number/(H)elp]
└@ [B/</>/name/number/H] : █
```
```
┌──────────────┐
│ Editing chat │
├──────────────┘
├1 Chat name : Cool Kids Club
├2 Description : A chat room only for those worthy of it B-)
│
└@ [B/name/number/H] : █
```
```
┌──────────────┐
│ Editing chat │
├──────────────┘
├1 Chat name : Cool Kids Club
├2 Description : A chat room only for those worthy of it B-)
│
├% Editing chat options : [(B)ack to chats page/(number) for edit option by number/(H)elp]
└@ [B/number/H] : █
```
Editing an option is just like editing an [account option](#Account%20page). Also, I'll only show editing Name, since the procedure is the same for editing the Description.
```
┌───────────────────┐
│ Editing chat name │
├───────────────────┘
└@ Account Password or [B/H] : █
```
```
┌───────────────────┐
│ Editing chat name │
├───────────────────┘
├% Editing chat name options : [(B)ack to Editing chat page/(H)elp]
└@ Account Password or [B/H] : █
```
```
┌───────────────────┐
│ Editing chat name │
├───────────────────┘
├@ Account Password : password1
└@ New name [2-20 characters; A-z, 0-9, spaces, _, -] : █
```
### Specific chat page
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% Computer geeks : You like computers? So do we. Join us for the nerdy experience
├% Brought to you by "David Robertson (robertson94)"
│
├% robertson94 : I think the new Windows 11 design looks horrible
├% steve : Yeah, right??
├─Page 50/50─┘
│
└@ Message or [C/D/A/L/</>/H] : █
```
With Help message:
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% Computer geeks : You like computers? So do we. Join us for the nerdy experience
├% Brought to you by "David Robertson (robertson94)"
│
├% robertson94 : I think the new Windows 11 design looks horrible
├% steve : Yeah, right??
├─Page 50/50─┘
│
├% Chat options : [(C)hats/(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(H)elp]
└@ Message or [C/D/A/L/</>/H] : █
```
**Note:** since a user might want to message with a letter/character **that could be interpreted as a command option**, putting a `\` in front must prevent the command from getting executed and just type in the letter:
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% Computer geeks : You like computers? So do we. Join us for the nerdy experience
├% Brought to you by "David Robertson (robertson94)"
│
├% robertson94 : I think the new Windows 11 design looks horrible
├% steve : Yeah, right??
├─Page 50/50─┘
│
└@ Message or [C/D/A/L/</>/H] : \L█
```
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% Computer geeks : You like computers? So do we. Join us for the nerdy experience
├% Brought to you by "David Robertson (robertson94)"
│
├% robertson94 : I think the new Windows 11 design looks horrible
├% steve : Yeah, right??
├% John : L
├─Page 50/50─┘
│
└@ Message or [C/D/A/L/</>/H] : █
```
- Sending `\\L` should result in `\L` message. It's not a problem if you just remove the first `\` in a message, so if someone sends `\B`, it's fine if it produces `B` as message.
- Letters that can't be interpreted as a command should be able to be written without worry. In the example above, if you enter `B`, it should just result in a message with `B`
### Direct messages page
```
┌───────┬─────────┬────────┐
│ Chats │ Account │ Logout │
├───────┴─────────┴────────┘
├1 David Robertson (robertson94)
├2 Bob J Stevenson (bjs)
├3 Steve (steve)
├─Page 2/2─┘
│
└@ [C/A/L/</>/username/number/H] : █
```
With Help message:
```
┌───────┬─────────┬────────┐
│ Chats │ Account │ Logout │
├───────┴─────────┴────────┘
├1 David Robertson (robertson94)
├2 Bob J Stevenson (bjs)
├3 Steve (steve)
├─Page 2/2─┘
│
├% Direct messages options : [(C)hats/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(username) for directly message person with username/(number) for enter direct messages by number/(H)elp]
└@ [C/A/L/</>/username/number/H] : █
```
When chatting with a person:
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% David Robertson (robertson94)
│
├% robertson94 : Hello
├% John : Hi
├─Page 1/1─┘
│
└@ Message or [C/D/A/L/</>/H] : █
```
With Help message:
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% David Robertson (robertson94)
│
├% robertson94 : Hello
├% John : Hi
├─Page 1/1─┘
│
├% Direct chat options : [(C)hats/(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(H)elp]
└@ Message or [C/D/A/L/</>/H] : █
```
**Note:** the same rule about writing a message that is just a letter (**that could be interpreted as a command**) in chats applies here. Adding a `\` in front of the letter prevents it from getting executed (and the letter gets sent as text):
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% David Robertson (robertson94)
│
├% robertson94 : Hello
├% John : Hi
├─Page 1/1─┘
│
└@ Message or [C/D/A/L/</>/H] : \L█
```
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% David Robertson (robertson94)
│
├% robertson94 : Hello
├% John : Hi
├% John : L
├─Page 1/1─┘
│
└@ Message or [C/D/A/L/</>/H] : █
```
- Sending `\\L` should result in `\L` message. It's not a problem if you just remove the first `\` in a message, so if someone sends `\B`, it's fine if it produces `B` as message.
- Letters that can't be interpreted as a command should be able to be written without worry. In the example above, if you enter `B`, it should just result in a message with `B`
### Account page
```
┌───────┬─────────────────┬────────┐
│ Chats │ Direct Messages │ Logout │
├───────┴─────────────────┴────────┘
├% Username : John
├1 Password : [HIDDEN]
├2 Name : John Smith
│
└@ [C/D/L/number/H] : █
```
With Help message:
```
┌───────┬─────────────────┬────────┐
│ Chats │ Direct Messages │ Logout │
├───────┴─────────────────┴────────┘
├% Username : John
├1 Password : [HIDDEN]
├2 Name : John Smith
│
├% Account options : [(C)hats/(D)irect Messages/(L)ogout/(number) for edit option by number/(H)elp]
└@ [C/D/L/number/H] : █
```
Editing an option requires you first input your password, then entering a new value for the chosen property (**don't forget to show the specification**). I'll only show an example for updating password:
```
┌──────────────────────────┐
│ Editing Account Password │
├──────────────────────────┘
└@ Password or [B/H] : █
```
```
┌──────────────────────────┐
│ Editing Account Password │
├──────────────────────────┘
├% Editing Account Password options : [(B)ack to account page/(H)elp]
└@ Password or [B/H] : █
```
```
┌──────────────────────────┐
│ Editing Account Password │
├──────────────────────────┘
├@ Password or [B/H] : password1
└@ New Password [5-40 characters; at least 1 number] : █
```
### Logout page
```
┌───────────────────────────────────────────┐
│ Are you sure you want to Log out of John? │
├───────────────────────────────────────────┘
│
└@ [Y/N] : █
```
Any option that isn't "Y" (and "y") should return the user to the chats page.
In place of John, there should be the username of the logged in user.
## Shortcomings
As I mentioned, this is meant to be an exercise task, not a real project. But, if you want to turn it into something useable, here are some suggestions on what you could do:
- Implement deletion of accounts and messages
- Replace text files with an actual database (because the file system doesn't scale at all)
- Add networking and maybe server application (or make it peer-to-peer)
- Implement friends and notifications and viewing accounts inside chats
- Add a biography/description field inside profiles
- Add profile email and implement a mail service (send password confirmation emails and such)
- Implement UI customization, or just rework the UI as a whole
|