This repository was archived by the owner on Dec 2, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,11 @@ $(function onload() {
56
56
objPanel . show ( ) ;
57
57
txtUsername . val ( '' ) ;
58
58
chatEmpty ( ) ;
59
+ < << << << HEAD
59
60
panelEmpty ( ) ;
61
+ = === ===
62
+ txtMessage . focus ( ) ;
63
+ > >>> >>> 91 bb2d2083828c1184c8b25621cd214d8688992f
60
64
chatWriteLine ( `You are connected! (${ s } )` ) ;
61
65
getUsers ( ) ;
62
66
} else {
@@ -159,6 +163,12 @@ $(function onload() {
159
163
) ;
160
164
} ) ;
161
165
166
+ txtUsername . on ( 'keypress' , ( e ) => {
167
+ if ( e . which === 13 ) {
168
+ btnJoin . click ( ) ;
169
+ }
170
+ } ) ;
171
+
162
172
txtMessage . on ( 'keypress' , ( e ) => {
163
173
if ( e . which === 13 ) {
164
174
btnSend . click ( ) ;
Original file line number Diff line number Diff line change
1
+ export const UPPERCASE_USERNAMES : boolean = false ;
Original file line number Diff line number Diff line change @@ -41,6 +41,17 @@ export function FindConnById(pId: string): Promise<Connection | null> {
41
41
} ) ;
42
42
}
43
43
44
+ export function FindConnByName ( pName : string ) : Promise < Connection | null > {
45
+ return new Promise ( ( resolve ) => {
46
+ for ( const [ _Id , _Conn ] of Connections . entries ( ) ) {
47
+ if ( _Conn . name . toUpperCase ( ) === pName . toUpperCase ( ) ) {
48
+ return resolve ( _Conn ) ;
49
+ }
50
+ }
51
+ resolve ( null ) ;
52
+ } ) ;
53
+ }
54
+
44
55
export function RemoveConnById ( pId : string ) : Promise < Boolean > {
45
56
return new Promise ( ( resolve ) => {
46
57
const deleted = Connections . delete ( pId ) ;
Original file line number Diff line number Diff line change @@ -10,8 +10,11 @@ import {
10
10
RemoveConnById ,
11
11
CheckConnById ,
12
12
ConnInfo ,
13
+ FindConnByName ,
13
14
} from './Connections.ts' ;
14
15
16
+ import { UPPERCASE_USERNAMES } from './Configuration.ts' ;
17
+
15
18
/**
16
19
* h: Handler
17
20
* s: Sender
@@ -49,14 +52,21 @@ export async function HandleWSConn(pWebSocket: WebSocket): Promise<void> {
49
52
const objEvent : WSMessage = JSON . parse ( event ) ;
50
53
switch ( objEvent . h ) {
51
54
case 'join' : {
52
- const _name = objEvent . d ;
53
- if ( / ^ [ a - z A - Z 0 - 9 ] + $ / i. test ( _name ) ) {
55
+ const _name = UPPERCASE_USERNAMES
56
+ ? objEvent . d . toUpperCase ( )
57
+ : objEvent . d ;
58
+ if ( ! / ^ [ a - z A - Z 0 - 9 ] + $ / i. test ( _name ) ) {
59
+ await RespondJoin ( _connInfo , 'Invalid username' ) ;
60
+ } else if ( await FindConnByName ( _name ) ) {
61
+ await RespondJoin (
62
+ _connInfo ,
63
+ 'Username already in use'
64
+ ) ;
65
+ } else {
54
66
_conn . state = true ;
55
- _conn . name = objEvent . d ;
67
+ _conn . name = _name ;
56
68
await BroadcastJoin ( _connInfo ) ;
57
69
await RespondJoin ( _connInfo , 'OK' ) ;
58
- } else {
59
- await RespondJoin ( _connInfo , 'Invalid username' ) ;
60
70
}
61
71
break ;
62
72
}
You can’t perform that action at this time.
0 commit comments