
#include "k.h"

/*
 *      s e r v e r
 */

server()
{
        int num, len;
        n = 0;                          /* initialize message number */
        numtry = 0;                     /* say no tries yet */

        while(TRUE) switch(rpack(&len,&num,packet))  
			   /* do this for as long as necessary */
        {
                case 'S':
                {
#if debug
                        fprintf(stderr,"server -- received an S packet\n");
#endif
                        n = num;
                        rpar(packet);
                        spar(packet);
                        spack('Y',n,6,packet);
                        oldtry = numtry;
                        numtry = 0;
                        n = (n+1)%64;
#if debug
                        fprintf(stderr,"server -- going to recsw\n");
#endif
                        recsw('F');
                        break;
                }

                case 'R':
                {
                        int i;
#if debug
                        fprintf(stderr,"server -- received an R packet\n");
#endif
                        i = 0;
                        do filnam[i] = toupper(packet[i]);
                                while((packet[i++] != '\0')&&(i<len));
#if debug
                        fprintf(stderr,"server -- will send %s\n",filnam);
                        fprintf(stderr,"server -- going to sendsw\n");
#endif
                        sendsw();
                        n = 0;
                        break;
                }

                case 'G':
                {
#if debug
                        fprintf(stderr,"server -- received an G packet\n");
#endif
                        switch(packet[0])
                        {
                                case 'L':       spack('Y',num,0,0);
                                                sys$delprc(0,0);
                                case 'F':       spack('Y',num,0,0);
                                                exit();
                        }
                        break;
                }
        }
}
