Subversion Repositories Kolibri OS

Rev

Rev 4623 | Rev 4710 | 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.         push    [window_active]   ; print to the current window
  17.         pop     [window_print]
  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      server_command
  26.  
  27. ; Ignore data commands when not connected.
  28.         cmp     [status], STATUS_CONNECTED
  29.         jne     .notconnected
  30.  
  31. ; Ok, we said something, print it to our textbox
  32. ; TODO: dont send if it's a server window?
  33.  
  34.         if TIMESTAMP
  35.         call    print_timestamp
  36.         end if
  37.  
  38.         mov     al, '<'
  39.         call    print_char
  40.  
  41.         mov     esi, user_nick
  42.         call    print_asciiz
  43.  
  44.         mov     al, '>'
  45.         call    print_char
  46.         mov     al, ' '
  47.         call    print_char
  48.  
  49.         mov     eax, [edit1.size]
  50.         mov     byte[usercommand + eax],0
  51.  
  52.         mov     esi, usercommand
  53.         call    print_asciiz
  54.  
  55.         mov     al, 10
  56.         call    print_char
  57.  
  58. ; and now send it to the server
  59.         mov     dword[packetbuf], 'PRIV'
  60.         mov     dword[packetbuf+4], 'MSG '
  61.  
  62.         mov     esi, [window_active]
  63.         add     esi, window.name
  64.         mov     edi, packetbuf+8
  65.         mov     ecx, MAX_WINDOWNAME_LEN
  66.   .loop:
  67.         lodsb
  68.         test    al, al
  69.         jz      .done
  70.         stosb
  71.         dec     ecx
  72.         jnz     .loop
  73.   .done:
  74.  
  75.         mov     ax, ' :'
  76.         stosw
  77.  
  78.         mov     esi, usercommand
  79.         mov     ecx, [edit1.size]
  80.         inc     ecx
  81.         call    recode
  82.  
  83. ; end the command with a CRLF
  84.         mov     ax, 0x0a0d
  85.         stosw
  86.  
  87.         lea     esi, [edi - packetbuf]
  88.         mcall   send, [socketnum], packetbuf, , 0
  89.   .ret:
  90.  
  91.         ret
  92.  
  93.   .notconnected:
  94.         mov     esi, str_notconnected
  95.         call    print_asciiz
  96.  
  97.         ret
  98.  
  99.  
  100.  
  101. user_commands:
  102.         dd      'nick', cmd_usr_nick
  103.         dd      'real', cmd_usr_real
  104.         dd      'serv', cmd_usr_server
  105.         dd      'help', cmd_usr_help
  106.         dd      'code', cmd_usr_code
  107.  
  108.         .number2 = ($ - user_commands) / 8
  109.  
  110. ; All following commands require a connection to the server.
  111.         dd      'quer', cmd_usr_quer
  112.         dd      'quit', cmd_usr_quit
  113.         dd      'part', cmd_usr_part
  114.         dd      'ctcp', cmd_usr_ctcp
  115.         dd      'msg ', cmd_usr_msg
  116.  
  117.         .number = ($ - user_commands) / 8
  118.  
  119.  
  120. server_command:
  121.  
  122.         mov     eax, dword[usercommand+1]       ; skip '/'
  123.         or      eax, 0x20202020                 ; convert to lowercase
  124.  
  125.         mov     edi, user_commands
  126.         mov     ecx, user_commands.number
  127.         cmp     [status], STATUS_CONNECTED
  128.         je      .loop
  129.         mov     ecx, user_commands.number2
  130.   .loop:
  131.         scasd
  132.         je      .got_cmd
  133.         add     edi, 4
  134.         dec     ecx
  135.         jnz     .loop
  136.  
  137.         cmp     [status], STATUS_CONNECTED
  138.         jne     .notconnected
  139. ; Commands shorter then 3 chars are placed here
  140.         and     eax, 0x00ffffff
  141.         cmp     eax, 'me '
  142.         je      cmd_usr_me
  143.  
  144.         jmp     cmd_usr_send                    ; If none of the previous commands, just send to server
  145.  
  146.   .got_cmd:
  147.         jmp     dword[edi]
  148.  
  149.   .notconnected:
  150.         mov     esi, str_notconnected
  151.         call    print_asciiz
  152.  
  153.         ret
  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.         mov     esi, quit_msg
  228.  
  229.         cmp     byte[usercommand+5], ' '
  230.         jne     .with_message
  231.         lea     esi, [usercommand+6]
  232.   .with_message:
  233.         call    cmd_usr_quit_server
  234.  
  235.         mcall   close, [socketnum]
  236.         mov     [status], STATUS_DISCONNECTED
  237.  
  238.         mov     ecx, MAX_WINDOWS
  239.         mov     edi, windows
  240.   .loop:
  241.         mov     [window_print], edi
  242.         push    edi ecx
  243.         call    window_close
  244.         pop     ecx edi
  245.         add     edi, sizeof.window
  246.         dec     ecx
  247.         jnz     .loop
  248.  
  249.         ret
  250.  
  251.  
  252.  
  253. ; esi = quit message
  254. cmd_usr_quit_server:
  255.  
  256. ; User wants to close a channel, send PART command to server
  257.         mov     dword[packetbuf], 'QUIT'
  258.         mov     word[packetbuf+4], ' :'
  259.         lea     edi, [packetbuf+6]
  260. ; Append our quit msg
  261.   @@:
  262.         lodsb
  263.         cmp     al, 13
  264.         je      @f
  265.         test    al, al
  266.         jz      @f
  267.         stosb
  268.         jmp     @r
  269.   @@:
  270. ; end the command with a CRLF
  271.         mov     ax, 0x0a0d
  272.         stosw
  273.  
  274.         lea     esi, [edi - packetbuf]                  ; calculate length
  275.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  276.  
  277.         ret
  278.  
  279.  
  280.  
  281.  
  282. cmd_usr_nick:
  283.  
  284.         cmp     [edit1.size], 5
  285.         je      .dontsend
  286.         cmp     byte[usercommand+5], ' '
  287.         jne     .fail
  288.         cmp     [socketnum], 0
  289.         je      .dontsend
  290.  
  291. ; Request nickname change to server
  292.         mov     dword[usercommand+1], 'NICK'
  293.         mov     esi, [edit1.size]
  294.         mov     word[usercommand + esi], 0x0a0d
  295.         inc     esi
  296.         mcall   send, [socketnum], usercommand+1, , 0
  297.  
  298.   .fail:
  299.  
  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.         mov     esi, str_nickchange
  319.         call    print_asciiz
  320.  
  321.         mov     esi, user_nick
  322.         call    print_asciiz
  323.  
  324.         mov     al, 10
  325.         call    print_char
  326.  
  327.         ret
  328.  
  329.  
  330.  
  331. cmd_usr_real:
  332.  
  333.         cmp     byte[usercommand+5], ' '
  334.         jne     cmd_usr_send
  335.  
  336.         mov     ecx, MAX_REAL_LEN
  337.         mov     esi, usercommand+6
  338.         mov     edi, user_real_name
  339.   .loop:
  340.         lodsb
  341.         cmp     al, 13
  342.         je      .done
  343.         stosb
  344.         dec     ecx
  345.         jnz     .loop
  346.   .done:
  347.         xor     al, al
  348.         stosb
  349.  
  350.         mov     esi, str_realchange
  351.         call    print_asciiz
  352.  
  353.         mov     esi, user_real_name
  354.         call    print_asciiz
  355.  
  356.         mov     al, 10
  357.         call    print_char
  358.  
  359.         ret
  360.  
  361.  
  362.  
  363. cmd_usr_server:
  364.  
  365.         mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
  366.         or      eax, 0x00002020
  367.         and     eax, 0x00ffffff
  368.         cmp     eax, 'er '
  369.         jne     cmd_usr_send
  370.  
  371.         mov     ecx, [edit1.size]               ; ok now set the address
  372.         sub     ecx, 8
  373.  
  374.         mov     esi, usercommand+8
  375.   .now:
  376.         push    esi
  377.         mov     edi, irc_server_name
  378.   .loop:                                        ; copy until zero byte, or ecx reaches zero.
  379.         lodsb
  380.         stosb
  381.         test    al, al
  382.         jz      .done
  383.         dec     ecx
  384.         jnz     .loop
  385.         xor     al, al
  386.         stosb
  387.   .done:
  388.         pop     esi
  389.  
  390. ; set it also in window name
  391.         mov     ebx, [window_print]
  392.         call    window_set_name
  393.  
  394. ; now connect
  395.         call    socket_connect
  396.  
  397.         ret
  398.  
  399.  
  400. cmd_usr_quer:
  401.  
  402.         mov     esi, usercommand+7
  403.         call    window_open
  404. ;        test    ebx, ebx
  405. ;        jz      .fail
  406.  
  407.         ret
  408.  
  409.  
  410.  
  411. cmd_usr_help:
  412.  
  413.         mov     esi, str_help
  414.         call    print_asciiz
  415.  
  416.         ret
  417.  
  418.  
  419.  
  420. cmd_usr_code:
  421.  
  422.         ; TODO
  423.  
  424.         ret
  425.  
  426.  
  427.  
  428. ; User typed a part command
  429. cmd_usr_part:
  430.  
  431.         cmp     byte[usercommand+5], 13         ; parameters given?
  432.         jne     cmd_usr_send                    ; yes, send command straight to server
  433.  
  434. ; close active window
  435. cmd_usr_close_window:
  436.  
  437.         mov     esi, [window_active]
  438.         cmp     [esi + window.type], WINDOWTYPE_SERVER
  439.         je      .not_channel
  440.  
  441.         lea     esi, [esi + window.name]
  442.         call    cmd_usr_part_channel
  443.         call    window_close
  444.         ret
  445.  
  446.   .not_channel:
  447.         cmp     [esi + window.type], WINDOWTYPE_CHAT
  448.         jne     .not_chat
  449.  
  450.         call    window_close
  451.   .not_chat:
  452.  
  453.         ret
  454.  
  455.  
  456.  
  457. ; Send part command to server
  458. ; esi must point to channel name (ASCIIZ)
  459. cmd_usr_part_channel:
  460.  
  461. ; User wants to close a channel, send PART command to server
  462.         mov     dword[packetbuf], 'PART'
  463.         mov     byte[packetbuf+4], ' '
  464.         lea     edi, [packetbuf+5]
  465.   @@:
  466.         lodsb
  467.         test    al, al
  468.         jz      @f
  469.         cmp     al, 13
  470.         je      @f
  471.         cmp     al, 10
  472.         je      @f
  473.         stosb
  474.         jmp     @r
  475.   @@:
  476. ; end the command with a CRLF
  477.         mov     ax, 0x0a0d
  478.         stosw
  479.  
  480.         lea     esi, [edi - packetbuf]                  ; calculate length
  481.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  482.  
  483.         ret
  484.  
  485.  
  486.  
  487. cmd_usr_ctcp:
  488.  
  489.         cmp     byte[usercommand+5], ' '
  490.         jne     cmd_usr_send
  491.  
  492.         mov     esi, usercommand+6
  493. ; prepare a 'PRIVMSG '
  494.         mov     dword[packetbuf], 'PRIV'
  495.         mov     dword[packetbuf+4], 'MSG '
  496.         lea     edi, [packetbuf+8]
  497.  
  498. ; append the destination (nickname/channel)
  499.   @@:
  500.         lodsb
  501.         test    al, al
  502.         jz      .fail
  503.         cmp     al, ' '
  504.         je      @f
  505.         stosb
  506.         jmp     @r
  507.   @@:
  508.  
  509.         mov     ax, ' :'
  510.         stosw
  511.         mov     al, 0x01
  512.         stosb
  513.  
  514. ; copy the message itself
  515.   @@:
  516.         lodsb
  517.         test    al, al
  518.         jz      @f
  519.         cmp     al, 13
  520.         je      @f
  521.         cmp     al, 10
  522.         je      @f
  523.         stosb
  524.         jmp     @r
  525.   @@:
  526.  
  527. ; end of message
  528.         mov     al, 0x01
  529.         stosb
  530.         mov     ax, 0x0a0d
  531.         stosw
  532.  
  533. ; now send it away
  534.         lea     esi, [edi - packetbuf]                  ; calculate length
  535.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  536.  
  537. ;; TODO: print to window
  538.  
  539.   .fail:
  540.  
  541.         ret
  542.  
  543.  
  544.  
  545. cmd_usr_me:
  546.  
  547. ; prepare a 'PRIVMSG '
  548.         mov     dword[packetbuf], 'PRIV'
  549.         mov     dword[packetbuf+4], 'MSG '
  550.         lea     edi, [packetbuf+8]
  551.  
  552. ; append the destination (nickname/channel)
  553.         mov     esi, [window_active]
  554.         lea     esi, [esi + window.name]
  555.   @@:
  556.         lodsb
  557.         test    al, al
  558.         je      @f
  559.         stosb
  560.         jmp     @r
  561.   @@:
  562.  
  563. ; Make the CTCP action header
  564.         mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
  565.         stosd
  566.         mov     eax, 'CTIO'
  567.         stosd
  568.         mov     al, 'N'
  569.         stosb
  570.  
  571. ; copy the message itself (including first space)
  572.         mov     esi, usercommand+3
  573.   @@:
  574.         lodsb
  575.         cmp     al, 13
  576.         je      @f
  577.         stosb
  578.         jmp     @r
  579.   @@:
  580.  
  581. ; end of CTCP message
  582.         mov     al, 0x01
  583.         stosb
  584.         mov     ax, 0x0a0d
  585.         stosw
  586.  
  587. ; now send it to the server
  588.         lea     esi, [edi - packetbuf]                  ; calculate length
  589.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  590.  
  591. ; print to local window
  592.         if TIMESTAMP
  593.         call    print_timestamp
  594.         end if
  595.  
  596.         mov     esi, action_header
  597.         call    print_asciiz
  598.  
  599.         mov     esi, user_nick
  600.         call    print_asciiz
  601.  
  602.         mov     esi, usercommand+3
  603.         mov     bl, 13
  604.         call    print_string
  605.  
  606.         mov     al, 10
  607.         call    print_char
  608.  
  609.         ret
  610.  
  611.  
  612.  
  613. ; The user typed some undefined command, just recode it and send to the server
  614. cmd_usr_send:
  615.  
  616.         mov     esi, usercommand+1
  617.         mov     ecx, [edit1.size]
  618.         inc     ecx
  619.         mov     edi, packetbuf
  620.         call    recode
  621.  
  622.         lea     esi, [edi - packetbuf]
  623.         mcall   send, [socketnum], packetbuf, , 0
  624.  
  625.         ret
  626.  
  627.  
  628.  
  629.  
  630.  
  631.