Subversion Repositories Kolibri OS

Rev

Rev 6027 | Rev 9981 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6027 Rev 7300
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2018. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;   Written by hidnplayr@kolibrios.org                            ;;
6
;;   Written by hidnplayr@kolibrios.org                            ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;         GNU GENERAL PUBLIC LICENSE                              ;;
8
;;         GNU GENERAL PUBLIC LICENSE                              ;;
9
;;          Version 2, June 1991                                   ;;
9
;;          Version 2, June 1991                                   ;;
10
;;                                                                 ;;
10
;;                                                                 ;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
 
12
 
13
 
13
 
14
user_parser:
14
user_parser:
15
 
15
 
16
        mov     ebp, [window_active]                    ; print to the current window
16
        mov     ebp, [window_active]                    ; print to the current window
17
        mov     [window_print], ebp
17
        mov     [window_print], ebp
18
 
18
 
19
        mov     ecx, [edit1.size]
19
        mov     ecx, [edit1.size]
20
        test    ecx, ecx
20
        test    ecx, ecx
21
        jz      .ret                                    ; ignore empty commands
21
        jz      .ret                                    ; ignore empty commands
22
 
22
 
23
        mov     esi, input_text
23
        mov     esi, input_text
24
        mov     edi, user_command
24
        mov     edi, user_command
25
        call    recode                                  ; Convert to UTF-8
25
        call    recode                                  ; Convert to UTF-8
26
        mov     word[edi], 0x0a0d                       ; terminate the line
26
        mov     word[edi], 0x0a0d                       ; terminate the line
27
        sub     edi, user_command
27
        sub     edi, user_command
28
        mov     [user_command.size], edi
28
        mov     [user_command.size], edi
29
 
29
 
30
        cmp     byte[user_command], '/'                 ; is it a server command ?
30
        cmp     byte[user_command], '/'                 ; is it a server command ?
31
        je      .command
31
        je      .command
32
 
32
 
33
        cmp     [status], STATUS_LOGGED_IN
33
        cmp     [status], STATUS_LOGGED_IN
34
        jne     .not_loggedin
34
        jne     .not_loggedin
35
 
35
 
36
        cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
36
        cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
37
        je      .send_privmsg
37
        je      .send_privmsg
38
        cmp     [ebp + window.type], WINDOWTYPE_CHAT
38
        cmp     [ebp + window.type], WINDOWTYPE_CHAT
39
        jne     .not_channel
39
        jne     .not_channel
40
 
40
 
41
  .send_privmsg:
41
  .send_privmsg:
42
        if TIMESTAMP
42
        if TIMESTAMP
43
        call    print_timestamp
43
        call    print_timestamp
44
        end if
44
        end if
45
 
45
 
46
        mov     al, '<'
46
        mov     al, '<'
47
        call    print_char
47
        call    print_char
48
 
48
 
49
        mov     esi, user_nick
49
        mov     esi, user_nick
50
        call    print_asciiz
50
        call    print_asciiz
51
 
51
 
52
        mov     al, '>'
52
        mov     al, '>'
53
        call    print_char
53
        call    print_char
54
        mov     al, ' '
54
        mov     al, ' '
55
        call    print_char
55
        call    print_char
56
 
56
 
57
        mov     eax, [user_command.size]
57
        mov     eax, [user_command.size]
58
        mov     byte[user_command + eax],0
58
        mov     byte[user_command + eax],0
59
        mov     esi, user_command
59
        mov     esi, user_command
60
        call    print_asciiz
60
        call    print_asciiz
61
 
61
 
62
        mov     al, 10
62
        mov     al, 10
63
        call    print_char
63
        call    print_char
64
 
64
 
65
; and now send it to the server
65
; and now send it to the server
66
        mov     dword[packetbuf], 'PRIV'
66
        mov     dword[packetbuf], 'PRIV'
67
        mov     dword[packetbuf+4], 'MSG '
67
        mov     dword[packetbuf+4], 'MSG '
68
 
68
 
69
        lea     esi, [ebp + window.name]
69
        lea     esi, [ebp + window.name]
70
        mov     edi, packetbuf+8
70
        mov     edi, packetbuf+8
71
        mov     ecx, MAX_WINDOWNAME_LEN
71
        mov     ecx, MAX_WINDOWNAME_LEN
72
  .loop:
72
  .loop:
73
        lodsb
73
        lodsb
74
        test    al, al
74
        test    al, al
75
        jz      .done
75
        jz      .done
76
        stosb
76
        stosb
77
        dec     ecx
77
        dec     ecx
78
        jnz     .loop
78
        jnz     .loop
79
  .done:
79
  .done:
80
 
80
 
81
        mov     ax, ' :'
81
        mov     ax, ' :'
82
        stosw
82
        stosw
83
 
83
 
84
        mov     esi, user_command
84
        mov     esi, user_command
85
        mov     ecx, [user_command.size]
85
        mov     ecx, [user_command.size]
86
;        inc     ecx
86
;        inc     ecx
87
        rep     movsb
87
        rep     movsb
88
 
88
 
89
; end the command with a CRLF
89
; end the command with a CRLF
90
        mov     ax, 0x0a0d
90
        mov     ax, 0x0a0d
91
        stosw
91
        stosw
92
 
92
 
93
        lea     esi, [edi - packetbuf]
93
        lea     esi, [edi - packetbuf]
94
        mcall   send, [socketnum], packetbuf, , 0
94
        mcall   send, [socketnum], packetbuf, , 0
95
 
95
 
96
  .ret:
96
  .ret:
97
        ret
97
        ret
98
 
98
 
99
; Text begins with a '/' lets try to find the command in the lookup table.
99
; Text begins with a '/' lets try to find the command in the lookup table.
100
  .command:
100
  .command:
101
        mov     eax, dword[user_command+1]      ; skip '/'
101
        mov     eax, dword[user_command+1]      ; skip '/'
102
        or      eax, 0x20202020                 ; convert to lowercase
102
        or      eax, 0x20202020                 ; convert to lowercase
103
 
103
 
104
        mov     edi, user_commands
104
        mov     edi, user_commands
105
        mov     ecx, user_commands.number
105
        mov     ecx, user_commands.number
106
        cmp     [status], STATUS_CONNECTED
106
        cmp     [status], STATUS_CONNECTED
107
        jae     .cmd_loop
107
        jae     .cmd_loop
108
        mov     ecx, user_commands.number2
108
        mov     ecx, user_commands.number2
109
  .cmd_loop:
109
  .cmd_loop:
110
        scasd
110
        scasd
111
        je      .got_cmd
111
        je      .got_cmd
112
        add     edi, 4
112
        add     edi, 4
113
        dec     ecx
113
        dec     ecx
114
        jnz     .cmd_loop
114
        jnz     .cmd_loop
115
 
115
 
116
        cmp     [status], STATUS_CONNECTED
116
        cmp     [status], STATUS_CONNECTED
117
        jb      .not_connected
117
        jb      .not_connected
118
 
118
 
119
; Commands shorter then 3 chars are placed here
119
; Commands shorter then 3 chars are placed here
120
        and     eax, 0x00ffffff
120
        and     eax, 0x00ffffff
121
        cmp     eax, 'me '
121
        cmp     eax, 'me '
122
        je      cmd_usr_me
122
        je      cmd_usr_me
123
 
123
 
124
; If none of the listed commands, send text straight to server
124
; If none of the listed commands, send text straight to server
125
        jmp     cmd_usr_send
125
        jmp     cmd_usr_send
126
 
126
 
127
  .got_cmd:
127
  .got_cmd:
128
        jmp     dword[edi]
128
        jmp     dword[edi]
129
 
129
 
130
  .not_loggedin:
130
  .not_loggedin:
131
        mov     esi, str_notloggedin
131
        mov     esi, str_notloggedin
132
        call    print_asciiz
132
        call    print_asciiz
133
        ret
133
        ret
134
 
134
 
135
  .not_connected:
135
  .not_connected:
136
        mov     esi, str_notconnected
136
        mov     esi, str_notconnected
137
        call    print_asciiz
137
        call    print_asciiz
138
        ret
138
        ret
139
 
139
 
140
  .not_channel:
140
  .not_channel:
141
        mov     esi, str_notchannel
141
        mov     esi, str_notchannel
142
        call    print_asciiz
142
        call    print_asciiz
143
        ret
143
        ret
144
 
144
 
145
 
145
 
146
; user commands lookup table
146
; user commands lookup table
147
user_commands:
147
user_commands:
148
        dd      'nick', cmd_usr_nick
148
        dd      'nick', cmd_usr_nick
149
        dd      'real', cmd_usr_real
149
        dd      'real', cmd_usr_real
150
        dd      'serv', cmd_usr_server
150
        dd      'serv', cmd_usr_server
151
        dd      'help', cmd_usr_help
151
        dd      'help', cmd_usr_help
152
        dd      'code', cmd_usr_code
152
        dd      'code', cmd_usr_code
153
 
153
 
154
        .number2 = ($ - user_commands) / 8
154
        .number2 = ($ - user_commands) / 8
155
 
155
 
156
; All following commands require a connection to the server.
156
; All following commands require a connection to the server.
157
        dd      'quer', cmd_usr_quer
157
        dd      'quer', cmd_usr_quer
158
        dd      'quit', cmd_usr_quit
158
        dd      'quit', cmd_usr_quit
159
        dd      'part', cmd_usr_part
159
        dd      'part', cmd_usr_part
160
        dd      'ctcp', cmd_usr_ctcp
160
        dd      'ctcp', cmd_usr_ctcp
161
        dd      'msg ', cmd_usr_msg
161
        dd      'msg ', cmd_usr_msg
162
 
162
 
163
        .number = ($ - user_commands) / 8
163
        .number = ($ - user_commands) / 8
164
 
164
 
165
 
165
 
166
 
166
 
167
cmd_usr_msg:
167
cmd_usr_msg:
168
 
168
 
169
        lea     esi, [user_command+5]
169
        lea     esi, [user_command+5]
170
 
170
 
171
        mov     dword[packetbuf], 'PRIV'
171
        mov     dword[packetbuf], 'PRIV'
172
        mov     dword[packetbuf+4], 'MSG '
172
        mov     dword[packetbuf+4], 'MSG '
173
        lea     edi, [packetbuf+8]
173
        lea     edi, [packetbuf+8]
174
 
174
 
175
  @@:
175
  @@:
176
        lodsb
176
        lodsb
177
        test    al, al
177
        test    al, al
178
        jz      .fail
178
        jz      .fail
179
        cmp     al, 10
179
        cmp     al, 10
180
        je      .fail
180
        je      .fail
181
        cmp     al, 13
181
        cmp     al, 13
182
        je      .fail
182
        je      .fail
183
        stosb
183
        stosb
184
        cmp     al, ' '
184
        cmp     al, ' '
185
        jne     @r
185
        jne     @r
186
 
186
 
187
        mov     al, ':'
187
        mov     al, ':'
188
        stosb
188
        stosb
189
 
189
 
190
        push    edi
190
        push    edi
191
  @@:
191
  @@:
192
        lodsb
192
        lodsb
193
        test    al, al
193
        test    al, al
194
        jz      @f
194
        jz      @f
195
        cmp     al, 10
195
        cmp     al, 10
196
        je      @f
196
        je      @f
197
        cmp     al, 13
197
        cmp     al, 13
198
        je      @f
198
        je      @f
199
        stosb
199
        stosb
200
        jmp     @r
200
        jmp     @r
201
  @@:
201
  @@:
202
; end the command with a CRLF
202
; end the command with a CRLF
203
        mov     ax, 0x0a0d
203
        mov     ax, 0x0a0d
204
        stosw
204
        stosw
205
        mov     byte[edi], 0
205
        mov     byte[edi], 0
206
 
-
 
207
        lea     esi, [edi - packetbuf]
-
 
208
        mcall   send, [socketnum], packetbuf, , 0
-
 
209
 
206
 
210
; now print to the window
207
; now print to the window
211
        if TIMESTAMP
208
        if TIMESTAMP
212
        call    print_timestamp
209
        call    print_timestamp
213
        end if
210
        end if
214
 
211
 
215
        mov     esi, msg_header
212
        mov     esi, msg_header
216
        call    print_asciiz
213
        call    print_asciiz
217
 
214
 
218
        mov     esi, packetbuf+8
215
        mov     esi, packetbuf+8
219
        mov     bl, ' '
216
        mov     bl, ' '
220
        call    print_string
217
        call    print_string
221
 
218
 
222
        mov     al, '*'
219
        mov     al, '*'
223
        call    print_char
220
        call    print_char
224
 
221
 
225
        mov     al, ' '
222
        mov     al, ' '
226
        call    print_char
223
        call    print_char
227
 
224
 
228
        pop     esi
225
        pop     esi
-
 
226
        push    esi
229
        call    print_asciiz
227
        call    print_asciiz
-
 
228
        pop     esi
-
 
229
 
-
 
230
 
-
 
231
        lea     esi, [edi - packetbuf]
-
 
232
        mcall   send, [socketnum], packetbuf, , 0
230
 
233
 
231
  .fail:
234
  .fail:
232
        ret
235
        ret
233
 
236
 
234
 
237
 
235
 
238
 
236
cmd_usr_quit:
239
cmd_usr_quit:
237
 
240
 
238
        mov     esi, quit_msg
241
        mov     esi, quit_msg
239
        cmp     byte[user_command+5], ' '
242
        cmp     byte[user_command+5], ' '
240
        jne     quit_server
243
        jne     quit_server
241
        lea     esi, [user_command+6]
244
        lea     esi, [user_command+6]
242
 
245
 
243
; esi = quit message
246
; esi = quit message
244
quit_server:
247
quit_server:
245
 
248
 
246
; User wants to close a channel, send PART command to server
249
; User wants to close a channel, send PART command to server
247
        mov     dword[packetbuf], 'QUIT'
250
        mov     dword[packetbuf], 'QUIT'
248
        mov     word[packetbuf+4], ' :'
251
        mov     word[packetbuf+4], ' :'
249
        lea     edi, [packetbuf+6]
252
        lea     edi, [packetbuf+6]
250
; Append our quit msg
253
; Append our quit msg
251
  @@:
254
  @@:
252
        lodsb
255
        lodsb
253
        cmp     al, 13
256
        cmp     al, 13
254
        je      @f
257
        je      @f
255
        test    al, al
258
        test    al, al
256
        jz      @f
259
        jz      @f
257
        stosb
260
        stosb
258
        jmp     @r
261
        jmp     @r
259
  @@:
262
  @@:
260
; end the command with a CRLF
263
; end the command with a CRLF
261
        mov     ax, 0x0a0d
264
        mov     ax, 0x0a0d
262
        stosw
265
        stosw
263
 
266
 
264
        lea     esi, [edi - packetbuf]                  ; calculate length
267
        lea     esi, [edi - packetbuf]                  ; calculate length
265
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
268
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
266
 
269
 
267
        mov     ebp, windows
270
        mov     ebp, windows
268
  .window_loop:
271
  .window_loop:
269
        cmp     [ebp + window.type], WINDOWTYPE_NONE
272
        cmp     [ebp + window.type], WINDOWTYPE_NONE
270
        je      .next_window
273
        je      .next_window
271
        mov     [window_print], ebp
274
        mov     [window_print], ebp
272
        if TIMESTAMP
275
        if TIMESTAMP
273
        call    print_timestamp
276
        call    print_timestamp
274
        end if
277
        end if
275
        mov     esi, str_disconnected
278
        mov     esi, str_disconnected
276
        call    print_asciiz
279
        call    print_asciiz
277
        cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
280
        cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
278
        jne     .next_window
281
        jne     .next_window
279
        call    user_remove_all
282
        call    user_remove_all
280
  .next_window:
283
  .next_window:
281
        add     ebp, sizeof.window
284
        add     ebp, sizeof.window
282
        cmp     ebp, windows + (MAX_WINDOWS * sizeof.window)
285
        cmp     ebp, windows + (MAX_WINDOWS * sizeof.window)
283
        jb      .window_loop
286
        jb      .window_loop
284
 
287
 
285
        mov     [status], STATUS_DISCONNECTED
288
        mov     [status], STATUS_DISCONNECTED
286
        mcall   close, [socketnum]
289
        mcall   close, [socketnum]
287
 
290
 
288
        ret
291
        ret
289
 
292
 
290
 
293
 
291
 
294
 
292
 
295
 
293
cmd_usr_nick:
296
cmd_usr_nick:
294
 
297
 
295
        cmp     [user_command.size], 5
298
        cmp     [user_command.size], 5
296
        je      .justprint
299
        je      .justprint
297
        cmp     byte[user_command+5], ' '
300
        cmp     byte[user_command+5], ' '
298
        jne     .fail
301
        jne     .fail
299
        cmp     [socketnum], 0
302
        cmp     [socketnum], 0
300
        je      .dontsend
303
        je      .dontsend
301
 
304
 
302
; Request nickname change to server
305
; Request nickname change to server
303
        mov     dword[user_command+1], 'NICK'
306
        mov     dword[user_command+1], 'NICK'
304
        mov     esi, [user_command.size]
307
        mov     esi, [user_command.size]
305
        mov     word[user_command + esi], 0x0a0d
308
        mov     word[user_command + esi], 0x0a0d
306
        inc     esi
309
        inc     esi
307
        mcall   send, [socketnum], user_command+1, , 0
310
        mcall   send, [socketnum], user_command+1, , 0
308
 
311
 
309
  .fail:
312
  .fail:
310
        ret
313
        ret
311
 
314
 
312
; We arent logged in yet, directly change user_nick field and print notification to user.
315
; We arent logged in yet, directly change user_nick field and print notification to user.
313
  .dontsend:
316
  .dontsend:
314
        mov     ecx, MAX_NICK_LEN
317
        mov     ecx, MAX_NICK_LEN
315
        mov     esi, user_command+6
318
        mov     esi, user_command+6
316
        mov     edi, user_nick
319
        mov     edi, user_nick
317
  @@:
320
  @@:
318
        lodsb
321
        lodsb
319
        cmp     al, 13
322
        cmp     al, 13
320
        je      @f
323
        je      @f
321
        stosb
324
        stosb
322
        dec     ecx
325
        dec     ecx
323
        jnz     @r
326
        jnz     @r
324
  @@:
327
  @@:
325
        xor     al, al
328
        xor     al, al
326
        stosb
329
        stosb
327
 
330
 
328
  .justprint:
331
  .justprint:
329
        mov     esi, str_nickchange
332
        mov     esi, str_nickchange
330
        call    print_asciiz
333
        call    print_asciiz
331
 
334
 
332
        mov     esi, user_nick
335
        mov     esi, user_nick
333
        call    print_asciiz
336
        call    print_asciiz
334
 
337
 
335
        mov     al, 10
338
        mov     al, 10
336
        call    print_char
339
        call    print_char
337
 
340
 
338
        ret
341
        ret
339
 
342
 
340
 
343
 
341
 
344
 
342
cmd_usr_real:
345
cmd_usr_real:
343
 
346
 
344
        cmp     byte[user_command+5], ' '
347
        cmp     byte[user_command+5], ' '
345
        jne     cmd_usr_send
348
        jne     cmd_usr_send
346
 
349
 
347
        mov     ecx, MAX_REAL_LEN
350
        mov     ecx, MAX_REAL_LEN
348
        mov     esi, user_command+6
351
        mov     esi, user_command+6
349
        mov     edi, user_real_name
352
        mov     edi, user_real_name
350
  .loop:
353
  .loop:
351
        lodsb
354
        lodsb
352
        cmp     al, 13
355
        cmp     al, 13
353
        je      .done
356
        je      .done
354
        stosb
357
        stosb
355
        dec     ecx
358
        dec     ecx
356
        jnz     .loop
359
        jnz     .loop
357
  .done:
360
  .done:
358
        xor     al, al
361
        xor     al, al
359
        stosb
362
        stosb
360
 
363
 
361
        mov     esi, str_realchange
364
        mov     esi, str_realchange
362
        call    print_asciiz
365
        call    print_asciiz
363
 
366
 
364
        mov     esi, user_real_name
367
        mov     esi, user_real_name
365
        call    print_asciiz
368
        call    print_asciiz
366
 
369
 
367
        mov     al, 10
370
        mov     al, 10
368
        call    print_char
371
        call    print_char
369
 
372
 
370
        ret
373
        ret
371
 
374
 
372
 
375
 
373
 
376
 
374
cmd_usr_server:
377
cmd_usr_server:
375
 
378
 
376
        mov     eax, dword[user_command+5]      ; check for 'er ', we only checked 'serv'
379
        mov     eax, dword[user_command+5]      ; check for 'er ', we only checked 'serv'
377
        or      eax, 0x00002020
380
        or      eax, 0x00002020
378
        and     eax, 0x00ffffff
381
        and     eax, 0x00ffffff
379
        cmp     eax, 'er '
382
        cmp     eax, 'er '
380
        jne     cmd_usr_send
383
        jne     cmd_usr_send
381
 
384
 
382
; Server window is always first window in the list, switch to it.
385
; Server window is always first window in the list, switch to it.
383
        mov     [window_print], windows
386
        mov     [window_print], windows
384
        mov     [window_active], windows
387
        mov     [window_active], windows
385
 
388
 
386
        mov     ecx, [user_command.size]        ; ok now set the address
389
        mov     ecx, [user_command.size]        ; ok now set the address
387
        sub     ecx, 8
390
        sub     ecx, 8
388
 
391
 
389
        mov     esi, user_command+8
392
        mov     esi, user_command+8
390
  .now:
393
  .now:
391
        push    esi
394
        push    esi
392
        mov     edi, irc_server_name
395
        mov     edi, irc_server_name
393
  .loop:                                        ; copy until zero byte, or ecx reaches zero.
396
  .loop:                                        ; copy until zero byte, or ecx reaches zero.
394
        lodsb
397
        lodsb
395
        stosb
398
        stosb
396
        test    al, al
399
        test    al, al
397
        jz      .done
400
        jz      .done
398
        dec     ecx
401
        dec     ecx
399
        jnz     .loop
402
        jnz     .loop
400
        xor     al, al
403
        xor     al, al
401
        stosb
404
        stosb
402
  .done:
405
  .done:
403
        pop     esi
406
        pop     esi
404
 
407
 
405
; set it also in window name
408
; set it also in window name
406
        mov     ebx, [window_print]
409
        mov     ebx, [window_print]
407
        call    window_set_name
410
        call    window_set_name
408
 
411
 
409
; now connect
412
; now connect
410
        call    socket_connect
413
        call    socket_connect
411
 
414
 
412
        ret
415
        ret
413
 
416
 
414
 
417
 
415
cmd_usr_quer:
418
cmd_usr_quer:
416
 
419
 
417
        mov     esi, user_command+7
420
        mov     esi, user_command+7
418
        call    window_open
421
        call    window_open
419
;        test    ebx, ebx
422
;        test    ebx, ebx
420
;        jz      .fail
423
;        jz      .fail
421
 
424
 
422
        ret
425
        ret
423
 
426
 
424
 
427
 
425
 
428
 
426
cmd_usr_help:
429
cmd_usr_help:
427
 
430
 
428
        mov     esi, str_help
431
        mov     esi, str_help
429
        call    print_asciiz
432
        call    print_asciiz
430
 
433
 
431
        ret
434
        ret
432
 
435
 
433
 
436
 
434
 
437
 
435
cmd_usr_code:
438
cmd_usr_code:
436
 
439
 
437
        ; TODO
440
        ; TODO
438
 
441
 
439
        ret
442
        ret
440
 
443
 
441
 
444
 
442
 
445
 
443
; User typed a part command
446
; User typed a part command
444
cmd_usr_part:
447
cmd_usr_part:
445
 
448
 
446
        cmp     byte[user_command+5], 13        ; parameters given?
449
        cmp     byte[user_command+5], 13        ; parameters given?
447
        jne     cmd_usr_send                    ; yes, send command straight to server
450
        jne     cmd_usr_send                    ; yes, send command straight to server
448
 
451
 
449
; close active window
452
; close active window
450
cmd_usr_close_window:
453
cmd_usr_close_window:
451
 
454
 
452
        mov     esi, [window_active]
455
        mov     esi, [window_active]
453
        mov     [window_print], esi
456
        mov     [window_print], esi
454
        cmp     [esi + window.type], WINDOWTYPE_SERVER
457
        cmp     [esi + window.type], WINDOWTYPE_SERVER
455
        je      .not_channel
458
        je      .not_channel
456
 
459
 
457
        lea     esi, [esi + window.name]
460
        lea     esi, [esi + window.name]
458
        call    cmd_usr_part_channel
461
        call    cmd_usr_part_channel
459
        call    window_close
462
        call    window_close
460
        ret
463
        ret
461
 
464
 
462
  .not_channel:
465
  .not_channel:
463
        cmp     [esi + window.type], WINDOWTYPE_CHAT
466
        cmp     [esi + window.type], WINDOWTYPE_CHAT
464
        jne     .not_chat
467
        jne     .not_chat
465
 
468
 
466
        call    window_close
469
        call    window_close
467
  .not_chat:
470
  .not_chat:
468
 
471
 
469
        ret
472
        ret
470
 
473
 
471
 
474
 
472
 
475
 
473
; Send part command to server
476
; Send part command to server
474
; esi must point to channel name (ASCIIZ)
477
; esi must point to channel name (ASCIIZ)
475
cmd_usr_part_channel:
478
cmd_usr_part_channel:
476
 
479
 
477
; User wants to close a channel, send PART command to server
480
; User wants to close a channel, send PART command to server
478
        mov     dword[packetbuf], 'PART'
481
        mov     dword[packetbuf], 'PART'
479
        mov     byte[packetbuf+4], ' '
482
        mov     byte[packetbuf+4], ' '
480
        lea     edi, [packetbuf+5]
483
        lea     edi, [packetbuf+5]
481
  @@:
484
  @@:
482
        lodsb
485
        lodsb
483
        test    al, al
486
        test    al, al
484
        jz      @f
487
        jz      @f
485
        cmp     al, 13
488
        cmp     al, 13
486
        je      @f
489
        je      @f
487
        cmp     al, 10
490
        cmp     al, 10
488
        je      @f
491
        je      @f
489
        stosb
492
        stosb
490
        jmp     @r
493
        jmp     @r
491
  @@:
494
  @@:
492
; end the command with a CRLF
495
; end the command with a CRLF
493
        mov     ax, 0x0a0d
496
        mov     ax, 0x0a0d
494
        stosw
497
        stosw
495
 
498
 
496
        lea     esi, [edi - packetbuf]                  ; calculate length
499
        lea     esi, [edi - packetbuf]                  ; calculate length
497
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
500
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
498
 
501
 
499
        ret
502
        ret
500
 
503
 
501
 
504
 
502
 
505
 
503
cmd_usr_ctcp:
506
cmd_usr_ctcp:
504
 
507
 
505
        cmp     byte[user_command+5], ' '
508
        cmp     byte[user_command+5], ' '
506
        jne     cmd_usr_send
509
        jne     cmd_usr_send
507
 
510
 
508
        mov     esi, user_command+6
511
        mov     esi, user_command+6
509
; prepare a 'PRIVMSG '
512
; prepare a 'PRIVMSG '
510
        mov     dword[packetbuf], 'PRIV'
513
        mov     dword[packetbuf], 'PRIV'
511
        mov     dword[packetbuf+4], 'MSG '
514
        mov     dword[packetbuf+4], 'MSG '
512
        lea     edi, [packetbuf+8]
515
        lea     edi, [packetbuf+8]
513
 
516
 
514
; append the destination (nickname/channel)
517
; append the destination (nickname/channel)
515
  @@:
518
  @@:
516
        lodsb
519
        lodsb
517
        test    al, al
520
        test    al, al
518
        jz      .fail
521
        jz      .fail
519
        cmp     al, ' '
522
        cmp     al, ' '
520
        je      @f
523
        je      @f
521
        stosb
524
        stosb
522
        jmp     @r
525
        jmp     @r
523
  @@:
526
  @@:
524
 
527
 
525
        mov     ax, ' :'
528
        mov     ax, ' :'
526
        stosw
529
        stosw
527
        mov     al, 0x01
530
        mov     al, 0x01
528
        stosb
531
        stosb
-
 
532
 
-
 
533
        push edi esi
529
 
534
 
530
; copy the message itself
535
; copy the message itself
531
  @@:
536
  @@:
532
        lodsb
537
        lodsb
533
        test    al, al
538
        test    al, al
534
        jz      @f
539
        jz      @f
535
        cmp     al, 13
540
        cmp     al, 13
536
        je      @f
541
        je      @f
537
        cmp     al, 10
542
        cmp     al, 10
538
        je      @f
543
        je      @f
539
        stosb
544
        stosb
540
        jmp     @r
545
        jmp     @r
541
  @@:
546
  @@:
542
 
547
 
543
; end of message
548
; end of message
544
        mov     al, 0x01
549
        mov     al, 0x01
545
        stosb
550
        stosb
546
        mov     ax, 0x0a0d
551
        mov     ax, 0x0a0d
547
        stosw
552
        stosw
-
 
553
        mov     byte[edi], 0
-
 
554
 
-
 
555
; now print to the window
-
 
556
        if TIMESTAMP
-
 
557
        call    print_timestamp
-
 
558
        end if
-
 
559
 
-
 
560
        mov     esi, ctcp_header
-
 
561
        call    print_asciiz
-
 
562
 
-
 
563
        mov     esi, packetbuf+8
-
 
564
        mov     bl, ' '
-
 
565
        call    print_string
-
 
566
 
-
 
567
        mov     al, ']'
-
 
568
        call    print_char
-
 
569
 
-
 
570
        mov     al, ' '
-
 
571
        call    print_char
-
 
572
 
-
 
573
        pop     esi
-
 
574
        call    print_asciiz
-
 
575
        pop     esi
-
 
576
 
548
 
577
 
549
; now send it away
578
; now send it away
550
        lea     esi, [edi - packetbuf]                  ; calculate length
579
        lea     esi, [edi - packetbuf]                  ; calculate length
551
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
580
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
552
 
-
 
553
;; TODO: print to window
-
 
554
 
581
 
555
  .fail:
582
  .fail:
556
 
583
 
557
        ret
584
        ret
558
 
585
 
559
 
586
 
560
 
587
 
561
cmd_usr_me:
588
cmd_usr_me:
562
 
589
 
563
; prepare a 'PRIVMSG '
590
; prepare a 'PRIVMSG '
564
        mov     dword[packetbuf], 'PRIV'
591
        mov     dword[packetbuf], 'PRIV'
565
        mov     dword[packetbuf+4], 'MSG '
592
        mov     dword[packetbuf+4], 'MSG '
566
        lea     edi, [packetbuf+8]
593
        lea     edi, [packetbuf+8]
567
 
594
 
568
; append the destination (nickname/channel)
595
; append the destination (nickname/channel)
569
        mov     esi, [window_active]
596
        mov     esi, [window_active]
570
        lea     esi, [esi + window.name]
597
        lea     esi, [esi + window.name]
571
  @@:
598
  @@:
572
        lodsb
599
        lodsb
573
        test    al, al
600
        test    al, al
574
        je      @f
601
        je      @f
575
        stosb
602
        stosb
576
        jmp     @r
603
        jmp     @r
577
  @@:
604
  @@:
578
 
605
 
579
; Make the CTCP action header
606
; Make the CTCP action header
580
        mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
607
        mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
581
        stosd
608
        stosd
582
        mov     eax, 'CTIO'
609
        mov     eax, 'CTIO'
583
        stosd
610
        stosd
584
        mov     al, 'N'
611
        mov     al, 'N'
585
        stosb
612
        stosb
586
 
613
 
587
; copy the message itself (including first space)
614
; copy the message itself (including first space)
588
        mov     esi, user_command+3
615
        mov     esi, user_command+3
589
  @@:
616
  @@:
590
        lodsb
617
        lodsb
591
        cmp     al, 13
618
        cmp     al, 13
592
        je      @f
619
        je      @f
593
        stosb
620
        stosb
594
        jmp     @r
621
        jmp     @r
595
  @@:
622
  @@:
596
 
623
 
597
; end of CTCP message
624
; end of CTCP message
598
        mov     al, 0x01
625
        mov     al, 0x01
599
        stosb
626
        stosb
600
        mov     ax, 0x0a0d
627
        mov     ax, 0x0a0d
601
        stosw
628
        stosw
602
 
629
 
603
; now send it to the server
630
; now send it to the server
604
        lea     esi, [edi - packetbuf]                  ; calculate length
631
        lea     esi, [edi - packetbuf]                  ; calculate length
605
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
632
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
606
 
633
 
607
; print to local window
634
; print to local window
608
        if TIMESTAMP
635
        if TIMESTAMP
609
        call    print_timestamp
636
        call    print_timestamp
610
        end if
637
        end if
611
 
638
 
612
        mov     esi, action_header
639
        mov     esi, action_header
613
        call    print_asciiz
640
        call    print_asciiz
614
 
641
 
615
        mov     esi, user_nick
642
        mov     esi, user_nick
616
        call    print_asciiz
643
        call    print_asciiz
617
 
644
 
618
        mov     esi, user_command+3
645
        mov     esi, user_command+3
619
        mov     bl, 13
646
        mov     bl, 13
620
        call    print_string
647
        call    print_string
621
 
648
 
622
        mov     al, 10
649
        mov     al, 10
623
        call    print_char
650
        call    print_char
624
 
651
 
625
        ret
652
        ret
626
 
653
 
627
 
654
 
628
 
655
 
629
; The user typed some undefined command, just send it to the server
656
; The user typed some undefined command, just send it to the server
630
cmd_usr_send:
657
cmd_usr_send:
631
 
658
 
632
        mov     esi, [user_command.size]
659
        mov     esi, [user_command.size]
633
        mov     eax, [user_command.size]
660
        mov     eax, [user_command.size]
634
        add     eax, user_command+1
661
        add     eax, user_command+1
635
        mov     word[eax], 0x0d0a
662
        mov     word[eax], 0x0d0a
636
        inc     esi
663
        inc     esi
637
        mcall   send, [socketnum], user_command+1, , 0
664
        mcall   send, [socketnum], user_command+1, , 0
638
 
665
 
639
        ret
666
        ret
640
>
667
>