Subversion Repositories Kolibri OS

Rev

Rev 3220 | 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.         add     esi, 8  ; skip 'PRIVMSG '
  199.  
  200. ; Check if it was destined for me privately
  201.         mov     edi, servercommand+1
  202.         call    compare_to_nick
  203. ;;;        je      .private
  204.  
  205. ; If not, find the correct window ???
  206.  
  207. ; now find the end of nick
  208.         mov     edi, esi
  209.   .loop:
  210.         inc     edi
  211.         cmp     byte [edi], 0
  212.         je      .fail
  213.         cmp     byte [edi], ' '
  214.         jne     .loop
  215.  
  216.   .loop2:
  217.         inc     edi
  218.         cmp     byte [edi], 0
  219.         je      .fail
  220.         cmp     byte [edi], ' '
  221.         je      .loop2
  222.         cmp     byte [edi], ':'
  223.         je      .loop2
  224.         cmp     byte [edi], 1
  225.         je      cmd_ctcp
  226.  
  227. ; Action?
  228.         cmp     dword[edi+1], 'ACTI'
  229.         je      .action
  230.  
  231. ; nope, just plain old privmsg
  232. if TIMESTAMP
  233.         call    print_timestamp
  234. end if
  235.  
  236.         push    edi
  237.         mov     bl, '<'
  238.         call    print_character
  239.  
  240.         mov     eax, servercommand+1
  241.         mov     dl, '!'
  242.         call    print_text
  243.  
  244.         mov     bl, '>'
  245.         call    print_character
  246.  
  247.         mov     bl, ' '
  248.         call    print_character
  249.  
  250.         pop     esi
  251.         call    print_text2
  252.  
  253.         mov     bl, 10
  254.         call    print_character
  255.  
  256.   .fail:
  257.         ret
  258.  
  259.   .action:
  260.         push    edi
  261.         if TIMESTAMP
  262.         call    print_timestamp
  263.         end if
  264.  
  265.         mov     esi, action_header_short
  266.         call    print_text2
  267.  
  268.         mov     eax, servercommand+1
  269.         mov     dl, ' '
  270.         call    print_text
  271.  
  272.         mov     bl, ' '
  273.         call    print_character
  274.  
  275.         pop     esi
  276.         add     esi, 8
  277.         call    print_text2
  278.  
  279.         mov     bl, 10
  280.         call    print_character
  281.  
  282.         ret
  283.  
  284. cmd_ctcp:
  285.  
  286.         cmp     dword[edi+1], 'VERS'
  287.         je      .version
  288.  
  289.         cmp     dword[edi+1], 'TIME'
  290.         je      .time
  291.  
  292.         cmp     dword[edi+1], 'PING'
  293.         je      .ping
  294.  
  295.         ret
  296.  
  297.   .time:
  298.         lea     esi, [edi+1]
  299.         mov     byte [edi+5], ' '
  300.         add     edi, 6
  301.  
  302.         ; TODO: add system date (fn 29) in human readable format
  303.  
  304.         mcall   3                       ; get system time
  305.  
  306.         mov     ecx, 3
  307.   .timeloop:
  308.         mov     bl, al
  309.         shr     al, 4
  310.         add     al, '0'
  311.         stosb
  312.  
  313.         mov     al, bl
  314.         and     al, 0x0f
  315.         add     al, '0'
  316.         stosb
  317.  
  318.         dec     ecx
  319.         jz      .timedone
  320.  
  321.         mov     al, ':'
  322.         stosb
  323.         shr     eax, 8
  324.         jmp     .timeloop
  325.  
  326.   .timedone:
  327.         xor     al, al
  328.         stosb
  329.         call    ctcp_reply
  330.  
  331.         if TIMESTAMP
  332.         call    print_timestamp
  333.         end if
  334.  
  335.         mov     esi, ctcp_header
  336.         call    print_text2
  337.  
  338.         mov     esi, servercommand+1
  339.         call    print_text2
  340.  
  341.         mov     esi, ctcp_time
  342.         call    print_text2
  343.  
  344.         ret
  345.  
  346.   .version:
  347.         mov     esi, str_version
  348.         call    ctcp_reply
  349.  
  350.         if TIMESTAMP
  351.         call    print_timestamp
  352.         end if
  353.  
  354.         mov     esi, ctcp_header
  355.         call    print_text2
  356.  
  357.         mov     esi, servercommand+1
  358.         call    print_text2
  359.  
  360.         mov     esi, ctcp_version
  361.         call    print_text2
  362.  
  363.         ret
  364.  
  365.   .ping:
  366.         lea     esi, [edi+1]
  367.         call    ctcp_reply
  368.  
  369.         if TIMESTAMP
  370.         call    print_timestamp
  371.         end if
  372.  
  373.         mov     esi, ctcp_header
  374.         call    print_text2
  375.  
  376.         mov     esi, servercommand+1
  377.         call    print_text2
  378.  
  379.         mov     esi, ctcp_ping
  380.         call    print_text2
  381.  
  382.         ret
  383.  
  384.  
  385.  
  386. ctcp_reply:
  387.  
  388.         push    esi
  389.  
  390.         mov     dword [usercommand], 'NOTI'
  391.         mov     dword [usercommand+4], 'CE  '
  392.  
  393.         mov     esi, servercommand+1
  394.         mov     edi, usercommand+7
  395.   .nickloop:
  396.         lodsb
  397.         cmp     al, '!'
  398.         je      .done
  399.         cmp     al, ' '
  400.         je      .done
  401.         test    al, al
  402.         je      .fail
  403.         stosb
  404.         jmp     .nickloop
  405.   .done:
  406.         mov     byte [esi-1], 0
  407.         mov     ax, ' :'
  408.         stosw
  409.         mov     al, 1
  410.         stosb
  411.  
  412.         pop     esi
  413.   .replyloop:
  414.         lodsb
  415.         cmp     al, 1
  416.         jbe     .done2
  417.         stosb
  418.         jmp     .replyloop
  419.   .done2:
  420.  
  421.         mov     al, 1
  422.         stosb
  423.         mov     ax, 0x0a0d
  424.         stosw
  425.  
  426.         lea     esi, [edi - usercommand]
  427.         mcall   send, [socketnum], usercommand, , 0
  428.   .fail:
  429.         ret
  430.  
  431.  
  432.  
  433. cmd_part:
  434.         add     esi, 5  ; skip 'PART '
  435.  
  436. ; Is it me who parted?
  437.         mov     edi, servercommand+1
  438.         call    compare_to_nick
  439.         jne     .dont_close
  440.  
  441. ; yes, close the window
  442.         mov     edi, [window_print]
  443.         mov     [edi + window.flags], FLAG_UPDATED + FLAG_CLOSE
  444.  
  445.         ret
  446.  
  447. ; somebody else parted, just print message
  448.   .dont_close:
  449.         push    esi
  450.         mov     esi, action_header
  451.         call    print_text2
  452.  
  453.         mov     eax, servercommand+1
  454.         mov     dl, '!'
  455.         mov     cl, ' '
  456.         call    print_text
  457.  
  458.         mov     esi, has_left_channel
  459.         call    print_text2
  460.  
  461.         pop     esi
  462.         call    print_text2
  463.  
  464.         mov     esi, str_newline
  465.         call    print_text2
  466.  
  467. ;;; TODO: dec [window.users], remove username from the userlist
  468.  
  469.  
  470.         ret
  471.  
  472.  
  473.  
  474. cmd_join:
  475.         add     esi, 5  ; skip 'JOIN '
  476.  
  477. ; compare nick: did we join a channel?
  478.         mov     edi, servercommand+1
  479.         call    compare_to_nick
  480.         jne     .no_new_window
  481.  
  482. ; create channel window - search for empty slot
  483.         mov     ebx, windows
  484.         mov     ecx, MAX_WINDOWS
  485.   .loop:
  486.         cmp     [ebx + window.data_ptr], 0
  487.         je      .free_found
  488.         add     ebx, sizeof.window
  489.         dec     ecx
  490.         jnz     .loop
  491. ; Error: no more available windows!! ;;;;; TODO
  492.   .fail:
  493.         ret
  494.  
  495.   .free_found:
  496.         push    ebx
  497.         call    window_create
  498.         pop     ebx
  499.         test    eax, eax
  500.         jz      .fail
  501.         mov     [ebx + window.data_ptr], eax
  502.         mov     [ebx + window.type], WINDOWTYPE_CHANNEL
  503.         mov     [ebx + window.flags], 0
  504.  
  505.         call    window_set_name
  506.  
  507.         mov     [window_open], ebx
  508.         mov     [window_print], ebx
  509.         call    window_refresh
  510.  
  511.         push    esi
  512.         mov     esi, action_header
  513.         call    print_text2
  514.  
  515.         mov     esi, str_talking
  516.         call    print_text2
  517.  
  518.         pop     eax
  519.         mov     dl, ' '
  520.         call    print_text
  521.  
  522.         mov     esi, str_dotnewline
  523.         call    print_text2
  524.  
  525.         call    draw_window
  526.  
  527.         ret
  528.  
  529.   .no_new_window:
  530.         push    esi
  531.         call    window_set_name
  532.  
  533.         mov     esi, action_header
  534.         call    print_text2
  535.  
  536.         mov     eax, servercommand+1
  537.         mov     dl, '!'
  538.         call    print_text
  539.  
  540.         mov     esi, joins_channel
  541.         call    print_text2
  542.  
  543.         pop     esi
  544.         call    print_text2
  545.  
  546.         mov     esi, str_newline
  547.         call    print_text2
  548.  
  549. ;;; TODO: inc [window.users], add username to the userlist
  550.  
  551.         ret
  552.  
  553.  
  554.  
  555.  
  556. cmd_nick:
  557.  
  558.         add     esi, 5  ; skip 'NICK '
  559.  
  560.         push    esi
  561. ; Is it me who changed nick?
  562.         mov     edi, servercommand+1
  563.         call    compare_to_nick
  564.         jne     .not_me
  565.  
  566.         mov     ecx, MAX_NICK_LEN-1
  567.         push    esi
  568.   .copyloop:
  569.         lodsb
  570.         test    al, al
  571.         jz      .copydone
  572.         cmp     al, ' '
  573.         je      .copydone
  574.         stosb
  575.         dec     ecx
  576.         jnz     .copyloop
  577.   .copydone:
  578.         xor     al, al
  579.         stosb
  580.         pop     esi
  581.  
  582.   .not_me:
  583.  
  584. ; TODO: if we reach here: change nick in userlist(s)
  585.  
  586.         push    esi
  587.         mov     esi, action_header_short
  588.         call    print_text2
  589.  
  590.         mov     eax, servercommand+1
  591.         mov     dl, '!'
  592.         call    print_text
  593.  
  594.         mov     esi, is_now_known_as
  595.         call    print_text2
  596.  
  597.         pop     esi
  598.         call    print_text2
  599.  
  600.         mov     esi, str_newline
  601.         call    print_text2
  602.  
  603.         ret
  604.  
  605.  
  606.  
  607.  
  608. cmd_kick:
  609.         add     esi, 5  ; skip 'KICK '
  610. ; Is it me who got kicked?
  611.         mov     edi, servercommand+1
  612.         call    compare_to_nick
  613.         jne     .not_me
  614.  
  615. ; TODO: mark channel as disconnected
  616.  
  617.   .not_me:
  618. ; find the channel user has been kicked from
  619.         push    esi
  620.         mov     esi, action_header_short
  621.         call    print_text2
  622.  
  623.         mov     eax, servercommand+1
  624.         mov     dl, '!'
  625.         call    print_text
  626.  
  627.         mov     esi, kicked
  628.         call    print_text2
  629.  
  630.         pop     esi
  631.         call    print_text2
  632.  
  633.         mov     esi, str_newline
  634.         call    print_text2
  635.  
  636. ;;; TODO: dec [window.users], remove username from the userlist
  637.  
  638.         ret
  639.  
  640.  
  641.  
  642. cmd_quit:
  643.  
  644.         mov     esi, action_header
  645.         call    print_text2
  646.  
  647.         mov     eax, servercommand+1
  648.         mov     dl, '!'
  649.         call    print_text
  650.  
  651.         mov     esi, has_quit_irc
  652.         call    print_text2
  653.  
  654. ;;; TODO: dec [window.users], remove username from the userlist
  655.  
  656.         ret
  657.  
  658.  
  659.  
  660. cmd_mode:
  661.  
  662.         add     esi, 5  ; skip 'MODE '
  663.  
  664.         push    esi
  665.         mov     esi, action_header_short
  666.         call    print_text2
  667.  
  668.         mov     eax, servercommand+1
  669.         mov     dl, ' '
  670.         call    print_text
  671.  
  672.         mov     esi, sets_mode
  673.         call    print_text2
  674.  
  675.         pop     esi
  676.         call    print_text2
  677.  
  678.         mov     esi, str_newline
  679.         call    print_text2
  680.  
  681. ;;; TODO: change username if needed
  682.  
  683.         ret
  684.  
  685.  
  686. cmd_353:        ; channel usernames reply
  687.  
  688.         add     esi, 4  ; skip '353 '
  689.  
  690. ; first, find the channel name
  691.   .loop1:
  692.         lodsb
  693.         cmp     al, '#'
  694.         je      .got_channel
  695.         test    al, al
  696.         jnz     .loop1
  697.         ret
  698.  
  699.   .got_channel:
  700.  
  701. ; now find the semicolon separating channelname and usernames
  702.   .loop2:
  703.         lodsb
  704.         cmp     al, ':'
  705.         je      .got_list
  706.         test    al, al
  707.         jnz     .loop2
  708.         ret
  709.  
  710.   .got_list:
  711.  
  712. ; now find window ptr and check if this is the first 353 message
  713.         mov     ebx, [window_print]
  714.         test    [ebx + window.flags], FLAG_RECEIVING_NAMES
  715.         jnz     .start
  716.  
  717.         or      [ebx + window.flags], FLAG_RECEIVING_NAMES
  718.         mov     [ebx + window.users], 0
  719.  
  720.   .start:
  721.         mov     eax, [ebx + window.users]
  722.         xor     edx, edx
  723.         mov     ecx, MAX_NICK_LEN
  724.         mul     ecx
  725.         ; eax is now offset
  726.         add     eax, [ebx + window.data_ptr]
  727.         lea     edi, [eax + window_data.names]
  728.         mov     edx, edi
  729.  
  730.         lea     ecx, [eax + window_data.names]
  731.         add     ecx, MAX_NICK_LEN + MAX_USERS
  732.  
  733.   .newname:
  734.         cmp     edi, ecx                ; check buffer overflow
  735.         jae     .done
  736.         inc     [ebx + window.users]
  737.   .namesloop:
  738.         lodsb
  739.         test    al, al
  740.         jz      .done
  741.         cmp     al, ' '                 ; names list is separated with spaces
  742.         je      .next
  743.         stosb
  744.         jmp     .namesloop
  745.   .next:
  746.         add     edx, MAX_NICK_LEN
  747.         mov     edi, edx
  748.   .loop3:
  749.         lodsb
  750.         test    al, al
  751.         jz      .done
  752.         cmp     al, ' '
  753.         je      .loop3
  754.         stosb
  755.         jmp     .newname
  756.  
  757.   .done:
  758.         call    redraw_channel_list
  759.  
  760.         ret
  761.  
  762.  
  763.  
  764.  
  765.  
  766. cmd_366:        ; channel usernames end
  767.  
  768.         mov     ebx, [window_print]
  769.         and     [ebx + window.flags], not FLAG_RECEIVING_NAMES
  770.  
  771.  
  772.         ret
  773.  
  774.  
  775. cmd_topic:
  776.  
  777.         add     esi, 4  ; skip '332 '
  778.  
  779.   .loop:
  780.         lodsb
  781.         test    al, al
  782.         je      .fail
  783.         cmp     al, ':'
  784.         jne     .loop
  785.  
  786.         push    esi
  787.         mov     esi, action_header
  788.         call    print_text2
  789.  
  790.         mov     esi, str_topic
  791.         call    print_text2
  792.  
  793.         pop     esi
  794.         call    print_text2
  795.  
  796.         mov     esi, str_newline
  797.         call    print_text2
  798.  
  799.   .fail:
  800.         ret
  801.  
  802.  
  803. cmd_333:
  804.  
  805.         add     esi, 4  ; skip '333 '
  806.  
  807. ; TODO: check channelname and change pointer accordingly
  808.  
  809.         mov     ecx, 3  ; number of spaces to find
  810.   .loop:
  811.         lodsb
  812.         test    al, al
  813.         je      .fail
  814.         cmp     al, ' '
  815.         jne     .loop
  816.         dec     ecx
  817.         jnz     .loop   ; find some more spaces
  818.  
  819.         push    esi
  820.         mov     esi, action_header
  821.         call    print_text2
  822.  
  823.         mov     esi, str_setby
  824.         call    print_text2
  825.  
  826.         pop     esi
  827.         call    print_text2
  828.  
  829.         mov     esi, str_newline
  830.         call    print_text2
  831.  
  832.   .fail:
  833.         ret
  834.  
  835.