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
10 +SRCS = scoring.c aop.c
17 + $(CC) $(CFLAGS) -c $*.c -o $*.o
20 + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@
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
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
43 /* Raffael Himmelreich <raffi@raffi.at> */
44 /* Clifford Wolf <clifford@clifford.at> */
46 +/* Patched by Jose V Beneyto <sepen@mikeux.dyndns.org> */
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;
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);
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);
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);
89 + playerName = strdup("UNKNOWN");
92 + scorepos = add_high_score(playerName, level, p);
94 + fprintf(stderr,"\nUnable to write highscore file %s\n\n", HIGHSCOREFILE);
97 + if (scorepos != MAXHIGHSCORES+1) {
98 + printf("\nYou got into position %d in the score table\n\n", scorepos);
100 + print_high_scores();
102 return strcmp(lastword, "Sucker!") == 0;
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
111 + Routines to deal with high score files for tetris.
112 + Copyright 1999 Jonathan McDowell for Project Purple
115 + 27/06/99 - Added date field
117 + Jose V Beneyto <sepen@mikeux.dyndns.org>
118 + 02/09/09 - Removed basedelay from the struct and fixed highscorefile usage
125 +#include "scoring.h"
127 +int get_high_scores(struct highscoreent *highscores[], int *numscores)
132 + if ((scorefile=fopen(HIGHSCOREFILE,"r"))==NULL) {
136 + fseek(scorefile, 0, SEEK_END);
137 + filelen=ftell(scorefile)+1;
140 + if ((*highscores=malloc(filelen))==NULL) {
144 + fread(*highscores, 1, filelen, scorefile);
145 + *numscores=filelen/sizeof(struct highscoreent);
146 + if (*numscores>MAXHIGHSCORES) *numscores=MAXHIGHSCORES;
152 +int save_high_scores(struct highscoreent highscores[], int *numscores)
156 + if ((scorefile=fopen(HIGHSCOREFILE,"w"))==NULL) {
160 + if (*numscores>MAXHIGHSCORES) *numscores=MAXHIGHSCORES;
161 + fwrite(highscores, 1, *numscores * sizeof(struct highscoreent), scorefile);
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)
173 + struct highscoreent highscore;
174 + struct highscoreent *scores, *newscores;
175 + int loop, numscores;
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);
183 + if (get_high_scores(&scores, &numscores)==0 || numscores==0) {
185 + if (save_high_scores(&highscore, &numscores))
191 + if (numscores==MAXHIGHSCORES) numscores--;
193 + if ((newscores=malloc(sizeof(struct highscoreent)*(numscores+1)))==NULL) {
197 + memcpy(newscores, scores, sizeof(struct highscoreent)*numscores);
200 + while (score<(scores[loop]).score && loop<numscores) loop++;
202 + if (score<(scores[loop]).score) {
203 + /* didn't get on score table */
204 + return (MAXHIGHSCORES+1);
207 + if (loop<numscores) {
208 + memmove(&(newscores[loop+1]), &(newscores[loop]), sizeof(struct highscoreent)*(numscores-loop));
210 + memcpy(&(newscores[loop]), &highscore, sizeof(highscore));
212 + save_high_scores(newscores, &numscores);
217 +void print_high_scores(void)
219 + struct highscoreent *scores;
220 + int numscores,loop;
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);
231 + printf("| %-16s | %5d | %8d | %21s |\n", scores[loop].name, scores[loop].endlvl, scores[loop].score, tempdate);
233 + printf("+------------------+-------+----------+-----------------------+\n");
235 + printf("Couldn't read high score file.\n");
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
243 + Routines to deal with high score files for tetris.
244 + Copyright 1999 Jonathan McDowell for Project Purple
247 + Jose V Beneyto <sepen@mikeux.dyndns.org>
248 + 02/09/09 - Removed basedelay from the struct and fixed highscorefile usage
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
258 +struct highscoreent {
260 + unsigned int endlvl, lines, score;
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);