@@ -284,69 +284,50 @@ void Player::clearHud()
284
284
}
285
285
286
286
287
- void RemotePlayer::save (const std::string & savedir)
287
+ void RemotePlayer::save (std::string savedir)
288
288
{
289
- bool newplayer = true ;
290
-
291
- /* We have to iterate through all files in the players directory
289
+ /*
290
+ * We have to open all possible player files in the players directory
292
291
* and check their player names because some file systems are not
293
292
* case-sensitive and player names are case-sensitive.
294
293
*/
295
294
296
295
// A player to deserialize files into to check their names
297
296
RemotePlayer testplayer (m_gamedef);
298
297
299
- std::vector<fs::DirListNode> player_files = fs::GetDirListing (savedir);
300
- for (u32 i = 0 ; i < player_files.size (); i++) {
301
- if (player_files[i].dir || player_files[i].name [0 ] == ' .' ) {
302
- continue ;
298
+ savedir += DIR_DELIM;
299
+ std::string path = savedir + m_name;
300
+ for (u32 i = 0 ; i < 1000 ; i++) {
301
+ if (!fs::PathExists (path)) {
302
+ // Open file and serialize
303
+ std::ostringstream ss (std::ios_base::binary);
304
+ serialize (ss);
305
+ if (!fs::safeWriteToFile (path, ss.str ())) {
306
+ infostream << " Failed to write " << path << std::endl;
307
+ }
308
+ return ;
303
309
}
304
-
305
- // Full path to this file
306
- std::string path = savedir + " /" + player_files[i].name ;
307
-
308
310
// Open file and deserialize
309
311
std::ifstream is (path.c_str (), std::ios_base::binary);
310
312
if (!is.good ()) {
311
- infostream << " Failed to read " << path << std::endl;
312
- continue ;
313
+ infostream << " Failed to open " << path << std::endl;
314
+ return ;
313
315
}
314
- testplayer.deSerialize (is, player_files[i].name );
315
-
316
+ testplayer.deSerialize (is, path);
316
317
if (strcmp (testplayer.getName (), m_name) == 0 ) {
317
318
// Open file and serialize
318
319
std::ostringstream ss (std::ios_base::binary);
319
320
serialize (ss);
320
321
if (!fs::safeWriteToFile (path, ss.str ())) {
321
322
infostream << " Failed to write " << path << std::endl;
322
323
}
323
- newplayer = false ;
324
- break ;
325
- }
326
- }
327
-
328
- if (newplayer) {
329
- bool found = false ;
330
- std::string path = savedir + " /" + m_name;
331
- for (u32 i = 0 ; i < 1000 ; i++) {
332
- if (!fs::PathExists (path)) {
333
- found = true ;
334
- break ;
335
- }
336
- path = savedir + " /" + m_name + itos (i);
337
- }
338
- if (!found) {
339
- infostream << " Didn't find free file for player " << m_name << std::endl;
340
324
return ;
341
325
}
342
-
343
- // Open file and serialize
344
- std::ostringstream ss (std::ios_base::binary);
345
- serialize (ss);
346
- if (!fs::safeWriteToFile (path, ss.str ())) {
347
- infostream << " Failed to write " << path << std::endl;
348
- }
326
+ path = savedir + m_name + itos (i);
349
327
}
328
+
329
+ infostream << " Didn't find free file for player " << m_name << std::endl;
330
+ return ;
350
331
}
351
332
352
333
/*
0 commit comments