Rev 3949 | Rev 4060 | 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 | |||
76 | |||
77 | format binary as "" |
||
78 | |||
79 | use32 |
||
80 | |||
81 | org 0x0 |
||
82 | |||
83 | db 'MENUET01' ; 8 byte id |
||
84 | dd 1 ; header version |
||
85 | dd START ; program start |
||
86 | dd I_END ; program image size |
||
87 | dd IM_END+2048 ; required amount of memory |
||
88 | dd IM_END+2048 |
||
89 | dd param |
||
90 | dd path |
||
91 | |||
3618 | hidnplayr | 92 | include "../../macros.inc" |
93 | include "../../proc32.inc" |
||
94 | include "../../dll.inc" |
||
95 | include "../../network.inc" |
||
96 | include "../../struct.inc" |
||
3549 | yogev_ezra | 97 | include '../../develop/libraries/box_lib/trunk/box_lib.mac' |
3545 | hidnplayr | 98 | |
99 | struct window |
||
100 | data_ptr dd ? ; zero if not used |
||
101 | flags db ? |
||
102 | type db ? |
||
103 | name rb MAX_WINDOWNAME_LEN |
||
104 | users dd ? |
||
105 | users_scroll dd ? |
||
106 | selected dd ? ; selected user, 0 if none selected |
||
107 | ends |
||
108 | |||
109 | struct window_data |
||
110 | text rb 120*60 |
||
111 | title rb 256 |
||
112 | names rb MAX_NICK_LEN * MAX_USERS |
||
113 | usertext rb 256 |
||
114 | usertextlen dd ? |
||
115 | ends |
||
116 | |||
117 | include "encodings.inc" |
||
118 | include "window.inc" ; also contains text print routines |
||
119 | include "serverparser.inc" |
||
120 | include "userparser.inc" |
||
121 | include "socket.inc" |
||
122 | include "gui.inc" |
||
123 | include "users.inc" |
||
124 | |||
125 | |||
126 | START: |
||
127 | |||
128 | mcall 68, 11 ; init heap so we can allocate memory dynamically |
||
129 | |||
130 | ; wanted events |
||
3981 | hidnplayr | 131 | mcall 40, EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_STACK+EVM_MOUSE+EVM_MOUSE_FILTER |
3545 | hidnplayr | 132 | |
133 | ; load libraries |
||
134 | stdcall dll.Load, @IMPORT |
||
135 | test eax, eax |
||
136 | jnz exit |
||
137 | |||
138 | ; find path to main settings file (ircc.ini) |
||
139 | mov edi, path ; Calculate the length of zero-terminated string |
||
140 | xor al, al |
||
141 | mov ecx, 1024 |
||
142 | repne scasb |
||
143 | dec edi |
||
144 | mov eax, '.ini' |
||
145 | stosd |
||
146 | xor al, al |
||
147 | stosb |
||
148 | |||
149 | ; Fill the window buffer with zeros |
||
150 | mov edi, windows |
||
151 | mov ecx, (sizeof.window*MAX_WINDOWS+3)/4 |
||
152 | xor eax, eax |
||
153 | rep stosd |
||
154 | |||
155 | ; clear command area too |
||
156 | mov edi, servercommand |
||
157 | mov ecx, 600/4 |
||
158 | rep stosd |
||
159 | |||
160 | ; allocate window data block |
||
161 | call window_create |
||
162 | mov ebx, windows |
||
163 | mov [ebx + window.data_ptr], eax |
||
164 | mov [ebx + window.flags], 0 |
||
165 | mov [ebx + window.type], WINDOWTYPE_SERVER |
||
166 | add eax, window_data.text |
||
167 | mov [text_start], eax |
||
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 |
||
413 | db '/real |
||
414 | db '/server : connect to server ',10 |
||
415 | db '/code |
||
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 | irc_data dd 0x0 ; encoder |
||
435 | textbox_width dd 80 ; in characters, not pixels ;) |
||
436 | pos dd 66 * 11 ; encoder |
||
437 | |||
3981 | hidnplayr | 438 | window_active dd windows |
3545 | hidnplayr | 439 | window_print dd windows |
440 | |||
441 | scroll dd 1 |
||
442 | dd 12 |
||
443 | |||
444 | align 4 |
||
445 | @IMPORT: |
||
446 | |||
447 | library network, 'network.obj',\ |
||
448 | libini, 'libini.obj',\ |
||
449 | boxlib, 'box_lib.obj' |
||
450 | |||
451 | import network,\ |
||
452 | getaddrinfo, 'getaddrinfo',\ |
||
453 | freeaddrinfo, 'freeaddrinfo',\ |
||
454 | inet_ntoa, 'inet_ntoa' |
||
455 | |||
456 | import libini,\ |
||
457 | ini.get_str, 'ini_get_str',\ |
||
458 | ini.get_int, 'ini_get_int' |
||
459 | |||
460 | import boxlib,\ |
||
461 | edit_box_draw ,'edit_box' ,\ |
||
462 | edit_box_key ,'edit_box_key' ,\ |
||
463 | edit_box_mouse ,'edit_box_mouse' ,\ |
||
464 | scrollbar_v_draw ,'scrollbar_v_draw' ,\ |
||
465 | scrollbar_v_mouse,'scrollbar_v_mouse' |
||
466 | |||
467 | I_END: |
||
468 | |||
469 | ; width, left, top |
||
470 | edit1 edit_box 0, 0, 0, 0xffffff, 0x6f9480, 0, 0, 0, USERCMD_MAX_SIZE, usercommand, mouse_dd, ed_focus, 25, 25 |
||
471 | ; xsize, xpos, ysize, ypos, max, cur, pos, bgcol, frcol, linecol |
||
472 | scroll1 scrollbar SCROLLBAR_WIDTH, 300, 150, TOP_Y, 10, 100, 0, 0, 0, 0, 0, 1 |
||
473 | scroll2 scrollbar SCROLLBAR_WIDTH, 300, 150, TOP_Y, 10, 100, 0, 0, 0, 0, 0, 1 |
||
474 | |||
3618 | hidnplayr | 475 | usercommand db '/server chat.freenode.net', 0 |
476 | rb MAX_COMMAND_LEN |
||
477 | |||
3545 | hidnplayr | 478 | main_PID dd ? ; identifier of main thread |
479 | utf8_bytes_rest dd ? ; bytes rest in current UTF8 sequence |
||
480 | utf8_char dd ? ; first bits of current UTF8 character |
||
481 | gai_reqdata rb 32 ; buffer for getaddrinfo_start/process |
||
482 | ip_list dd ? ; will be filled as pointer to addrinfo list |
||
483 | packetbuf rb 1024 ; buffer for packets to server |
||
484 | path rb 1024 |
||
485 | param rb 1024 |
||
486 | |||
487 | socketnum dd ? |
||
488 | |||
489 | servercommand rb 600 |
||
490 | |||
491 | thread_info rb 1024 |
||
492 | xsize dd ? |
||
493 | ysize dd ? |
||
494 | |||
495 | colors system_colors |
||
496 | |||
497 | irc_server_name rb MAX_SERVER_NAME |
||
498 | |||
499 | user_nick rb MAX_NICK_LEN |
||
500 | user_real_name rb MAX_REAL_LEN |
||
3981 | hidnplayr | 501 | quit_msg rb 250 |
3545 | hidnplayr | 502 | |
503 | windows rb MAX_WINDOWS*sizeof.window |
||
504 | |||
505 | mouse_dd dd ? |
||
506 | |||
507 | IM_END: |
||
508 |