Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  IRC client for KolibriOS                                       ;;
  7. ;;                                                                 ;;
  8. ;;   Written by hidnplayr@kolibrios.org,                           ;;
  9. ;;     text encoder/decoder by Clevermouse.                        ;;
  10. ;;                                                                 ;;
  11. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  12. ;;          Version 2, June 1991                                   ;;
  13. ;;                                                                 ;;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15.  
  16. version equ '0.29'
  17.  
  18. ; connection status
  19. STATUS_DISCONNECTED     = 0
  20. STATUS_RESOLVING        = 1
  21. STATUS_CONNECTING       = 2
  22. STATUS_CONNECTED        = 3
  23. STATUS_LOGGED_IN        = 4
  24.  
  25. ; window flags
  26. FLAG_UPDATED            = 1 shl 0
  27. FLAG_RECEIVING_NAMES    = 1 shl 1
  28. FLAG_SCROLL_LOW         = 1 shl 2
  29.  
  30. ; window types
  31. WINDOWTYPE_NONE         = 0
  32. WINDOWTYPE_SERVER       = 1
  33. WINDOWTYPE_CHANNEL      = 2
  34. WINDOWTYPE_CHAT         = 3
  35. WINDOWTYPE_LIST         = 4
  36. WINDOWTYPE_DCC          = 5
  37.  
  38. ; supported encodings
  39. CP866                   = 0
  40. CP1251                  = 1
  41. UTF8                    = 2
  42.  
  43. ; settings
  44. USERCMD_MAX_SIZE        = 400
  45.  
  46. WIN_MIN_X               = 600
  47. WIN_MIN_Y               = 183
  48.  
  49. TEXT_X                  = 2
  50. TEXT_Y                  = TOP_Y + 2
  51.  
  52. TOP_SPACE               = 2
  53. TAB_HEIGHT              = 14
  54. TAB_WIDTH               = 120
  55. TAB_SPACE               = 5
  56. TOP_Y                   = TOP_SPACE+ TAB_HEIGHT
  57. INPUTBOX_HEIGHT         = 13
  58.  
  59. MAX_WINDOWS             = 20
  60. MAX_USERS               = 4096
  61. TEXT_BUFFERSIZE         = 1024*1024
  62.  
  63. MAX_NICK_LEN            = 32
  64. MAX_REAL_LEN            = 32    ; realname
  65. MAX_SERVER_NAME         = 256
  66.  
  67. MAX_CHANNEL_LEN         = 40
  68. MAX_CHANNELS            = 37
  69.  
  70. MAX_COMMAND_LEN         = 512
  71.  
  72. TIMESTAMP               = 3     ; 3 = hh:mm:ss, 2 = hh:mm, 0 = no timestamp
  73.  
  74. MAX_WINDOWNAME_LEN      = 256
  75.  
  76. WINDOW_BTN_START        = 100
  77. WINDOW_BTN_CLOSE        = 2
  78. WINDOW_BTN_LIST         = 3
  79.  
  80. SCROLLBAR_WIDTH         = 14
  81. USERLIST_WIDTH          = 160
  82.  
  83. FONT_WIDTH              = 8
  84. FONT_HEIGHT             = 16
  85.  
  86. format binary as ""
  87.  
  88. use32
  89.  
  90.         org     0x0
  91.  
  92.         db      'MENUET01'              ; 8 byte id
  93.         dd      1                       ; header version
  94.         dd      START                   ; program start
  95.         dd      I_END                   ; program image size
  96.         dd      IM_END+2048             ; required amount of memory
  97.         dd      IM_END+2048
  98.         dd      param
  99.         dd      path
  100.  
  101. include "../../macros.inc"
  102. include "../../proc32.inc"
  103. include "../../dll.inc"
  104. include "../../network.inc"
  105. include "../../struct.inc"
  106. include "../../develop/libraries/box_lib/trunk/box_lib.mac"
  107.  
  108. struct  window
  109.         data_ptr        dd ?
  110.         flags           db ?
  111.         type            db ?
  112.         name            rb MAX_WINDOWNAME_LEN
  113.         users           dd ?
  114.         users_scroll    dd ?
  115.         selected        dd ?            ; selected user, 0 if none selected
  116.  
  117.         text_start      dd ?            ; pointer to current textbox data
  118.         text_end        dd ?
  119.         text_print      dd ?            ; pointer to first character to print on screen
  120.         text_line_print dd ?            ; line number of that character
  121.         text_write      dd ?            ; write pointer
  122.         text_lines      dd ?            ; total number of lines
  123.         text_scanned    dd ?            ; pointer to beginning of unscanned data (we still need to count number of lines, insert newline characters,..)
  124.  
  125. ends
  126.  
  127. struct  window_data
  128.         text            rb TEXT_BUFFERSIZE
  129.         names           rb MAX_NICK_LEN * MAX_USERS
  130. ends
  131.  
  132. include "encodings.inc"
  133. include "window.inc"
  134. include "serverparser.inc"
  135. include "userparser.inc"
  136. include "socket.inc"
  137. include "gui.inc"
  138. include "users.inc"
  139. include "textbox.inc"
  140.  
  141.  
  142. START:
  143.  
  144.         mcall   68, 11                  ; init heap so we can allocate memory dynamically
  145.  
  146. ; wanted events
  147.         mcall   40, EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_STACK+EVM_MOUSE+EVM_MOUSE_FILTER
  148.  
  149. ; load libraries
  150.         stdcall dll.Load, @IMPORT
  151.         test    eax, eax
  152.         jnz     exit
  153.  
  154. ; find path to main settings file (ircc.ini)
  155.         mov     edi, path               ; Calculate the length of zero-terminated string
  156.         xor     al, al
  157.         mov     ecx, 1024
  158.         repne   scasb
  159.         dec     edi
  160.         mov     eax, '.ini'
  161.         stosd
  162.         xor     al, al
  163.         stosb
  164.  
  165. ; Fill the window buffer with zeros
  166.         mov     edi, windows
  167.         mov     ecx, (sizeof.window*MAX_WINDOWS+3)/4
  168.         xor     eax, eax
  169.         rep     stosd
  170.  
  171. ; clear command area too
  172.         mov     edi, servercommand
  173.         mov     ecx, 600/4
  174.         rep     stosd
  175.  
  176. ; allocate window data block
  177.         mov     ebx, windows
  178.         call    window_create_textbox
  179.         test    eax, eax
  180.         jz      error
  181.         mov     [ebx + window.type], WINDOWTYPE_SERVER
  182.  
  183. ; get system colors
  184.         mcall   48, 3, colors, 40
  185.  
  186. ; set edit box and scrollbar colors
  187.         mov     eax, [colors.work]
  188.         mov     [scroll1.bg_color], eax
  189.         mov     [scroll2.bg_color], eax
  190.  
  191.         mov     eax, [colors.work_button]
  192.         mov     [scroll1.front_color], eax
  193.         mov     [scroll2.front_color], eax
  194.  
  195.         mov     eax, [colors.work_text]
  196.         mov     [scroll1.line_color], eax
  197.         mov     [scroll2.line_color], eax
  198.  
  199.         mov     [scroll1.type], 1               ; 0 = simple, 1 = skinned
  200.         mov     [scroll2.type], 1
  201.  
  202. ; get settings from ini
  203.         invoke  ini.get_str, path, str_user, str_nick, user_nick, MAX_NICK_LEN, default_nick
  204.         invoke  ini.get_str, path, str_user, str_real, user_real_name, MAX_REAL_LEN, default_real
  205.         invoke  ini.get_str, path, str_user, str_quitmsg, quit_msg, 250, default_quit
  206.  
  207. ; Welcome user
  208.         mov     esi, str_welcome
  209.         call    print_asciiz
  210.  
  211. ; Check if parameter contains an URL
  212.         cmp     byte[param], 0
  213.         je      @f
  214.         mov     esi, param
  215.         mov     ecx, 1024
  216.         call    cmd_usr_server.now
  217.   @@:
  218.  
  219. redraw:
  220.         call    draw_window
  221.  
  222. mainloop:
  223.         mcall   10              ; wait for event
  224.  
  225.         dec     eax
  226.         jz      redraw
  227.  
  228.         dec     eax
  229.         jz      main_window_key
  230.  
  231.         dec     eax
  232.         jz      button
  233.  
  234.         cmp     al, 3
  235.         je      mouse
  236.  
  237.         call    process_network_event
  238.  
  239.         mov     edi, [window_active]
  240.         test    [edi + window.flags], FLAG_UPDATED
  241.         jz      .no_update
  242.         call    draw_channel_text
  243.         mov     edi, [window_active]
  244.         cmp     [edi + window.type], WINDOWTYPE_CHANNEL
  245.         jne     .no_update
  246.         call    draw_user_list
  247.   .no_update:
  248.         call    highlight_updated_tabs
  249.  
  250.         jmp     mainloop
  251.  
  252. button:
  253.  
  254.         mcall   17              ; get id
  255.         ror     eax, 8
  256.  
  257.         cmp     ax, 1           ; close program
  258.         je      exit
  259.  
  260.         cmp     ax, WINDOW_BTN_CLOSE
  261.         jne     @f
  262.         call    cmd_usr_close_window
  263.         jmp     mainloop
  264.  
  265.   @@:
  266.         cmp     ax, WINDOW_BTN_LIST
  267.         jne     @f
  268.  
  269.         push    eax
  270.  
  271.         mcall   37, 1           ; Get mouse position
  272.         sub     ax, TEXT_Y
  273.         mov     bl, FONT_HEIGHT
  274.         div     bl
  275.         and     eax, 0x000000ff
  276.         inc     eax
  277.         add     eax, [scroll1.position]
  278.         mov     ebx, [window_active]
  279.         mov     [ebx + window.selected], eax
  280.  
  281.         call    draw_user_list
  282.  
  283.         pop     eax
  284.         test    eax, 1 shl 25   ; Right mouse button pressed?
  285.         jz      mainloop
  286.  
  287. ; TODO: check if selected nick is my nick!
  288.  
  289. ; Right mouse BTN was pressed, open chat window
  290.         mov     ebx, [window_active]
  291.         mov     eax, [ebx + window.selected]
  292.         dec     eax
  293.         imul    eax, MAX_NICK_LEN
  294.         mov     ebx, [ebx + window.data_ptr]
  295.         lea     esi, [ebx + window_data.names + eax]
  296.         call    window_open
  297.         test    ebx, ebx
  298.         jz      mainloop
  299.         mov     [window_active], ebx
  300.         call    redraw
  301.  
  302.         jmp     mainloop
  303.  
  304.   @@:
  305.         sub     ax, WINDOW_BTN_START
  306.         jb      exit
  307.  
  308.         cmp     ax, MAX_WINDOWS
  309.         ja      exit
  310.  
  311. ; Save users scrollbar position
  312.         push    [scroll1.position]
  313.         mov     edx, [window_active]
  314.         pop     [edx + window.users_scroll]
  315.  
  316. ; OK, time to switch to another window.
  317.         mov     dx, sizeof.window
  318.         mul     dx
  319.         shl     edx, 16
  320.         mov     dx, ax
  321.         add     edx, windows
  322.         cmp     [edx + window.type], WINDOWTYPE_NONE
  323.         je      exit
  324.         mov     [window_active], edx
  325.  
  326.         push    [edx + window.text_line_print]
  327.         pop     [scroll2.position]
  328.  
  329.         push    [edx + window.users_scroll]
  330.         pop     [scroll1.position]
  331.  
  332.         call    draw_window
  333.         jmp     mainloop
  334.  
  335. exit:
  336.  
  337.         cmp     [socketnum], 0
  338.         je      @f
  339.         mov     esi, quit_msg
  340.         call    quit_server
  341.   @@:
  342.  
  343. error:
  344.  
  345.         mcall   -1
  346.  
  347.  
  348.  
  349. main_window_key:
  350.  
  351.         mcall   2
  352.  
  353.         push    dword edit1
  354.         call    [edit_box_key]
  355.  
  356. ;        cmp     ah, 178
  357. ;        jne     .no_up
  358. ;
  359. ;        jmp     mainloop
  360. ;
  361. ;
  362. ;  .no_up:
  363. ;        cmp     ah, 177
  364. ;        jne     .no_down
  365. ;
  366. ;        jmp     mainloop
  367. ;
  368. ;  .no_down:
  369.         cmp     ah, 13          ; enter
  370.         jne     no_send2
  371.  
  372.         call    user_parser
  373.  
  374.         mov     eax, [edit1.size]
  375.  
  376.         mov     [edit1.size], 0
  377.         mov     [edit1.pos], 0
  378.  
  379.         invoke  edit_box_draw, edit1
  380.  
  381.         call    draw_channel_text
  382.  
  383.         jmp     mainloop
  384.   no_send2:
  385.  
  386.         jmp     mainloop
  387.  
  388. mouse:
  389.         invoke  edit_box_mouse, edit1
  390.  
  391. ;        mcall   37, 7
  392. ;        movsx   eax, ax
  393. ;        add     [scroll2.position], eax
  394.  
  395. ; TODO: check if scrollbar is active?
  396.         mov     edi, [window_active]
  397.         cmp     [edi + window.type], WINDOWTYPE_CHANNEL
  398.         jne     @f
  399.         push    [scroll1.position]
  400.         invoke  scrollbar_mouse, scroll1
  401.         pop     eax
  402.         cmp     eax, [scroll1.position] ; did the scrollbar move?
  403.         je      @f
  404.         call    draw_user_list
  405.   @@:
  406.  
  407. ; TODO: check if scrollbar is active?
  408.         mov     edi, [window_active]
  409.         mov     eax, [edi + window.text_lines]
  410.         cmp     eax, [textbox_height]
  411.         jbe     @f
  412.         invoke  scrollbar_mouse, scroll2
  413.         mov     edi, [window_active]
  414.         and     [edi+window.flags], not FLAG_SCROLL_LOW
  415.         mov     edx, [scroll2.position]
  416.         add     edx, [scroll2.cur_area]
  417.         sub     edx, [scroll2.max_area]
  418.         jne     .not_low
  419.         or      [edi+window.flags], FLAG_SCROLL_LOW
  420.   .not_low:
  421.         mov     edx, [scroll2.position]
  422.         sub     edx, [edi + window.text_line_print]
  423.         je      @f
  424.         call    draw_channel_text.scroll_to_pos
  425.   @@:
  426.  
  427.         jmp     mainloop
  428.  
  429.  
  430. ; DATA AREA
  431.  
  432. encoding_text:
  433. db      'CP866 '
  434. db      'CP1251'
  435. db      'UTF-8 '
  436. encoding_text_len = 6
  437.  
  438. join_header             db 3, '3* ', 0
  439. quit_header             db 3, '5* ', 0
  440. nick_header             db 3, '2* ', 0
  441. kick_header             db 3, '5* ', 0
  442. mode_header             db 3, '2* ', 0
  443. part_header             db 3, '5* ', 0
  444. topic_header            db 3, '3* ', 0
  445. action_header           db 3, '6* ', 0
  446. ctcp_header             db 3, '13-> [', 0
  447. msg_header              db 3, '7-> *', 0
  448. ctcp_version            db '] VERSION', 10, 0
  449. ctcp_ping               db '] PING', 10, 0
  450. ctcp_time               db '] TIME', 10, 0
  451.  
  452. has_left_channel        db ' has left ', 0
  453. joins_channel           db ' has joined ', 0
  454. is_now_known_as         db ' is now known as ', 0
  455. has_quit_irc            db ' has quit IRC', 10, 0
  456.  
  457. sets_mode               db ' sets mode ', 0
  458. str_kicked              db ' is kicked from ', 0
  459. str_by                  db ' by ', 0
  460. str_nickchange          db 'Nickname is now ', 0
  461. str_realchange          db 'Real name is now ', 0
  462. str_talking             db 'Now talking in ', 0
  463. str_topic               db 'Topic is "', 0
  464. str_topic_end           db '"', 10, 0
  465. str_setby               db 'Set by ', 0
  466.  
  467. str_connecting          db 3, '3* Connecting to ', 0
  468. str_sockerr             db 3, '5* Socket error', 10, 0
  469. str_dnserr              db 3, '5* Unable to resolve hostname', 10, 0
  470. str_refused             db 3, '5* Connection refused', 10, 0
  471. str_srv_disconnected    db 3, '5* Server disconnected', 10, 0
  472. str_disconnected        db 3, '5* Disconnected', 10, 0
  473. str_reconnect           db 3, '5* Connection reset by user', 10, 0
  474. str_notconnected        db 3, '5* You are not connected', 10, 0
  475. str_notchannel          db 3, '5* You are not on a channel', 10, 0
  476. str_notloggedin         db 3, '5* You are not logged in to the server', 10, 0
  477.  
  478. str_1                   db 3, '13 -', 0
  479. str_2                   db '- ', 0
  480.  
  481. str_list                db 'list', 0
  482.  
  483. str_help                db 'The following commands are available:', 10
  484.                         db 10
  485.                         db '/nick <nick>        : change nickname', 10
  486.                         db '/real <real name>   : change real name', 10
  487.                         db '/server <address>   : connect to server', 10
  488.                         db '/code <code>        : change codepage (cp866, cp1251, or utf8)', 10
  489.                         db '/join <channel>     : join a channel', 10
  490.                         db '/part <channel>     : part from a channel', 10
  491.                         db '/quit               : quit server', 10
  492.                         db '/msg <user>         : send a private message', 10
  493.                         db '/ctcp <user>        : send a message using client to client protocol', 10
  494.                         db 10
  495.                         db 'Other commands are send straight to server.', 10
  496.                         db 10, 0
  497.  
  498. str_welcome             db 3, '3 ___', 3, '7__________', 3, '6_________  ', 3, '4         __   __               __', 10
  499.                         db 3, '3|   \', 3, '7______   \', 3, '6_   ___ \ ', 3, '4   ____ |  | |__| ____   _____/  |_', 10
  500.                         db 3, '3|   |', 3, '7|       _/', 3, '6    \  \/ ', 3, '4 _/ ___\|  | |  |/ __ \ /    \   __\', 10
  501.                         db 3, '3|   |', 3, '7|    |   \', 3, '6     \____', 3, '4 \  \___|  |_|  \  ___/|   |  \  |', 10
  502.                         db 3, '3|___|', 3, '7|____|_  /', 3, '6\______  /', 3, '4  \___  >____/__|\___  >___|  /__|', 10
  503.                         db 3, '3     ', 3, '7       \/ ', 3, '6       \/ ', 3, '4      \/             \/     \/', 10
  504.                         db 'Welcome to KolibriOS IRC client ', version, 10
  505.                         db 'Type /help for help', 10, 0
  506.  
  507. str_version             db 'VERSION KolibriOS '
  508. str_programname         db 'IRC client ', version, 0
  509.  
  510. str_user                db 'user', 0
  511. str_nick                db 'nick', 0
  512. str_real                db 'realname', 0
  513. str_email               db 'email', 0
  514. str_quitmsg             db 'quitmsg', 0
  515.  
  516. default_nick            db 'kolibri_user', 0
  517. default_real            db 'Kolibri User', 0
  518. default_quit            db 'KolibriOS forever', 0
  519.  
  520. irc_colors              dd 0xffffff     ;  0 white
  521.                         dd 0x000000     ;  1 black
  522.                         dd 0x00007f     ;  2 blue (navy)
  523.                         dd 0x009300     ;  3 green
  524.                         dd 0xff0000     ;  4 red
  525.                         dd 0x7f0000     ;  5 brown (maroon)
  526.                         dd 0x9c009c     ;  6 purple
  527.                         dd 0xfc7f00     ;  7 olive
  528.                         dd 0xffff00     ;  8 yellow
  529.                         dd 0x00fc00     ;  9 light green
  530.                         dd 0x009393     ; 10 teal
  531.                         dd 0x00ffff     ; 11 cyan
  532.                         dd 0x0000fc     ; 12 royal blue
  533.                         dd 0xff00ff     ; 13 pink
  534.                         dd 0x7f7f7f     ; 14 grey
  535.                         dd 0xd4d0c4     ; 15 light grey (silver)
  536.  
  537. sockaddr1:
  538.         dw AF_INET4
  539. .port   dw 0x0b1a       ; 6667          FIXMEEEEEE
  540. .ip     dd 0
  541.         rb 10
  542.  
  543.  
  544. status                  dd STATUS_DISCONNECTED
  545.  
  546. window_active           dd windows
  547. window_print            dd windows
  548.  
  549. align 4
  550. @IMPORT:
  551.  
  552. library network,        'network.obj',\
  553.         libini,         'libini.obj',\
  554.         boxlib,         'box_lib.obj'
  555.  
  556. import  network,\
  557.         getaddrinfo,    'getaddrinfo',\
  558.         freeaddrinfo,   'freeaddrinfo',\
  559.         inet_ntoa,      'inet_ntoa'
  560.  
  561. import  libini,\
  562.         ini.get_str,    'ini_get_str',\
  563.         ini.get_int,    'ini_get_int'
  564.  
  565. import  boxlib,\
  566.         edit_box_draw,  'edit_box',\
  567.         edit_box_key,   'edit_box_key',\
  568.         edit_box_mouse, 'edit_box_mouse',\
  569.         scrollbar_draw, 'scrollbar_v_draw',\
  570.         scrollbar_mouse,'scrollbar_v_mouse'
  571.  
  572.         ;         width, left, top
  573. edit1   edit_box  0, 0, 0, 0xffffff, 0x6f9480, 0, 0, 0x000000, USERCMD_MAX_SIZE, input_text, mouse_dd, ed_always_focus, 25, 25
  574.         ;         xsize, xpos, ysize, ypos, btn_height, max, cur, pos, bgcol, frcol, linecol
  575. scroll1 scrollbar SCROLLBAR_WIDTH, 0, 0, TOP_Y, SCROLLBAR_WIDTH, 0, 0, 0, 0, 0, 0, 1
  576. scroll2 scrollbar SCROLLBAR_WIDTH, 0, 0, TOP_Y, SCROLLBAR_WIDTH, 0, 0, 0, 0, 0, 0, 1
  577.  
  578. input_text      db '/server chat.freenode.net', 0
  579.                 rb MAX_COMMAND_LEN
  580.  
  581. I_END:
  582.  
  583. user_command    rb MAX_COMMAND_LEN*4
  584. .size           dd ?
  585.  
  586. utf8_bytes_rest dd ?            ; bytes rest in current UTF8 sequence
  587. utf8_char       dd ?            ; first bits of current UTF8 character
  588.  
  589. packetbuf       rb 1024         ; buffer for packets to server
  590. path            rb 1024
  591. param           rb 1024
  592.  
  593. servercommand   rb 600
  594.  
  595. thread_info     process_information
  596. xsize           dd ?
  597. ysize           dd ?
  598. mouse_dd        dd ?
  599.  
  600. textbox_height  dd ?            ; in characters
  601. textbox_width   dd ?            ; in characters, not pixels ;)
  602.  
  603. colors          system_colors
  604.  
  605. irc_server_name rb MAX_SERVER_NAME      ; TODO: move this server URL into window struct
  606. socketnum       dd ?                    ; TODO: same for socket
  607.  
  608. user_nick       rb MAX_NICK_LEN
  609. user_real_name  rb MAX_REAL_LEN
  610. quit_msg        rb 250
  611.  
  612. windows         rb MAX_WINDOWS*sizeof.window
  613.  
  614. IM_END: