Subversion Repositories Kolibri OS

Rev

Rev 9979 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
9979 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved.    ;;
3545 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
4143 hidnplayr 6
;;   Written by hidnplayr@kolibrios.org                            ;;
3545 hidnplayr 7
;;                                                                 ;;
8
;;         GNU GENERAL PUBLIC LICENSE                              ;;
9
;;          Version 2, June 1991                                   ;;
10
;;                                                                 ;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
 
13
 
14
server_parser:
15
 
16
        mov     esi, servercommand
9979 hidnplayr 17
        mov     ebx, ecx
3545 hidnplayr 18
 
19
        cmp     byte [esi], ':'
20
        jne     .parse
21
 
22
  .spaceloop:
23
        lodsb
24
        test    al, al
25
        jz      .fail
26
        cmp     al, ' '
27
        jne     .spaceloop
28
 
29
  .parse:
30
        mov     eax, [esi]
9979 hidnplayr 31
        or      eax, 0x20202020         ; convert to lowercase
3545 hidnplayr 32
        mov     edi, server_commands
33
        mov     ecx, server_commands.number
34
 
35
  .loop:
36
        scasd
37
        je      .got_cmd
38
        add     edi, 4
39
        dec     ecx
40
        jnz     .loop
41
 
42
  .fail:
43
        ret
44
 
45
  .got_cmd:
9979 hidnplayr 46
        mov     ecx, ebx
3545 hidnplayr 47
        jmp     dword[edi]
48
 
49
 
50
server_commands:
51
 
6027 hidnplayr 52
        dd      '001 ', cmd_welcome
4622 hidnplayr 53
        dd      '002 ', cmd_justprint
54
        dd      '003 ', cmd_justprint
55
        dd      '004 ', cmd_justprint
56
        dd      '005 ', cmd_justprint
57
 
58
        dd      '250 ', cmd_justprint
59
        dd      '251 ', cmd_justprint
60
        dd      '252 ', cmd_justprint
61
        dd      '253 ', cmd_justprint
62
        dd      '254 ', cmd_justprint
63
        dd      '255 ', cmd_justprint
64
 
65
        dd      '265 ', cmd_justprint
66
        dd      '266 ', cmd_justprint
67
 
5411 hidnplayr 68
        dd      '311 ', cmd_justprint   ; RPL_WHOISUSER
69
        dd      '312 ', cmd_justprint   ; RPL_WHOISSERVER
9092 hidnplayr 70
        dd      '317 ', cmd_justprint   ; RPL_WHOISIDLE
5411 hidnplayr 71
        dd      '318 ', cmd_justprint   ; RPL_ENDOFWHOIS
9092 hidnplayr 72
        dd      '319 ', cmd_justprint   ; RPL_WHOISCHANNELS
3545 hidnplayr 73
        dd      '322 ', cmd_322         ; RPL_LIST
74
        dd      '323 ', cmd_323         ; RPL_LISTEND
5411 hidnplayr 75
        dd      '324 ', cmd_justprint   ; RPL_CHANNELMODEIS
4622 hidnplayr 76
        dd      '328 ', cmd_justprint   ; RPL_CHANNEL_URL
5411 hidnplayr 77
        dd      '329 ', cmd_justprint   ; RPL_CREATIONTIME
78
        dd      '330 ', cmd_justprint
79
        dd      '332 ', cmd_topic       ; topic
3545 hidnplayr 80
        dd      '333 ', cmd_333         ; nickname and time of topic
9092 hidnplayr 81
        dd      '338 ', cmd_justprint   ; RPL_CHANPASSOK
3545 hidnplayr 82
        dd      '353 ', cmd_353         ; name reply
83
        dd      '366 ', cmd_366         ; end of names list
4622 hidnplayr 84
        dd      '372 ', cmd_justprint   ; motd
85
        dd      '375 ', cmd_justprint   ; start of motd
86
        dd      '376 ', cmd_justprint   ; end of motd
87
        dd      '421 ', cmd_justprint   ; unknown command
6027 hidnplayr 88
        dd      '432 ', cmd_justprint   ; erroneous nickname
4622 hidnplayr 89
        dd      '433 ', cmd_justprint   ; nickname already in use
6027 hidnplayr 90
        dd      '436 ', cmd_justprint   ; nickname collision
9092 hidnplayr 91
        dd      '671 ', cmd_justprint   ; RPL_WHOISSECURE
4622 hidnplayr 92
 
3545 hidnplayr 93
        dd      'join', cmd_join
94
        dd      'kick', cmd_kick
95
        dd      'mode', cmd_mode
96
        dd      'nick', cmd_nick
97
        dd      'part', cmd_part
98
        dd      'ping', cmd_ping
99
        dd      'priv', cmd_privmsg
100
        dd      'quit', cmd_quit
101
        dd      'noti', cmd_notice
102
 
103
        .number = ($ - server_commands) / 8
104
 
105
 
106
align 4
107
compare_to_nick:
108
 
109
        push    esi
110
        mov     ecx, MAX_NICK_LEN
111
        mov     esi, user_nick
112
  .loop:
113
        lodsb
114
        cmp     al, ' '
115
        jbe     .done
4477 hidnplayr 116
        test    al, al
117
        jz      .done
3545 hidnplayr 118
        cmp     al, 'a'
119
        jb      .ok
120
        cmp     al, 'z'
121
        ja      .ok
122
        sub     al, 0x20
123
  .ok:
124
 
125
        mov     bl, byte[edi]
126
        cmp     bl, 'a'
127
        jb      .ok2
128
        cmp     bl, 'z'
129
        ja      .ok2
130
        sub     bl, 0x20
131
  .ok2:
132
        cmp     bl, al
133
        jne     .not_equal
134
        inc     edi
135
        dec     ecx
136
        jnz     .loop
137
 
138
  .done:
139
        xor     eax, eax
140
        pop     esi
141
        ret
142
 
143
  .not_equal:
144
        or      eax, -1
145
        pop     esi
146
        ret
147
 
4143 hidnplayr 148
 
149
 
3545 hidnplayr 150
align 4
4477 hidnplayr 151
skip_parameter:
3545 hidnplayr 152
 
4595 hidnplayr 153
; First: skip the parameter (scan untill space or colon)
4477 hidnplayr 154
  .part1:
3545 hidnplayr 155
        lodsb
156
        cmp     al, ' '
4477 hidnplayr 157
        je      .part2
3545 hidnplayr 158
        cmp     al, ':'
4477 hidnplayr 159
        jne     .part1
3545 hidnplayr 160
 
4595 hidnplayr 161
; Skip all trailing spaces
162
  .part3:
163
        lodsb
164
        cmp     al, ' '
165
        je      .part3
166
        dec     esi
167
        ret
168
 
169
; Now, skip all trailing spaces and first semicolon
4477 hidnplayr 170
  .part2:
3545 hidnplayr 171
        lodsb
172
        cmp     al, ' '
4477 hidnplayr 173
        je      .part2
3545 hidnplayr 174
        cmp     al, ':'
4595 hidnplayr 175
        je      .part3
3545 hidnplayr 176
        dec     esi
177
        ret
178
 
179
 
180
 
6027 hidnplayr 181
cmd_welcome:
4595 hidnplayr 182
 
6027 hidnplayr 183
        mov     [status], STATUS_LOGGED_IN
4595 hidnplayr 184
 
4622 hidnplayr 185
cmd_justprint:
186
 
3545 hidnplayr 187
        add     esi, 4
4623 hidnplayr 188
        call    skip_parameter          ; our nickname
3545 hidnplayr 189
 
4623 hidnplayr 190
        call    print_asciiz
191
 
192
        mov     al, 10
193
        call    print_char
194
 
4622 hidnplayr 195
        ret
196
 
197
 
6027 hidnplayr 198
 
3545 hidnplayr 199
cmd_notice:
200
 
4622 hidnplayr 201
        if TIMESTAMP
202
        call    print_timestamp
203
        end if
204
 
3545 hidnplayr 205
        cmp     byte[servercommand], ':'
206
        jne     .gogogo
207
 
208
        mov     byte [esi-1], 0
209
        push    esi
210
        mov     esi, str_1
4623 hidnplayr 211
        call    print_asciiz
212
        mov     esi, servercommand+1
213
        mov     bl, '!'
214
        call    print_string
3545 hidnplayr 215
        mov     esi, str_2
4623 hidnplayr 216
        call    print_asciiz
3545 hidnplayr 217
        pop     esi
218
 
219
  .gogogo:
220
        add     esi, 6
4622 hidnplayr 221
        call    skip_parameter
222
        call    skip_parameter
4623 hidnplayr 223
        call    print_asciiz
3545 hidnplayr 224
 
4623 hidnplayr 225
        mov     al, 10
226
        call    print_char
3545 hidnplayr 227
 
228
        ret
229
 
230
 
231
 
232
cmd_ping:
233
 
234
; Just change PING to PONG
235
        mov     dword[esi], 'PONG'
236
 
9979 hidnplayr 237
; Append \r\n
238
        mov     word[esi+ecx], 0x0a0d
3545 hidnplayr 239
 
9979 hidnplayr 240
; And send the response to the server
3545 hidnplayr 241
        mov     edx, esi
9979 hidnplayr 242
        lea     esi, [ecx+2]
3545 hidnplayr 243
        mcall   send, [socketnum], , , 0
244
 
245
        ret
246
 
247
 
248
 
249
cmd_privmsg:
250
 
4143 hidnplayr 251
        mov     eax, dword[esi+4]
252
        or      eax, 0x20202020
253
        cmp     eax, 'msg '
254
        jne     .fail
3545 hidnplayr 255
        add     esi, 8          ; skip 'PRIVMSG '
256
 
4477 hidnplayr 257
        mov     edi, esi
258
        call    compare_to_nick
259
        jne     .channel
260
 
261
; private chat message
262
        push    esi
263
        mov     esi, servercommand+1
264
        call    window_open
4623 hidnplayr 265
        test    ebx, ebx
266
        jz      .fail2
4477 hidnplayr 267
        pop     esi
268
        call    skip_parameter  ; our own nickname
269
        jmp     .print
270
 
271
  .channel:
272
        call    window_open
4623 hidnplayr 273
        test    ebx, ebx
274
        jz      .fail
4477 hidnplayr 275
 
276
  .print:
4659 hidnplayr 277
        cmp     byte[esi], 1    ; Client to Client protocol?
278
        je      cmd_ctcp
279
 
4143 hidnplayr 280
        if TIMESTAMP
3545 hidnplayr 281
        call    print_timestamp
4143 hidnplayr 282
        end if
3545 hidnplayr 283
 
284
        push    esi
4623 hidnplayr 285
        mov     al, '<'
286
        call    print_char
3545 hidnplayr 287
 
4623 hidnplayr 288
        mov     esi, servercommand+1
289
        mov     bl, '!'
290
        call    print_string
3545 hidnplayr 291
 
4623 hidnplayr 292
        mov     al, '>'
293
        call    print_char
3545 hidnplayr 294
 
4623 hidnplayr 295
        mov     al, ' '
296
        call    print_char
3545 hidnplayr 297
 
298
        pop     esi
4623 hidnplayr 299
        call    print_asciiz
3545 hidnplayr 300
 
4623 hidnplayr 301
        mov     al, 10
302
        call    print_char
3545 hidnplayr 303
 
4623 hidnplayr 304
        ret
305
 
306
  .fail2:
307
        pop     esi
3545 hidnplayr 308
  .fail:
309
        ret
310
 
311
 
312
 
313
 
4143 hidnplayr 314
cmd_ctcp:
3545 hidnplayr 315
 
316
        inc     esi
4143 hidnplayr 317
        mov     eax, dword[esi]
318
        or      eax, 0x20202020
3545 hidnplayr 319
 
4143 hidnplayr 320
        cmp     eax, 'vers'
3545 hidnplayr 321
        je      .version
4143 hidnplayr 322
        cmp     eax, 'time'
3545 hidnplayr 323
        je      .time
4143 hidnplayr 324
        cmp     eax, 'ping'
3545 hidnplayr 325
        je      .ping
4143 hidnplayr 326
        cmp     eax, 'acti'
327
        je      .action
4477 hidnplayr 328
        cmp     eax, 'dcc '    ; TODO
329
        je      cmd_dcc
3545 hidnplayr 330
 
7300 hidnplayr 331
; Unknown CTCP command - just print to window
4143 hidnplayr 332
 
7300 hidnplayr 333
  .just_print:
4143 hidnplayr 334
 
7300 hidnplayr 335
        push    esi
336
 
337
        if TIMESTAMP
338
        call    print_timestamp
339
        end if
340
 
341
        mov     esi, ctcp_header_recv
342
        call    print_asciiz
343
 
344
        mov     al, '<'
345
        call    print_char
346
 
347
        mov     esi, servercommand+1    ; print nickname
348
        mov     bl, '!'
349
        call    print_string
350
 
351
        mov     al, '>'
352
        call    print_char
353
 
354
        mov     al, ' '
355
        call    print_char
356
 
357
        pop     esi
358
        mov     bl, 1
359
        call    print_string
360
 
361
        mov     al, 10
362
        call    print_char
363
 
3545 hidnplayr 364
        ret
365
 
366
  .time:
4143 hidnplayr 367
        mov     byte[esi+4], ' '
3545 hidnplayr 368
        lea     edi, [esi+5]
369
 
370
        ; TODO: add system date (fn 29) in human readable format
371
 
372
        mcall   3                       ; get system time
373
 
374
        mov     ecx, 3
375
  .timeloop:
376
        mov     bl, al
377
        shr     al, 4
378
        add     al, '0'
379
        stosb
380
 
381
        mov     al, bl
382
        and     al, 0x0f
383
        add     al, '0'
384
        stosb
385
 
386
        dec     ecx
387
        jz      .timedone
388
 
389
        mov     al, ':'
390
        stosb
391
        shr     eax, 8
392
        jmp     .timeloop
393
 
394
  .timedone:
395
        xor     al, al
396
        stosb
397
        call    ctcp_reply
398
 
399
        if TIMESTAMP
400
        call    print_timestamp
401
        end if
402
 
403
        mov     esi, ctcp_header
4623 hidnplayr 404
        call    print_asciiz
3545 hidnplayr 405
 
406
        mov     esi, servercommand+1
4623 hidnplayr 407
        call    print_asciiz
3545 hidnplayr 408
 
409
        mov     esi, ctcp_time
4623 hidnplayr 410
        call    print_asciiz
3545 hidnplayr 411
 
412
        ret
413
 
414
  .version:
415
        mov     esi, str_version
416
        call    ctcp_reply
417
 
418
        if TIMESTAMP
419
        call    print_timestamp
420
        end if
421
 
422
        mov     esi, ctcp_header
4623 hidnplayr 423
        call    print_asciiz
3545 hidnplayr 424
 
425
        mov     esi, servercommand+1
4623 hidnplayr 426
        call    print_asciiz
3545 hidnplayr 427
 
428
        mov     esi, ctcp_version
4623 hidnplayr 429
        call    print_asciiz
3545 hidnplayr 430
 
431
        ret
432
 
433
  .ping:
434
        call    ctcp_reply
435
 
436
        if TIMESTAMP
437
        call    print_timestamp
438
        end if
439
 
440
        mov     esi, ctcp_header
4623 hidnplayr 441
        call    print_asciiz
3545 hidnplayr 442
 
443
        mov     esi, servercommand+1
4623 hidnplayr 444
        call    print_asciiz
3545 hidnplayr 445
 
446
        mov     esi, ctcp_ping
4623 hidnplayr 447
        call    print_asciiz
3545 hidnplayr 448
 
449
        ret
450
 
4143 hidnplayr 451
  .action:
452
        add     esi, 7
453
        push    esi
3545 hidnplayr 454
 
4143 hidnplayr 455
        if TIMESTAMP
456
        call    print_timestamp
457
        end if
3545 hidnplayr 458
 
4143 hidnplayr 459
        mov     esi, action_header
4623 hidnplayr 460
        call    print_asciiz
4143 hidnplayr 461
 
4623 hidnplayr 462
        mov     esi, servercommand+1    ; print nickname
463
        mov     bl, '!'
464
        call    print_string
4143 hidnplayr 465
 
4623 hidnplayr 466
        mov     al, ' '
467
        call    print_char
4143 hidnplayr 468
 
469
        pop     esi
4623 hidnplayr 470
        call    print_asciiz
4143 hidnplayr 471
 
4623 hidnplayr 472
        mov     al, 10
473
        call    print_char
4143 hidnplayr 474
 
475
        ret
476
 
477
 
478
cmd_dcc:
479
        add     esi, 4
480
        mov     eax, dword[esi]
481
        or      eax, 0x202020
482
 
483
        cmp     eax, 'send'
484
        je      .send
485
 
486
        ret
487
 
488
  .send:
4477 hidnplayr 489
        call    window_open
4623 hidnplayr 490
        test    ebx, ebx
491
        jz      .fail
4477 hidnplayr 492
        mov     [ebx + window.type], WINDOWTYPE_DCC
493
 
4623 hidnplayr 494
  .fail:
495
 
4143 hidnplayr 496
        ret
497
 
498
 
499
 
3545 hidnplayr 500
ctcp_reply:
501
 
502
        push    esi
6027 hidnplayr 503
        mov     dword[user_command], 'NOTI'
504
        mov     dword[user_command+4], 'CE  '
3545 hidnplayr 505
 
506
        mov     esi, servercommand+1
6027 hidnplayr 507
        mov     edi, user_command+7
3545 hidnplayr 508
  .nickloop:
509
        lodsb
510
        cmp     al, '!'
511
        je      .done
512
        cmp     al, ' '
513
        je      .done
514
        test    al, al
515
        je      .fail
516
        stosb
517
        jmp     .nickloop
518
  .done:
519
        mov     byte [esi-1], 0
520
        mov     ax, ' :'
521
        stosw
522
        mov     al, 1
523
        stosb
524
 
525
        pop     esi
526
  .replyloop:
527
        lodsb
528
        cmp     al, 1
529
        jbe     .done2
530
        stosb
531
        jmp     .replyloop
532
  .done2:
533
 
534
        mov     al, 1
535
        stosb
536
        mov     ax, 0x0a0d
537
        stosw
538
 
6027 hidnplayr 539
        lea     esi, [edi - user_command]
540
        mcall   send, [socketnum], user_command, , 0
3545 hidnplayr 541
  .fail:
542
        ret
543
 
544
 
545
 
546
cmd_part:
4143 hidnplayr 547
 
548
        cmp     byte [esi+4], ' '
549
        jne     .fail
3545 hidnplayr 550
        add     esi, 5  ; skip 'PART '
9984 hidnplayr 551
        cmp     byte[esi], ':'
552
        jne     @f
553
        inc     esi
554
  @@:
3545 hidnplayr 555
 
556
; Is it me who parted?
557
        mov     edi, servercommand+1
558
        call    compare_to_nick
4477 hidnplayr 559
        jne     .not_me
3545 hidnplayr 560
 
4143 hidnplayr 561
; yes, close the window (if its open)
562
        call    window_find
563
        test    ebx, ebx
564
        jz      @f
565
        call    window_close
566
  @@:
567
  .fail:
3545 hidnplayr 568
 
569
        ret
570
 
4143 hidnplayr 571
 
3545 hidnplayr 572
; somebody else parted, just print message
4477 hidnplayr 573
  .not_me:
3545 hidnplayr 574
        push    esi
4143 hidnplayr 575
        call    window_open
4623 hidnplayr 576
        test    ebx, ebx
577
        jz      .fail2
4143 hidnplayr 578
 
4477 hidnplayr 579
        if TIMESTAMP
580
        call    print_timestamp
581
        end if
582
 
4143 hidnplayr 583
        mov     esi, part_header
4623 hidnplayr 584
        call    print_asciiz
3545 hidnplayr 585
 
4623 hidnplayr 586
        mov     esi, servercommand+1
587
        mov     bl, '!'
588
        call    print_string
3545 hidnplayr 589
 
590
        mov     esi, has_left_channel
4623 hidnplayr 591
        call    print_asciiz
3545 hidnplayr 592
 
593
        pop     esi
4623 hidnplayr 594
        call    print_asciiz
3545 hidnplayr 595
 
4623 hidnplayr 596
        mov     al, 10
597
        call    print_char
3545 hidnplayr 598
 
599
        mov     ebx, [window_print]
600
        mov     esi, servercommand+1
601
        call    user_remove
602
 
603
        ret
604
 
4623 hidnplayr 605
  .fail2:
606
        pop     esi
3545 hidnplayr 607
 
4623 hidnplayr 608
        ret
3545 hidnplayr 609
 
4623 hidnplayr 610
 
611
 
3545 hidnplayr 612
cmd_join:
4143 hidnplayr 613
 
4477 hidnplayr 614
        cmp     byte[esi+4], ' '
4143 hidnplayr 615
        jne     .fail
3545 hidnplayr 616
        add     esi, 5  ; skip 'JOIN '
9984 hidnplayr 617
        cmp     byte[esi], ':'
618
        jne     @f
619
        inc     esi
620
  @@:
3545 hidnplayr 621
 
4623 hidnplayr 622
; did we join a channel?
3545 hidnplayr 623
        mov     edi, servercommand+1
624
        call    compare_to_nick
4477 hidnplayr 625
        jne     .not_me
3545 hidnplayr 626
 
4477 hidnplayr 627
        push    esi
628
        call    window_open
4623 hidnplayr 629
        test    ebx, ebx
3545 hidnplayr 630
        jz      .fail
631
        mov     [ebx + window.type], WINDOWTYPE_CHANNEL
3981 hidnplayr 632
        mov     [window_active], ebx
3545 hidnplayr 633
 
4143 hidnplayr 634
        if TIMESTAMP
635
        call    print_timestamp
636
        end if
637
 
638
        mov     esi, join_header
4623 hidnplayr 639
        call    print_asciiz
3545 hidnplayr 640
 
641
        mov     esi, str_talking
4623 hidnplayr 642
        call    print_asciiz
3545 hidnplayr 643
 
4623 hidnplayr 644
        pop     esi
645
        mov     bl, ' '
646
        call    print_string
3545 hidnplayr 647
 
4623 hidnplayr 648
        mov     al, 10
649
        call    print_char
3545 hidnplayr 650
 
651
        call    draw_window
652
 
653
        ret
654
 
4477 hidnplayr 655
  .not_me:
3545 hidnplayr 656
        push    esi
3981 hidnplayr 657
        call    window_open
4623 hidnplayr 658
        test    ebx, ebx
659
        jz      .fail
3545 hidnplayr 660
 
4143 hidnplayr 661
        if TIMESTAMP
662
        call    print_timestamp
663
        end if
664
 
665
        mov     esi, join_header
4623 hidnplayr 666
        call    print_asciiz
3545 hidnplayr 667
 
4623 hidnplayr 668
        mov     esi, servercommand+1
669
        mov     bl, '!'
670
        call    print_string
3545 hidnplayr 671
 
672
        mov     esi, joins_channel
4623 hidnplayr 673
        call    print_asciiz
3545 hidnplayr 674
 
675
        pop     esi
4623 hidnplayr 676
        call    print_asciiz
3545 hidnplayr 677
 
4623 hidnplayr 678
        mov     al, 10
679
        call    print_char
3545 hidnplayr 680
 
681
        mov     ebx, [window_print]
682
        mov     esi, servercommand+1
683
        call    user_add
684
 
4477 hidnplayr 685
        ret
686
 
4143 hidnplayr 687
  .fail:
4623 hidnplayr 688
        pop     esi
3545 hidnplayr 689
        ret
690
 
691
 
692
 
693
 
694
cmd_nick:
695
 
4143 hidnplayr 696
        cmp     byte[esi+4], ' '
697
        jne     .fail
698
        add     esi, 5          ; skip 'NICK '
699
        cmp     byte[esi], ':'
3545 hidnplayr 700
        jne     @f
701
        inc     esi
4143 hidnplayr 702
  @@:
3545 hidnplayr 703
 
4143 hidnplayr 704
; Is it me who changed nick?
3545 hidnplayr 705
        push    esi
706
        mov     edi, servercommand+1
707
        call    compare_to_nick
708
        jne     .not_me
709
 
4617 hidnplayr 710
; Yup, update user_nick
3545 hidnplayr 711
        mov     ecx, MAX_NICK_LEN-1
4143 hidnplayr 712
        mov     esi, [esp]
4617 hidnplayr 713
        mov     edi, user_nick
4143 hidnplayr 714
  @@:
3545 hidnplayr 715
        lodsb
716
        test    al, al
4143 hidnplayr 717
        jz      @f
3545 hidnplayr 718
        cmp     al, ' '
4143 hidnplayr 719
        je      @f
720
        cmp     al, 10
721
        je      @f
722
        cmp     al, 13
723
        je      @f
4617 hidnplayr 724
        cmp     al, ':'
725
        je      @r
3545 hidnplayr 726
        stosb
727
        dec     ecx
4143 hidnplayr 728
        jnz     @r
729
  @@:
3545 hidnplayr 730
        xor     al, al
731
        stosb
4982 hidnplayr 732
 
733
; Print a message on the server window
734
        mov     [window_print], windows
735
 
736
        mov     esi, str_nickchange
737
        call    print_asciiz
738
 
739
        mov     esi, user_nick
740
        call    print_asciiz
741
 
742
        mov     al, 10
743
        call    print_char
744
 
3545 hidnplayr 745
  .not_me:
746
 
4617 hidnplayr 747
; Update in userlist
4143 hidnplayr 748
        mov     ebx, windows
749
        mov     ecx, MAX_WINDOWS
750
  .window_loop:
751
        push    ecx ebx
752
        cmp     [ebx + window.type], WINDOWTYPE_CHANNEL
753
        jne     .next_window
754
 
755
        mov     esi, servercommand+1
756
        call    user_remove
757
        test    edi, edi
758
        jz      .next_window
759
 
760
        mov     esi, [esp + 8]
761
        call    user_add
762
 
4617 hidnplayr 763
; And print a notification in the channel
4143 hidnplayr 764
        mov     [window_print], ebx
765
 
766
        if TIMESTAMP
767
        call    print_timestamp
768
        end if
769
 
770
        mov     esi, nick_header
4623 hidnplayr 771
        call    print_asciiz
3545 hidnplayr 772
 
4623 hidnplayr 773
        mov     esi, servercommand+1
774
        mov     bl, '!'
775
        call    print_string
3545 hidnplayr 776
 
777
        mov     esi, is_now_known_as
4623 hidnplayr 778
        call    print_asciiz
3545 hidnplayr 779
 
4623 hidnplayr 780
        mov     esi, [esp + 8]
781
        call    print_asciiz
3545 hidnplayr 782
 
4623 hidnplayr 783
        mov     al, 10
784
        call    print_char
3545 hidnplayr 785
 
4617 hidnplayr 786
; Now do this for all open windows
4143 hidnplayr 787
  .next_window:
788
        pop     ebx ecx
789
        add     ebx, sizeof.window
790
        dec     ecx
791
        jnz     .window_loop
792
 
793
        pop     esi
794
 
795
  .fail:
796
 
3545 hidnplayr 797
        ret
798
 
799
 
800
 
801
 
802
cmd_kick:
4143 hidnplayr 803
 
804
        cmp     byte [esi+4], ' '
805
        jne     .fail
3545 hidnplayr 806
        add     esi, 5  ; skip 'KICK '
807
 
4595 hidnplayr 808
; TODO: Is it me who got kicked?
809
; if so, mark channel as disconnected
3545 hidnplayr 810
 
811
  .not_me:
812
; find the channel user has been kicked from
813
        push    esi
3981 hidnplayr 814
        call    window_open
4623 hidnplayr 815
        test    ebx, ebx
816
        jz      .fail
4595 hidnplayr 817
        push    esi
3545 hidnplayr 818
 
4143 hidnplayr 819
        if TIMESTAMP
820
        call    print_timestamp
821
        end if
822
 
823
        mov     esi, kick_header
4623 hidnplayr 824
        call    print_asciiz
3545 hidnplayr 825
 
4623 hidnplayr 826
        pop     esi
827
        mov     bl, ' '
828
        call    print_string
3545 hidnplayr 829
 
4595 hidnplayr 830
        mov     esi, str_kicked
4623 hidnplayr 831
        call    print_asciiz
3545 hidnplayr 832
 
4623 hidnplayr 833
        pop     esi
834
        mov     bl, ' '
835
        call    print_string
3545 hidnplayr 836
 
4595 hidnplayr 837
        mov     esi, str_by
4623 hidnplayr 838
        call    print_asciiz
3545 hidnplayr 839
 
4623 hidnplayr 840
        mov     esi, servercommand+1
841
        mov     bl, '!'
842
        call    print_string
4595 hidnplayr 843
 
4623 hidnplayr 844
        mov     al, 10
845
        call    print_char
4595 hidnplayr 846
 
3545 hidnplayr 847
        mov     ebx, [window_print]
848
        mov     esi, servercommand+1
849
        call    user_remove
850
 
4623 hidnplayr 851
        ret
852
 
4143 hidnplayr 853
  .fail:
4623 hidnplayr 854
        pop     esi
4143 hidnplayr 855
 
3545 hidnplayr 856
        ret
857
 
858
 
859
 
860
cmd_quit:
861
 
4143 hidnplayr 862
        cmp     byte [esi+4], ' '
863
        jne     .fail
864
 
865
        mov     ebx, windows
866
        mov     ecx, MAX_WINDOWS
867
 
868
  .window_loop:
869
        push    ecx
870
        cmp     [ebx + window.type], WINDOWTYPE_CHANNEL
871
        jne     .next_window
872
 
873
        mov     esi, servercommand+1
874
        call    user_remove
875
        test    edi, edi
876
        jz      .next_window
877
 
878
        push    ebx
879
        mov     [window_print], ebx
880
 
881
        if TIMESTAMP
882
        call    print_timestamp
883
        end if
884
 
885
        mov     esi, quit_header
4623 hidnplayr 886
        call    print_asciiz
3545 hidnplayr 887
 
4623 hidnplayr 888
        mov     esi, servercommand+1
889
        mov     bl, '!'
890
        call    print_string
3545 hidnplayr 891
 
892
        mov     esi, has_quit_irc
4623 hidnplayr 893
        call    print_asciiz
3545 hidnplayr 894
 
4143 hidnplayr 895
; TODO: check if quit message was given, and print it to the window
896
        pop     ebx
897
  .next_window:
898
        pop     ecx
899
        add     ebx, sizeof.window
900
        dec     ecx
901
        jnz     .window_loop
3545 hidnplayr 902
 
4143 hidnplayr 903
  .fail:
904
 
905
 
3545 hidnplayr 906
        ret
907
 
908
 
909
 
910
cmd_mode:
911
 
4143 hidnplayr 912
        cmp     byte [esi+4], ' '
913
        jne     .fail
3545 hidnplayr 914
        add     esi, 5  ; skip 'MODE '
4622 hidnplayr 915
        push    esi
4143 hidnplayr 916
        call    window_find
917
        test    ebx, ebx
4622 hidnplayr 918
        jz      .user
919
        mov     [esp], esi
4477 hidnplayr 920
        mov     [window_print], ebx
4143 hidnplayr 921
 
922
        if TIMESTAMP
923
        call    print_timestamp
924
        end if
925
 
926
        mov     esi, mode_header
4623 hidnplayr 927
        call    print_asciiz
3545 hidnplayr 928
 
4623 hidnplayr 929
        mov     esi, servercommand+1
930
        mov     bl, '!'
931
        call    print_string
3545 hidnplayr 932
 
933
        mov     esi, sets_mode
4623 hidnplayr 934
        call    print_asciiz
3545 hidnplayr 935
 
936
        pop     esi
4623 hidnplayr 937
        call    print_asciiz
3545 hidnplayr 938
 
4623 hidnplayr 939
        mov     al, 10
940
        call    print_char
3545 hidnplayr 941
 
4622 hidnplayr 942
; TODO: keep track of user modes in username list
3545 hidnplayr 943
 
4143 hidnplayr 944
  .fail:
4622 hidnplayr 945
        ret
4143 hidnplayr 946
 
4622 hidnplayr 947
 
948
  .user:
949
        if TIMESTAMP
950
        call    print_timestamp
951
        end if
952
 
953
        mov     esi, mode_header
4623 hidnplayr 954
        call    print_asciiz
4622 hidnplayr 955
 
4623 hidnplayr 956
        mov     esi, [esp]
957
        mov     bl, ' '
958
        call    print_string
4622 hidnplayr 959
 
960
        mov     esi, sets_mode
4623 hidnplayr 961
        call    print_asciiz
4622 hidnplayr 962
 
963
        pop     esi
964
        call    skip_parameter
4623 hidnplayr 965
        call    print_asciiz
4622 hidnplayr 966
 
4623 hidnplayr 967
        mov     al, 10
968
        call    print_char
4622 hidnplayr 969
 
3545 hidnplayr 970
        ret
971
 
972
 
973
cmd_353:                ; channel usernames reply
974
 
975
        add     esi, 4  ; skip '353 '
4477 hidnplayr 976
        call    skip_parameter
3545 hidnplayr 977
        inc     esi     ; channel type '*', '=' or '@'
978
        inc     esi     ; ' '
3981 hidnplayr 979
        call    window_open
4623 hidnplayr 980
        test    ebx, ebx
981
        jz      .fail
3545 hidnplayr 982
 
983
; now find window ptr and check if this is the first 353 message
984
        mov     ebx, [window_print]
985
        test    [ebx + window.flags], FLAG_RECEIVING_NAMES
986
        jnz     .add
987
 
988
        or      [ebx + window.flags], FLAG_RECEIVING_NAMES
989
;        mov     [ebx + window.users], 0
990
        ; TODO: remove all users?
991
 
992
  .add:
993
        lodsb
994
        test    al, al
995
        jz      .done
9984 hidnplayr 996
        cmp     al, ' '
997
        je      .add
998
        dec     esi
999
        call    user_add
3545 hidnplayr 1000
        jmp     .add
1001
 
1002
  .done:
6026 hidnplayr 1003
        call    draw_user_list
9984 hidnplayr 1004
 
4623 hidnplayr 1005
  .fail:
3545 hidnplayr 1006
        ret
1007
 
1008
 
1009
 
1010
 
1011
 
1012
cmd_366:        ; channel usernames end
1013
 
1014
        add     esi, 4          ; skip '366 '
4477 hidnplayr 1015
        call    skip_parameter
3981 hidnplayr 1016
        call    window_open
4623 hidnplayr 1017
        test    ebx, ebx
1018
        jz      .fail
3545 hidnplayr 1019
        and     [ebx + window.flags], not FLAG_RECEIVING_NAMES
4623 hidnplayr 1020
  .fail:
3545 hidnplayr 1021
 
1022
        ret
1023
 
1024
 
1025
 
1026
 
1027
cmd_topic:
1028
 
1029
        add     esi, 4          ; skip '332 '
4477 hidnplayr 1030
        call    skip_parameter
3981 hidnplayr 1031
        call    window_open
4623 hidnplayr 1032
        test    ebx, ebx
1033
        jz      .fail
3545 hidnplayr 1034
 
4143 hidnplayr 1035
        if TIMESTAMP
1036
        call    print_timestamp
1037
        end if
1038
 
3545 hidnplayr 1039
        push    esi
4143 hidnplayr 1040
        mov     esi, topic_header
4623 hidnplayr 1041
        call    print_asciiz
3545 hidnplayr 1042
 
1043
        mov     esi, str_topic
4623 hidnplayr 1044
        call    print_asciiz
3545 hidnplayr 1045
 
1046
        pop     esi
4623 hidnplayr 1047
        call    print_asciiz
3545 hidnplayr 1048
 
4477 hidnplayr 1049
        mov     esi, str_topic_end
4623 hidnplayr 1050
        call    print_asciiz
3545 hidnplayr 1051
 
4623 hidnplayr 1052
  .fail:
1053
 
3545 hidnplayr 1054
        ret
1055
 
1056
 
1057
cmd_333:
1058
 
1059
        add     esi, 4          ; skip '333 '
4622 hidnplayr 1060
        call    skip_parameter
3981 hidnplayr 1061
        call    window_open
4623 hidnplayr 1062
        test    ebx, ebx
1063
        jz      .fail
3545 hidnplayr 1064
 
4143 hidnplayr 1065
        if TIMESTAMP
1066
        call    print_timestamp
1067
        end if
1068
 
3545 hidnplayr 1069
        push    esi
4143 hidnplayr 1070
        mov     esi, topic_header
4623 hidnplayr 1071
        call    print_asciiz
3545 hidnplayr 1072
 
1073
        mov     esi, str_setby
4623 hidnplayr 1074
        call    print_asciiz
3545 hidnplayr 1075
 
4623 hidnplayr 1076
        pop     esi
1077
        mov     bl, '!'
1078
        call    print_string
3545 hidnplayr 1079
 
4623 hidnplayr 1080
        mov     al, 10
1081
        call    print_char
3545 hidnplayr 1082
 
1083
  .fail:
4623 hidnplayr 1084
 
3545 hidnplayr 1085
        ret
1086
 
4623 hidnplayr 1087
 
1088
 
4143 hidnplayr 1089
cmd_322:        ; LIST
1090
 
3545 hidnplayr 1091
        add     esi, 4
4477 hidnplayr 1092
        call    skip_parameter
3545 hidnplayr 1093
 
4623 hidnplayr 1094
        push    esi
1095
        mov     esi, str_list
1096
        call    window_open
1097
        test    ebx, ebx
1098
        jz      .fail
1099
 
1100
        mov     [window_active], ebx
6026 hidnplayr 1101
        call    draw_window_tabs
4623 hidnplayr 1102
        pop     esi
1103
        call    print_asciiz
1104
        mov     al, 10
1105
        call    print_char
1106
 
3545 hidnplayr 1107
        ret
1108
 
4623 hidnplayr 1109
  .fail:
1110
        pop     esi
1111
 
1112
        ret
1113
 
4143 hidnplayr 1114
cmd_323:        ; LIST END
3545 hidnplayr 1115
 
9984 hidnplayr 1116
        ret