Subversion Repositories Kolibri OS

Rev

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

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