Subversion Repositories Kolibri OS

Rev

Rev 3215 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3215 Rev 3216
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;                                                                 ;;
6
;;                                                                 ;;
7
;;         GNU GENERAL PUBLIC LICENSE                              ;;
7
;;         GNU GENERAL PUBLIC LICENSE                              ;;
8
;;          Version 2, June 1991                                   ;;
8
;;          Version 2, June 1991                                   ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
 
11
 
12
 
12
 
13
server_parser:
13
server_parser:
14
 
14
 
15
        mov     esi, servercommand
15
        mov     esi, servercommand
16
 
16
 
17
        cmp     byte [esi], ':'
17
        cmp     byte [esi], ':'
18
        jne     .parse
18
        jne     .parse
19
 
19
 
20
  .spaceloop:
20
  .spaceloop:
21
        lodsb
21
        lodsb
22
        test    al, al
22
        test    al, al
23
        jz      .fail
23
        jz      .fail
24
        cmp     al, ' '
24
        cmp     al, ' '
25
        jne     .spaceloop
25
        jne     .spaceloop
26
 
26
 
27
  .parse:
27
  .parse:
28
        mov     eax, [esi]
28
        mov     eax, [esi]
29
        or      eax, 0x20202020
29
        or      eax, 0x20202020
30
        mov     edi, server_commands
30
        mov     edi, server_commands
31
        mov     ecx, server_commands.number
31
        mov     ecx, server_commands.number
32
 
32
 
33
  .loop:
33
  .loop:
34
        scasd
34
        scasd
35
        je      .got_cmd
35
        je      .got_cmd
36
        add     edi, 4
36
        add     edi, 4
37
        dec     ecx
37
        dec     ecx
38
        jnz     .loop
38
        jnz     .loop
39
 
39
 
40
  .fail:
40
  .fail:
41
        ret
41
        ret
42
 
42
 
43
  .got_cmd:
43
  .got_cmd:
44
        jmp     dword[edi]
44
        jmp     dword[edi]
45
 
45
 
46
 
46
 
47
server_commands:
47
server_commands:
48
 
48
 
49
        dd      '328 ', cmd_328
49
        dd      '328 ', cmd_328
50
        dd      '332 ', cmd_topic
50
        dd      '332 ', cmd_topic
51
        dd      '333 ', cmd_333         ; nickname and time of topic
51
        dd      '333 ', cmd_333         ; nickname and time of topic
52
        dd      '353 ', cmd_353         ; name reply
52
        dd      '353 ', cmd_353         ; name reply
53
        dd      '366 ', cmd_366         ; end of names list
53
        dd      '366 ', cmd_366         ; end of names list
54
        dd      '372 ', cmd_372         ; motd
54
        dd      '372 ', cmd_372         ; motd
55
        dd      '375 ', cmd_375         ; start of motd
55
        dd      '375 ', cmd_375         ; start of motd
56
        dd      '376 ', cmd_376         ; end of motd
56
        dd      '376 ', cmd_376         ; end of motd
57
        dd      '421 ', cmd_421         ; unknown command
57
        dd      '421 ', cmd_421         ; unknown command
58
        dd      'join', cmd_join
58
        dd      'join', cmd_join
59
        dd      'kick', cmd_kick
59
        dd      'kick', cmd_kick
60
        dd      'mode', cmd_mode
60
        dd      'mode', cmd_mode
61
        dd      'nick', cmd_nick
61
        dd      'nick', cmd_nick
62
        dd      'part', cmd_part
62
        dd      'part', cmd_part
63
        dd      'ping', cmd_ping
63
        dd      'ping', cmd_ping
64
        dd      'priv', cmd_privmsg
64
        dd      'priv', cmd_privmsg
65
        dd      'quit', cmd_quit
65
        dd      'quit', cmd_quit
66
        dd      'noti', cmd_notice
66
        dd      'noti', cmd_notice
67
 
67
 
68
        .number = ($ - server_commands) / 8
68
        .number = ($ - server_commands) / 8
69
 
69
 
70
compare_to_nick:
70
compare_to_nick:
71
 
71
 
72
        push    esi
72
        push    esi
73
        mov     ecx, MAX_NICK_LEN
73
        mov     ecx, MAX_NICK_LEN
74
        mov     esi, user_nick
74
        mov     esi, user_nick
75
  .loop:
75
  .loop:
76
        lodsb
76
        lodsb
77
        cmp     al, ' '
77
        cmp     al, ' '
78
        jbe     .done
78
        jbe     .done
79
        cmp     al, 'a'
79
        cmp     al, 'a'
80
        jb      .ok
80
        jb      .ok
81
        cmp     al, 'z'
81
        cmp     al, 'z'
82
        ja      .ok
82
        ja      .ok
83
        sub     al, 0x20
83
        sub     al, 0x20
84
  .ok:
84
  .ok:
85
 
85
 
86
        mov     bl, byte[edi]
86
        mov     bl, byte[edi]
87
        cmp     bl, 'a'
87
        cmp     bl, 'a'
88
        jb      .ok2
88
        jb      .ok2
89
        cmp     bl, 'z'
89
        cmp     bl, 'z'
90
        ja      .ok2
90
        ja      .ok2
91
        sub     bl, 0x20
91
        sub     bl, 0x20
92
  .ok2:
92
  .ok2:
93
        cmp     bl, al
93
        cmp     bl, al
94
        jne     .not_equal
94
        jne     .not_equal
95
        inc     edi
95
        inc     edi
96
        dec     ecx
96
        dec     ecx
97
        jnz     .loop
97
        jnz     .loop
98
 
98
 
99
  .done:
99
  .done:
100
        xor     eax, eax
100
        xor     eax, eax
101
        pop     esi
101
        pop     esi
102
        ret
102
        ret
103
 
103
 
104
  .not_equal:
104
  .not_equal:
105
        or      eax, -1
105
        or      eax, -1
106
        pop     esi
106
        pop     esi
107
        ret
107
        ret
108
 
108
 
109
 
109
 
110
 
110
 
111
find_window:
111
find_window:
112
 
112
 
113
;        mov     [window_print],
113
;        mov     [window_print],
114
 
114
 
115
        ret
115
        ret
116
 
116
 
117
 
117
 
118
 
118
 
119
cmd_328:
119
cmd_328:
120
cmd_421:
120
cmd_421:
121
cmd_372:
121
cmd_372:
122
cmd_375:
122
cmd_375:
123
cmd_376:
123
cmd_376:
124
        add     esi, 4
124
        add     esi, 4
125
        jmp     cmd_notice.loop
125
        jmp     cmd_notice.loop
126
 
126
 
127
cmd_notice:
127
cmd_notice:
128
 
128
 
129
        cmp     byte[servercommand], ':'
129
        cmp     byte[servercommand], ':'
130
        jne     .gogogo
130
        jne     .gogogo
131
 
131
 
132
        mov     byte [esi-1], 0
132
        mov     byte [esi-1], 0
133
        push    esi
133
        push    esi
134
        mov     esi, str_1
134
        mov     esi, str_1
135
        call    print_text2
135
        call    print_text2
136
        mov     esi, servercommand+1
136
        mov     esi, servercommand+1
137
        call    print_text2
137
        call    print_text2
138
        mov     esi, str_2
138
        mov     esi, str_2
139
        call    print_text2
139
        call    print_text2
140
        pop     esi
140
        pop     esi
141
 
141
 
142
  .gogogo:
142
  .gogogo:
143
        add     esi, 6
143
        add     esi, 6
144
 
144
 
145
  .loop:
145
  .loop:
146
        inc     esi
146
        inc     esi
147
        cmp     byte [esi], 0
147
        cmp     byte [esi], 0
148
        je      .fail
148
        je      .fail
149
;        cmp     byte [esi], 10  ; newline
149
;        cmp     byte [esi], 10  ; newline
150
;        je      server_parser.parse
150
;        je      server_parser.parse
151
        cmp     byte [esi], ' '
151
        cmp     byte [esi], ' '
152
        jne     .loop
152
        jne     .loop
153
 
153
 
154
  .loop2:
154
  .loop2:
155
        inc     esi
155
        inc     esi
156
        cmp     byte [esi], 0
156
        cmp     byte [esi], 0
157
        je      .fail
157
        je      .fail
158
        cmp     byte [esi], ' '
158
        cmp     byte [esi], ' '
159
        je      .loop2
159
        je      .loop2
160
        cmp     byte [esi], ':'
160
        cmp     byte [esi], ':'
161
        je      .loop2
161
        je      .loop2
162
 
162
 
163
        call    print_text2
163
        call    print_text2
164
        mov     esi, str_newline
164
        mov     esi, str_newline
165
        call    print_text2
165
        call    print_text2
166
 
166
 
167
  .fail:
167
  .fail:
168
 
168
 
169
        ret
169
        ret
170
 
170
 
171
 
171
 
172
 
172
 
173
cmd_ping:
173
cmd_ping:
174
 
174
 
175
; Just change PING to PONG
175
; Just change PING to PONG
176
        mov     dword[esi], 'PONG'
176
        mov     dword[esi], 'PONG'
177
 
177
 
178
; Find the end of the command
178
; Find the end of the command
179
        lea     edi, [esi + 5]
179
        lea     edi, [esi + 5]
180
        xor     al, al
180
        xor     al, al
181
        repne   scasb
181
        repne   scasb
182
 
182
 
183
; Now send it back
183
; Now send it back
184
        mov     edx, esi
184
        mov     edx, esi
185
        mov     esi, edi
185
        mov     esi, edi
186
        mov     word [esi], 0x0d0a
186
        mov     word [esi], 0x0d0a
187
        inc     esi
187
        inc     esi
188
        inc     esi
188
        inc     esi
189
        sub     esi, edx
189
        sub     esi, edx
190
        mcall   send, [socketnum], , , 0
190
        mcall   send, [socketnum], , , 0
191
 
191
 
192
        ret
192
        ret
193
 
193
 
194
 
194
 
195
 
195
 
196
cmd_privmsg:
196
cmd_privmsg:
197
 
197
 
198
        add     esi, 8  ; skip 'PRIVMSG '
198
        add     esi, 8  ; skip 'PRIVMSG '
199
 
199
 
200
; Check if it was destined for me privately
200
; Check if it was destined for me privately
201
        mov     edi, servercommand+1
201
        mov     edi, servercommand+1
202
        call    compare_to_nick
202
        call    compare_to_nick
203
;;;        je      .private
203
;;;        je      .private
204
 
204
 
205
; If not, find the correct window ???
205
; If not, find the correct window ???
206
 
206
 
207
; now find the end of nick
207
; now find the end of nick
208
        mov     edi, esi
208
        mov     edi, esi
209
  .loop:
209
  .loop:
210
        inc     edi
210
        inc     edi
211
        cmp     byte [edi], 0
211
        cmp     byte [edi], 0
212
        je      .fail
212
        je      .fail
213
        cmp     byte [edi], ' '
213
        cmp     byte [edi], ' '
214
        jne     .loop
214
        jne     .loop
215
 
215
 
216
  .loop2:
216
  .loop2:
217
        inc     edi
217
        inc     edi
218
        cmp     byte [edi], 0
218
        cmp     byte [edi], 0
219
        je      .fail
219
        je      .fail
220
        cmp     byte [edi], ' '
220
        cmp     byte [edi], ' '
221
        je      .loop2
221
        je      .loop2
222
        cmp     byte [edi], ':'
222
        cmp     byte [edi], ':'
223
        je      .loop2
223
        je      .loop2
224
        cmp     byte [edi], 1
224
        cmp     byte [edi], 1
225
        je      cmd_ctcp
225
        je      cmd_ctcp
226
 
226
 
227
; Action?
227
; Action?
228
        cmp     dword[edi+1], 'ACTI'
228
        cmp     dword[edi+1], 'ACTI'
229
        je      .action
229
        je      .action
230
 
230
 
231
; nope, just plain old privmsg
231
; nope, just plain old privmsg
232
if TIMESTAMP
232
if TIMESTAMP
233
        call    print_timestamp
233
        call    print_timestamp
234
end if
234
end if
235
 
235
 
236
        push    edi
236
        push    edi
237
        mov     bl, '<'
237
        mov     bl, '<'
238
        call    print_character
238
        call    print_character
239
 
239
 
240
        mov     eax, servercommand+1
240
        mov     eax, servercommand+1
241
        mov     dl, '!'
241
        mov     dl, '!'
242
        call    print_text
242
        call    print_text
243
 
243
 
244
        mov     bl, '>'
244
        mov     bl, '>'
245
        call    print_character
245
        call    print_character
246
 
246
 
247
        mov     bl, ' '
247
        mov     bl, ' '
248
        call    print_character
248
        call    print_character
249
 
249
 
250
        pop     esi
250
        pop     esi
251
        call    print_text2
251
        call    print_text2
252
 
252
 
253
        mov     bl, 10
253
        mov     bl, 10
254
        call    print_character
254
        call    print_character
255
 
255
 
256
  .fail:
256
  .fail:
257
        ret
257
        ret
258
 
258
 
259
  .action:
259
  .action:
260
        push    edi
260
        push    edi
261
        if TIMESTAMP
261
        if TIMESTAMP
262
        call    print_timestamp
262
        call    print_timestamp
263
        end if
263
        end if
264
 
264
 
265
        mov     esi, action_header_short
265
        mov     esi, action_header_short
266
        call    print_text2
266
        call    print_text2
267
 
267
 
268
        mov     eax, servercommand+1
268
        mov     eax, servercommand+1
269
        mov     dl, ' '
269
        mov     dl, ' '
270
        call    print_text
270
        call    print_text
271
 
271
 
272
        mov     bl, ' '
272
        mov     bl, ' '
273
        call    print_character
273
        call    print_character
274
 
274
 
275
        pop     esi
275
        pop     esi
276
        add     esi, 8
276
        add     esi, 8
277
        call    print_text2
277
        call    print_text2
278
 
278
 
279
        mov     bl, 10
279
        mov     bl, 10
280
        call    print_character
280
        call    print_character
281
 
281
 
282
        ret
282
        ret
283
 
283
 
284
cmd_ctcp:
284
cmd_ctcp:
285
 
285
 
286
        cmp     dword[edi+1], 'VERS'
286
        cmp     dword[edi+1], 'VERS'
287
        je      .version
287
        je      .version
288
 
288
 
289
        cmp     dword[edi+1], 'TIME'
289
        cmp     dword[edi+1], 'TIME'
290
        je      .time
290
        je      .time
291
 
291
 
292
        cmp     dword[edi+1], 'PING'
292
        cmp     dword[edi+1], 'PING'
293
        je      .ping
293
        je      .ping
294
 
294
 
295
        ret
295
        ret
296
 
296
 
297
  .time:
297
  .time:
298
        lea     esi, [edi+1]
298
        lea     esi, [edi+1]
299
        mov     byte [edi+5], ' '
299
        mov     byte [edi+5], ' '
300
        add     edi, 6
300
        add     edi, 6
301
 
301
 
302
        ; TODO: add system date (fn 29) in human readable format
302
        ; TODO: add system date (fn 29) in human readable format
303
 
303
 
304
        mcall   3                       ; get system time
304
        mcall   3                       ; get system time
305
 
305
 
306
        mov     ecx, 3
306
        mov     ecx, 3
307
  .timeloop:
307
  .timeloop:
308
        mov     bl, al
308
        mov     bl, al
309
        shr     al, 4
309
        shr     al, 4
310
        add     al, '0'
310
        add     al, '0'
311
        stosb
311
        stosb
312
 
312
 
313
        mov     al, bl
313
        mov     al, bl
314
        and     al, 0x0f
314
        and     al, 0x0f
315
        add     al, '0'
315
        add     al, '0'
316
        stosb
316
        stosb
317
 
317
 
318
        dec     ecx
318
        dec     ecx
319
        jz      .timedone
319
        jz      .timedone
320
 
320
 
321
        mov     al, ':'
321
        mov     al, ':'
322
        stosb
322
        stosb
323
        shr     eax, 8
323
        shr     eax, 8
324
        jmp     .timeloop
324
        jmp     .timeloop
325
 
325
 
326
  .timedone:
326
  .timedone:
327
        xor     al, al
327
        xor     al, al
328
        stosb
328
        stosb
329
        call    ctcp_reply
329
        call    ctcp_reply
330
 
330
 
331
        if TIMESTAMP
331
        if TIMESTAMP
332
        call    print_timestamp
332
        call    print_timestamp
333
        end if
333
        end if
334
 
334
 
335
        mov     esi, ctcp_header
335
        mov     esi, ctcp_header
336
        call    print_text2
336
        call    print_text2
337
 
337
 
338
        mov     esi, servercommand+1
338
        mov     esi, servercommand+1
339
        call    print_text2
339
        call    print_text2
340
 
340
 
341
        mov     esi, ctcp_time
341
        mov     esi, ctcp_time
342
        call    print_text2
342
        call    print_text2
343
 
343
 
344
        ret
344
        ret
345
 
345
 
346
  .version:
346
  .version:
347
        mov     esi, str_version
347
        mov     esi, str_version
348
        call    ctcp_reply
348
        call    ctcp_reply
349
 
349
 
350
        if TIMESTAMP
350
        if TIMESTAMP
351
        call    print_timestamp
351
        call    print_timestamp
352
        end if
352
        end if
353
 
353
 
354
        mov     esi, ctcp_header
354
        mov     esi, ctcp_header
355
        call    print_text2
355
        call    print_text2
356
 
356
 
357
        mov     esi, servercommand+1
357
        mov     esi, servercommand+1
358
        call    print_text2
358
        call    print_text2
359
 
359
 
360
        mov     esi, ctcp_version
360
        mov     esi, ctcp_version
361
        call    print_text2
361
        call    print_text2
362
 
362
 
363
        ret
363
        ret
364
 
364
 
365
  .ping:
365
  .ping:
366
        lea     esi, [edi+1]
366
        lea     esi, [edi+1]
367
        call    ctcp_reply
367
        call    ctcp_reply
368
 
368
 
369
        if TIMESTAMP
369
        if TIMESTAMP
370
        call    print_timestamp
370
        call    print_timestamp
371
        end if
371
        end if
372
 
372
 
373
        mov     esi, ctcp_header
373
        mov     esi, ctcp_header
374
        call    print_text2
374
        call    print_text2
375
 
375
 
376
        mov     esi, servercommand+1
376
        mov     esi, servercommand+1
377
        call    print_text2
377
        call    print_text2
378
 
378
 
379
        mov     esi, ctcp_ping
379
        mov     esi, ctcp_ping
380
        call    print_text2
380
        call    print_text2
381
 
381
 
382
        ret
382
        ret
383
 
383
 
384
 
384
 
385
 
385
 
386
ctcp_reply:
386
ctcp_reply:
387
 
387
 
388
        push    esi
388
        push    esi
389
 
389
 
390
        mov     dword [usercommand], 'NOTI'
390
        mov     dword [usercommand], 'NOTI'
391
        mov     dword [usercommand+4], 'CE  '
391
        mov     dword [usercommand+4], 'CE  '
392
 
392
 
393
        mov     esi, servercommand+1
393
        mov     esi, servercommand+1
394
        mov     edi, usercommand+7
394
        mov     edi, usercommand+7
395
  .nickloop:
395
  .nickloop:
396
        lodsb
396
        lodsb
397
        cmp     al, '!'
397
        cmp     al, '!'
398
        je      .done
398
        je      .done
399
        cmp     al, ' '
399
        cmp     al, ' '
400
        je      .done
400
        je      .done
401
        test    al, al
401
        test    al, al
402
        je      .fail
402
        je      .fail
403
        stosb
403
        stosb
404
        jmp     .nickloop
404
        jmp     .nickloop
405
  .done:
405
  .done:
406
        mov     byte [esi-1], 0
406
        mov     byte [esi-1], 0
407
        mov     ax, ' :'
407
        mov     ax, ' :'
408
        stosw
408
        stosw
409
        mov     al, 1
409
        mov     al, 1
410
        stosb
410
        stosb
411
 
411
 
412
        pop     esi
412
        pop     esi
413
  .replyloop:
413
  .replyloop:
414
        lodsb
414
        lodsb
415
        cmp     al, 1
415
        cmp     al, 1
416
        jbe     .done2
416
        jbe     .done2
417
        stosb
417
        stosb
418
        jmp     .replyloop
418
        jmp     .replyloop
419
  .done2:
419
  .done2:
420
 
420
 
421
        mov     al, 1
421
        mov     al, 1
422
        stosb
422
        stosb
423
        mov     ax, 0x0a0d
423
        mov     ax, 0x0a0d
424
        stosw
424
        stosw
425
 
425
 
426
        lea     esi, [edi - usercommand]
426
        lea     esi, [edi - usercommand]
427
        mcall   send, [socketnum], usercommand, , 0
427
        mcall   send, [socketnum], usercommand, , 0
428
  .fail:
428
  .fail:
429
        ret
429
        ret
430
 
430
 
431
 
431
 
432
 
432
 
433
cmd_part:
433
cmd_part:
434
        add     esi, 5  ; skip 'PART '
434
        add     esi, 5  ; skip 'PART '
435
 
435
 
436
; Is it me who parted?
436
; Is it me who parted?
437
        mov     edi, servercommand+1
437
        mov     edi, servercommand+1
438
        call    compare_to_nick
438
        call    compare_to_nick
439
        jne     .dont_close
439
        jne     .dont_close
440
 
440
 
441
; yes, close the window
441
; yes, close the window
442
        mov     edi, [window_print]
442
        mov     edi, [window_print]
443
        mov     [edi + window.flags], FLAG_UPDATED + FLAG_CLOSE
443
        mov     [edi + window.flags], FLAG_UPDATED + FLAG_CLOSE
444
 
444
 
445
        ret
445
        ret
446
 
446
 
447
; somebody else parted, just print message
447
; somebody else parted, just print message
448
  .dont_close:
448
  .dont_close:
449
        push    esi
449
        push    esi
450
        mov     esi, action_header
450
        mov     esi, action_header
451
        call    print_text2
451
        call    print_text2
452
 
452
 
453
        mov     eax, servercommand+1
453
        mov     eax, servercommand+1
454
        mov     dl, '!'
454
        mov     dl, '!'
455
        mov     cl, ' '
455
        mov     cl, ' '
456
        call    print_text
456
        call    print_text
457
 
457
 
458
        mov     esi, has_left_channel
458
        mov     esi, has_left_channel
459
        call    print_text2
459
        call    print_text2
460
 
460
 
461
        pop     esi
461
        pop     esi
462
        call    print_text2
462
        call    print_text2
463
 
463
 
464
        mov     esi, str_newline
464
        mov     esi, str_newline
465
        call    print_text2
465
        call    print_text2
466
 
466
 
467
;;; TODO: dec [window.users], remove username from the userlist
467
;;; TODO: dec [window.users], remove username from the userlist
468
 
468
 
469
 
469
 
470
        ret
470
        ret
471
 
471
 
472
 
472
 
473
 
473
 
474
cmd_join:
474
cmd_join:
475
        add     esi, 5  ; skip 'JOIN '
475
        add     esi, 5  ; skip 'JOIN '
476
 
476
 
477
; compare nick: did we join a channel?
477
; compare nick: did we join a channel?
478
        mov     edi, servercommand+1
478
        mov     edi, servercommand+1
479
        call    compare_to_nick
479
        call    compare_to_nick
480
        jne     .no_new_window
480
        jne     .no_new_window
481
 
481
 
482
; create channel window - search for empty slot
482
; create channel window - search for empty slot
483
        mov     ebx, windows
483
        mov     ebx, windows
484
        mov     ecx, MAX_WINDOWS
484
        mov     ecx, MAX_WINDOWS
485
  .loop:
485
  .loop:
486
        cmp     [ebx + window.data_ptr], 0
486
        cmp     [ebx + window.data_ptr], 0
487
        je      .free_found
487
        je      .free_found
488
        add     ebx, sizeof.window
488
        add     ebx, sizeof.window
489
        dec     ecx
489
        dec     ecx
490
        jnz     .loop
490
        jnz     .loop
491
; Error: no more available windows!! ;;;;; TODO
491
; Error: no more available windows!! ;;;;; TODO
492
  .fail:
492
  .fail:
493
        ret
493
        ret
494
 
494
 
495
  .free_found:
495
  .free_found:
496
        push    ebx
496
        push    ebx
497
        call    window_create
497
        call    window_create
498
        pop     ebx
498
        pop     ebx
499
        test    eax, eax
499
        test    eax, eax
500
        jz      .fail
500
        jz      .fail
501
        mov     [ebx + window.data_ptr], eax
501
        mov     [ebx + window.data_ptr], eax
502
        mov     [ebx + window.type], WINDOWTYPE_CHANNEL
502
        mov     [ebx + window.type], WINDOWTYPE_CHANNEL
503
        mov     [ebx + window.flags], 0
503
        mov     [ebx + window.flags], 0
504
 
504
 
505
        call    window_set_name
505
        call    window_set_name
506
 
506
 
507
        mov     [window_open], ebx
507
        mov     [window_open], ebx
508
        mov     [window_print], ebx
508
        mov     [window_print], ebx
509
        call    window_refresh
509
        call    window_refresh
510
 
510
 
511
        push    esi
511
        push    esi
512
        mov     esi, action_header
512
        mov     esi, action_header
513
        call    print_text2
513
        call    print_text2
514
 
514
 
515
        mov     esi, str_talking
515
        mov     esi, str_talking
516
        call    print_text2
516
        call    print_text2
517
 
517
 
518
        pop     eax
518
        pop     eax
519
        mov     dl, ' '
519
        mov     dl, ' '
520
        call    print_text
520
        call    print_text
521
 
521
 
522
        mov     esi, str_dotnewline
522
        mov     esi, str_dotnewline
523
        call    print_text2
523
        call    print_text2
524
 
524
 
525
        call    draw_window
525
        call    draw_window
526
 
526
 
527
        ret
527
        ret
528
 
528
 
529
  .no_new_window:
529
  .no_new_window:
530
        push    esi
530
        push    esi
531
        call    window_set_name
531
        call    window_set_name
532
 
532
 
533
        mov     esi, action_header
533
        mov     esi, action_header
534
        call    print_text2
534
        call    print_text2
535
 
535
 
536
        mov     eax, servercommand+1
536
        mov     eax, servercommand+1
537
        mov     dl, ' '
537
        mov     dl, ' '
538
        call    print_text
538
        call    print_text
539
 
539
 
540
        mov     esi, joins_channel
540
        mov     esi, joins_channel
541
        call    print_text2
541
        call    print_text2
542
 
542
 
543
        pop     esi
543
        pop     esi
544
        call    print_text2
544
        call    print_text2
545
 
545
 
546
        mov     esi, str_newline
546
        mov     esi, str_newline
547
        call    print_text2
547
        call    print_text2
548
 
548
 
549
;;; TODO: inc [window.users], add username to the userlist
549
;;; TODO: inc [window.users], add username to the userlist
550
 
550
 
551
        ret
551
        ret
552
 
552
 
553
 
553
 
554
 
554
 
555
 
555
 
556
cmd_nick:       ; FIXME
556
cmd_nick:       ; FIXME
557
 
557
 
558
        add     esi, 5  ; skip 'NICK '
558
        add     esi, 5  ; skip 'NICK '
559
 
559
 
560
        push    esi
560
        push    esi
561
; test for change of my nick
561
; test for change of my nick
562
        mov     esi, servercommand+1
562
        mov     esi, servercommand+1
563
        mov     edi, user_nick
563
        mov     edi, user_nick
564
        mov     ecx, MAX_NICK_LEN
564
        mov     ecx, MAX_NICK_LEN
565
        rep     cmpsb
565
        rep     cmpsb
566
        cmp     byte[edi-1], 0
566
        cmp     byte[edi-1], 0
567
        jne     .notmy
567
        jne     .notmy
568
        cmp     byte[esi-1], '!'
568
        cmp     byte[esi-1], '!'
569
        jne     .notmy
569
        jne     .notmy
570
 
570
 
571
; yes, this is my nick, set to new
571
; yes, this is my nick, set to new
572
        pop     esi
572
        pop     esi
573
        or      ecx, -1
573
        or      ecx, -1
574
        mov     edi, esi
574
        mov     edi, esi
575
        xor     eax, eax
575
        xor     eax, eax
576
        repne   scasb
576
        repne   scasb
577
        neg     ecx
577
        neg     ecx
578
        cmp     ecx, MAX_NICK_LEN
578
        cmp     ecx, MAX_NICK_LEN
579
        jb      @f
579
        jb      @f
580
        mov     ecx, MAX_NICK_LEN
580
        mov     ecx, MAX_NICK_LEN
581
      @@:
581
      @@:
582
        mov     edi, user_nick
582
        mov     edi, user_nick
583
        rep     movsb
583
        rep     movsb
584
  .notmy:
584
  .notmy:
585
 
585
 
586
; replace nick in all lists of users
586
; replace nick in all lists of users
587
        mov     ebx, windows
587
        mov     ebx, windows
588
  .channels:
588
  .channels:
589
        mov     esi, [ebx + window.data_ptr]
589
        mov     esi, [ebx + window.data_ptr]
590
        lea     esi, [esi + window_data.names]
590
        lea     esi, [esi + window_data.names]
591
;;;;;        mov     edx, [esi + window_data.nameslen]
591
;;;;;        mov     edx, [esi + window_data.nameslen]
592
        add     edx, esi
592
        add     edx, esi
593
  .nicks:
593
  .nicks:
594
        mov     edi, servercommand+1
594
        mov     edi, servercommand+1
595
        cmp     byte[esi], '@'
595
        cmp     byte[esi], '@'
596
        jne     @f
596
        jne     @f
597
        inc     esi
597
        inc     esi
598
 
598
 
599
  @@:
599
  @@:
600
        cmp     esi, edx
600
        cmp     esi, edx
601
        jae     .srcdone
601
        jae     .srcdone
602
        lodsb
602
        lodsb
603
        cmp     al, ' '
603
        cmp     al, ' '
604
        je      .srcdone
604
        je      .srcdone
605
        scasb
605
        scasb
606
        je      @b
606
        je      @b
607
 
607
 
608
  @@:
608
  @@:
609
        cmp     esi, edx
609
        cmp     esi, edx
610
        jae     .nextchannel
610
        jae     .nextchannel
611
        lodsb
611
        lodsb
612
        cmp     al, ' '
612
        cmp     al, ' '
613
        jne     @b
613
        jne     @b
614
 
614
 
615
  .nextnick:
615
  .nextnick:
616
        cmp     esi, edx
616
        cmp     esi, edx
617
        jae     .nextchannel
617
        jae     .nextchannel
618
        lodsb
618
        lodsb
619
        cmp     al, ' '
619
        cmp     al, ' '
620
        jz      .nextnick
620
        jz      .nextnick
621
        dec     esi
621
        dec     esi
622
        jmp     .nicks
622
        jmp     .nicks
623
 
623
 
624
 
624
 
625
  .srcdone:
625
  .srcdone:
626
        cmp     byte [edi], '!'
626
        cmp     byte [edi], '!'
627
        jne     .nextnick
627
        jne     .nextnick
628
 
628
 
629
; here we have esi -> end of nick which must be replaced to [servercommand_position]+6
629
; here we have esi -> end of nick which must be replaced to [servercommand_position]+6
630
        lea     edx, [edi-servercommand-1]
630
        lea     edx, [edi-servercommand-1]
631
        sub     esi, edx
631
        sub     esi, edx
632
        or      ecx, -1
632
        or      ecx, -1
633
        xor     eax, eax
633
        xor     eax, eax
634
;        mov     edi, [servercommand_position]        ;;;;; FIXME
634
;        mov     edi, [servercommand_position]        ;;;;; FIXME
635
        repnz   scasb
635
        repnz   scasb
636
        not     ecx
636
        not     ecx
637
        dec     ecx
637
        dec     ecx
638
        push    ecx
638
        push    ecx
639
        cmp     ecx, edx
639
        cmp     ecx, edx
640
        jb      .decrease
640
        jb      .decrease
641
        jz      .copy
641
        jz      .copy
642
  .increase:
642
  .increase:
643
 
643
 
644
; new nick is longer than the old
644
; new nick is longer than the old
645
        push    esi
645
        push    esi
646
        lea     edi, [ebx+120*10] ;;;;;;
646
        lea     edi, [ebx+120*10] ;;;;;;
647
        lea     esi, [edi+edx]
647
        lea     esi, [edi+edx]
648
        sub     esi, ecx
648
        sub     esi, ecx
649
        mov     ecx, esi
649
        mov     ecx, esi
650
        sub     ecx, [esp]
650
        sub     ecx, [esp]
651
        dec     esi
651
        dec     esi
652
        dec     edi
652
        dec     edi
653
        std
653
        std
654
        rep     movsb
654
        rep     movsb
655
        cld
655
        cld
656
        pop     esi
656
        pop     esi
657
        jmp     .copy
657
        jmp     .copy
658
  .decrease:
658
  .decrease:
659
; new nick is shorter than the old
659
; new nick is shorter than the old
660
        push    esi
660
        push    esi
661
        lea     edi, [esi+ecx]
661
        lea     edi, [esi+ecx]
662
        add     esi, edx
662
        add     esi, edx
663
        lea     ecx, [ebx+120*10]
663
        lea     ecx, [ebx+120*10]
664
        sub     ecx, edi
664
        sub     ecx, edi
665
        rep     movsb
665
        rep     movsb
666
        pop     esi
666
        pop     esi
667
  .copy:
667
  .copy:
668
; copy nick
668
; copy nick
669
        mov     edi, esi
669
        mov     edi, esi
670
        dec     edi
670
        dec     edi
671
;        mov     esi, [servercommand_position]        ;;;;; FIXME
671
;        mov     esi, [servercommand_position]        ;;;;; FIXME
672
        pop     ecx
672
        pop     ecx
673
        sub     edx, ecx
673
        sub     edx, ecx
674
        sub     [ebx-4], edx
674
        sub     [ebx-4], edx
675
        rep     movsb
675
        rep     movsb
676
        mov     al, ' '
676
        mov     al, ' '
677
        stosb
677
        stosb
678
 
678
 
679
  .nextchannel:
679
  .nextchannel:
680
        add     ebx, sizeof.window
680
        add     ebx, sizeof.window
681
        cmp     ebx, windows + sizeof.window*MAX_WINDOWS
681
        cmp     ebx, windows + sizeof.window*MAX_WINDOWS
682
        jb      .channels
682
        jb      .channels
683
 
683
 
684
;        mov  [text_start], window_text + 120*80
684
;        mov  [text_start], window_text + 120*80
685
 new_all_channels3:
685
 new_all_channels3:
686
 
686
 
687
        mov     esi, action_header_short
687
        mov     esi, action_header_short
688
        call    print_text2
688
        call    print_text2
689
 
689
 
690
        mov     eax, servercommand+1
690
        mov     eax, servercommand+1
691
        mov     dl,'!'
691
        mov     dl,'!'
692
        call    print_text
692
        call    print_text
693
 
693
 
694
        mov     esi,is_now_known_as
694
        mov     esi,is_now_known_as
695
        call    print_text2
695
        call    print_text2
696
 
696
 
697
;       mov     esi,[servercommand_position]        ;;;;; FIXME
697
;       mov     esi,[servercommand_position]        ;;;;; FIXME
698
        call    print_text2
698
        call    print_text2
699
 
699
 
700
;;;        call    notify_channel_thread
700
;;;        call    notify_channel_thread
701
 
701
 
702
; go to next window (and check if its a channel!)
702
; go to next window (and check if its a channel!)
703
 
703
 
704
;        add     [text_start], 120*80
704
;        add     [text_start], 120*80
705
;        cmp     [text_start], I_END+120*80*20
705
;        cmp     [text_start], I_END+120*80*20
706
;        jb      new_all_channels3
706
;        jb      new_all_channels3
707
 
707
 
708
        ret
708
        ret
709
 
709
 
710
 
710
 
711
 
711
 
712
 
712
 
713
cmd_kick:
713
cmd_kick:
714
        add     esi, 5  ; skip 'KICK '
714
        add     esi, 5  ; skip 'KICK '
715
; Is it me who got kicked?
715
; Is it me who got kicked?
716
        mov     edi, servercommand+1
716
        mov     edi, servercommand+1
717
        call    compare_to_nick
717
        call    compare_to_nick
718
        jne     .not_me
718
        jne     .not_me
719
 
719
 
720
; TODO: mark channel as disconnected
720
; TODO: mark channel as disconnected
721
 
721
 
722
  .not_me:
722
  .not_me:
723
; find the channel user has been kicked from
723
; find the channel user has been kicked from
724
        push    esi
724
        push    esi
725
        mov     esi, action_header_short
725
        mov     esi, action_header_short
726
        call    print_text2
726
        call    print_text2
727
 
727
 
728
        mov     eax, servercommand+1
728
        mov     eax, servercommand+1
729
        mov     dl,'!'
729
        mov     dl,'!'
730
        call    print_text
730
        call    print_text
731
 
731
 
732
        mov     esi, kicked
732
        mov     esi, kicked
733
        call    print_text2
733
        call    print_text2
734
 
734
 
735
        pop     esi
735
        pop     esi
736
        call    print_text2
736
        call    print_text2
737
 
737
 
738
;;; TODO: dec [window.users], remove username from the userlist
738
;;; TODO: dec [window.users], remove username from the userlist
739
 
739
 
740
        ret
740
        ret
741
 
741
 
742
 
742
 
743
 
743
 
744
cmd_quit:
744
cmd_quit:
745
 
745
 
746
        mov     esi, action_header
746
        mov     esi, action_header
747
        call    print_text2
747
        call    print_text2
748
 
748
 
749
        mov     eax, servercommand+1
749
        mov     eax, servercommand+1
750
        mov     dl, '!'
750
        mov     dl, '!'
751
        call    print_text
751
        call    print_text
752
 
752
 
753
        mov     esi, has_quit_irc
753
        mov     esi, has_quit_irc
754
        call    print_text2
754
        call    print_text2
755
 
755
 
756
;;; TODO: dec [window.users], remove username from the userlist
756
;;; TODO: dec [window.users], remove username from the userlist
757
 
757
 
758
        ret
758
        ret
759
 
759
 
760
 
760
 
761
 
761
 
762
cmd_mode:
762
cmd_mode:
763
 
763
 
764
        add     esi, 5  ; skip 'MODE '
764
        add     esi, 5  ; skip 'MODE '
765
 
765
 
766
        push    esi
766
        push    esi
767
        mov     esi, action_header_short
767
        mov     esi, action_header_short
768
        call    print_text2
768
        call    print_text2
769
 
769
 
770
        mov     eax, servercommand+1
770
        mov     eax, servercommand+1
771
        mov     dl, ' '
771
        mov     dl, ' '
772
        call    print_text
772
        call    print_text
773
 
773
 
774
        mov     esi, sets_mode
774
        mov     esi, sets_mode
775
        call    print_text2
775
        call    print_text2
776
 
776
 
777
        pop     esi
777
        pop     esi
778
        call    print_text2
778
        call    print_text2
779
 
779
 
780
        mov     esi, str_newline
780
        mov     esi, str_newline
781
        call    print_text2
781
        call    print_text2
782
 
782
 
783
;;; TODO: change username if needed
783
;;; TODO: change username if needed
784
 
784
 
785
        ret
785
        ret
786
 
786
 
787
 
787
 
788
cmd_353:        ; channel usernames reply
788
cmd_353:        ; channel usernames reply
789
 
789
 
790
        add     esi, 4  ; skip '353 '
790
        add     esi, 4  ; skip '353 '
791
 
791
 
792
; TODO: mark a bit that we are receiving names
792
; TODO: mark a bit that we are receiving names
793
 
793
 
794
; first, find the channel name
794
; first, find the channel name
795
  .loop1:
795
  .loop1:
796
        lodsb
796
        lodsb
797
        cmp     al, '#'
797
        cmp     al, '#'
798
        je      .got_channel
798
        je      .got_channel
799
        test    al, al
799
        test    al, al
800
        jnz     .loop1
800
        jnz     .loop1
801
 
801
 
802
        ret
802
        ret
803
 
803
 
804
  .got_channel:
804
  .got_channel:
805
;        call    find_channel   ;;;; ASSUME current channel for now
805
;        call    find_channel   ;;;; ASSUME current channel for now
806
        mov     ebx, [window_print]
806
        mov     ebx, [window_print]
807
        mov     [ebx + window.users], 0              ;;; FIXME: Only if we have just set the receiving names bit
807
        mov     [ebx + window.users], 0              ;;; FIXME: Only if we have just set the receiving names bit
808
        mov     eax, [ebx + window.data_ptr]
808
        mov     eax, [ebx + window.data_ptr]
809
        lea     edi, [eax + window_data.names]
809
        lea     edi, [eax + window_data.names]
810
        lea     edx, [edi + MAX_NICK_LEN]
810
        mov     edx, edi
811
 
811
 
812
; now find the semicolon separating channelname and usernames
812
; now find the semicolon separating channelname and usernames
813
  .loop2:
813
  .loop2:
814
        lodsb
814
        lodsb
815
        cmp     al, ':'
815
        cmp     al, ':'
816
        je      .namesloop
816
        je      .newname
817
        test    al, al
817
        test    al, al
818
        jnz     .loop2
818
        jnz     .loop2
819
 
819
 
820
        ret
820
        ret
-
 
821
 
-
 
822
  .next:
-
 
823
        add     edx, MAX_NICK_LEN
-
 
824
        mov     edi, edx
-
 
825
;;;        cmp     edi, ..              ; TODO: Check for buffer overflow
-
 
826
        jmp     .namesloop            ;;;;
-
 
827
 
-
 
828
  .newname:
821
 
829
        inc     [ebx + window.users]
822
  .namesloop:
830
  .namesloop:
823
; now the names list begins, separated with spaces
831
; now the names list begins, separated with spaces
824
        lodsb
832
        lodsb
825
        test    al, al
833
        test    al, al
826
        jz      .done
834
        jz      .done
827
        cmp     al, ' '
835
        cmp     al, ' '
828
        jz      .next
836
        jz      .next
829
        stosb
837
        stosb
830
        jmp     .namesloop
838
        jmp     .namesloop
831
 
-
 
832
  .next:
-
 
833
        inc     [ebx + window.users]
-
 
834
        mov     edi, edx
-
 
835
        add     edx, MAX_NICK_LEN
-
 
836
 
-
 
837
;;;        cmp     edi, ..              ; TODO: Check for buffer overflow
-
 
838
        jmp     .namesloop
-
 
839
 
839
 
840
  .done:
840
  .done:
841
        call    users_calculate
841
        call    users_calculate
842
        call    print_channel_list
842
        call    print_channel_list
843
 
843
 
844
        ret
844
        ret
845
 
845
 
846
 
846
 
847
users_calculate:
847
users_calculate:
848
 
-
 
849
        mov     eax, [ysize]
-
 
850
        sub     eax, TEXT_Y + 35 + 10 ;;;;
-
 
851
        xor     edx, edx
-
 
852
        mov     ecx, 10
-
 
853
        div     ecx
-
 
854
        mov     [scroll1.max_area], eax
-
 
855
 
848
 
856
        mov     ebx, [window_print]
849
        mov     ebx, [window_print]
857
        mov     eax, [ebx + window.users]
850
        mov     eax, [ebx + window.users]
858
        mov     [scroll1.max_area], eax
851
        mov     [scroll1.max_area], eax
859
        ; TODO: check if cur pos isnt greater then max
852
        ; TODO: check if cur pos isnt greater then max
-
 
853
 
-
 
854
        ; OK, now redraw the scrollbar
-
 
855
        mov     [scroll1.all_redraw], 1
-
 
856
        push    dword scroll1
-
 
857
        call    [scrollbar_v_draw]
-
 
858
 
860
        ret
859
        ret
861
 
860
 
862
 
861
 
863
 
862
 
864
 
863
 
865
 
864
 
866
cmd_366:        ; channel usernames end
865
cmd_366:        ; channel usernames end
867
 
866
 
868
; TODO: clear the bit that we are receiving names
867
; TODO: clear the bit that we are receiving names
869
 
868
 
870
 
869
 
871
        ret
870
        ret
872
 
871
 
873
 
872
 
874
cmd_topic:
873
cmd_topic:
875
 
874
 
876
        add     esi, 4  ; skip '332 '
875
        add     esi, 4  ; skip '332 '
877
 
876
 
878
  .loop:
877
  .loop:
879
        lodsb
878
        lodsb
880
        test    al, al
879
        test    al, al
881
        je      .fail
880
        je      .fail
882
        cmp     al, ':'
881
        cmp     al, ':'
883
        jne     .loop
882
        jne     .loop
884
 
883
 
885
        push    esi
884
        push    esi
886
        mov     esi, action_header
885
        mov     esi, action_header
887
        call    print_text2
886
        call    print_text2
888
 
887
 
889
        mov     esi, str_topic
888
        mov     esi, str_topic
890
        call    print_text2
889
        call    print_text2
891
 
890
 
892
        pop     esi
891
        pop     esi
893
        call    print_text2
892
        call    print_text2
894
 
893
 
895
        mov     esi, str_newline
894
        mov     esi, str_newline
896
        call    print_text2
895
        call    print_text2
897
 
896
 
898
  .fail:
897
  .fail:
899
        ret
898
        ret
900
 
899
 
901
 
900
 
902
cmd_333:
901
cmd_333:
903
 
902
 
904
        add     esi, 4  ; skip '333 '
903
        add     esi, 4  ; skip '333 '
905
 
904
 
906
; TODO: check channelname and change pointer accordingly
905
; TODO: check channelname and change pointer accordingly
907
 
906
 
908
        mov     ecx, 3  ; number of spaces to find
907
        mov     ecx, 3  ; number of spaces to find
909
  .loop:
908
  .loop:
910
        lodsb
909
        lodsb
911
        test    al, al
910
        test    al, al
912
        je      .fail
911
        je      .fail
913
        cmp     al, ' '
912
        cmp     al, ' '
914
        jne     .loop
913
        jne     .loop
915
        dec     ecx
914
        dec     ecx
916
        jnz     .loop   ; find some more spaces
915
        jnz     .loop   ; find some more spaces
917
 
916
 
918
        push    esi
917
        push    esi
919
        mov     esi, action_header
918
        mov     esi, action_header
920
        call    print_text2
919
        call    print_text2
921
 
920
 
922
        mov     esi, str_setby
921
        mov     esi, str_setby
923
        call    print_text2
922
        call    print_text2
924
 
923
 
925
        pop     esi
924
        pop     esi
926
        call    print_text2
925
        call    print_text2
927
 
926
 
928
        mov     esi, str_newline
927
        mov     esi, str_newline
929
        call    print_text2
928
        call    print_text2
930
 
929
 
931
  .fail:
930
  .fail:
932
        ret
931
        ret
933
>
932
>