Rev 3704 | Rev 3790 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3701 | hidnplayr | 1 | server_parser: |
2 | |||
3 | ; Commands are always 3 numbers and followed by a space |
||
4 | ; If a server decides it needs multiline output, |
||
5 | ; first lines will have a dash instead of space after numbers, |
||
3789 | hidnplayr | 6 | ; thus they are simply ignored in this simple command parser. |
3701 | hidnplayr | 7 | |
8 | cmp dword[s], "150 " |
||
9 | je data_ok |
||
10 | |||
11 | cmp dword[s], "220 " |
||
12 | je welcome |
||
13 | |||
3789 | hidnplayr | 14 | cmp dword[s], "226 " |
15 | ; je list_ok |
||
16 | |||
3701 | hidnplayr | 17 | cmp dword[s], "227 " |
18 | je pasv_ok |
||
19 | |||
20 | cmp dword[s], "230 " |
||
21 | je login_ok |
||
22 | |||
23 | cmp dword[s], "331 " |
||
24 | je pass |
||
25 | |||
3789 | hidnplayr | 26 | cmp dword[s], "421 " |
27 | ; je timeout |
||
3701 | hidnplayr | 28 | |
3789 | hidnplayr | 29 | cmp dword[s], "530" ; password incorrect |
30 | je welcome |
||
3701 | hidnplayr | 31 | |
3789 | hidnplayr | 32 | jmp wait_for_usercommand |
33 | |||
34 | |||
3701 | hidnplayr | 35 | welcome: |
36 | |||
37 | mov [status], STATUS_CONNECTED |
||
3789 | hidnplayr | 38 | jmp wait_for_usercommand |
3701 | hidnplayr | 39 | |
40 | |||
41 | pass: |
||
42 | |||
43 | mov [status], STATUS_NEEDPASSWORD |
||
3789 | hidnplayr | 44 | jmp wait_for_usercommand |
3701 | hidnplayr | 45 | |
46 | |||
47 | login_ok: |
||
48 | |||
49 | mov [status], STATUS_LOGGED_IN |
||
3789 | hidnplayr | 50 | jmp wait_for_usercommand |
3701 | hidnplayr | 51 | |
52 | |||
53 | pasv_ok: |
||
54 | |||
55 | sub ecx, 5 |
||
56 | jb .fail |
||
57 | mov al, "(" |
||
58 | mov edi, s + 5 |
||
59 | repne scasb |
||
60 | |||
61 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
||
62 | cmp eax, -1 |
||
63 | je fail |
||
64 | mov [datasocket], eax |
||
65 | |||
66 | mov esi, edi |
||
67 | call ascii_dec |
||
68 | mov byte[sockaddr2.ip+0], bl |
||
69 | call ascii_dec |
||
70 | mov byte[sockaddr2.ip+1], bl |
||
71 | call ascii_dec |
||
72 | mov byte[sockaddr2.ip+2], bl |
||
73 | call ascii_dec |
||
74 | mov byte[sockaddr2.ip+3], bl |
||
75 | |||
76 | call ascii_dec |
||
3789 | hidnplayr | 77 | mov byte[sockaddr2.port+0], bl |
78 | call ascii_dec |
||
3701 | hidnplayr | 79 | mov byte[sockaddr2.port+1], bl |
80 | |||
3789 | hidnplayr | 81 | invoke con_write_asciiz, str_open |
3701 | hidnplayr | 82 | mcall connect, [datasocket], sockaddr2, 18 |
83 | |||
84 | .fail: |
||
3789 | hidnplayr | 85 | jmp wait_for_servercommand |
3701 | hidnplayr | 86 | |
87 | |||
88 | data_ok: |
||
89 | |||
3704 | hidnplayr | 90 | mcall recv, [datasocket], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT ; fixme: use other buffer |
3701 | hidnplayr | 91 | inc eax |
92 | jz .fail |
||
93 | dec eax |
||
94 | jz .fail |
||
95 | mov byte[buffer_ptr + eax], 0 |
||
96 | |||
3789 | hidnplayr | 97 | invoke con_write_asciiz, buffer_ptr |
98 | |||
3701 | hidnplayr | 99 | .fail: |
3789 | hidnplayr | 100 | mcall close, [datasocket] |
101 | jmp wait_for_servercommand |
||
3701 | hidnplayr | 102 | |
103 | |||
104 | ascii_dec: |
||
105 | |||
106 | xor ebx, ebx |
||
3789 | hidnplayr | 107 | mov cl, 4 ; max length is 3 digits + 1 separator |
3701 | hidnplayr | 108 | .loop: |
109 | lodsb |
||
110 | sub al, '0' |
||
111 | jb .done |
||
112 | cmp al, 9 |
||
113 | ja .done |
||
3789 | hidnplayr | 114 | lea ebx, [ebx*4+ebx] ; ebx *5 |
115 | shl ebx, 1 ; ebx *2 |
||
3701 | hidnplayr | 116 | add bl, al |
117 | dec cl |
||
118 | jnz .loop |
||
119 | |||
120 | .done: |
||
121 | ret |