home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*_______________________________________________________________________
- |
- | blixserver.c - server side of the world highscore for blix
- |
- | this is one program that needs to run on a server. It is
- | not a buller proof program in the sense that it produces
- | nice warningmessages when you install it wrong, nor does
- | it produce any loging of the access done to this server.
- |
- | to install make a user with name blix;
- | o copy the executable blixserver to ~blix/bin/blixserver
- | o make a directory ~blix/scores
- | o adding a line in two files
- | ==> /etc/services
- | blix 8181/tcp # blix highscore server
- | ==> /etc/inetd.conf (or /usr/etc/inetd.conf)
- | blix stream tcp nowait blix /usr/people/blix/bin/blixserver blixserver
- | ^^^^
- | This is an abritary user, but it must have
- | read/write permission to the directory
- | /usr/people/blix/scores/
- |
- | o to get things working do a kill -HUP <inetd.processid>
- |
- | (c) 1994 Frans van Hoesel, hoesel@chem.rug.nl
- | Xtreme Graphics Software
- */
-
- #define SCOREDIR "/usr/people/blix/scores"
-
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
-
- int openscore(void) {
- int f;
- int retry;
- int lck;
-
- f = open(SCOREDIR "/worldscore", O_RDWR | O_CREAT );
-
- /* my guess is that the next test will always fail (f is always
- * set, but just in case)
- */
- if (f == -1 && errno == EAGAIN) {
- while (f == -1 && (errno == EAGAIN || errno == EACCES) && retry < 30) {
- sleep(1);
- retry++;
- f = open(SCOREDIR "/worldscore", O_RDWR | O_CREAT);
- }
- }
- if (f != -1) {
- lck = lockf(f, F_LOCK, 0);
- if (lck != -1) {
- return f;
- } else {
- close(f);
- return -1;
- }
- }
- return -1;
- }
-
- int main(int argc, char *argv[]) {
-
- int lck = 0;
- int f = 0;
- int retry = 0;
- char cmd[5];
-
- int world_id;
-
- if (read(0, cmd, 4) != 4) {
- return -1;
- }
- cmd[4] = '\0';
- if (strcmp(cmd, "INFO") == 0) {
- /* return only the sequence number of this highscore list */
- f = openscore();
- if (f == -1) {
- return -1;
- }
- read(f, &world_id, 4);
- close(f);
- write(1, &world_id, 4);
- return 0;
- }
- return -1;
- }
-