Subversion Repositories Kolibri OS

Rev

Rev 4477 | Rev 4659 | 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     bl, '<'
  39.         call    print_character
  40.  
  41.         mov     esi, user_nick
  42.         call    print_text2
  43.  
  44.         mov     bl, '>'
  45.         call    print_character
  46.         mov     bl, ' '
  47.         call    print_character
  48.  
  49.         mov     eax, [edit1.size]
  50.         mov     byte[usercommand + eax],0
  51.  
  52.         mov     esi, usercommand
  53.         call    print_text2
  54.  
  55.         mov     bl, 10
  56.         call    print_character
  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_text2
  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.  
  121. server_command:
  122.  
  123.         mov     eax, dword[usercommand+1]       ; skip '/'
  124.         or      eax, 0x20202020                 ; convert to lowercase
  125.  
  126.         mov     edi, user_commands
  127.         mov     ecx, user_commands.number
  128.         cmp     [status], STATUS_CONNECTED
  129.         jne     .loop
  130.         mov     ecx, user_commands.number2
  131.   .loop:
  132.         scasd
  133.         je      .got_cmd
  134.         add     edi, 4
  135.         dec     ecx
  136.         jnz     .loop
  137.  
  138.         cmp     [status], STATUS_CONNECTED
  139.         jne     .notconnected
  140.  
  141.         jmp     cmd_usr_send                    ; If none of the previous commands, just send to server
  142.  
  143.   .got_cmd:
  144.         jmp     dword[edi]
  145.  
  146.   .notconnected:
  147.         mov     esi, str_notconnected
  148.         call    print_text2
  149.  
  150.         ret
  151.  
  152.  
  153.  
  154. cmd_usr_msg:
  155.  
  156.         lea     esi, [usercommand+5]
  157.  
  158.         mov     dword[packetbuf], 'PRIV'
  159.         mov     dword[packetbuf+4], 'MSG '
  160.         lea     edi, [packetbuf+8]
  161.  
  162.   @@:
  163.         lodsb
  164.         test    al, al
  165.         jz      .fail
  166.         cmp     al, 10
  167.         je      .fail
  168.         cmp     al, 13
  169.         je      .fail
  170.         stosb
  171.         cmp     al, ' '
  172.         jne     @r
  173.  
  174.         mov     al, ':'
  175.         stosb
  176.  
  177.         push    edi
  178.   @@:
  179.         lodsb
  180.         test    al, al
  181.         jz      @f
  182.         cmp     al, 10
  183.         je      @f
  184.         cmp     al, 13
  185.         je      @f
  186.         stosb
  187.         jmp     @r
  188.   @@:
  189. ; end the command with a CRLF
  190.         mov     ax, 0x0a0d
  191.         stosw
  192.         mov     byte[edi], 0
  193.  
  194.         lea     esi, [edi - packetbuf]
  195.         mcall   send, [socketnum], packetbuf, , 0
  196.  
  197. ; now print to the window
  198.         if TIMESTAMP
  199.         call    print_timestamp
  200.         end if
  201.  
  202.         mov     esi, msg_header
  203.         call    print_text2
  204.  
  205.         mov     eax, packetbuf+8
  206.         mov     dl, ' '
  207.         call    print_text
  208.  
  209.         mov     bl, '*'
  210.         call    print_character
  211.  
  212.         mov     bl, ' '
  213.         call    print_character
  214.  
  215.         pop     esi
  216.         call    print_text2
  217.  
  218.   .fail:
  219.         ret
  220.  
  221.  
  222.  
  223. cmd_usr_quit:
  224.         mov     esi, quit_msg
  225.  
  226.         cmp     byte[usercommand+5], ' '
  227.         jne     .with_message
  228.         lea     esi, [usercommand+6]
  229.   .with_message:
  230.         call    cmd_usr_quit_server
  231.  
  232.         mcall   close, [socketnum]
  233.         mov     [status], STATUS_DISCONNECTED
  234.  
  235.         mov     ecx, MAX_WINDOWS
  236.         mov     edi, windows
  237.   .loop:
  238.         mov     [window_print], edi
  239.         push    edi ecx
  240.         call    window_close
  241.         pop     ecx edi
  242.         add     edi, sizeof.window
  243.         dec     ecx
  244.         jnz     .loop
  245.  
  246.         ret
  247.  
  248.  
  249.  
  250. ; esi = quit message
  251. cmd_usr_quit_server:
  252.  
  253. ; User wants to close a channel, send PART command to server
  254.         mov     dword[packetbuf], 'QUIT'
  255.         mov     word[packetbuf+4], ' :'
  256.         lea     edi, [packetbuf+6]
  257. ; Append our quit msg
  258.   @@:
  259.         lodsb
  260.         cmp     al, 13
  261.         je      @f
  262.         test    al, al
  263.         jz      @f
  264.         stosb
  265.         jmp     @r
  266.   @@:
  267. ; end the command with a CRLF
  268.         mov     ax, 0x0a0d
  269.         stosw
  270.  
  271.         lea     esi, [edi - packetbuf]                  ; calculate length
  272.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  273.  
  274.         ret
  275.  
  276.  
  277.  
  278.  
  279. cmd_usr_nick:
  280.  
  281.         cmp     [edit1.size], 5
  282.         je      .dontsend
  283.         cmp     byte[usercommand+5], ' '
  284.         jne     .fail
  285.         cmp     [socketnum], 0
  286.         je      .dontsend
  287.  
  288. ; Request nickname change to server
  289.         mov     dword[usercommand+1], 'NICK'
  290.         mov     esi, [edit1.size]
  291.         mov     word[usercommand + esi], 0x0a0d
  292.         inc     esi
  293.         mcall   send, [socketnum], usercommand+1, , 0
  294.  
  295.   .fail:
  296.  
  297.         ret
  298.  
  299. ; We arent logged in yet, directly change user_nick field and print notification to user.
  300.   .dontsend:
  301.         mov     ecx, MAX_NICK_LEN
  302.         mov     esi, usercommand+6
  303.         mov     edi, user_nick
  304.   @@:
  305.         lodsb
  306.         cmp     al, 13
  307.         je      @f
  308.         stosb
  309.         dec     ecx
  310.         jnz     @r
  311.   @@:
  312.         xor     al, al
  313.         stosb
  314.  
  315.         mov     esi, str_nickchange
  316.         call    print_text2
  317.         mov     esi, user_nick
  318.         call    print_text2
  319.         mov     esi, str_dotnewline
  320.         call    print_text2
  321.  
  322.         ret
  323.  
  324.  
  325.  
  326. cmd_usr_real:
  327.  
  328.         cmp     byte[usercommand+5], ' '
  329.         jne     cmd_usr_send
  330.  
  331.         mov     ecx, MAX_REAL_LEN
  332.         mov     esi, usercommand+6
  333.         mov     edi, user_real_name
  334.   .loop:
  335.         lodsb
  336.         cmp     al, 13
  337.         je      .done
  338.         stosb
  339.         dec     ecx
  340.         jnz     .loop
  341.   .done:
  342.         xor     al, al
  343.         stosb
  344.  
  345.         mov     esi, str_realchange
  346.         call    print_text2
  347.         mov     esi, user_real_name
  348.         call    print_text2
  349.         mov     esi, str_dotnewline
  350.         call    print_text2
  351.  
  352.         ret
  353.  
  354.  
  355.  
  356. cmd_usr_server:
  357.  
  358.         mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
  359.         or      eax, 0x00002020
  360.         and     eax, 0x00ffffff
  361.         cmp     eax, 'er '
  362.         jne     cmd_usr_send
  363.  
  364.         mov     ecx, [edit1.size]               ; ok now set the address
  365.         sub     ecx, 8
  366.  
  367.         mov     esi, usercommand+8
  368.   .now:
  369.         push    esi
  370.         mov     edi, irc_server_name
  371.   .loop:                                        ; copy until zero byte, or ecx reaches zero.
  372.         lodsb
  373.         stosb
  374.         test    al, al
  375.         jz      .done
  376.         dec     ecx
  377.         jnz     .loop
  378.         xor     al, al
  379.         stosb
  380.   .done:
  381.         pop     esi
  382.  
  383. ; set it also in window name
  384.         mov     ebx, [window_print]
  385.         call    window_set_name
  386.  
  387. ; now connect
  388.         call    socket_connect
  389.  
  390.         ret
  391.  
  392.  
  393. cmd_usr_quer:
  394.  
  395.         mov     esi, usercommand+7
  396.         call    window_open
  397.  
  398.         ret
  399.  
  400.  
  401.  
  402. cmd_usr_help:
  403.  
  404.         mov     esi, str_help
  405.         call    print_text2
  406.  
  407.         ret
  408.  
  409.  
  410.  
  411. cmd_usr_code:
  412.  
  413.         ; TODO
  414.  
  415.         ret
  416.  
  417.  
  418.  
  419. ; User typed a part command
  420. cmd_usr_part:
  421.  
  422.         cmp     byte[usercommand+5], 13         ; parameters given?
  423.         jne     cmd_usr_send                    ; yes, send command straight to server
  424.  
  425. ; close active window
  426. cmd_usr_close_window:
  427.  
  428.         mov     esi, [window_active]
  429.         mov     [window_print], esi
  430.         cmp     [esi + window.type], WINDOWTYPE_SERVER
  431.         je      .not_channel
  432.  
  433.         lea     esi, [esi + window.name]
  434.         call    cmd_usr_part_channel
  435.         call    window_close
  436.         ret
  437.  
  438.   .not_channel:
  439.         cmp     [esi + window.type], WINDOWTYPE_CHAT
  440.         jne     .not_chat
  441.  
  442.         call    window_close
  443.   .not_chat:
  444.  
  445.         ret
  446.  
  447.  
  448.  
  449. ; Send part command to server
  450. ; esi must point to channel name (ASCIIZ)
  451. cmd_usr_part_channel:
  452.  
  453. ; User wants to close a channel, send PART command to server
  454.         mov     dword[packetbuf], 'PART'
  455.         mov     byte[packetbuf+4], ' '
  456.         lea     edi, [packetbuf+5]
  457.   @@:
  458.         lodsb
  459.         test    al, al
  460.         jz      @f
  461.         cmp     al, 13
  462.         je      @f
  463.         cmp     al, 10
  464.         je      @f
  465.         stosb
  466.         jmp     @r
  467.   @@:
  468. ; end the command with a CRLF
  469.         mov     ax, 0x0a0d
  470.         stosw
  471.  
  472.         lea     esi, [edi - packetbuf]                  ; calculate length
  473.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  474.  
  475.         ret
  476.  
  477.  
  478.  
  479. cmd_usr_ctcp:
  480.  
  481.         cmp     byte[usercommand+5], ' '
  482.         jne     cmd_usr_send
  483.  
  484.         mov     esi, usercommand+6
  485. ; prepare a 'PRIVMSG '
  486.         mov     dword[packetbuf], 'PRIV'
  487.         mov     dword[packetbuf+4], 'MSG '
  488.         lea     edi, [packetbuf+8]
  489.  
  490. ; append the destination (nickname/channel)
  491.   @@:
  492.         lodsb
  493.         test    al, al
  494.         jz      .fail
  495.         cmp     al, ' '
  496.         je      @f
  497.         stosb
  498.         jmp     @r
  499.   @@:
  500.  
  501.         mov     ax, ' :'
  502.         stosw
  503.         mov     al, 0x01
  504.         stosb
  505.  
  506. ; copy the message itself
  507.   @@:
  508.         lodsb
  509.         test    al, al
  510.         jz      @f
  511.         cmp     al, 13
  512.         je      @f
  513.         cmp     al, 10
  514.         je      @f
  515.         stosb
  516.         jmp     @r
  517.   @@:
  518.  
  519. ; end of message
  520.         mov     al, 0x01
  521.         stosb
  522.         mov     ax, 0x0a0d
  523.         stosw
  524.  
  525. ; now send it away
  526.         lea     esi, [edi - packetbuf]                  ; calculate length
  527.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  528.  
  529. ;; TODO: print to window
  530.  
  531.   .fail:
  532.  
  533.         ret
  534.  
  535.  
  536.  
  537. ; The user typed some undefined command, just recode it and send to the server
  538. cmd_usr_send:
  539.  
  540.         mov     esi, usercommand+1
  541.         mov     ecx, [edit1.size]
  542.         inc     ecx
  543.         mov     edi, packetbuf
  544.         call    recode
  545.  
  546.         lea     esi, [edi - packetbuf]
  547.         mcall   send, [socketnum], packetbuf, , 0
  548.  
  549.         ret
  550.  
  551.  
  552.  
  553.  
  554.  
  555.