Subversion Repositories Kolibri OS

Rev

Rev 3545 | Rev 4143 | 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_open]   ; 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_open]
  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.  
  107.         .number = ($ - user_commands) / 8
  108.  
  109.  
  110.  
  111. server_command:
  112.  
  113.         mov     eax, dword[usercommand+1]
  114.         or      eax, 0x20202020
  115.  
  116.         mov     edi, user_commands
  117.         mov     ecx, user_commands.number
  118.   .loop:
  119.         scasd
  120.         je      .got_cmd
  121.         add     edi, 4
  122.         dec     ecx
  123.         jnz     .loop
  124.         jmp     cmd_usr_send            ; If none of the previous commands, just send to server
  125.  
  126.   .got_cmd:
  127.         jmp     dword[edi]
  128.  
  129.  
  130.  
  131.  
  132.  
  133. cmd_usr_quit:
  134.  
  135.         cmp     [edit1.size], 5
  136.         je      .ok
  137.         jb      cmd_usr_send
  138.         cmp     byte[usercommand+5], ' '
  139.         jne     cmd_usr_send
  140.  
  141.   .ok:
  142.         call    cmd_usr_send
  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.  
  159. cmd_usr_nick:
  160.  
  161.         cmp     [edit1.size], 5
  162.         je      .justprint
  163.         cmp     byte[usercommand+5], ' '
  164.         jne     cmd_usr_send
  165.  
  166.         mov     ecx, MAX_NICK_LEN
  167.         mov     esi, usercommand+6
  168.         mov     edi, user_nick
  169.   .loop:
  170.         lodsb
  171.         cmp     al, 13
  172.         je      .done
  173.         stosb
  174.         dec     ecx
  175.         jnz     .loop
  176.   .done:
  177.         xor     al, al
  178.         stosb
  179.  
  180.         cmp     [socketnum], 0
  181.         je      .justprint
  182.  
  183.         lea     esi, [edi - usercommand]
  184.         mcall   send, [socketnum], usercommand+1, , 0
  185.  
  186.   .justprint:
  187.         mov     esi, str_nickchange
  188.         call    print_text2
  189.         mov     esi, user_nick
  190.         call    print_text2
  191.         mov     esi, str_dotnewline
  192.         call    print_text2
  193.  
  194.         ret
  195.  
  196.  
  197.  
  198. cmd_usr_real:
  199.  
  200.         cmp     byte[usercommand+5], ' '
  201.         jne     cmd_usr_send
  202.  
  203.         mov     ecx, MAX_REAL_LEN
  204.         mov     esi, usercommand+6
  205.         mov     edi, user_real_name
  206.   .loop:
  207.         lodsb
  208.         cmp     al, 13
  209.         je      .done
  210.         stosb
  211.         dec     ecx
  212.         jnz     .loop
  213.   .done:
  214.         xor     al, al
  215.         stosb
  216.  
  217.         mov     esi, str_realchange
  218.         call    print_text2
  219.         mov     esi, user_real_name
  220.         call    print_text2
  221.         mov     esi, str_dotnewline
  222.         call    print_text2
  223.  
  224.         ret
  225.  
  226.  
  227.  
  228. cmd_usr_server:
  229.  
  230.         mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
  231.         or      eax, 0x00002020
  232.         and     eax, 0x00ffffff
  233.         cmp     eax, 'er '
  234.         jne     cmd_usr_send
  235.  
  236.         mov     ecx, [edit1.size]         ; ok now set the address
  237.         sub     ecx, 8
  238.  
  239.         mov     esi, usercommand+8
  240.         push    esi
  241.         mov     edi, irc_server_name
  242.         rep     movsb
  243.         xor     al, al
  244.         stosb
  245.         pop     esi
  246.  
  247. ; set it also in window name
  248.         mov     ebx, [window_print]
  249.         call    window_set_name
  250.  
  251. ; now connect
  252.         call    socket_connect
  253.  
  254.         ret
  255.  
  256.  
  257. cmd_usr_quer:
  258.  
  259.         mov     ecx, MAX_WINDOWS
  260.         mov     ebx, windows
  261.   .loop:
  262.         cmp     [ebx + window.data_ptr], 0
  263.         je      .found
  264.         add     ebx, sizeof.window
  265.         dec     ecx
  266.         jnz     .loop
  267.  
  268. ; error: no available channels ! FIXME
  269.  
  270.         ret
  271.  
  272.  
  273.   .found:
  274.         call    window_create
  275.         test    eax, eax
  276.         jz      .error
  277.         mov     [ebx + window.data_ptr], eax
  278.  
  279.         mov     esi, usercommand+7
  280.         call    window_set_name
  281.  
  282.         mov     [ebx + window.type], WINDOWTYPE_CHAT
  283.         mov     [ebx + window.flags], 0
  284.  
  285.   .error:
  286.  
  287.         ret
  288.  
  289.  
  290.  
  291. cmd_usr_help:
  292.  
  293.         mov     esi, str_help
  294.         call    print_text2
  295.  
  296.         ret
  297.  
  298.  
  299.  
  300. cmd_usr_code:
  301.  
  302.         ; TODO
  303.  
  304.         ret
  305.  
  306.  
  307.  
  308. cmd_usr_send:
  309.  
  310.         mov     esi, usercommand+1
  311.         mov     ecx, [edit1.size]
  312.         inc     ecx
  313.         mov     edi, packetbuf
  314.         call    recode
  315.  
  316.         lea     esi, [edi - packetbuf]
  317.         mcall   send, [socketnum], packetbuf, , 0
  318.  
  319.         ret
  320.  
  321.