@@ -18,6 +18,7 @@ import handleRequestMoreMessages from './server/socket/event_handlers/RequestMor
18
18
import handleAddServer from './server/socket/event_handlers/AddServer.js' ;
19
19
import handleRemoveServer from './server/socket/event_handlers/RemoveServer.js' ;
20
20
import handleRequestLinkPreview from './server/socket/event_handlers/RequestLinkPreview.js' ;
21
+ import handleAddReaction from './server/socket/event_handlers/AddReaction.js' ;
21
22
import ArrayMap from './server/util/ArrayMap.js' ;
22
23
23
24
// Finish importing rate-limiter flexible
@@ -55,6 +56,12 @@ global.mutedList = [];
55
56
// Setup the muted ip list as a shared global variable
56
57
global . mutedIpList = [ ] ;
57
58
59
+ // Setup the muted list as a shared global variable
60
+ global . bannedList = [ ] ;
61
+
62
+ // Setup the muted ip list as a shared global variable
63
+ global . bannedIpList = [ ] ;
64
+
58
65
// Setup the user list contents as a shared global variable
59
66
global . userListContents = [ ] ;
60
67
@@ -94,7 +101,8 @@ const messageSchema = new Schema({
94
101
badge : String ,
95
102
special : { type : Boolean , required : false } ,
96
103
usernameColor : { type : String , required : false } ,
97
- badgeColor : { type : String , required : false }
104
+ badgeColor : { type : String , required : false } ,
105
+ reactions : { type : Array , default : [ ] }
98
106
} ) ;
99
107
100
108
// Create a new schema for servers
@@ -115,28 +123,33 @@ global.serverModel = mongoose.model('serverModel', serverSchema, 'servers');
115
123
116
124
// Setup rate limiters
117
125
const messageRateLimiter = new RateLimiterMemory ( {
118
- points : 2 , // 2 points
119
- duration : 3 // per 3 seconds
126
+ points : 3 , // 2 points
127
+ duration : 5 // per 3 seconds
120
128
} ) ;
121
129
122
130
const loginRateLimiter = new RateLimiterMemory ( {
123
131
points : 3 , // 3 points
124
132
duration : 5 // per 5 seconds
125
133
} ) ;
126
134
135
+ // Define a new array of strings of admin usernames
136
+ export const admins = [ "justsnoopy30" , "nolski" , "pixxi" ] ;
137
+
127
138
// And everything starts here where a user makes a connection to the socket.io server...
128
139
io . on ( 'connection' , ( socket ) => {
129
140
socket . authenticated = false ;
130
141
131
142
// When the client emits 'login', this listens and executes
132
143
socket . on ( 'login' , ( { username, password, server } ) => {
133
- loginRateLimiter . consume ( socket . handshake . headers [ 'cf-connecting-ip' ] || socket . handshake . address )
144
+ // loginRateLimiter.consume(socket.handshake.headers['cf-connecting-ip'] || socket.handshake.address)
145
+ loginRateLimiter . consume ( username )
134
146
. then ( rateLimiterRes => {
135
147
handleLogin ( { io, socket, username, password, server} ) ;
136
148
} )
137
149
. catch ( rej => {
138
- console . log ( rej ) ;
139
- socket . emit ( 'loginDenied' , { loginDeniedReason : 'You are logging in too fast! Try again in a few seconds.' } ) ;
150
+ console . log ( `Rejected login for ${ username } due to rate limiting: ${ rej } ` ) ;
151
+ handleLogin ( { io, socket, username, password, server} ) ;
152
+ socket . emit ( 'login denied' , { loginDeniedReason : 'You are logging in too fast! Try again in a few seconds.' } ) ;
140
153
socket . disconnect ( ) ;
141
154
} ) ;
142
155
} ) ;
@@ -203,12 +216,22 @@ io.on('connection', (socket) => {
203
216
handleRemoveServer ( { io, socket, serverName} ) ;
204
217
} ) ;
205
218
206
- // When the client emits 'request limit preview', fetch a link preview for the link and send it back
219
+ // When the client emits 'request link preview', fetch a link preview for the link and send it back
207
220
socket . on ( 'request link preview' , ( messageId , link ) => {
208
221
if ( ! socket . authenticated ) return ;
209
222
handleRequestLinkPreview ( { io, socket, messageId, link} ) ;
210
223
} ) ;
211
224
225
+ // When the client emits 'add reaction', add a reaction to the message denoted by the messageId provided
226
+ socket . on ( 'add reaction' , ( { url, name, messageId } ) => {
227
+ if ( ! socket . authenticated ) return ;
228
+ handleAddReaction ( { io, socket, url, name, messageId} ) ;
229
+ } ) ;
230
+
231
+ socket . on ( 'drawing' , ( data ) => {
232
+ socket . broadcast . emit ( 'drawing' , data ) ;
233
+ } ) ;
234
+
212
235
// When the user disconnects, perform this
213
236
socket . on ( 'disconnect' , ( ) => {
214
237
handleDisconnect ( { io, socket} ) ;
0 commit comments