Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > b3e39ada975d6747d645d7c2ea00cc64 > files > 6

methane-1.5.0-2.fc13.src.rpm

diff -up methane-1.5.0/sources/doc.cpp~ methane-1.5.0/sources/doc.cpp
--- methane-1.5.0/sources/doc.cpp~	2009-10-22 10:33:21.000000000 +0200
+++ methane-1.5.0/sources/doc.cpp	2009-11-08 18:37:31.000000000 +0100
@@ -16,7 +16,10 @@
 #include "doc.h"
 #include "target.h"
 #include "snddef.h"
+#include <stdio.h>
 
+extern FILE *methanescoresfptr;
+
 //------------------------------------------------------------------------------
 //! \brief Initialise Document
 //!
@@ -110,28 +112,13 @@ void CMethDoc::DisplayOptions( CL_Displa
 //------------------------------------------------------------------------------
 void CMethDoc::LoadScores(void)
 {
-	CL_String dirname = CL_Directory::get_appdata("clanlib", "methane", "1.5", false);
-
-	try
-	{
-		CL_File file(dirname+"highscores");
-		HISCORES *hs;
-		int cnt;
-		for (cnt=0, hs=m_GameTarget.m_Game.m_HiScores; cnt<MAX_HISCORES; cnt++, hs++)
-		{
-			char buffer[5];
-			file.read(buffer, 4, true);
-			buffer[4] = 0;
-			int score = file.read_int32();
-
-			m_GameTarget.m_Game.InsertHiScore( score, buffer );
+	size_t ign;
 
-		}
-	}
-	catch(CL_Exception& exception)
-	{
-	}
+	if (!methanescoresfptr) return;	// No scores available
 
+	rewind(methanescoresfptr);
+	ign = fread(m_GameTarget.m_Game.m_HiScores, sizeof(HISCORES),
+		    MAX_HISCORES, methanescoresfptr);
 }
 
 //------------------------------------------------------------------------------
@@ -139,21 +126,11 @@ void CMethDoc::LoadScores(void)
 //------------------------------------------------------------------------------
 void CMethDoc::SaveScores(void)
 {
-	CL_String dirname = CL_Directory::get_appdata("clanlib", "methane", "1.5");
+	size_t ign;
 
-	try
-	{
-		CL_File file(dirname+"highscores", CL_File::create_always, CL_File::access_write);
-		HISCORES *hs;
-		int cnt;
-		for (cnt=0, hs=m_GameTarget.m_Game.m_HiScores; cnt<MAX_HISCORES; cnt++, hs++)
-		{
-			file.write(hs->name, 4, true);
-			file.write_int32(hs->score);
-		}
-	}
-	catch(CL_Exception& exception)
-	{
-	}
-}
+	if (!methanescoresfptr) return;	// No scores available
 
+	rewind(methanescoresfptr);
+	ign = fwrite(m_GameTarget.m_Game.m_HiScores, sizeof(HISCORES),
+		     MAX_HISCORES, methanescoresfptr);
+}
diff -up methane-1.5.0/sources/game.cpp~ methane-1.5.0/sources/game.cpp
--- methane-1.5.0/sources/game.cpp~	2009-04-28 16:42:43.000000000 +0200
+++ methane-1.5.0/sources/game.cpp	2009-11-08 18:44:46.000000000 +0100
@@ -27,6 +27,7 @@
 #include "weapon.h"
 #include "target.h"
 #include <stdlib.h>
+#include <stdio.h>
 
 //------------------------------------------------------------------------------
 // The Game Version Number
diff -up methane-1.5.0/sources/methane.cpp~ methane-1.5.0/sources/methane.cpp
--- methane-1.5.0/sources/methane.cpp~	2009-10-22 10:47:43.000000000 +0200
+++ methane-1.5.0/sources/methane.cpp	2009-11-08 18:30:40.000000000 +0100
@@ -12,6 +12,14 @@
 //------------------------------------------------------------------------------
 // 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>
+#include <stdlib.h>
+
 #include <ClanLib/core.h>
 #include <ClanLib/application.h>
 #include <ClanLib/display.h>
@@ -24,6 +31,8 @@
 
 #include "doc.h"
 
+FILE *methanescoresfptr = NULL;
+
 RenderTarget GLOBAL_RenderTarget = opengl;
 bool GLOBAL_SoundEnable = true;
 
@@ -236,6 +245,8 @@ public:
 				last_time = last_time + game_speed; 
 			}
 			Game.SaveScores();
+			if (methanescoresfptr)
+				fclose(methanescoresfptr);
 		}
 		catch(CL_Exception& exception)
 		{
@@ -340,6 +351,15 @@ class Program
 public:
 	static int main(const std::vector<CL_String> &args)
 	{
+ 		gid_t realgid = getgid();
+ 		
+ 		methanescoresfptr = fopen("/var/games/methane.scores", "r+");
+ 		
+ 		if (setresgid(-1, realgid, realgid) != 0) {
+ 			perror("Could not drop setgid privileges.  Aborting.");
+ 			exit(1);
+ 		}
+
 		CL_SetupCore setup_core;
 		CL_SetupDisplay setup_display;