| 1 |
diff -ru Maelstrom-3.0.6/main.cpp Maelstrom-3.0.6-new/main.cpp
|
| 2 |
--- Maelstrom-3.0.6/main.cpp 2002-10-19 22:53:32.000000000 -0400
|
| 3 |
+++ Maelstrom-3.0.6-new/main.cpp 2006-05-09 01:05:07.000000000 -0400
|
| 4 |
@@ -170,12 +170,21 @@
|
| 5 |
/* Command line flags */
|
| 6 |
int doprinthigh = 0;
|
| 7 |
int speedtest = 0;
|
| 8 |
+ gid_t gid;
|
| 9 |
+
|
| 10 |
Uint32 video_flags = SDL_SWSURFACE;
|
| 11 |
|
| 12 |
/* Normal variables */
|
| 13 |
SDL_Event event;
|
| 14 |
LibPath::SetExePath(argv[0]);
|
| 15 |
|
| 16 |
+ GetScoreFile();
|
| 17 |
+ gid = getgid();
|
| 18 |
+ if (setresgid(-1,gid,gid) != 0) {
|
| 19 |
+ error("Could not drop privleges. -- Exiting.\n");
|
| 20 |
+ exit(1);
|
| 21 |
+ }
|
| 22 |
+
|
| 23 |
#ifndef __WIN95__
|
| 24 |
/* The first thing we do is calculate our checksum */
|
| 25 |
(void) checksum();
|
| 26 |
diff -ru Maelstrom-3.0.6/scores.cpp Maelstrom-3.0.6-new/scores.cpp
|
| 27 |
--- Maelstrom-3.0.6/scores.cpp 2000-09-24 13:55:39.000000000 -0400
|
| 28 |
+++ Maelstrom-3.0.6-new/scores.cpp 2006-05-09 01:26:19.000000000 -0400
|
| 29 |
@@ -4,6 +4,8 @@
|
| 30 |
*/
|
| 31 |
|
| 32 |
#ifdef unix
|
| 33 |
+#include <arpa/inet.h>
|
| 34 |
+#include <fcntl.h>
|
| 35 |
#include <sys/types.h>
|
| 36 |
#include <sys/stat.h>
|
| 37 |
#endif
|
| 38 |
@@ -15,22 +17,42 @@
|
| 39 |
#include "load.h"
|
| 40 |
#include "dialog.h"
|
| 41 |
|
| 42 |
-#define MAELSTROM_SCORES "Maelstrom-Scores"
|
| 43 |
+#define MAELSTROM_SCORES "/var/lib/games/Maelstrom-Scores"
|
| 44 |
#define NUM_SCORES 10 // Do not change this!
|
| 45 |
|
| 46 |
/* Everyone can write to scores file if defined to 0 */
|
| 47 |
-#define SCORES_PERMMASK 0
|
| 48 |
+#define SCORES_PERMMASK 002
|
| 49 |
|
| 50 |
#define CLR_DIALOG_WIDTH 281
|
| 51 |
#define CLR_DIALOG_HEIGHT 111
|
| 52 |
|
| 53 |
Bool gNetScores = 0;
|
| 54 |
Scores hScores[NUM_SCORES];
|
| 55 |
+int gScoreFile = -1;
|
| 56 |
+
|
| 57 |
+void GetScoreFile(void)
|
| 58 |
+{
|
| 59 |
+#ifdef unix
|
| 60 |
+ int omask;
|
| 61 |
+#endif
|
| 62 |
+ int f;
|
| 63 |
+
|
| 64 |
+#ifdef unix
|
| 65 |
+ omask=umask(SCORES_PERMMASK);
|
| 66 |
+#endif
|
| 67 |
+ f = open(MAELSTROM_SCORES,O_RDWR|O_CREAT);
|
| 68 |
+ if (f == -1)
|
| 69 |
+ f = open(MAELSTROM_SCORES,O_RDONLY);
|
| 70 |
+ if (f == -1)
|
| 71 |
+ error("Couldn't open score file %s.\n",MAELSTROM_SCORES);
|
| 72 |
+ gScoreFile = f;
|
| 73 |
+#ifdef unix
|
| 74 |
+ umask(omask);
|
| 75 |
+#endif
|
| 76 |
+}
|
| 77 |
|
| 78 |
void LoadScores(void)
|
| 79 |
{
|
| 80 |
- LibPath path;
|
| 81 |
- SDL_RWops *scores_src;
|
| 82 |
int i;
|
| 83 |
|
| 84 |
/* Try to load network scores, if we can */
|
| 85 |
@@ -44,50 +64,50 @@
|
| 86 |
}
|
| 87 |
memset(&hScores, 0, sizeof(hScores));
|
| 88 |
|
| 89 |
- scores_src = SDL_RWFromFile(path.Path(MAELSTROM_SCORES), "rb");
|
| 90 |
- if ( scores_src != NULL ) {
|
| 91 |
+ if (gScoreFile != -1) {
|
| 92 |
+ lseek(gScoreFile,0,SEEK_SET);
|
| 93 |
for ( i=0; i<NUM_SCORES; ++i ) {
|
| 94 |
- SDL_RWread(scores_src, hScores[i].name,
|
| 95 |
- sizeof(hScores[i].name), 1);
|
| 96 |
- hScores[i].wave = SDL_ReadBE32(scores_src);
|
| 97 |
- hScores[i].score = SDL_ReadBE32(scores_src);
|
| 98 |
+ Uint32 tmp;
|
| 99 |
+
|
| 100 |
+ if (read(gScoreFile,hScores[i].name,sizeof(hScores[i].name)) != sizeof(hScores[i].name))
|
| 101 |
+ break;
|
| 102 |
+ if (read(gScoreFile,&tmp,sizeof(Uint32)) != sizeof(Uint32))
|
| 103 |
+ break;
|
| 104 |
+ hScores[i].wave = ntohl(tmp);
|
| 105 |
+ if (read(gScoreFile,&tmp,sizeof(Uint32)) != sizeof(Uint32))
|
| 106 |
+ break;
|
| 107 |
+ hScores[i].score = ntohl(tmp);
|
| 108 |
}
|
| 109 |
- SDL_RWclose(scores_src);
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
| 113 |
void SaveScores(void)
|
| 114 |
{
|
| 115 |
- LibPath path;
|
| 116 |
- SDL_RWops *scores_src;
|
| 117 |
int i;
|
| 118 |
-#ifdef unix
|
| 119 |
- int omask;
|
| 120 |
-#endif
|
| 121 |
|
| 122 |
/* Don't save network scores */
|
| 123 |
if ( gNetScores )
|
| 124 |
return;
|
| 125 |
-
|
| 126 |
-#ifdef unix
|
| 127 |
- omask=umask(SCORES_PERMMASK);
|
| 128 |
-#endif
|
| 129 |
- scores_src = SDL_RWFromFile(path.Path(MAELSTROM_SCORES), "wb");
|
| 130 |
- if ( scores_src != NULL ) {
|
| 131 |
+
|
| 132 |
+ if (gScoreFile != -1) {
|
| 133 |
+ lseek(gScoreFile,0,SEEK_SET);
|
| 134 |
for ( i=0; i<NUM_SCORES; ++i ) {
|
| 135 |
- SDL_RWwrite(scores_src, hScores[i].name,
|
| 136 |
- sizeof(hScores[i].name), 1);
|
| 137 |
- SDL_WriteBE32(scores_src, hScores[i].wave);
|
| 138 |
- SDL_WriteBE32(scores_src, hScores[i].score);
|
| 139 |
+ Uint32 tmp;
|
| 140 |
+
|
| 141 |
+ if (write(gScoreFile, hScores[i].name, sizeof(hScores[i].name)) != sizeof(hScores[i].name))
|
| 142 |
+ goto out_err;
|
| 143 |
+ tmp = htonl(hScores[i].wave);
|
| 144 |
+ if (write(gScoreFile, &tmp,sizeof(Uint32)) != sizeof(Uint32))
|
| 145 |
+ goto out_err;
|
| 146 |
+ tmp = htonl(hScores[i].score);
|
| 147 |
+ if (write(gScoreFile, &tmp,sizeof(Uint32)) != sizeof(Uint32))
|
| 148 |
+ goto out_err;
|
| 149 |
}
|
| 150 |
- SDL_RWclose(scores_src);
|
| 151 |
- } else {
|
| 152 |
- error("Warning: Couldn't save scores to %s\n",
|
| 153 |
- path.Path(MAELSTROM_SCORES));
|
| 154 |
+ fsync(gScoreFile);
|
| 155 |
+ return;
|
| 156 |
}
|
| 157 |
-#ifdef unix
|
| 158 |
- umask(omask);
|
| 159 |
-#endif
|
| 160 |
+out_err:
|
| 161 |
+ error("Warning: Couldn't save scores to %s\n", MAELSTROM_SCORES);
|
| 162 |
}
|
| 163 |
|
| 164 |
/* Just show the high scores */
|
| 165 |
diff -ru Maelstrom-3.0.6/scores.h Maelstrom-3.0.6-new/scores.h
|
| 166 |
--- Maelstrom-3.0.6/scores.h 1998-07-13 21:50:17.000000000 -0400
|
| 167 |
+++ Maelstrom-3.0.6-new/scores.h 2006-05-09 01:05:25.000000000 -0400
|
| 168 |
@@ -2,6 +2,7 @@
|
| 169 |
// Functions from scores.cc
|
| 170 |
extern void LoadScores(void);
|
| 171 |
extern void SaveScores(void);
|
| 172 |
+extern void GetScoreFile(void);
|
| 173 |
extern int ZapHighScores(void);
|
| 174 |
extern int GetStartLevel(void);
|
| 175 |
extern void PrintHighScores(void);
|