allow local game player join from unpacked player file

stable-5.2
Sven Eberhardt 2009-10-13 20:42:20 +02:00
parent af8a4d56b7
commit 15c95d5c57
2 changed files with 29 additions and 4 deletions

View File

@ -703,10 +703,35 @@ C4ControlJoinPlayer::C4ControlJoinPlayer(const char *szFilename, int32_t iAtClie
{
// load from file if filename is given - which may not be the case for script players
if (szFilename)
{
StdStrBuf filename_buf;
const char *filename = Config.AtDataReadPath(szFilename);
bool file_is_temp = false;
if (DirectoryExists(filename))
{
bool fSuccess = PlrData.LoadFromFile(Config.AtDataReadPath(szFilename));
assert(fSuccess);
// the player file is unpacked - temp pack and read
filename_buf.Copy(Config.AtTempPath(GetFilenameOnly(filename)));
MakeTempFilename(&filename_buf);
if (C4Group_PackDirectoryTo(filename, filename_buf.getData()))
{
filename = filename_buf.getData();
file_is_temp = true;
}
else
{
// pack failed
LogF("[!]Error packing player file %s to %s for join: Pack failed.", filename, filename_buf.getData());
assert(false);
}
}
bool fSuccess = PlrData.LoadFromFile(filename);
if (!fSuccess)
{
assert(false);
LogF("[!]Error loading player file from %s.", filename);
}
if (file_is_temp) EraseFile(filename);
}
}
void C4ControlJoinPlayer::Execute() const

View File

@ -1358,8 +1358,8 @@ bool C4PlayerInfoList::LocalJoinUnjoinedPlayersInQueue()
LogF(LoadResStr("IDS_ERR_JOINQUEUEPLRS"), szPlrName);
continue;
}
Game.Input.Add(CID_JoinPlr,
new C4ControlJoinPlayer(szFilename, ::Control.ClientID(), pInfo->GetID()));
Game.Input.Add(CID_JoinPlr,
new C4ControlJoinPlayer(szFilename, ::Control.ClientID(), pInfo->GetID()));
}
// done, success
return true;