Subversion Repositories Kolibri OS

Rev

Rev 4710 | Rev 6023 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;   Written by hidnplayr@kolibrios.org                            ;;
  7. ;;                                                                 ;;
  8. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  9. ;;          Version 2, June 1991                                   ;;
  10. ;;                                                                 ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13.  
  14. user_parser:
  15.  
  16.         mov     ebp, [window_active]   ; print to the current window
  17.         mov     [window_print], ebp
  18.  
  19.         mov     eax, [edit1.size]
  20.         test    eax, eax
  21.         jz      .ret                                    ; ignore empty commands
  22.         mov     word[usercommand + eax], 0x0a0d         ; terminate the line
  23.  
  24.         cmp     byte[usercommand], '/'                  ; is it a server command ?
  25.         je      .command
  26.  
  27.         cmp     [status], STATUS_CONNECTED
  28.         jne     .not_connected
  29.  
  30.         cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
  31.         je      .send_privmsg
  32.         cmp     [ebp + window.type], WINDOWTYPE_CHAT
  33.         jne     .not_channel
  34.  
  35.   .send_privmsg:
  36.         if TIMESTAMP
  37.         call    print_timestamp
  38.         end if
  39.  
  40.         mov     al, '<'
  41.         call    print_char
  42.  
  43.         mov     esi, user_nick
  44.         call    print_asciiz
  45.  
  46.         mov     al, '>'
  47.         call    print_char
  48.         mov     al, ' '
  49.         call    print_char
  50.  
  51.         mov     eax, [edit1.size]
  52.         mov     byte[usercommand + eax],0
  53.  
  54.         mov     esi, usercommand
  55.         call    print_asciiz
  56.  
  57.         mov     al, 10
  58.         call    print_char
  59.  
  60. ; and now send it to the server
  61.         mov     dword[packetbuf], 'PRIV'
  62.         mov     dword[packetbuf+4], 'MSG '
  63.  
  64.         lea     esi, [ebp + window.name]
  65.         mov     edi, packetbuf+8
  66.         mov     ecx, MAX_WINDOWNAME_LEN
  67.   .loop:
  68.         lodsb
  69.         test    al, al
  70.         jz      .done
  71.         stosb
  72.         dec     ecx
  73.         jnz     .loop
  74.   .done:
  75.  
  76.         mov     ax, ' :'
  77.         stosw
  78.  
  79.         mov     esi, usercommand
  80.         mov     ecx, [edit1.size]
  81.         inc     ecx
  82.         call    recode
  83.  
  84. ; end the command with a CRLF
  85.         mov     ax, 0x0a0d
  86.         stosw
  87.  
  88.         lea     esi, [edi - packetbuf]
  89.         mcall   send, [socketnum], packetbuf, , 0
  90.  
  91.   .ret:
  92.         ret
  93.  
  94. ; Text begins with a '/' lets try to find the command in the lookup table.
  95.   .command:
  96.         mov     eax, dword[usercommand+1]       ; skip '/'
  97.         or      eax, 0x20202020                 ; convert to lowercase
  98.  
  99.         mov     edi, user_commands
  100.         mov     ecx, user_commands.number
  101.         cmp     [status], STATUS_CONNECTED
  102.         je      .cmd_loop
  103.         mov     ecx, user_commands.number2
  104.   .cmd_loop:
  105.         scasd
  106.         je      .got_cmd
  107.         add     edi, 4
  108.         dec     ecx
  109.         jnz     .cmd_loop
  110.  
  111.         cmp     [status], STATUS_CONNECTED
  112.         jne     .not_connected
  113.  
  114. ; Commands shorter then 3 chars are placed here
  115.         and     eax, 0x00ffffff
  116.         cmp     eax, 'me '
  117.         je      cmd_usr_me
  118.  
  119. ; If none of the listed commands, send text straight to server
  120.         jmp     cmd_usr_send
  121.  
  122.   .got_cmd:
  123.         jmp     dword[edi]
  124.  
  125.   .not_connected:
  126.         mov     esi, str_notconnected
  127.         call    print_asciiz
  128.         ret
  129.  
  130.   .not_channel:
  131.         mov     esi, str_notchannel
  132.         call    print_asciiz
  133.         ret
  134.  
  135.  
  136. ; user commands lookup table
  137. user_commands:
  138.         dd      'nick', cmd_usr_nick
  139.         dd      'real', cmd_usr_real
  140.         dd      'serv', cmd_usr_server
  141.         dd      'help', cmd_usr_help
  142.         dd      'code', cmd_usr_code
  143.  
  144.         .number2 = ($ - user_commands) / 8
  145.  
  146. ; All following commands require a connection to the server.
  147.         dd      'quer', cmd_usr_quer
  148.         dd      'quit', cmd_usr_quit
  149.         dd      'part', cmd_usr_part
  150.         dd      'ctcp', cmd_usr_ctcp
  151.         dd      'msg ', cmd_usr_msg
  152.  
  153.         .number = ($ - user_commands) / 8
  154.  
  155.  
  156.  
  157. cmd_usr_msg:
  158.  
  159.         lea     esi, [usercommand+5]
  160.  
  161.         mov     dword[packetbuf], 'PRIV'
  162.         mov     dword[packetbuf+4], 'MSG '
  163.         lea     edi, [packetbuf+8]
  164.  
  165.   @@:
  166.         lodsb
  167.         test    al, al
  168.         jz      .fail
  169.         cmp     al, 10
  170.         je      .fail
  171.         cmp     al, 13
  172.         je      .fail
  173.         stosb
  174.         cmp     al, ' '
  175.         jne     @r
  176.  
  177.         mov     al, ':'
  178.         stosb
  179.  
  180.         push    edi
  181.   @@:
  182.         lodsb
  183.         test    al, al
  184.         jz      @f
  185.         cmp     al, 10
  186.         je      @f
  187.         cmp     al, 13
  188.         je      @f
  189.         stosb
  190.         jmp     @r
  191.   @@:
  192. ; end the command with a CRLF
  193.         mov     ax, 0x0a0d
  194.         stosw
  195.         mov     byte[edi], 0
  196.  
  197.         lea     esi, [edi - packetbuf]
  198.         mcall   send, [socketnum], packetbuf, , 0
  199.  
  200. ; now print to the window
  201.         if TIMESTAMP
  202.         call    print_timestamp
  203.         end if
  204.  
  205.         mov     esi, msg_header
  206.         call    print_asciiz
  207.  
  208.         mov     esi, packetbuf+8
  209.         mov     bl, ' '
  210.         call    print_string
  211.  
  212.         mov     al, '*'
  213.         call    print_char
  214.  
  215.         mov     al, ' '
  216.         call    print_char
  217.  
  218.         pop     esi
  219.         call    print_asciiz
  220.  
  221.   .fail:
  222.         ret
  223.  
  224.  
  225.  
  226. cmd_usr_quit:
  227.  
  228.         mov     esi, quit_msg
  229.         cmp     byte[usercommand+5], ' '
  230.         jne     quit_server
  231.         lea     esi, [usercommand+6]
  232.  
  233. ; esi = quit message
  234. quit_server:
  235.  
  236. ; User wants to close a channel, send PART command to server
  237.         mov     dword[packetbuf], 'QUIT'
  238.         mov     word[packetbuf+4], ' :'
  239.         lea     edi, [packetbuf+6]
  240. ; Append our quit msg
  241.   @@:
  242.         lodsb
  243.         cmp     al, 13
  244.         je      @f
  245.         test    al, al
  246.         jz      @f
  247.         stosb
  248.         jmp     @r
  249.   @@:
  250. ; end the command with a CRLF
  251.         mov     ax, 0x0a0d
  252.         stosw
  253.  
  254.         lea     esi, [edi - packetbuf]                  ; calculate length
  255.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  256.  
  257.         mov     ebp, windows
  258.   .window_loop:
  259.         cmp     [ebp + window.type], WINDOWTYPE_NONE
  260.         je      .next_window
  261.         mov     [window_print], ebp
  262.         if TIMESTAMP
  263.         call    print_timestamp
  264.         end if
  265.         mov     esi, str_disconnected
  266.         call    print_asciiz
  267.         cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
  268.         jne     .next_window
  269.         call    user_remove_all
  270.   .next_window:
  271.         add     ebp, sizeof.window
  272.         cmp     ebp, windows + (MAX_WINDOWS * sizeof.window)
  273.         jb      .window_loop
  274.  
  275.         mov     [status], STATUS_DISCONNECTED
  276.         mcall   close, [socketnum]
  277.  
  278.         ret
  279.  
  280.  
  281.  
  282.  
  283. cmd_usr_nick:
  284.  
  285.         cmp     [edit1.size], 5
  286.         je      .justprint
  287.         cmp     byte[usercommand+5], ' '
  288.         jne     .fail
  289.         cmp     [socketnum], 0
  290.         je      .dontsend
  291.  
  292. ; Request nickname change to server
  293.         mov     dword[usercommand+1], 'NICK'
  294.         mov     esi, [edit1.size]
  295.         mov     word[usercommand + esi], 0x0a0d
  296.         inc     esi
  297.         mcall   send, [socketnum], usercommand+1, , 0
  298.  
  299.   .fail:
  300.         ret
  301.  
  302. ; We arent logged in yet, directly change user_nick field and print notification to user.
  303.   .dontsend:
  304.         mov     ecx, MAX_NICK_LEN
  305.         mov     esi, usercommand+6
  306.         mov     edi, user_nick
  307.   @@:
  308.         lodsb
  309.         cmp     al, 13
  310.         je      @f
  311.         stosb
  312.         dec     ecx
  313.         jnz     @r
  314.   @@:
  315.         xor     al, al
  316.         stosb
  317.  
  318.   .justprint:
  319.         mov     esi, str_nickchange
  320.         call    print_asciiz
  321.  
  322.         mov     esi, user_nick
  323.         call    print_asciiz
  324.  
  325.         mov     al, 10
  326.         call    print_char
  327.  
  328.         ret
  329.  
  330.  
  331.  
  332. cmd_usr_real:
  333.  
  334.         cmp     byte[usercommand+5], ' '
  335.         jne     cmd_usr_send
  336.  
  337.         mov     ecx, MAX_REAL_LEN
  338.         mov     esi, usercommand+6
  339.         mov     edi, user_real_name
  340.   .loop:
  341.         lodsb
  342.         cmp     al, 13
  343.         je      .done
  344.         stosb
  345.         dec     ecx
  346.         jnz     .loop
  347.   .done:
  348.         xor     al, al
  349.         stosb
  350.  
  351.         mov     esi, str_realchange
  352.         call    print_asciiz
  353.  
  354.         mov     esi, user_real_name
  355.         call    print_asciiz
  356.  
  357.         mov     al, 10
  358.         call    print_char
  359.  
  360.         ret
  361.  
  362.  
  363.  
  364. cmd_usr_server:
  365.  
  366.         mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
  367.         or      eax, 0x00002020
  368.         and     eax, 0x00ffffff
  369.         cmp     eax, 'er '
  370.         jne     cmd_usr_send
  371.  
  372. ; Server window is always first window in the list, switch to it.
  373.         mov     [window_print], windows
  374.         mov     [window_active], windows
  375.  
  376.         mov     ecx, [edit1.size]               ; ok now set the address
  377.         sub     ecx, 8
  378.  
  379.         mov     esi, usercommand+8
  380.   .now:
  381.         push    esi
  382.         mov     edi, irc_server_name
  383.   .loop:                                        ; copy until zero byte, or ecx reaches zero.
  384.         lodsb
  385.         stosb
  386.         test    al, al
  387.         jz      .done
  388.         dec     ecx
  389.         jnz     .loop
  390.         xor     al, al
  391.         stosb
  392.   .done:
  393.         pop     esi
  394.  
  395. ; set it also in window name
  396.         mov     ebx, [window_print]
  397.         call    window_set_name
  398.  
  399. ; now connect
  400.         call    socket_connect
  401.  
  402.         ret
  403.  
  404.  
  405. cmd_usr_quer:
  406.  
  407.         mov     esi, usercommand+7
  408.         call    window_open
  409. ;        test    ebx, ebx
  410. ;        jz      .fail
  411.  
  412.         ret
  413.  
  414.  
  415.  
  416. cmd_usr_help:
  417.  
  418.         mov     esi, str_help
  419.         call    print_asciiz
  420.  
  421.         ret
  422.  
  423.  
  424.  
  425. cmd_usr_code:
  426.  
  427.         ; TODO
  428.  
  429.         ret
  430.  
  431.  
  432.  
  433. ; User typed a part command
  434. cmd_usr_part:
  435.  
  436.         cmp     byte[usercommand+5], 13         ; parameters given?
  437.         jne     cmd_usr_send                    ; yes, send command straight to server
  438.  
  439. ; close active window
  440. cmd_usr_close_window:
  441.  
  442.         mov     esi, [window_active]
  443.         cmp     [esi + window.type], WINDOWTYPE_SERVER
  444.         je      .not_channel
  445.  
  446.         lea     esi, [esi + window.name]
  447.         call    cmd_usr_part_channel
  448.         call    window_close
  449.         ret
  450.  
  451.   .not_channel:
  452.         cmp     [esi + window.type], WINDOWTYPE_CHAT
  453.         jne     .not_chat
  454.  
  455.         call    window_close
  456.   .not_chat:
  457.  
  458.         ret
  459.  
  460.  
  461.  
  462. ; Send part command to server
  463. ; esi must point to channel name (ASCIIZ)
  464. cmd_usr_part_channel:
  465.  
  466. ; User wants to close a channel, send PART command to server
  467.         mov     dword[packetbuf], 'PART'
  468.         mov     byte[packetbuf+4], ' '
  469.         lea     edi, [packetbuf+5]
  470.   @@:
  471.         lodsb
  472.         test    al, al
  473.         jz      @f
  474.         cmp     al, 13
  475.         je      @f
  476.         cmp     al, 10
  477.         je      @f
  478.         stosb
  479.         jmp     @r
  480.   @@:
  481. ; end the command with a CRLF
  482.         mov     ax, 0x0a0d
  483.         stosw
  484.  
  485.         lea     esi, [edi - packetbuf]                  ; calculate length
  486.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  487.  
  488.         ret
  489.  
  490.  
  491.  
  492. cmd_usr_ctcp:
  493.  
  494.         cmp     byte[usercommand+5], ' '
  495.         jne     cmd_usr_send
  496.  
  497.         mov     esi, usercommand+6
  498. ; prepare a 'PRIVMSG '
  499.         mov     dword[packetbuf], 'PRIV'
  500.         mov     dword[packetbuf+4], 'MSG '
  501.         lea     edi, [packetbuf+8]
  502.  
  503. ; append the destination (nickname/channel)
  504.   @@:
  505.         lodsb
  506.         test    al, al
  507.         jz      .fail
  508.         cmp     al, ' '
  509.         je      @f
  510.         stosb
  511.         jmp     @r
  512.   @@:
  513.  
  514.         mov     ax, ' :'
  515.         stosw
  516.         mov     al, 0x01
  517.         stosb
  518.  
  519. ; copy the message itself
  520.   @@:
  521.         lodsb
  522.         test    al, al
  523.         jz      @f
  524.         cmp     al, 13
  525.         je      @f
  526.         cmp     al, 10
  527.         je      @f
  528.         stosb
  529.         jmp     @r
  530.   @@:
  531.  
  532. ; end of message
  533.         mov     al, 0x01
  534.         stosb
  535.         mov     ax, 0x0a0d
  536.         stosw
  537.  
  538. ; now send it away
  539.         lea     esi, [edi - packetbuf]                  ; calculate length
  540.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  541.  
  542. ;; TODO: print to window
  543.  
  544.   .fail:
  545.  
  546.         ret
  547.  
  548.  
  549.  
  550. cmd_usr_me:
  551.  
  552. ; prepare a 'PRIVMSG '
  553.         mov     dword[packetbuf], 'PRIV'
  554.         mov     dword[packetbuf+4], 'MSG '
  555.         lea     edi, [packetbuf+8]
  556.  
  557. ; append the destination (nickname/channel)
  558.         mov     esi, [window_active]
  559.         lea     esi, [esi + window.name]
  560.   @@:
  561.         lodsb
  562.         test    al, al
  563.         je      @f
  564.         stosb
  565.         jmp     @r
  566.   @@:
  567.  
  568. ; Make the CTCP action header
  569.         mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
  570.         stosd
  571.         mov     eax, 'CTIO'
  572.         stosd
  573.         mov     al, 'N'
  574.         stosb
  575.  
  576. ; copy the message itself (including first space)
  577.         mov     esi, usercommand+3
  578.   @@:
  579.         lodsb
  580.         cmp     al, 13
  581.         je      @f
  582.         stosb
  583.         jmp     @r
  584.   @@:
  585.  
  586. ; end of CTCP message
  587.         mov     al, 0x01
  588.         stosb
  589.         mov     ax, 0x0a0d
  590.         stosw
  591.  
  592. ; now send it to the server
  593.         lea     esi, [edi - packetbuf]                  ; calculate length
  594.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  595.  
  596. ; print to local window
  597.         if TIMESTAMP
  598.         call    print_timestamp
  599.         end if
  600.  
  601.         mov     esi, action_header
  602.         call    print_asciiz
  603.  
  604.         mov     esi, user_nick
  605.         call    print_asciiz
  606.  
  607.         mov     esi, usercommand+3
  608.         mov     bl, 13
  609.         call    print_string
  610.  
  611.         mov     al, 10
  612.         call    print_char
  613.  
  614.         ret
  615.  
  616.  
  617.  
  618. ; The user typed some undefined command, just recode it and send to the server
  619. cmd_usr_send:
  620.  
  621.         mov     esi, usercommand+1
  622.         mov     ecx, [edit1.size]
  623.         inc     ecx
  624.         mov     edi, packetbuf
  625.         call    recode
  626.  
  627.         lea     esi, [edi - packetbuf]
  628.         mcall   send, [socketnum], packetbuf, , 0
  629.  
  630.         ret
  631.  
  632.  
  633.  
  634.  
  635.  
  636.