hunt/playit.c
/*
 * playit:
 *	Play a given game, handling all the curses commands from
 *	the driver.
 */
Play a given game, handling all the curses commands from
the driver.
Play a given game handling all the curses commands from the driver .
void
playit()
{
	int		ch;
	int		clr = 0;
	int		y, x;
	uint32_t	version;
	int		otto_y, otto_x;
	char		otto_face = ' ';
	int		chars_processed;
	if (read(Socket, &version, sizeof version) != sizeof version) {
		bad_con();
	}
	if (ntohl(version) != HUNT_VERSION) {
		bad_ver();
	}
	errno = 0;
	nchar_send = MAX_SEND;
	Otto_expect = 0;
	while ((ch = GETCHR()) != EOF) {
		switch (ch & 0377) {
		  case MOVE:
			y = GETCHR();
			x = GETCHR();
			display_move(y, x);
			break;
		  case CLRTOEOL:
			display_clear_eol();
			break;
		  case CLEAR:
			display_clear_the_screen();
			break;
		  case REFRESH:
			display_refresh();
			break;
		  case REDRAW:
			display_redraw_screen();
			display_refresh();
			break;
		  case ENDWIN:
			display_refresh();
			if ((ch = GETCHR()) == LAST_PLAYER)
				Last_player = TRUE;
			ch = EOF;
			goto out;
		  case BELL:
			if (!no_beep)
			    display_beep();
			break;
		  case READY:
			chars_processed = GETCHR();
			display_refresh();
			if (nchar_send < 0)
				tcflush(STDIN_FILENO, TCIFLUSH);
			nchar_send += chars_processed;
			if (nchar_send > MAX_SEND)
				nchar_send = MAX_SEND;
			if (Otto_mode) {
				Otto_expect -= chars_processed;
				if (Otto_expect == 0) {
					static char buf[MAX_SEND * 2];
					int len;
					len = otto(otto_y, otto_x, otto_face,
						buf, sizeof buf);
					if (len) {
						write(Socket, buf, len);
						Otto_expect += len;
					}
				}
			}
			break;
		  case SETCOLOR:
			if (Use_Color)
				display_set_colour(GETCHR());
			break;
		  case CLEARCOLOR:
			if (Use_Color)
				display_clear_colour(GETCHR());
			break;
		  case ADDCOLORCH:
			clr = GETCHR();
		  case ADDCH:
			ch = GETCHR();
		  default:
			if (!isprint(ch))
				ch = ' ';
			if (clr && Use_Color) {
				display_put_ch_color(ch, clr);
			}
			else {
				if (clr && !Use_Color &&
						(ch == '{' ||
						 ch == '}' ||
						 ch == 'i' ||
						 ch == '!')) {
					int nteam = team_of_color(clr);
					if (nteam != ' ' &&
							(Am_monitor ||
							 team == nteam))
						ch = nteam;
				}
				display_put_ch(ch);
			}
			if (Otto_mode)
				switch (ch) {
				case '<':
				case '>':
				case '^':
				case 'v':
					otto_face = ch;
					display_getyx(&otto_y, &otto_x);
					otto_x--;
					break;
				}
			clr = 0;
			break;
		}
	}
out:
	(void) close(Socket);
}
void playit ( ) { int ch ; int clr = 0 ; int y , x ; uint32_t version ; int otto_y , otto_x ; char otto_face = ' ' ; int chars_processed ; if ( read ( Socket , & version , sizeof version ) != sizeof version ) { bad_con ( ) ; } if ( ntohl ( version ) != HUNT_VERSION ) { bad_ver ( ) ; } errno = 0 ; nchar_send = MAX_SEND ; Otto_expect = 0 ; while ( ( ch = GETCHR ( ) ) != EOF ) { switch ( ch & 0377 ) { case MOVE : y = GETCHR ( ) ; x = GETCHR ( ) ; display_move ( y , x ) ; break ; case CLRTOEOL : display_clear_eol ( ) ; break ; case CLEAR : display_clear_the_screen ( ) ; break ; case REFRESH : display_refresh ( ) ; break ; case REDRAW : display_redraw_screen ( ) ; display_refresh ( ) ; break ; case ENDWIN : display_refresh ( ) ; if ( ( ch = GETCHR ( ) ) == LAST_PLAYER ) Last_player = TRUE ; ch = EOF ; goto out ; case BELL : if ( ! no_beep ) display_beep ( ) ; break ; case READY : chars_processed = GETCHR ( ) ; display_refresh ( ) ; if ( nchar_send < 0 ) tcflush ( STDIN_FILENO , TCIFLUSH ) ; nchar_send += chars_processed ; if ( nchar_send > MAX_SEND ) nchar_send = MAX_SEND ; if ( Otto_mode ) { Otto_expect -= chars_processed ; if ( Otto_expect == 0 ) { static char buf [ MAX_SEND * 2 ] ; int len ; len = otto ( otto_y , otto_x , otto_face , buf , sizeof buf ) ; if ( len ) { write ( Socket , buf , len ) ; Otto_expect += len ; } } } break ; case SETCOLOR : if ( Use_Color ) display_set_colour ( GETCHR ( ) ) ; break ; case CLEARCOLOR : if ( Use_Color ) display_clear_colour ( GETCHR ( ) ) ; break ; case ADDCOLORCH : clr = GETCHR ( ) ; case ADDCH : ch = GETCHR ( ) ; default : if ( ! isprint ( ch ) ) ch = ' ' ; if ( clr && Use_Color ) { display_put_ch_color ( ch , clr ) ; } else { if ( clr && ! Use_Color && ( ch == ' ' || ch == ' ' || ch == ' ' || ch == ' ' ) ) { int nteam = team_of_color ( clr ) ; if ( nteam != ' ' && ( Am_monitor || team == nteam ) ) ch = nteam ; } display_put_ch ( ch ) ; } if ( Otto_mode ) switch ( ch ) { case ' ' : case ' ' : case ' ' : case ' ' : otto_face = ch ; display_getyx ( & otto_y , & otto_x ) ; otto_x -- ; break ; } clr = 0 ; break ; } } out : ( void ) close ( Socket ) ; }
playit:
      Play a given game, handling all the curses commands from
      the driver.
playit : Play a given game handling all the curses commands from the driver .
/* NOTREACHED */ /* NOTREACHED */ /*
				 * The driver returns the number of keypresses
				 * that it has processed. Use this to figure
				 * out if otto's commands have completed.
				 */ /* not very fair! */ /* Ask otto what it wants to do: */ /* Pass it on to the driver: */ /* Update expectations: */ /* FALLTHROUGH */ /* FALLTHROUGH */ /* We aren't using colour, but the
					 * server differentiates between teams
					 * by colour, so we may have to change
					 * the character to a team digit
					 * (losing facing information in the
					 * process). 
					 */ /* Monitors see all team members as
					 * digits, and team members see their
					 * team-mates as digits.
					 */ /* Output the colorless character */