/[emacs]/emacs/lisp/play/gamegrid.el
ViewVC logotype

Diff of /emacs/lisp/play/gamegrid.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by lektu, Tue Feb 4 13:20:41 2003 UTC revision 1.15 by lektu, Wed Feb 26 10:18:43 2003 UTC
# Line 427  static unsigned char gamegrid_bits[] = { Line 427  static unsigned char gamegrid_bits[] = {
427  ;; ;;;;;;;;;;;;;;; high score functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ;; ;;;;;;;;;;;;;;; high score functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
428    
429  (defun gamegrid-add-score (file score)  (defun gamegrid-add-score (file score)
430    "Add the current score to the high score file."    "Add the current score to the high score file.
431    
432    On POSIX systems there may be a shared game directory for all users in
433    which the scorefiles are kept. On such systems Emacs doesn't create
434    the score file FILE in this directory, if it doesn't already exist. In
435    this case Emacs searches for FILE in the directory specified by
436    `gamegrid-user-score-file-directory' and creates it there, if
437    necessary.
438    
439    To add the score file for a game to the system wide shared game
440    directory, create the file with the shell command \"touch\" in this
441    directory and make sure that it is owned by the correct user and
442    group. You probably need special user privileges to do this.
443    
444    On non-POSIX systems Emacs searches for FILE in the directory
445    specified by the variable `temporary-file-directory'. If necessary,
446    FILE is created there."
447    (case system-type    (case system-type
448      ((ms-dos windows-nt)      ((ms-dos windows-nt)
449       (gamegrid-add-score-insecure file score))       (gamegrid-add-score-insecure file score))
# Line 435  static unsigned char gamegrid_bits[] = { Line 451  static unsigned char gamegrid_bits[] = {
451       (gamegrid-add-score-with-update-game-score file score))))       (gamegrid-add-score-with-update-game-score file score))))
452    
453  (defun gamegrid-add-score-with-update-game-score (file score)  (defun gamegrid-add-score-with-update-game-score (file score)
454    (let* ((result nil)    (let* ((result nil) ;; What is this good for? -- os
          (errbuf (generate-new-buffer " *update-game-score loss*"))  
455           (have-shared-game-dir           (have-shared-game-dir
456            (not (zerop (logand (file-modes            (not (zerop (logand (file-modes
457                                 (expand-file-name "update-game-score"                                 (expand-file-name "update-game-score"
458                                                   exec-directory))                                                   exec-directory))
459                                #o4000))))                                #o4000)))))
460           (target (if have-shared-game-dir      (if (and have-shared-game-dir
461                       (expand-file-name file shared-game-score-directory)               (file-exists-p (expand-file-name file shared-game-score-directory)))
462                     (let ((f (expand-file-name          ;; Use the setuid update-gamescore program to update a
463                               gamegrid-user-score-file-directory)))          ;; system-wide score file.
464                       (when (file-writable-p f)          (gamegrid-add-score-with-update-game-score-1
465                         (unless (eq (car-safe (file-attributes f))           (expand-file-name file shared-game-score-directory) score)
466                                     t)        ;; Else: Add the score to a score file in the user's home
467                           (make-directory f))        ;; directory. If `have-shared-game-dir' is non-nil, the
468                         (setq f (expand-file-name file f))        ;; "update-gamescore" program is setuid, so don't use it.
469                         (unless (file-exists-p f)        (if have-shared-game-dir
470                           (write-region "" nil f nil 'silent nil 'excl)))            (gamegrid-add-score-insecure file score
471                       f))))                                         gamegrid-user-score-file-directory)
472      (let ((default-directory "/"))          (let ((f (expand-file-name
473        (apply                    gamegrid-user-score-file-directory)))
474         'call-process            (when (file-writable-p f)
475         (append              (unless (eq (car-safe (file-attributes f))
476          (list                          t)
477           (expand-file-name "update-game-score" exec-directory)                (make-directory f))
478           nil errbuf nil              (setq f (expand-file-name file f))
479           "-m" (int-to-string gamegrid-score-file-length)              (unless (file-exists-p f)
480           "-d" (if have-shared-game-dir                (write-region "" nil f nil 'silent nil 'excl)))
481                    (expand-file-name shared-game-score-directory)            (gamegrid-add-score-with-update-game-score-1 f score))))))
482                  (file-name-directory target))  
483           file  (defun gamegrid-add-score-with-update-game-score-1 (target score)
484           (int-to-string score)    (let ((default-directory "/")
485           (concat          (errbuf (generate-new-buffer " *update-game-score loss*")))
486            (user-full-name)      (apply
487            " <"       'call-process
488            (cond ((fboundp 'user-mail-address)       (append
489                   (user-mail-address))        (list
490                  ((boundp 'user-mail-address)         (expand-file-name "update-game-score" exec-directory)
491                   user-mail-address)         nil errbuf nil
492                  (t ""))         "-m" (int-to-string gamegrid-score-file-length)
493            ">  "         "-d" (if have-shared-game-dir
494            (current-time-string))))))                  (expand-file-name shared-game-score-directory)
495                  (file-name-directory target))
496           file
497           (int-to-string score)
498           (concat
499            (user-full-name)
500            " <"
501            (cond ((fboundp 'user-mail-address)
502                   (user-mail-address))
503                  ((boundp 'user-mail-address)
504                   user-mail-address)
505                  (t ""))
506            ">  "
507            (current-time-string)))))
508      (if (buffer-modified-p errbuf)      (if (buffer-modified-p errbuf)
509          (progn          (progn
510            (display-buffer errbuf)            (display-buffer errbuf)
# Line 491  static unsigned char gamegrid_bits[] = { Line 519  static unsigned char gamegrid_bits[] = {
519                (display-buffer buf))                (display-buffer buf))
520            (find-file-read-only-other-window target))))))            (find-file-read-only-other-window target))))))
521    
522  (defun gamegrid-add-score-insecure (file score)  (defun gamegrid-add-score-insecure (file score &optional directory)
523    (save-excursion    (save-excursion
524      (setq file (expand-file-name file temporary-file-directory))      (setq file (expand-file-name file (or directory
525                                              temporary-file-directory)))
526      (find-file-other-window file)      (find-file-other-window file)
527      (setq buffer-read-only nil)      (setq buffer-read-only nil)
528      (goto-char (point-max))      (goto-char (point-max))

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26