Subversion Repositories Kolibri OS

Rev

Rev 3981 | Rev 4143 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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