… | |
… | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | |
7 | |
8 | my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; |
8 | my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; |
9 | |
9 | |
10 | # testbed for coroutines in crossfire : |
10 | # paranoia function to overwrite a string-in-place |
|
|
11 | sub nuke_str { |
|
|
12 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
|
|
13 | } |
11 | |
14 | |
12 | sub query { |
15 | sub query { |
13 | my ($ns, $flags, $text) = @_; |
16 | my ($ns, $flags, $text) = @_; |
14 | |
17 | |
15 | my $current = $Coro::current; |
18 | my $current = $Coro::current; |
… | |
… | |
145 | 0 < aio_read $fh, 0, 16384, my $buf, 0 or next; |
148 | 0 < aio_read $fh, 0, 16384, my $buf, 0 or next; |
146 | $buf =~ /^password (\S+)$/m or next; |
149 | $buf =~ /^password (\S+)$/m or next; |
147 | my $hash = $1; |
150 | my $hash = $1; |
148 | |
151 | |
149 | if ($hash eq crypt $pass, $hash) { |
152 | if ($hash eq crypt $pass, $hash) { |
|
|
153 | nuke_str $pass; |
150 | # password matches, wonderful |
154 | # password matches, wonderful |
151 | my $pl = cf::player::load $plfile or next; |
155 | my $pl = cf::player::load $plfile or next; |
152 | $pl->enable_save (1); |
156 | $pl->enable_save (1); |
153 | $pl->connect ($ns); |
157 | $pl->connect ($ns); |
154 | last; |
158 | last; |
… | |
… | |
160 | . "please try again. If not, you can now decide to take over this account " |
164 | . "please try again. If not, you can now decide to take over this account " |
161 | . "because it has not been in-use for some time.", |
165 | . "because it has not been in-use for some time.", |
162 | cf::NDI_RED |
166 | cf::NDI_RED |
163 | ); |
167 | ); |
164 | |
168 | |
|
|
169 | #TODO: nuke_str |
165 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
170 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
166 | or next; |
171 | or next; |
167 | |
172 | |
168 | # check if the file hasn't changed |
173 | # check if the file hasn't changed |
169 | aio_stat $plfile and next; |
174 | aio_stat $plfile and next; |
… | |
… | |
171 | |
176 | |
172 | nuke_playerdir $user; |
177 | nuke_playerdir $user; |
173 | |
178 | |
174 | # fall through to creation |
179 | # fall through to creation |
175 | } else { |
180 | } else { |
|
|
181 | nuke_str $pass; |
|
|
182 | |
176 | Coro::Timer::sleep 1; |
183 | Coro::Timer::sleep 1; |
177 | |
184 | |
178 | $ns->send_drawinfo ( |
185 | $ns->send_drawinfo ( |
179 | "Wrong username or password. Please try again " |
186 | "Wrong username or password. Please try again " |
180 | . "(check for Numlock and other semi-obvious error sources).", |
187 | . "(check for Numlock and other semi-obvious error sources).", |
… | |
… | |
190 | nuke_playerdir $user; |
197 | nuke_playerdir $user; |
191 | |
198 | |
192 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
199 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
193 | |
200 | |
194 | if ($pass2 ne $pass) { |
201 | if ($pass2 ne $pass) { |
|
|
202 | nuke_str $pass; |
|
|
203 | nuke_str $pass2; |
195 | $ns->send_drawinfo ( |
204 | $ns->send_drawinfo ( |
196 | "The passwords do not match, please try again.", |
205 | "The passwords do not match, please try again.", |
197 | cf::NDI_RED |
206 | cf::NDI_RED |
198 | ); |
207 | ); |
199 | next; |
208 | next; |
200 | } |
209 | } |
201 | |
210 | |
|
|
211 | nuke_str $pass2; |
|
|
212 | |
202 | my $pl = cf::player::create; |
213 | my $pl = cf::player::create; |
203 | $pl->ob->name ($user); |
214 | $pl->ob->name ($user); |
204 | $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); |
215 | $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); |
|
|
216 | nuke_str $pass; |
205 | $pl->connect ($ns); |
217 | $pl->connect ($ns); |
206 | |
218 | |
207 | my $ob = $pl->ob; |
219 | my $ob = $pl->ob; |
208 | |
220 | |
209 | while () { |
221 | while () { |