Subversion Repositories Kolibri OS

Rev

Rev 3563 | Rev 4477 | Go to most recent revision | Blame | Compare with Previous | 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. user_parser:
  14.  
  15.         mov     eax, [edit1.size]
  16.         test    eax, eax
  17.         jz      sdts_ret                                ; ignore empty commands
  18.         mov     word [usercommand + eax], 0x0a0d        ; terminate the line
  19.  
  20.         cmp     byte[usercommand], '/'                  ; is it a server command ?
  21.         je      server_command
  22.  
  23. ; Ignore data commands when not connected.
  24.         cmp     [status], STATUS_CONNECTED
  25.         jne     sdts_ret
  26.  
  27. ; Ok, we said something, print it to our textbox
  28.  
  29. ; TODO: dont send if it's a server window?
  30.  
  31.         push    [window_active]   ; print to the current window
  32.         pop     [window_print]
  33.         call    window_refresh
  34.  
  35.         if      TIMESTAMP
  36.         call    print_timestamp
  37.         end     if
  38.  
  39.         mov     bl, '<'
  40.         call    print_character
  41.  
  42.         mov     esi, user_nick
  43.         call    print_text2
  44.  
  45.         mov     bl, '>'
  46.         call    print_character
  47.         mov     bl, ' '
  48.         call    print_character
  49.  
  50.         mov     eax, [edit1.size]
  51.         mov     byte[usercommand + eax],0
  52.  
  53.         mov     esi, usercommand
  54.         call    print_text2
  55.  
  56.         mov     bl, 10
  57.         call    print_character
  58.  
  59. ; and now send it to the server
  60.  
  61.         mov     dword[packetbuf], 'priv'
  62.         mov     dword[packetbuf+4], 'msg '
  63.  
  64.         mov     esi, [window_active]
  65.         add     esi, window.name
  66.         mov     edi, packetbuf+8
  67.         mov     ecx, MAX_WINDOWNAME_LEN
  68.   .loop:
  69.         lodsb
  70.         test    al, al
  71.         jz      .done
  72.         stosb
  73.         dec     ecx
  74.         jnz     .loop
  75.   .done:
  76.  
  77.         mov     ax, ' :'
  78.         stosw
  79.  
  80.         mov     esi, usercommand
  81.         mov     ecx, [edit1.size]
  82.         inc     ecx
  83.         call    recode
  84.  
  85.         mov     al, 10
  86.         stosb
  87.  
  88.         lea     esi, [edi - packetbuf]
  89.         mcall   send, [socketnum], packetbuf, , 0
  90.  
  91. sdts_ret:
  92.  
  93.         ret
  94.  
  95.  
  96.  
  97. user_commands:
  98.         dd      'nick', cmd_usr_nick
  99.         dd      'real', cmd_usr_real
  100.         dd      'serv', cmd_usr_server
  101.         dd      'help', cmd_usr_help
  102.         dd      'code', cmd_usr_code
  103. ; TODO: All other commands require a connection to the server.
  104.         dd      'quer', cmd_usr_quer
  105.         dd      'quit', cmd_usr_quit
  106.         dd      'part', cmd_usr_part
  107.  
  108.         .number = ($ - user_commands) / 8
  109.  
  110.  
  111.  
  112. server_command:
  113.  
  114.         mov     eax, dword[usercommand+1]
  115.         or      eax, 0x20202020
  116.  
  117.         mov     edi, user_commands
  118.         mov     ecx, user_commands.number
  119.   .loop:
  120.         scasd
  121.         je      .got_cmd
  122.         add     edi, 4
  123.         dec     ecx
  124.         jnz     .loop
  125.         jmp     cmd_usr_send            ; If none of the previous commands, just send to server
  126.  
  127.   .got_cmd:
  128.         jmp     dword[edi]
  129.  
  130.  
  131.  
  132.  
  133.  
  134. cmd_usr_quit:
  135.  
  136.         mov     esi, quit_msg
  137.  
  138.         cmp     byte[usercommand+5], ' '
  139.         jne     .default_msg
  140.         lea     esi,[usercommand+6]
  141.   .default_msg:
  142.         call    cmd_usr_quit_server
  143.  
  144.         mcall   close, [socketnum]
  145.  
  146.         mov     ecx, MAX_WINDOWS
  147.         mov     edi, windows
  148.   .loop:
  149.         mov     [edi + window.flags], FLAG_CLOSE
  150.         add     edi, sizeof.window
  151.         dec     ecx
  152.         jnz     .loop
  153.  
  154.         ret
  155.  
  156.  
  157.  
  158. ; esi = quit message
  159. cmd_usr_quit_server:
  160.  
  161. ; User wants to close a channel, send PART command to server
  162.         mov     dword[packetbuf], 'QUIT'
  163.         mov     word[packetbuf+4], ' :'
  164.         lea     edi, [packetbuf+6]
  165. ; Append our quit msg
  166.   @@:
  167.         lodsb
  168.         stosb
  169.         test    al, al
  170.         jnz     @r
  171. ; end the command with a CRLF
  172.         dec     edi
  173.         mov     ax, 0x0a0d
  174.         stosw
  175.  
  176.         lea     esi, [edi - packetbuf]                  ; calculate length
  177.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  178.  
  179.         ret
  180.  
  181.  
  182.  
  183.  
  184. cmd_usr_nick:
  185.  
  186.         cmp     [edit1.size], 5
  187.         je      .justprint
  188.         cmp     byte[usercommand+5], ' '
  189.         jne     cmd_usr_send
  190.  
  191.         mov     ecx, MAX_NICK_LEN
  192.         mov     esi, usercommand+6
  193.         mov     edi, user_nick
  194.   .loop:
  195.         lodsb
  196.         cmp     al, 13
  197.         je      .done
  198.         stosb
  199.         dec     ecx
  200.         jnz     .loop
  201.   .done:
  202.         xor     al, al
  203.         stosb
  204.  
  205.         cmp     [socketnum], 0
  206.         je      .justprint
  207.  
  208.         lea     esi, [edi - usercommand]
  209.         mcall   send, [socketnum], usercommand+1, , 0
  210.  
  211.   .justprint:
  212.         mov     esi, str_nickchange
  213.         call    print_text2
  214.         mov     esi, user_nick
  215.         call    print_text2
  216.         mov     esi, str_dotnewline
  217.         call    print_text2
  218.  
  219.         ret
  220.  
  221.  
  222.  
  223. cmd_usr_real:
  224.  
  225.         cmp     byte[usercommand+5], ' '
  226.         jne     cmd_usr_send
  227.  
  228.         mov     ecx, MAX_REAL_LEN
  229.         mov     esi, usercommand+6
  230.         mov     edi, user_real_name
  231.   .loop:
  232.         lodsb
  233.         cmp     al, 13
  234.         je      .done
  235.         stosb
  236.         dec     ecx
  237.         jnz     .loop
  238.   .done:
  239.         xor     al, al
  240.         stosb
  241.  
  242.         mov     esi, str_realchange
  243.         call    print_text2
  244.         mov     esi, user_real_name
  245.         call    print_text2
  246.         mov     esi, str_dotnewline
  247.         call    print_text2
  248.  
  249.         ret
  250.  
  251.  
  252.  
  253. cmd_usr_server:
  254.  
  255.         mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
  256.         or      eax, 0x00002020
  257.         and     eax, 0x00ffffff
  258.         cmp     eax, 'er '
  259.         jne     cmd_usr_send
  260.  
  261.         mov     ecx, [edit1.size]         ; ok now set the address
  262.         sub     ecx, 8
  263.  
  264.         mov     esi, usercommand+8
  265.         push    esi
  266.         mov     edi, irc_server_name
  267.         rep     movsb
  268.         xor     al, al
  269.         stosb
  270.         pop     esi
  271.  
  272. ; set it also in window name
  273.         mov     ebx, [window_print]
  274.         call    window_set_name
  275.  
  276. ; now connect
  277.         call    socket_connect
  278.  
  279.         ret
  280.  
  281.  
  282. cmd_usr_quer:
  283.  
  284.         mov     ecx, MAX_WINDOWS
  285.         mov     ebx, windows
  286.   .loop:
  287.         cmp     [ebx + window.data_ptr], 0
  288.         je      .found
  289.         add     ebx, sizeof.window
  290.         dec     ecx
  291.         jnz     .loop
  292.  
  293. ; error: no available channels ! FIXME
  294.  
  295.         ret
  296.  
  297.  
  298.   .found:
  299.         call    window_create
  300.         test    eax, eax
  301.         jz      .error
  302.         mov     [ebx + window.data_ptr], eax
  303.  
  304.         mov     esi, usercommand+7
  305.         call    window_set_name
  306.  
  307.         mov     [ebx + window.type], WINDOWTYPE_CHAT
  308.         mov     [ebx + window.flags], 0
  309.  
  310.   .error:
  311.  
  312.         ret
  313.  
  314.  
  315.  
  316. cmd_usr_help:
  317.  
  318.         mov     esi, str_help
  319.         call    print_text2
  320.  
  321.         ret
  322.  
  323.  
  324.  
  325. cmd_usr_code:
  326.  
  327.         ; TODO
  328.  
  329.         ret
  330.  
  331.  
  332.  
  333. ; User typed a part command
  334. cmd_usr_part:
  335.  
  336.         cmp     byte[usercommand+5], 13 ; parameters given?
  337.         jne     cmd_usr_send
  338.  
  339.         mov     esi, [window_active]      ; window is not a server window?
  340.         cmp     [esi + window.type], WINDOWTYPE_SERVER
  341.         je      @f
  342.  
  343.         call    window_close            ; OK, close currently open (channel/chat/..) window
  344.   @@:
  345.  
  346.         ret
  347.  
  348. ; Send part command to server
  349. ; esi must point to channel name (ASCIIZ)
  350. cmd_usr_part_channel:
  351.  
  352. ; User wants to close a channel, send PART command to server
  353.         mov     dword[packetbuf], 'PART'
  354.         mov     byte[packetbuf+4], ' '
  355.         lea     edi, [packetbuf+5]
  356.   @@:
  357.         lodsb
  358.         stosb
  359.         test    al, al
  360.         jnz     @r
  361. ; end the command with a CRLF
  362.         dec     edi
  363.         mov     ax, 0x0a0d
  364.         stosw
  365.  
  366.         lea     esi, [edi - packetbuf]                  ; calculate length
  367.         mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
  368.  
  369.         ret
  370.  
  371.  
  372. ; The user typed some undefined command, just recode it and send to the server
  373. cmd_usr_send:
  374.  
  375.         mov     esi, usercommand+1
  376.         mov     ecx, [edit1.size]
  377.         inc     ecx
  378.         mov     edi, packetbuf
  379.         call    recode
  380.  
  381.         lea     esi, [edi - packetbuf]
  382.         mcall   send, [socketnum], packetbuf, , 0
  383.  
  384.         ret
  385.  
  386.