New .sta file format in plain text. This should fix problems people have had
with corrupted player name and such when mixing 2.0 and 2.1 versions, or old and new versions of 2.1. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2070 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
d079d6cf08
commit
f94ff0ce9d
|
@ -585,47 +585,52 @@ BOOL setMultiStats(SDWORD dp, PLAYERSTATS plStats, BOOL bLocal)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ////////////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////////////
|
||||||
// Load Player Stats
|
// Load Player Stats
|
||||||
BOOL loadMultiStats(char *sPlayerName, PLAYERSTATS *playerStats)
|
BOOL loadMultiStats(char *sPlayerName, PLAYERSTATS *st)
|
||||||
{
|
{
|
||||||
char fileName[255];
|
char fileName[255];
|
||||||
UDWORD size;
|
UDWORD size;
|
||||||
char *pFileData;
|
char *pFileData;
|
||||||
PLAYERSTATS blankstats = {0};
|
|
||||||
SAVEDPLAYERSTATS st;
|
|
||||||
|
|
||||||
// Prevent an empty player name (where the first byte is a 0x0 terminating char already)
|
// Prevent an empty player name (where the first byte is a 0x0 terminating char already)
|
||||||
if (!*sPlayerName)
|
if (!*sPlayerName)
|
||||||
|
{
|
||||||
strcpy(sPlayerName, _("Player"));
|
strcpy(sPlayerName, _("Player"));
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(fileName, sizeof(fileName), "%s%s.sta", MultiPlayersPath, sPlayerName);
|
snprintf(fileName, sizeof(fileName), "%s%s.sta", MultiPlayersPath, sPlayerName);
|
||||||
|
|
||||||
debug(LOG_WZ, "loadMultiStats: %s", fileName);
|
debug(LOG_WZ, "loadMultiStats: %s", fileName);
|
||||||
|
|
||||||
// check player already exists
|
// check player already exists
|
||||||
if ( !PHYSFS_exists( fileName ) )
|
if ( !PHYSFS_exists( fileName ) )
|
||||||
{
|
{
|
||||||
|
PLAYERSTATS blankstats;
|
||||||
|
|
||||||
|
memset(&blankstats, 0, sizeof(PLAYERSTATS));
|
||||||
saveMultiStats(sPlayerName,sPlayerName,&blankstats); // didnt exist so create.
|
saveMultiStats(sPlayerName,sPlayerName,&blankstats); // didnt exist so create.
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loadFile(fileName,&pFileData,&size);
|
||||||
|
|
||||||
loadFile(fileName,&pFileData,&size);
|
if (strncmp(pFileData, "WZ.STA.v2", 9) != 0)
|
||||||
memcpy(&st, (SAVEDPLAYERSTATS*)pFileData, sizeof(SAVEDPLAYERSTATS));
|
{
|
||||||
|
return FALSE; // wrong version or not a stats file
|
||||||
|
}
|
||||||
|
|
||||||
//set stats.
|
sscanf(pFileData, "WZ.STA.v2\n%s %u %u %u %u",
|
||||||
memcpy(playerStats,&(st.stats), sizeof(PLAYERSTATS)); // get
|
sPlayerName, &st->wins, &st->losses, &st->totalKills, &st->totalScore);
|
||||||
|
|
||||||
//set the name. ASSUME STRING IS LONG ENOUGH!
|
free(pFileData);
|
||||||
strcpy(sPlayerName,st.name);
|
}
|
||||||
|
|
||||||
free(pFileData);
|
|
||||||
|
|
||||||
// reset recent scores
|
// reset recent scores
|
||||||
playerStats->recentKills = 0;
|
st->recentKills = 0;
|
||||||
playerStats->recentScore = 0;
|
st->recentScore = 0;
|
||||||
playerStats->killsToAdd = 0;
|
st->killsToAdd = 0;
|
||||||
playerStats->scoreToAdd = 0;
|
st->scoreToAdd = 0;
|
||||||
|
|
||||||
|
|
||||||
// clear any skirmish stats.
|
// clear any skirmish stats.
|
||||||
for(size = 0;size<MAX_PLAYERS;size++)
|
for(size = 0;size<MAX_PLAYERS;size++)
|
||||||
|
@ -639,24 +644,20 @@ BOOL loadMultiStats(char *sPlayerName, PLAYERSTATS *playerStats)
|
||||||
|
|
||||||
// ////////////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////////////
|
||||||
// Save Player Stats
|
// Save Player Stats
|
||||||
BOOL saveMultiStats(const char *sFileName, const char *sPlayerName, const PLAYERSTATS *playerStats)
|
#define MAX_STA_SIZE 500
|
||||||
|
BOOL saveMultiStats(const char *sFileName, const char *sPlayerName, const PLAYERSTATS *st)
|
||||||
{
|
{
|
||||||
char fileName[255]="";
|
char buffer[MAX_STA_SIZE];
|
||||||
SAVEDPLAYERSTATS st;
|
char fileName[255]="";
|
||||||
|
|
||||||
// prepare file.
|
snprintf(buffer, MAX_STA_SIZE, "WZ.STA.v2\n%s %u %u %u %u",
|
||||||
memcpy(&st.stats, playerStats, sizeof(PLAYERSTATS));
|
sPlayerName, st->wins, st->losses, st->totalKills, st->totalScore);
|
||||||
memset(st.name, 0, 255);
|
|
||||||
strcpy(st.name, sPlayerName);
|
|
||||||
|
|
||||||
strcpy(fileName,MultiPlayersPath);
|
strcpy(fileName,MultiPlayersPath);
|
||||||
strcat(fileName,sFileName);
|
strcat(fileName,sFileName);
|
||||||
strcat(fileName,".sta");
|
strcat(fileName,".sta");
|
||||||
|
|
||||||
// we write some uninitialised bytes here (the last of the struct)
|
saveFile(fileName, buffer, strlen(buffer));
|
||||||
// this is caused by struct sizes getting rounded up to a nice value
|
|
||||||
// FIXME: ugly cast
|
|
||||||
saveFile(fileName, (char *)&st, sizeof(SAVEDPLAYERSTATS));
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -665,7 +666,7 @@ BOOL saveMultiStats(const char *sFileName, const char *sPlayerName, const PLAYER
|
||||||
// score update functions
|
// score update functions
|
||||||
|
|
||||||
// update players damage stats.
|
// update players damage stats.
|
||||||
void updateMultiStatsDamage (UDWORD attacker, UDWORD defender, UDWORD inflicted)
|
void updateMultiStatsDamage(UDWORD attacker, UDWORD defender, UDWORD inflicted)
|
||||||
{
|
{
|
||||||
PLAYERSTATS st;
|
PLAYERSTATS st;
|
||||||
|
|
||||||
|
|
|
@ -43,14 +43,6 @@ typedef struct
|
||||||
|
|
||||||
} PLAYERSTATS;
|
} PLAYERSTATS;
|
||||||
|
|
||||||
// This is the definition of the multiplay/players/*.sta files
|
|
||||||
typedef struct // complete info.
|
|
||||||
{
|
|
||||||
char name[255];
|
|
||||||
PLAYERSTATS stats;
|
|
||||||
} SAVEDPLAYERSTATS;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _forcemember {
|
typedef struct _forcemember {
|
||||||
DROID_TEMPLATE *pTempl; // pointer to template to use for this droid
|
DROID_TEMPLATE *pTempl; // pointer to template to use for this droid
|
||||||
struct _forcemember *psNext; // Pointer to next template
|
struct _forcemember *psNext; // Pointer to next template
|
||||||
|
|
Loading…
Reference in New Issue