Commit | Line | Data |
---|---|---|
b44f8225 VM |
1 | diff -purN aop-0.6.orig/Makefile aop-0.6/Makefile |
2 | --- aop-0.6.orig/Makefile 2009-09-02 08:19:08.652153613 +0200 | |
3 | +++ aop-0.6/Makefile 2009-09-02 09:26:25.984152748 +0200 | |
4 | @@ -1,14 +1,27 @@ | |
5 | +DESTDIR = | |
6 | ||
7 | +CC = gcc | |
8 | +CFLAGS = -Wall -O2 | |
9 | LDFLAGS = -lncurses | |
10 | +SRCS = scoring.c aop.c | |
11 | +OBJS = $(SRCS:.c=.o) | |
12 | ||
13 | -aop: aop.c | |
14 | +all: aop | |
15 | + | |
16 | +.c.o: | |
17 | + $(CC) $(CFLAGS) -c $*.c -o $*.o | |
18 | + | |
19 | +aop: $(OBJS) | |
20 | + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ | |
21 | ||
22 | install: aop | |
23 | - install -d /usr/local/bin | |
24 | - install -d /usr/local/share/aop | |
25 | - install -m 755 aop /usr/local/bin/aop | |
26 | - install -m 644 aop-level-*.txt /usr/local/share/aop/ | |
27 | + install -d $(DESTDIR)/usr/bin | |
28 | + install -d $(DESTDIR)/usr/share/aop | |
29 | + install -m 755 aop $(DESTDIR)/usr/bin/aop | |
30 | + install -m 644 aop-level-*.txt $(DESTDIR)/usr/share/aop/ | |
31 | + install -d -m 777 $(DESTDIR)/var/spool/aop | |
32 | + touch $(DESTDIR)/var/spool/aop/score | |
33 | + chmod 666 $(DESTDIR)/var/spool/aop/score | |
34 | ||
35 | clean: | |
36 | - rm -f aop core* *~ | |
37 | - | |
38 | + rm -f aop *.o *~ | |
39 | diff -purN aop-0.6.orig/aop.c aop-0.6/aop.c | |
40 | --- aop-0.6.orig/aop.c 2009-09-02 08:19:08.652153613 +0200 | |
41 | +++ aop-0.6/aop.c 2009-09-02 10:22:28.457051144 +0200 | |
42 | @@ -2,14 +2,20 @@ | |
43 | /* Raffael Himmelreich <raffi@raffi.at> */ | |
44 | /* Clifford Wolf <clifford@clifford.at> */ | |
45 | ||
46 | +/* Patched by Jose V Beneyto <sepen@mikeux.dyndns.org> */ | |
47 | + | |
48 | #include <curses.h> | |
49 | #include <unistd.h> | |
50 | #include <string.h> | |
51 | +#include <pwd.h> | |
52 | +#include "scoring.h" | |
53 | ||
54 | int main(int argc, char *argv[]) { | |
55 | - int px, py, opx, opy, ipx, ipy, x, y, c=0, p=0, op, dir; | |
56 | + int px, py, opx, opy, ipx, ipy, x, y, c=0, p=0, op, dir, scorepos; | |
57 | int last_lv = argc>=2 ? argc-1 : 11, level=1, lifes=5; FILE *f; | |
58 | char ch, field[25][81], tmp[96], *lastword = "Bye."; | |
59 | + char *playerName=NULL; | |
60 | + struct passwd *userinfo; | |
61 | ||
62 | if ( argc > 1 && *argv[1] == '-' ) { | |
63 | printf("Usage: %s [aop-level-01.txt [..] ]\n", argv[0]); | |
64 | @@ -21,7 +27,7 @@ int main(int argc, char *argv[]) { | |
65 | init_pair(1, COLOR_RED, COLOR_BLACK); | |
66 | ||
67 | start: memset(field, ' ', 25*81); | |
68 | - snprintf(tmp, 96, "/usr/local/share/aop/aop-level-%02d.txt", level); | |
69 | + snprintf(tmp, 96, "/usr/share/aop/aop-level-%02d.txt", level); | |
70 | f = fopen(argc>=2 ? argv[level] : tmp, "r"); | |
71 | if (!f) { endwin(); printf("Can't open level file.\n"); return 1; } | |
72 | opx=ipx=px=3, opy=ipy=py=2; op=p; p += 700000 + level*373737; | |
73 | @@ -55,10 +61,28 @@ start: memset(field, ' ', 25*81); | |
74 | attron(COLOR_PAIR(1)); | |
75 | mvprintw(0, 0, "Lifes: %d, Points: %d ", | |
76 | lifes, p=p-(dir < 5 ? 1 : 2)); | |
77 | - refresh(); usleep(dir < 5 ? 50000 : 100000); | |
78 | + refresh(); usleep(dir < 5 ? 100000 : 200000); | |
79 | } while( (c=getch()) != 'q' ); | |
80 | - endwin(); printf("%s (%d points)\n", lastword, p); | |
81 | + endwin(); | |
82 | + printf("%s (%d points)\n", lastword, p); | |
83 | + if (playerName==NULL) { | |
84 | + userinfo = getpwuid(getuid()); | |
85 | + if (userinfo!=NULL) { | |
86 | + playerName = strdup(userinfo->pw_name); | |
87 | + } | |
88 | + else { | |
89 | + playerName = strdup("UNKNOWN"); | |
90 | + } | |
91 | + } | |
92 | + scorepos = add_high_score(playerName, level, p); | |
93 | + if (scorepos==0) { | |
94 | + fprintf(stderr,"\nUnable to write highscore file %s\n\n", HIGHSCOREFILE); | |
95 | + } | |
96 | + else { | |
97 | + if (scorepos != MAXHIGHSCORES+1) { | |
98 | + printf("\nYou got into position %d in the score table\n\n", scorepos); | |
99 | + } | |
100 | + print_high_scores(); | |
101 | + } | |
102 | return strcmp(lastword, "Sucker!") == 0; | |
103 | } | |
104 | - | |
105 | -/* Yup - This are 64 lines of C code. ;-) */ | |
106 | diff -purN aop-0.6.orig/scoring.c aop-0.6/scoring.c | |
107 | --- aop-0.6.orig/scoring.c 1970-01-01 01:00:00.000000000 +0100 | |
108 | +++ aop-0.6/scoring.c 2009-09-02 10:24:39.536533588 +0200 | |
109 | @@ -0,0 +1,128 @@ | |
110 | +/* | |
111 | + Routines to deal with high score files for tetris. | |
112 | + Copyright 1999 Jonathan McDowell for Project Purple | |
113 | + 21/05/99 | |
114 | + | |
115 | + 27/06/99 - Added date field | |
116 | + | |
117 | + Jose V Beneyto <sepen@mikeux.dyndns.org> | |
118 | + 02/09/09 - Removed basedelay from the struct and fixed highscorefile usage | |
119 | +*/ | |
120 | + | |
121 | +#include <stdio.h> | |
122 | +#include <stdlib.h> | |
123 | +#include <string.h> | |
124 | +#include <time.h> | |
125 | +#include "scoring.h" | |
126 | + | |
127 | +int get_high_scores(struct highscoreent *highscores[], int *numscores) | |
128 | +{ | |
129 | + FILE *scorefile; | |
130 | + long filelen; | |
131 | + | |
132 | + if ((scorefile=fopen(HIGHSCOREFILE,"r"))==NULL) { | |
133 | + return 0; | |
134 | + } | |
135 | + | |
136 | + fseek(scorefile, 0, SEEK_END); | |
137 | + filelen=ftell(scorefile)+1; | |
138 | + rewind(scorefile); | |
139 | + | |
140 | + if ((*highscores=malloc(filelen))==NULL) { | |
141 | + return 0; | |
142 | + } | |
143 | + | |
144 | + fread(*highscores, 1, filelen, scorefile); | |
145 | + *numscores=filelen/sizeof(struct highscoreent); | |
146 | + if (*numscores>MAXHIGHSCORES) *numscores=MAXHIGHSCORES; | |
147 | + | |
148 | + fclose(scorefile); | |
149 | + return 1; | |
150 | +} | |
151 | + | |
152 | +int save_high_scores(struct highscoreent highscores[], int *numscores) | |
153 | +{ | |
154 | + FILE *scorefile; | |
155 | + | |
156 | + if ((scorefile=fopen(HIGHSCOREFILE,"w"))==NULL) { | |
157 | + return 0; | |
158 | + } | |
159 | + | |
160 | + if (*numscores>MAXHIGHSCORES) *numscores=MAXHIGHSCORES; | |
161 | + fwrite(highscores, 1, *numscores * sizeof(struct highscoreent), scorefile); | |
162 | + | |
163 | + fclose(scorefile); | |
164 | + return 1; | |
165 | +} | |
166 | + | |
167 | +/* Checks if a score got into the high score table and if so add it to | |
168 | + the high score file. Returns 0 if unable to do so, MAXHIGHSCORES+1 | |
169 | + if the score didn't get into the high score table, otherwise the | |
170 | + position in the table. */ | |
171 | +int add_high_score(const char name[], unsigned int endlvl, unsigned int score) | |
172 | +{ | |
173 | + struct highscoreent highscore; | |
174 | + struct highscoreent *scores, *newscores; | |
175 | + int loop, numscores; | |
176 | + | |
177 | + strncpy(highscore.name, name, 15); | |
178 | + highscore.name[15]=numscores=0; | |
179 | + highscore.endlvl=endlvl; | |
180 | + highscore.score=score; | |
181 | + highscore.date=time(NULL); | |
182 | + | |
183 | + if (get_high_scores(&scores, &numscores)==0 || numscores==0) { | |
184 | + numscores=1; | |
185 | + if (save_high_scores(&highscore, &numscores)) | |
186 | + return 1; | |
187 | + else | |
188 | + return 0; | |
189 | + } | |
190 | + | |
191 | + if (numscores==MAXHIGHSCORES) numscores--; | |
192 | + | |
193 | + if ((newscores=malloc(sizeof(struct highscoreent)*(numscores+1)))==NULL) { | |
194 | + return 0; | |
195 | + } | |
196 | + | |
197 | + memcpy(newscores, scores, sizeof(struct highscoreent)*numscores); | |
198 | + | |
199 | + loop=0; | |
200 | + while (score<(scores[loop]).score && loop<numscores) loop++; | |
201 | + | |
202 | + if (score<(scores[loop]).score) { | |
203 | + /* didn't get on score table */ | |
204 | + return (MAXHIGHSCORES+1); | |
205 | + } | |
206 | + | |
207 | + if (loop<numscores) { | |
208 | + memmove(&(newscores[loop+1]), &(newscores[loop]), sizeof(struct highscoreent)*(numscores-loop)); | |
209 | + } | |
210 | + memcpy(&(newscores[loop]), &highscore, sizeof(highscore)); | |
211 | + ++numscores; | |
212 | + save_high_scores(newscores, &numscores); | |
213 | + | |
214 | + return (loop+1); | |
215 | +} | |
216 | + | |
217 | +void print_high_scores(void) | |
218 | +{ | |
219 | + struct highscoreent *scores; | |
220 | + int numscores,loop; | |
221 | + char tempdate[30]; | |
222 | + | |
223 | + if (get_high_scores(&scores, &numscores)==1) { | |
224 | + printf("+------------------+-------+----------+-----------------------+\n"); | |
225 | + printf("| Name | Level | Score | Date |\n"); | |
226 | + printf("+------------------+-------+----------+-----------------------+\n"); | |
227 | + for (loop=0; loop<numscores; loop++) { | |
228 | + strncpy(tempdate, ctime(&scores[loop].date), 29); | |
229 | + strncpy(tempdate+16,tempdate+19,5); | |
230 | + tempdate[21]=0; | |
231 | + printf("| %-16s | %5d | %8d | %21s |\n", scores[loop].name, scores[loop].endlvl, scores[loop].score, tempdate); | |
232 | + } | |
233 | + printf("+------------------+-------+----------+-----------------------+\n"); | |
234 | + } else { | |
235 | + printf("Couldn't read high score file.\n"); | |
236 | + } | |
237 | +} | |
238 | diff -purN aop-0.6.orig/scoring.h aop-0.6/scoring.h | |
239 | --- aop-0.6.orig/scoring.h 1970-01-01 01:00:00.000000000 +0100 | |
240 | +++ aop-0.6/scoring.h 2009-09-02 09:18:04.072154104 +0200 | |
241 | @@ -0,0 +1,30 @@ | |
242 | +/* | |
243 | + Routines to deal with high score files for tetris. | |
244 | + Copyright 1999 Jonathan McDowell for Project Purple | |
245 | + 21/05/99 | |
246 | + | |
247 | + Jose V Beneyto <sepen@mikeux.dyndns.org> | |
248 | + 02/09/09 - Removed basedelay from the struct and fixed highscorefile usage | |
249 | +*/ | |
250 | + | |
251 | +#include <time.h> | |
252 | + | |
253 | +/* Default high score file location */ | |
254 | +#define HIGHSCOREFILE "/var/spool/aop/score" | |
255 | +/* Max number of high scores we store */ | |
256 | +#define MAXHIGHSCORES 20 | |
257 | + | |
258 | +struct highscoreent { | |
259 | + char name[16]; | |
260 | + unsigned int endlvl, lines, score; | |
261 | + time_t date; | |
262 | +}; | |
263 | + | |
264 | +int get_high_scores(struct highscoreent *highscores[], int *numscores); | |
265 | +int save_high_scores(struct highscoreent highscores[], int *numscores); | |
266 | +/* Checks if a score got into the high score table and if so add it to | |
267 | + the high score file. Returns 0 if unable to do so, MAXHIGHSCORE+1 | |
268 | + if the score didn't get into the high score table, otherwise the | |
269 | + position in the table. */ | |
270 | +int add_high_score(const char name[], unsigned int endlvl, unsigned int score); | |
271 | +void print_high_scores(void); |