2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-02-23 22:15:46 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
2013-11-01 15:02:08 +01:00
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
|
socket_connect:
|
|
|
|
|
|
|
|
; ignore if status is not "disconnected"
|
|
|
|
cmp [status], STATUS_DISCONNECTED
|
2013-11-01 15:02:08 +01:00
|
|
|
jne .reconnect
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-11-01 15:02:08 +01:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, str_connecting
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, irc_server_name
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
|
|
|
|
|
|
|
mov al, 10
|
|
|
|
call print_char
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; update status
|
|
|
|
inc [status] ; was STATUS_DISCONNECTED, now STATUS_RESOLVING
|
|
|
|
|
|
|
|
; resolve name
|
|
|
|
push esp ; reserve stack place
|
|
|
|
push esp ; fourth parameter
|
|
|
|
push 0 ; third parameter
|
|
|
|
push 0 ; second parameter
|
|
|
|
push irc_server_name
|
|
|
|
call [getaddrinfo]
|
|
|
|
pop esi
|
|
|
|
; test for error
|
|
|
|
test eax, eax
|
|
|
|
jnz .fail_dns
|
|
|
|
|
|
|
|
; fill in ip in sockstruct
|
|
|
|
mov eax, [esi + addrinfo.ai_addr]
|
|
|
|
mov eax, [eax + sockaddr_in.sin_addr]
|
|
|
|
mov [sockaddr1.ip], eax
|
|
|
|
|
|
|
|
; free allocated memory
|
|
|
|
push esi
|
|
|
|
call [freeaddrinfo]
|
|
|
|
|
|
|
|
; update status
|
|
|
|
inc [status]
|
|
|
|
|
|
|
|
; connect
|
|
|
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
|
|
|
cmp eax, -1
|
|
|
|
jz .fail
|
|
|
|
mov [socketnum], eax
|
|
|
|
|
|
|
|
mcall connect, [socketnum], sockaddr1, 18
|
|
|
|
cmp eax, -1
|
|
|
|
jz .fail_refused
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
|
2013-11-01 15:02:08 +01:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, str_sockerr
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail_dns:
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
|
2013-11-01 15:02:08 +01:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, str_dnserr
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail_refused:
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
|
2013-11-01 15:02:08 +01:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, str_refused
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2013-11-01 15:02:08 +01:00
|
|
|
.reconnect:
|
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
|
|
|
mov esi, str_reconnect
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
2013-11-01 15:02:08 +01:00
|
|
|
|
|
|
|
mov esi, quit_msg
|
2014-03-28 21:03:30 +01:00
|
|
|
call quit_server
|
2013-11-01 15:02:08 +01:00
|
|
|
|
|
|
|
jmp socket_connect
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
socket_write_userinfo:
|
|
|
|
|
|
|
|
; create packet in packetbuf
|
|
|
|
mov edi, packetbuf
|
|
|
|
|
|
|
|
mov eax, 'NICK'
|
|
|
|
stosd
|
|
|
|
mov al, ' '
|
|
|
|
stosb
|
|
|
|
mov esi, user_nick
|
|
|
|
mov ecx, MAX_NICK_LEN
|
|
|
|
.loop:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .done
|
|
|
|
stosb
|
|
|
|
dec ecx
|
|
|
|
jnz .loop
|
|
|
|
.done:
|
2013-10-07 16:02:05 +02:00
|
|
|
mov ax, 0x0a0d
|
2013-05-28 19:34:26 +02:00
|
|
|
stosw
|
|
|
|
|
|
|
|
mov eax, 'USER'
|
|
|
|
stosd
|
|
|
|
mov al, ' '
|
|
|
|
stosb
|
|
|
|
mov esi, user_nick
|
|
|
|
mov ecx, MAX_NICK_LEN
|
|
|
|
.loop2:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .done2
|
|
|
|
stosb
|
|
|
|
dec ecx
|
|
|
|
jnz .loop2
|
|
|
|
.done2:
|
|
|
|
mov eax, ' 8 *'
|
|
|
|
stosd
|
|
|
|
mov ax, ' :'
|
|
|
|
stosw
|
|
|
|
mov al, ' '
|
|
|
|
stosb
|
|
|
|
mov esi, user_real_name
|
|
|
|
mov ecx, MAX_REAL_LEN
|
|
|
|
.loop3:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .done3
|
|
|
|
stosb
|
|
|
|
dec ecx
|
|
|
|
jnz .loop3
|
|
|
|
.done3:
|
2013-10-07 16:02:05 +02:00
|
|
|
mov ax, 0x0a0d
|
2013-05-28 19:34:26 +02:00
|
|
|
stosw
|
|
|
|
|
|
|
|
lea esi, [edi - packetbuf]
|
|
|
|
mcall send, [socketnum], packetbuf, , 0
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process_network_event:
|
|
|
|
; values for status: 0, 1, 2, 3
|
|
|
|
mov eax, [status]
|
|
|
|
dec eax
|
|
|
|
; 0 = STATUS_DISCONNECTED - do nothing
|
|
|
|
; (ignore network events if we are disconnected from network)
|
|
|
|
js .nothing
|
|
|
|
; 1 = STATUS_RESOLVING
|
|
|
|
jz .nothing
|
|
|
|
; 2 = STATUS_CONNECTING
|
|
|
|
dec eax
|
|
|
|
jz .connecting
|
|
|
|
; 3 = STATUS_CONNECTED
|
|
|
|
jmp .connected
|
|
|
|
|
|
|
|
.nothing:
|
|
|
|
ret
|
|
|
|
|
|
|
|
.connecting:
|
|
|
|
call socket_write_userinfo
|
|
|
|
|
|
|
|
; The connection has been established, change status from "connecting" to "connected".
|
|
|
|
inc [status]
|
|
|
|
|
|
|
|
.connected:
|
2013-11-01 15:02:08 +01:00
|
|
|
call socket_receive
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
2013-11-01 15:02:08 +01:00
|
|
|
socket_receive:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
pusha
|
|
|
|
|
2024-03-05 10:49:00 +01:00
|
|
|
.recv_more:
|
|
|
|
mcall recv, [socketnum], packetbuf , PACKETBUF_SIZE, MSG_DONTWAIT ; read a packet
|
2018-07-01 16:29:23 +02:00
|
|
|
inc eax ; check if we got any data
|
|
|
|
jz .done ; TODO: handle errors!
|
2013-05-28 19:34:26 +02:00
|
|
|
dec eax
|
2014-01-18 16:51:43 +01:00
|
|
|
jz .disconnected
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2016-01-02 22:03:09 +01:00
|
|
|
; ok we have data, now feed it to the command splicer
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2016-01-02 22:03:09 +01:00
|
|
|
mov ecx, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, packetbuf ; esi = start pointer
|
|
|
|
mov edi, servercommand
|
2024-03-05 10:49:00 +01:00
|
|
|
add edi, [cmd_remaining]
|
2013-05-28 19:34:26 +02:00
|
|
|
.byteloop:
|
2024-02-23 22:15:46 +01:00
|
|
|
test ecx, ecx
|
2024-03-05 10:49:00 +01:00
|
|
|
jz .recv_more
|
2016-01-02 22:03:09 +01:00
|
|
|
lodsb
|
2024-02-23 22:15:46 +01:00
|
|
|
dec ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp al, 10
|
|
|
|
je .got_command
|
|
|
|
cmp al, 13
|
|
|
|
je .got_command
|
2024-03-05 10:49:00 +01:00
|
|
|
cmp edi, servercommand + SERVERCOMMAND_SIZE ; Prevent command buffer overflow
|
|
|
|
jae .byteloop
|
2013-05-28 19:34:26 +02:00
|
|
|
stosb
|
2024-02-23 22:15:46 +01:00
|
|
|
jmp .byteloop
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; we have a command, call the serverparser
|
|
|
|
|
|
|
|
.got_command:
|
2024-02-23 22:15:46 +01:00
|
|
|
cmp edi, servercommand + 4
|
|
|
|
jb .nextcommand
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
mov byte[edi], 0 ; mark the end of the command
|
2016-01-02 22:03:09 +01:00
|
|
|
push esi ecx
|
2024-02-23 22:15:46 +01:00
|
|
|
mov ecx, edi
|
|
|
|
sub ecx, servercommand ; put length in ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
call server_parser
|
2016-01-02 22:03:09 +01:00
|
|
|
pop ecx esi
|
2024-03-05 10:49:00 +01:00
|
|
|
|
|
|
|
.nextcommand:
|
|
|
|
mov edi, servercommand
|
|
|
|
mov [cmd_remaining], ecx ; remaining bytes since last EOL
|
|
|
|
jmp .byteloop
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.done:
|
|
|
|
popa
|
2014-01-18 16:51:43 +01:00
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-01-18 16:51:43 +01:00
|
|
|
|
|
|
|
.disconnected:
|
2014-03-28 21:03:30 +01:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
|
|
|
mov esi, str_srv_disconnected
|
2014-03-09 22:57:21 +01:00
|
|
|
call print_asciiz
|
2014-01-18 16:51:43 +01:00
|
|
|
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
mcall close, [socketnum]
|
|
|
|
|
|
|
|
popa
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|