Subversion Repositories Kolibri OS

Rev

Rev 5411 | Rev 6027 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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