
/*
 * Copyright (c) 1991    Jon Wesener 
 * Gaming Software
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting
 * documentation.  No representations are made about the
 * suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 */

#ident	"@(#)tankmsg_svc.c	1.4 :/usr/key/jojow/X/src/guts/SCCS/s.tankmsg_svc.c 3/19/91 10:16:36 "

#include <stdio.h>
#include <rpc/rpc.h>
#include "tankmsg.h"

static void messageprog_1();
char *Mazefnm;

main(ac,av)
	int ac;
	char *av[];
{
	SVCXPRT *transp;

	/* usage line */
	if( ac < 2 ) {
		(void)fprintf(stderr,"usage: %s maze [profile]\n",av[0]);
		exit( 1 );
	}

	Mazefnm = av[1];

	/* load the profile */
	if( (ac >= 3) && load_profile(av[2]) ) {
		(void)fprintf(stderr,"%s: invalid profile\n",av[0]);
		exit( 1 );
	}

	(void)pmap_unset(MESSAGEPROG, MESSAGEVERS);

	transp = svcudp_create(RPC_ANYSOCK);
	if (transp == NULL) {
		(void)fprintf(stderr, "cannot create udp service.\n");
		exit(1);
	}
	if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_UDP)) {
		(void)fprintf(stderr, "unable to register (MESSAGEPROG, MESSAGEVERS, udp).\n");
		exit(1);
	}

	transp = svctcp_create(RPC_ANYSOCK, 0, 0);
	if (transp == NULL) {
		(void)fprintf(stderr, "cannot create tcp service.\n");
		exit(1);
	}
	if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_TCP)) {
		(void)fprintf(stderr, "unable to register (MESSAGEPROG, MESSAGEVERS, tcp).\n");
		exit(1);
	}
	svc_run();
	(void)fprintf(stderr, "svc_run returned\n");
	exit(1);
}

static void
messageprog_1(rqstp, transp)
	struct svc_req *rqstp;
	SVCXPRT *transp;
{
	union {
		char *tenter_1_arg;
		char *getpos_1_arg;
		int getmaze_1_arg;
		char *texit_1_arg;
	} argument;
	char *result;
	bool_t (*xdr_argument)(), (*xdr_result)();
	char *(*local)();

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void)svc_sendreply(transp, xdr_void, (char *)NULL);
		return;

	case TENTER:
		xdr_argument = xdr_wrapstring;
		xdr_result = xdr_wrapstring;
		local = (char *(*)()) tenter_1;
		break;

	case GETPOS:
		xdr_argument = xdr_wrapstring;
		xdr_result = xdr_wrapstring;
		local = (char *(*)()) getpos_1;
		break;

	case GETMAZE:
		xdr_argument = xdr_int;
		xdr_result = xdr_wrapstring;
		local = (char *(*)()) getmaze_1;
		break;

	case TEXIT:
		xdr_argument = xdr_wrapstring;
		xdr_result = xdr_wrapstring;
		local = (char *(*)()) texit_1;
		break;

	case GETPLYRCNT:
		xdr_argument = xdr_void;
		xdr_result = xdr_int;
		local = (char *(*)()) getplyrcnt_1;
		break;

	default:
		svcerr_noproc(transp);
		return;
	}
	bzero((char *)&argument, sizeof(argument));
	if (!svc_getargs(transp, xdr_argument, &argument)) {
		svcerr_decode(transp);
		return;
	}
	result = (*local)(&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
		svcerr_systemerr(transp);
	}
	if (!svc_freeargs(transp, xdr_argument, &argument)) {
		(void)fprintf(stderr, "unable to free arguments\n");
		exit(1);
	}
}


/* Lint Output
*/
