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