home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / blix / blixserver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.0 KB  |  111 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*_______________________________________________________________________
  18.  |
  19.  | blixserver.c - server side of the world highscore for blix
  20.  |
  21.  | this is one program that needs to run on a server. It is
  22.  | not a buller proof program in the sense that it produces
  23.  | nice warningmessages when you install it wrong, nor does
  24.  | it produce any loging of the access done to this server.
  25.  | 
  26.  | to install make a user with name blix;
  27.  | o copy the executable blixserver to ~blix/bin/blixserver
  28.  | o make a directory ~blix/scores
  29.  | o adding a line in two files
  30.  |   ==> /etc/services
  31.  |     blix 8181/tcp    # blix highscore server
  32.  |   ==> /etc/inetd.conf (or /usr/etc/inetd.conf)
  33.  |    blix stream tcp nowait blix /usr/people/blix/bin/blixserver blixserver
  34.  |                           ^^^^
  35.  |                             This is an abritary user, but it must have
  36.  |                read/write permission to the directory
  37.  |                /usr/people/blix/scores/
  38.  |
  39.  | o to get things working do a kill -HUP <inetd.processid>
  40.  |
  41.  | (c) 1994 Frans van Hoesel, hoesel@chem.rug.nl
  42.  |               Xtreme Graphics Software
  43. */
  44.  
  45. #define SCOREDIR "/usr/people/blix/scores"
  46.  
  47. #include <unistd.h>
  48. #include <sys/types.h>
  49. #include <sys/stat.h>
  50. #include <fcntl.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <errno.h>
  55.  
  56. int openscore(void) {
  57.     int f;
  58.     int retry;
  59.     int lck;
  60.     
  61.     f = open(SCOREDIR "/worldscore", O_RDWR | O_CREAT );
  62.     
  63.     /* my guess is that the next test will always fail (f is always 
  64.      * set, but just in case)
  65.     */
  66.     if (f == -1 && errno == EAGAIN) {
  67.     while (f == -1 && (errno == EAGAIN || errno == EACCES) && retry < 30) {
  68.         sleep(1);
  69.         retry++;
  70.         f = open(SCOREDIR "/worldscore", O_RDWR | O_CREAT);
  71.     }
  72.     }
  73.     if (f != -1) {
  74.     lck = lockf(f, F_LOCK, 0);
  75.     if (lck != -1) {
  76.         return f;
  77.     } else {
  78.         close(f);
  79.         return -1;
  80.     }
  81.     }
  82.     return -1;
  83. }
  84.  
  85. int main(int argc, char *argv[]) {
  86.  
  87.     int lck = 0;
  88.     int f = 0;
  89.     int retry = 0;
  90.     char cmd[5];
  91.     
  92.     int world_id;
  93.     
  94.     if (read(0, cmd, 4) != 4) {
  95.     return -1;
  96.     }
  97.     cmd[4] = '\0';
  98.     if (strcmp(cmd, "INFO") == 0) {
  99.     /* return only the sequence number of this highscore list */
  100.     f = openscore();
  101.     if (f == -1) {
  102.         return -1;
  103.     }
  104.     read(f, &world_id, 4);
  105.     close(f);
  106.     write(1, &world_id, 4);
  107.     return 0;
  108.     }
  109.     return -1;
  110. }
  111.