Subversion Repositories Kolibri OS

Rev

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