Subversion Repositories Kolibri OS

Rev

Rev 3191 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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