2013-05-28 21:34:26 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2018-07-01 17:29:23 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2018. All rights reserved. ;;
|
2013-05-28 21:34:26 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
2013-11-01 18:02:08 +04:00
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
2013-05-28 21:34:26 +04:00
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
|
socket_connect:
|
|
|
|
|
|
|
|
; ignore if status is not "disconnected"
|
|
|
|
cmp [status], STATUS_DISCONNECTED
|
2013-11-01 18:02:08 +04:00
|
|
|
jne .reconnect
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-11-01 18:02:08 +04:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, str_connecting
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
|
|
|
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, irc_server_name
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
|
|
|
|
|
|
|
mov al, 10
|
|
|
|
call print_char
|
2013-05-28 21:34:26 +04: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 18:02:08 +04:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, str_sockerr
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail_dns:
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
|
2013-11-01 18:02:08 +04:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, str_dnserr
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail_refused:
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
|
2013-11-01 18:02:08 +04:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, str_refused
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2013-11-01 18:02:08 +04:00
|
|
|
.reconnect:
|
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
|
|
|
mov esi, str_reconnect
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
2013-11-01 18:02:08 +04:00
|
|
|
|
|
|
|
mov esi, quit_msg
|
2014-03-29 00:03:30 +04:00
|
|
|
call quit_server
|
2013-11-01 18:02:08 +04:00
|
|
|
|
|
|
|
jmp socket_connect
|
2013-05-28 21:34:26 +04: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 18:02:05 +04:00
|
|
|
mov ax, 0x0a0d
|
2013-05-28 21:34:26 +04: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 18:02:05 +04:00
|
|
|
mov ax, 0x0a0d
|
2013-05-28 21:34:26 +04: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 18:02:08 +04:00
|
|
|
call socket_receive
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
2013-11-01 18:02:08 +04:00
|
|
|
socket_receive:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
pusha
|
|
|
|
|
2016-01-03 00:03:09 +03:00
|
|
|
; FIXME: make this a proper stream!
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
.nextpacket:
|
2018-07-01 17:29:23 +03:00
|
|
|
mcall recv, [socketnum], packetbuf, PACKETBUF_SIZE, MSG_DONTWAIT ; read a packet
|
|
|
|
inc eax ; check if we got any data
|
|
|
|
jz .done ; TODO: handle errors!
|
2013-05-28 21:34:26 +04:00
|
|
|
dec eax
|
2014-01-18 19:51:43 +04:00
|
|
|
jz .disconnected
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2016-01-03 00:03:09 +03:00
|
|
|
; ok we have data, now feed it to the command splicer
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2016-01-03 00:03:09 +03:00
|
|
|
mov ecx, eax
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, packetbuf ; esi = start pointer
|
|
|
|
.nextcommand:
|
|
|
|
mov edi, servercommand
|
|
|
|
.byteloop:
|
2016-01-03 00:03:09 +03:00
|
|
|
lodsb
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp al, 10
|
|
|
|
je .got_command
|
|
|
|
cmp al, 13
|
|
|
|
je .got_command
|
|
|
|
stosb
|
2016-01-03 00:03:09 +03:00
|
|
|
dec ecx
|
|
|
|
jnz .byteloop
|
|
|
|
;;; FIXME
|
|
|
|
jmp .nextpacket
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; we have a command, call the serverparser
|
|
|
|
|
|
|
|
.got_command:
|
|
|
|
mov byte[edi], 0 ; mark the end of the command
|
2016-01-03 00:03:09 +03:00
|
|
|
push esi ecx
|
2013-05-28 21:34:26 +04:00
|
|
|
call server_parser
|
2016-01-03 00:03:09 +03:00
|
|
|
pop ecx esi
|
|
|
|
test ecx, ecx
|
|
|
|
jnz .nextcommand
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
.done:
|
|
|
|
popa
|
2014-01-18 19:51:43 +04:00
|
|
|
ret
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-01-18 19:51:43 +04:00
|
|
|
|
|
|
|
.disconnected:
|
2014-03-29 00:03:30 +04:00
|
|
|
if TIMESTAMP
|
|
|
|
call print_timestamp
|
|
|
|
end if
|
|
|
|
mov esi, str_srv_disconnected
|
2014-03-10 01:57:21 +04:00
|
|
|
call print_asciiz
|
2014-01-18 19:51:43 +04:00
|
|
|
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
mcall close, [socketnum]
|
|
|
|
|
|
|
|
popa
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|