--- methane-1.4.7/source/linux/doc.cpp.highscore 2005-01-20 17:22:02.000000000 +0100
+++ methane-1.4.7/source/linux/doc.cpp 2007-02-07 15:24:55.000000000 +0100
@@ -40,7 +40,7 @@
//------------------------------------------------------------------------------
// The HighScore table filename
//------------------------------------------------------------------------------
-static char HighScoreFileName[] = "/var/games/methanescores";
+extern FILE *methanescoresfptr;
#define HighScoreLoadBufferSize (MAX_HISCORES * 64)
//------------------------------------------------------------------------------
@@ -382,23 +382,19 @@
//------------------------------------------------------------------------------
void CMethDoc::LoadScores(void)
{
- FILE *fptr;
char *mptr;
char *tptr;
char let;
int cnt;
- fptr = fopen(HighScoreFileName, "r");
- if (!fptr) return; // No scores available
+ if (!methanescoresfptr) return; // No scores available
+ rewind(methanescoresfptr);
// Allocate file memory, which is cleared to zero
mptr = (char *) calloc(1, HighScoreLoadBufferSize);
if (!mptr) // No memory
- {
- fclose(fptr);
return;
- }
- fread( mptr, 1, HighScoreLoadBufferSize-2, fptr); // Get the file
+ fread( mptr, 1, HighScoreLoadBufferSize-2, methanescoresfptr); // Get the file
// (Note: mptr is zero terminated)
tptr = mptr;
@@ -417,9 +413,6 @@
}
free(mptr);
-
- fclose(fptr);
-
}
//------------------------------------------------------------------------------
@@ -427,17 +420,14 @@
//------------------------------------------------------------------------------
void CMethDoc::SaveScores(void)
{
- FILE *fptr;
int cnt;
HISCORES *hs;
- fptr = fopen(HighScoreFileName, "w");
- if (!fptr) return; // Cannot write scores
+ if (!methanescoresfptr) return; // Cannot write scores
+ rewind(methanescoresfptr);
for (cnt=0, hs=m_GameTarget.m_Game.m_HiScores; cnt<MAX_HISCORES; cnt++, hs++)
{
- fprintf(fptr, "%c%c%c%c%d$", hs->name[0], hs->name[1], hs->name[2], hs->name[3], hs->score);
+ fprintf(methanescoresfptr, "%c%c%c%c%d$", hs->name[0], hs->name[1], hs->name[2], hs->name[3], hs->score);
}
- fclose(fptr);
-
}
--- methane-1.4.7/source/linux/main.cpp.highscore 2005-01-20 17:22:02.000000000 +0100
+++ methane-1.4.7/source/linux/main.cpp 2007-02-07 15:26:13.000000000 +0100
@@ -13,6 +13,13 @@
//------------------------------------------------------------------------------
// Methane brothers main source file
//------------------------------------------------------------------------------
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE /* this must be done before the first include of unistd.h */
+#endif
+#include<unistd.h>
+#include<string.h>
+#include <stdio.h>
+
#ifdef METHANE_OLD_CPP
#include <iostream.h>
#else
@@ -32,6 +39,7 @@
// The Game Instance
//------------------------------------------------------------------------------
CMethDoc Game;
+FILE *methanescoresfptr = NULL;
//------------------------------------------------------------------------------
// Keyboard stuff
@@ -60,6 +68,15 @@
virtual int main(int argc, char **argv)
{
+ gid_t realgid = getgid();
+
+ methanescoresfptr = fopen("/var/games/methanescores", "r+");
+
+ if (setresgid(-1, realgid, realgid) != 0) {
+ perror("Could not drop setgid privileges. Aborting.");
+ exit(1);
+ }
+
// Create a console window for text-output if not available
CL_ConsoleWindow console("Console");
console.redirect_stdio();
@@ -305,6 +322,9 @@
Game.SaveScores();
Game.RemoveSoundDriver();
+
+ if (methanescoresfptr)
+ fclose(methanescoresfptr);
}
catch(CL_Error error)
{