Rev 3790 | Rev 3800 | 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 | |||
3790 | hidnplayr | 14 | ; cmp dword[s], "226 " |
3789 | hidnplayr | 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 | |||
3790 | hidnplayr | 23 | ; cmp dword[s], "250" |
24 | ; je dir_ok |
||
25 | |||
3701 | hidnplayr | 26 | cmp dword[s], "331 " |
27 | je pass |
||
28 | |||
3790 | hidnplayr | 29 | ; cmp dword[s], "421 " |
3789 | hidnplayr | 30 | ; je timeout |
3701 | hidnplayr | 31 | |
3789 | hidnplayr | 32 | cmp dword[s], "530" ; password incorrect |
33 | je welcome |
||
3701 | hidnplayr | 34 | |
3789 | hidnplayr | 35 | jmp wait_for_usercommand |
36 | |||
37 | |||
3701 | hidnplayr | 38 | welcome: |
39 | |||
40 | mov [status], STATUS_CONNECTED |
||
3789 | hidnplayr | 41 | jmp wait_for_usercommand |
3701 | hidnplayr | 42 | |
43 | |||
44 | pass: |
||
45 | |||
46 | mov [status], STATUS_NEEDPASSWORD |
||
3789 | hidnplayr | 47 | jmp wait_for_usercommand |
3701 | hidnplayr | 48 | |
49 | |||
50 | login_ok: |
||
51 | |||
52 | mov [status], STATUS_LOGGED_IN |
||
3789 | hidnplayr | 53 | jmp wait_for_usercommand |
3701 | hidnplayr | 54 | |
55 | |||
56 | pasv_ok: |
||
57 | |||
58 | sub ecx, 5 |
||
59 | jb .fail |
||
60 | mov al, "(" |
||
61 | mov edi, s + 5 |
||
62 | repne scasb |
||
63 | |||
64 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
||
65 | cmp eax, -1 |
||
66 | je fail |
||
67 | mov [datasocket], eax |
||
68 | |||
69 | mov esi, edi |
||
70 | call ascii_dec |
||
71 | mov byte[sockaddr2.ip+0], bl |
||
72 | call ascii_dec |
||
73 | mov byte[sockaddr2.ip+1], bl |
||
74 | call ascii_dec |
||
75 | mov byte[sockaddr2.ip+2], bl |
||
76 | call ascii_dec |
||
77 | mov byte[sockaddr2.ip+3], bl |
||
78 | |||
79 | call ascii_dec |
||
3789 | hidnplayr | 80 | mov byte[sockaddr2.port+0], bl |
81 | call ascii_dec |
||
3701 | hidnplayr | 82 | mov byte[sockaddr2.port+1], bl |
83 | |||
3789 | hidnplayr | 84 | invoke con_write_asciiz, str_open |
3701 | hidnplayr | 85 | mcall connect, [datasocket], sockaddr2, 18 |
86 | |||
87 | .fail: |
||
3789 | hidnplayr | 88 | jmp wait_for_servercommand |
3701 | hidnplayr | 89 | |
90 | |||
91 | data_ok: |
||
92 | |||
3792 | hidnplayr | 93 | mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0 |
94 | test ebx, ebx |
||
95 | jnz .fail |
||
3790 | hidnplayr | 96 | mov byte[buffer_ptr2 + eax], 0 |
3701 | hidnplayr | 97 | |
3790 | hidnplayr | 98 | invoke con_write_asciiz, buffer_ptr2 |
3789 | hidnplayr | 99 | |
3792 | hidnplayr | 100 | jmp data_ok |
101 | |||
3701 | hidnplayr | 102 | .fail: |
3789 | hidnplayr | 103 | mcall close, [datasocket] |
104 | jmp wait_for_servercommand |
||
3701 | hidnplayr | 105 | |
106 | |||
107 | ascii_dec: |
||
108 | |||
109 | xor ebx, ebx |
||
3789 | hidnplayr | 110 | mov cl, 4 ; max length is 3 digits + 1 separator |
3701 | hidnplayr | 111 | .loop: |
112 | lodsb |
||
113 | sub al, '0' |
||
114 | jb .done |
||
115 | cmp al, 9 |
||
116 | ja .done |
||
3789 | hidnplayr | 117 | lea ebx, [ebx*4+ebx] ; ebx *5 |
118 | shl ebx, 1 ; ebx *2 |
||
3701 | hidnplayr | 119 | add bl, al |
120 | dec cl |
||
121 | jnz .loop |
||
122 | |||
123 | .done: |
||
124 | ret |