Esempio n. 1
0
void drawgames(int pos) {
    int selected_game = 0;

    if (games[pos].status != GAME_FREE) {
        selected_game = pos;
    }
    else
        selected_game = 0;

    dispmultiframe();
    xt_par0(XT_CH_NORMAL);

    int c = 0;
    int useroffsettotal = 0;
    int ioffset = 0;

    while (2 * ioffset + useroffsettotal + (games[numgames - c].status == GAME_FREE ? 0 : games[numgames - c].slots_filled) < ROWS - 20){
        useroffsettotal += games[numgames - c].status == GAME_FREE ? 0 : games[numgames - c].slots_filled;
        c++;
    }

    int i = selected_game - c;
    int ii;

    useroffsettotal = 1;
    int useroffset = 1;
    if (i < 0) i = 0;


    for (; i < MAX_GAMES; i++) {

        if (games[i].status == GAME_FREE)
            continue;

        printgame(5 + 2 * ioffset + useroffsettotal, i == selected_game, games[i]);
        for (ii = 0; ii < games[i].slots_filled; ii++) {
            if (games[i].players[ii] == EMPTY_SLOT)
                continue;
            SETPOS(6 + 2 * ioffset + useroffsettotal, 8);
            printf("%s", users[games[i].players[ii]].username);
            useroffset++;
            useroffsettotal++;
        }
        useroffset = 1;
        i++;
        ioffset++;

    }


    SETPOS(2, 3);
    printf("Open Lobbies (Up/Down to select, %sJ%soin, %sC%sreate, %sQ%suit, %sH%selp)", XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL);

    xt_par0(XT_CH_BOLD);
    SETPOS(3, 3);
    printf("terminvaders MuLtIpLaYeR Lobby");

    xt_par0(XT_CH_DEFAULT);

}
Esempio n. 2
0
void printgame(int row, int is_selected, multiplayergame_t game) {
    SETPOS(row, 4);
    if (is_selected)
        printf("> %s (%d/%d)", game.name, game.slots_filled, game.slots_total);
    else
        printf("  %s (%d/%d)", game.name, game.slots_filled, game.slots_total);
    SETPOS(row, COLS - 30);
    switch(game.mode){
        case MODE_TEAM:
            printf("Team");
            break;
    }
}
Esempio n. 3
0
File: syntax.c Progetto: E-LLP/VICAR
    FUNCTION BOOL dash_dash (FAST struct SYNBLK	*sb)
    {
    TEXT    token[TOKESIZ+1];
    CODE    toke_type;
    TEXT    *init_pos;
    
    init_pos = SAVPOS;
    toke_type = gettok(sb, token);
    if (toke_type == S_WHITE)
        toke_type = gettok(sb, token);
    if (toke_type == '-')
        {
	toke_type = gettok(sb, token);		/* look for 2nd dash 	*/
	if (toke_type == '-')
	    {
	    toke_type = gettok(sb, token);	/* get separator	*/
	    if (toke_type == S_WHITE || toke_type == S_COMSEP ||
	        toke_type == EOS)
		{
		(*sb).lstcg = toke_type;
	        return (TRUE);
		}
	    }
	}
    SETPOS(init_pos);				/* return to init pos	*/
    return (FALSE);
    }	    
Esempio n. 4
0
void file_string_init (STRING *s,void *data,unsigned long size)
{
  s->data = data;		/* note fd */
  s->size = size;		/* note size */
  s->chunk = chunk;
  s->chunksize = (unsigned long) CHUNKLEN;
  SETPOS (s,0);			/* set initial position */
}
Esempio n. 5
0
/* Clear the screen. */
static void clear(void) {
    int r, c;
    for (r = 1; r <= ROWS; r++) {
        SETPOS(r, 1);
        for (c = 1; c <= COLS; c++)
            putchar(' ');
    }
}
Esempio n. 6
0
unsigned long strcrlflen (STRING *s)
{
  unsigned long pos = GETPOS (s);
  unsigned long i = SIZE (s);
  unsigned long j = i;
  while (j--) if ((SNX (s) == '\015') && ((CHR (s) != '\012') || !j)) i++;
  SETPOS (s,pos);		/* restore old position */
  return i;
}
Esempio n. 7
0
void draw_users() {
    int i;
    int userdisplayoffset = 0;
    printf("Who's Online");
    for (i = 0; i < 16; i++) {
        if (users[i].status != CLIENT_FREE) {
            SETPOS(4 + userdisplayoffset, COLS - 18);
            printf("%s", users[i].username);
            userdisplayoffset++;
        }
    }
}
Esempio n. 8
0
File: syntax.c Progetto: E-LLP/VICAR
FUNCTION static CODE de_ref 
(
    FAST struct SYNBLK	*sb,			/* in/out: syntax blk -- cmd stream*/
    FAST TEXT		name[F_Q_NAMESIZ+1]	/* out: deref'd var name string	*/

 )
    {
    TEXT	token[TOKESIZ+1];
    FAST CODE	toke_type;
    TEXT	*init_pos, *fld_pos;
    CODE	code;
    
    name[0] = EOS;
    init_pos = SAVPOS;
    toke_type = gettok(sb, token);
    if (toke_type == S_WHITE)
        toke_type = gettok(sb, token);
    if (toke_type == '@')
        {
	fld_pos = SAVPOS;			/* posit of begin of name field	*/
	toke_type = gettok(sb, token);		/* look for symbol	*/
	if (toke_type == S_ALPHA  ||  toke_type == S_QALPHA)
	    {
	    SETPOS(fld_pos);			/* back up to get entire name fld*/
	    code = getfld(sb, token);
	    if (code == SUCCESS  ||
		code == S_WHITE  ||  code == S_COMSEP  ||  code == EOS)
    	        {
		s_bcopy(token, name, F_Q_NAMESIZ);
		(*sb).lstcg = code;
	        return (SUCCESS);
		}
	    }
	(*sb).errchr = (*sb).curchr - 1;
	synerr(sb, "A variable name must follow '@'.");
	return (S_SYNERR);
	}
    SETPOS(init_pos);				/* return to init pos	*/
    return (FAIL);
    }	    
void ms_init (STRING *s,void *data,unsigned long size)
{
  APPENDPACKAGE *md = (APPENDPACKAGE *) data;
  s->data = data;		/* note stream/msgno and header length */
  mail_fetch_header (md->stream,md->msgno,NIL,NIL,&s->data1,
		     FT_PREFETCHTEXT|FT_PEEK);
#if 0
  s->size = size;		/* message size */
#else	/* This kludge is necessary because of broken IMAP servers (sigh!) */
  mail_fetch_text (md->stream,md->msgno,NIL,&s->size,FT_PEEK);
  s->size += s->data1;		/* header + body size */
#endif
  SETPOS (s,0);
}
Esempio n. 10
0
unsigned long unix_crlflen (STRING *s)
{
  unsigned long pos = GETPOS (s);
  unsigned long i = SIZE (s);
  unsigned long j = i;
  while (j--) switch (SNX (s)) {/* search for newlines */
  case '\015':			/* unlikely carriage return */
    if (j && (CHR (s) == '\012')) {
      SNX (s);			/* eat the line feed */
      j--;
    }
    break;
  case '\012':			/* line feed? */
    i++;
  default:			/* ordinary chararacter */
    break;
  }
  SETPOS (s,pos);		/* restore old position */
  return i;
}
Esempio n. 11
0
void dispmultiframe(){
    xt_par0(XT_CLEAR_SCREEN);
    SETPOS(10,10);
    xt_par0(XT_CH_NORMAL);
    int cursor_r = 1, cursor_c = 1;
    SETPOS(1, 1);
    int test = 0;
    int lim = 3;
    while (cursor_c <= COLS) {
        cursor_r = 1;
        SETPOS(cursor_r, cursor_c);
        printf("~");
        cursor_r = ROWS;
        SETPOS(cursor_r, cursor_c);
        printf("~");
        cursor_c++;

        if (test == lim){
            fflush(stdout);
            test = 0;
        }
        test++;
    }


    cursor_r = 2;
    while (cursor_r < ROWS) {
        cursor_c = 1;
        SETPOS(cursor_r, cursor_c);
        printf("#");
        cursor_c = COLS - 20;
        SETPOS(cursor_r, cursor_c);
        putchar('|');
        cursor_c = COLS;
        SETPOS(cursor_r, cursor_c);
        printf("#");
        cursor_r++;
        if (test == lim){
            fflush(stdout);
            test = 0;
        }
        test++;
    }
}
Esempio n. 12
0
int create_popup () {
    int key;
    // here should check if max games has been reached.
    if (numgames >= MAX_GAMES) {
        xt_par0(XT_CH_NORMAL);
        SETPOS(ROWS / 2 - 2, COLS / 2 - 15);
        printf("%s         Create Game          %s", XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 - 1, COLS / 2 - 15);
        printf("%s  %s                          %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 , COLS / 2 - 15);
        printf("%s  %s      Lobby is full!      %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 1, COLS / 2 - 15);
        printf("%s  %s                          %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 2, COLS / 2 - 15);
        printf("%s   Press any key to go back   %s", XT_CH_INVERSE, XT_CH_NORMAL);
        fflush(stdout);

        int key;
        while ((key = getkey()) == KEY_NOTHING);
        xt_par0(XT_CLEAR_SCREEN);

        return 0;
    }

    int type = 0, users = 2, field = 0, pos = 0, titlelen = 0, i;

    char title[NAME_LEN + 1] = "";

    while(1){
        xt_par0(XT_CH_NORMAL);
        SETPOS(ROWS / 2 - 2, COLS / 2 - 35);
        printf("%s                             Create Game                              %s", XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 - 1, COLS / 2 - 35);
        printf("%s  %s                                                                  %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 , COLS / 2 - 35);
        printf("%s  %s  Title: %s%-32s%s Users: %s%d%s Type: %s%s   %s %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_UNDERLINE, title, XT_CH_NORMAL,XT_CH_UNDERLINE, users,XT_CH_NORMAL, XT_CH_UNDERLINE, types[type],XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 1, COLS / 2 - 35);
        printf("%s  %s                                                                  %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 2, COLS / 2 - 35);
        printf("%s       Esc to cancel, Tab to switch field, Up/Down/Type to input      %s", XT_CH_INVERSE, XT_CH_NORMAL);

        if (titlelen < 32)
            xt_par0(XT_CH_UNDERLINE);
        SETPOS(ROWS / 2, COLS / 2 - 24 + titlelen);
        putchar(' ');
        xt_par0(XT_CH_NORMAL);

        switch (field) {
            case 0:
                SETPOS(ROWS / 2 , COLS / 2 - 24 + pos);
                break;
            case 1:
                SETPOS(ROWS / 2, COLS / 2 + 16);
                break;
            case 2:
                SETPOS(ROWS / 2, COLS / 2 + 24);
                break;
        }
        fflush(stdout);

        while((key = getkey()) == KEY_NOTHING);
        switch(key){
            case KEY_ENTER: {
                char* bufff;
                serialize_game_setup(type, users, title, &bufff);
                transmit(sockfd, CMD_SETUP_GAME, bufff);
                free(bufff);
                int nnn = numgames;
                games[nnn] = (multiplayergame_t) {nnn, GAME_WAITING, users, 0, {0}, {0}, type};
                strcpy(games[nnn].name, title);
                numgames++;
                xt_par0(XT_CLEAR_SCREEN);
                return 1;
            }
            case 9: //TAB
                if (field < 2)
                    field++;
                else
                    field = 0;
                break;
            case 27: //ESC
                xt_par0(XT_CLEAR_SCREEN);
                return 0;
            case KEY_UP:
                if (field == 1){
                    if (users < maxplayers_pertype[type])
                        users++;
                } else if (field == 2) {
                    if (type < 2) {
                        type++;
                        if (users > maxplayers_pertype[type])
                            users = maxplayers_pertype[type];
                    }
                }
                break;
            case KEY_DOWN:
                if (field == 1){
                    if (users > 2)
                        users--;
                } else if (field == 2) {
                    if (type > 0) {
                        type--;
                        if (users > maxplayers_pertype[type])
                            users = maxplayers_pertype[type];
                    }
                }
                break;
            case KEY_LEFT:
                if (pos > 0){
                    pos--;
                }
                break;
            case KEY_RIGHT:
                if (pos < titlelen){
                    pos++;
                }
                break;
            case KEY_BACKSPACE:
                if (field == 0) {
                    if (pos > 0) {
                        title[--pos] = ' ';
                        title[titlelen] = '\0';
                        titlelen--;
                    }
                    for (i = pos + 1; i <= titlelen; i++) {
                        title[i-1] = title[i];
                    }
                }
            default:
                if ((key >= ' ' && key <= '~') && field == 0 && titlelen < 32) {
                    if (pos != titlelen) {
                        for (i = titlelen; i > pos; i--) {
                            title[i] = title[i-1];
                        }
                    }
                    title[pos] = key;
                    pos++;
                    putchar(key);
                    titlelen++;
                }
                break;
        }
        fflush(stdout);
    }
}
Esempio n. 13
0
static void drawmenu(int choice) {

    int cursor_r = 1, cursor_c = 1;
    SETPOS(1, 1);
    int test = 0;
    int lim = 3;
    while (cursor_c <= COLS) {
        cursor_r = 1;
        SETPOS(cursor_r, cursor_c);
        printf("~");
        cursor_r = ROWS;
        SETPOS(cursor_r, cursor_c);
        printf("~");
        cursor_c++;

        if (test == lim){
            test = 0;
        }
        test++;
    }
    cursor_r = 2;
    while (cursor_r < ROWS) {
        cursor_c = 1;
        SETPOS(cursor_r, cursor_c);
        printf("#");
        cursor_c = COLS;
        SETPOS(cursor_r, cursor_c);
        printf("#");
        cursor_r++;
        if (test == lim){
            test = 0;
        }
        test++;
    }

    xt_par0(XT_CH_BOLD);
    xt_par0(XT_CH_YELLOW);
    SETPOS(ROWS / 4, COLS / 2 - 11);
    printf("-~<[ terminvaders ]>~-");

    /*xt_par0(XT_CH_NORMAL);
    xt_par0(XT_CH_GREEN);
    xt_par0(XT_CH_INVERSE);
    xt_par0(XT_CH_BOLD);
    SETPOS(ROWS / 2, COLS / 2 - 2);
    printf("Play");

    xt_par0(XT_CH_NORMAL);
    SETPOS(5 * ROWS / 8, COLS / 2 - 4);
    printf("Settings");

    xt_par0(XT_CH_RED);
    SETPOS(3 * ROWS / 4, COLS / 2 - 2);
    printf("Quit");*/

    xt_par0(XT_CH_DEFAULT);

    SETPOS(ROWS / 2, COLS / 2 - 6);
    xt_par0(XT_CH_GREEN);
    printf("Single Player");

    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
    xt_par0(XT_CH_WHITE);
    printf("Settings");

    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
    xt_par0(XT_CH_RED);
    printf("Quit");

    SETPOS(ROWS / 2 + OFFSET, COLS / 2 - 5);
    xt_par0(XT_CH_RED);
    xt_par0(XT_CH_BOLD);
    printf("M");
    xt_par0(XT_CH_YELLOW);
    printf("u");
    xt_par0(XT_CH_GREEN);
    printf("L");
    xt_par0(XT_CH_CYAN);
    printf("t");
    xt_par0(XT_CH_BLUE);
    printf("I");
    xt_par0(XT_CH_MAGENTA);
    printf("p");
    xt_par0(XT_CH_RED);
    printf("L");
    xt_par0(XT_CH_YELLOW);
    printf("a");
    xt_par0(XT_CH_GREEN);
    printf("Y");
    xt_par0(XT_CH_CYAN);
    printf("e");
    xt_par0(XT_CH_BLUE);
    printf("R");



    xt_par0(XT_CH_BOLD);
    xt_par0(XT_CH_INVERSE);
    switch (choice) { // makes the button highlighted
        case 0:
            SETPOS(ROWS / 2, COLS / 2 - 6);
            xt_par0(XT_CH_GREEN);
            printf("Single Player");
            SETPOS(ROWS, COLS);
            break;
        case 2:
            SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
            xt_par0(XT_CH_WHITE);
            xt_par0(XT_CH_BOLD);
            printf("Settings");
            SETPOS(ROWS, COLS);
            break;
        case 3:
            SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
            xt_par0(XT_CH_RED);
            printf("Quit");
            SETPOS(ROWS, COLS);
            break;
        case 1:
            SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
            xt_par0(XT_CH_RED);
            xt_par0(XT_CH_BOLD);
            printf("M");
            xt_par0(XT_CH_YELLOW);
            printf("u");
            xt_par0(XT_CH_GREEN);
            printf("L");
            xt_par0(XT_CH_CYAN);
            printf("t");
            xt_par0(XT_CH_BLUE);
            printf("I");
            xt_par0(XT_CH_MAGENTA);
            printf("p");
            xt_par0(XT_CH_RED);
            printf("L");
            xt_par0(XT_CH_YELLOW);
            printf("a");
            xt_par0(XT_CH_GREEN);
            printf("Y");
            xt_par0(XT_CH_CYAN);
            printf("e");
            xt_par0(XT_CH_BLUE);
            printf("R");
            SETPOS(ROWS, COLS);
            break;
    }
    xt_par0(XT_CH_NORMAL);

    }
Esempio n. 14
0
char file_string_next (STRING *s)
{
  char c = *s->curpos++;	/* get next byte */
  SETPOS (s,GETPOS (s));	/* move to next chunk */
  return c;			/* return the byte */
}
Esempio n. 15
0
/* Reset the keyboard and screen. */
static void finish(void) {
    getkey_terminate();
    xt_par0(XT_CLEAR_SCREEN);
    xt_par0(XT_CH_NORMAL);
    SETPOS(1, 1);
}
Esempio n. 16
0
int deliver (FILE *f,unsigned long msglen,char *user)
{
  MAILSTREAM *ds = NIL;
  char *s,*mailbox,tmp[MAILTMPLEN],path[MAILTMPLEN];
  STRING st;
  struct stat sbuf;
				/* have a mailbox specifier? */
  if ((mailbox = strchr (user,'+')) != NULL) {
    *mailbox++ = '\0';		/* yes, tie off user name */
    if (!*mailbox || !compare_cstring ((unsigned char *) mailbox,"INBOX"))
      mailbox = NIL;		/* user+ and user+INBOX same as user */
  }
  if (!*user) user = myusername ();
  else if (strcmp (user,myusername ()))
    return fail ("can't deliver to other user",EX_CANTCREAT);
  sprintf (tmp,"delivering to %.80s+%.80s",user,mailbox ? mailbox : "INBOX");
  mm_dlog (tmp);
				/* prepare stringstruct */
  INIT (&st,file_string,(void *) f,msglen);
  if (mailbox) {		/* non-INBOX name */
    switch (mailbox[0]) {	/* make sure a valid name */
    default:			/* other names, try to deliver if not INBOX */
      if ((strlen (mailbox) <= NETMAXMBX) &&
	  !strstr (mailbox,"..") && !strstr (mailbox,"//") &&
	  !strstr (mailbox,"/~") && mailboxfile (path,mailbox) && path[0] &&
	  !deliver_safely (NIL,&st,mailbox,path,tmp)) return NIL;
    case '%': case '*':		/* wildcards not valid */
    case '/':			/* absolute path names not valid */
    case '~':			/* user names not valid */
      sprintf (tmp,"invalid mailbox name %.80s+%.80s",user,mailbox);
      mm_log (tmp,WARN);
      break;
    }
    mm_dlog ("retrying delivery to INBOX");
    SETPOS (&st,0);		/* rewind stringstruct just in case */
  }

				/* no -I, resolve "INBOX" into path */
  if (mailboxfile (path,mailbox = "INBOX") && !path[0]) {
				/* clear box, get generic INBOX prototype */
    if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE)))
      fatal ("no INBOX prototype");
				/* standard system driver? */
    if (!strcmp (ds->dtb->name,"unix") || !strcmp (ds->dtb->name,"mmdf")) {
      strcpy (path,sysinbox ());/* use system INBOX */
      if (!lstat (path,&sbuf))	/* deliver to existing system INBOX */
	return deliver_safely (ds,&st,mailbox,path,tmp);
    }
    else {			/* other driver, try ~/INBOX */
      if ((mailboxfile (path,"&&&&&") == path) &&
	  (s = strstr (path,"&&&&&")) && strcpy (s,"INBOX") &&
	  !lstat (path,&sbuf)){	/* deliver to existing ~/INBOX */
	sprintf (tmp,"#driver.%s/INBOX",ds->dtb->name);
	return deliver_safely (ds,&st,cpystr (tmp),path,tmp);
      }
    }
				/* not dummy, deliver to driver imputed path */
    if (strcmp (ds->dtb->name,"dummy"))
      return (ibxpath (ds,&mailbox,path) && !lstat (path,&sbuf)) ?
	deliver_safely (ds,&st,mailbox,path,tmp) :
	  fail ("unable to resolve INBOX path",EX_CANTCREAT);
				/* dummy, empty imputed append path exist? */
    if (ibxpath (ds = default_proto (T),&mailbox,path) &&
	!lstat (path,&sbuf) && !sbuf.st_size)
      return deliver_safely (ds,&st,mailbox,path,tmp);
				/* impute path that we will create */
    if (!ibxpath (ds = default_proto (NIL),&mailbox,path))
      return fail ("unable to resolve INBOX",EX_CANTCREAT);
  }
				/* black box, must create, get create proto */
  else if (lstat (path,&sbuf)) ds = default_proto (NIL);
  else {			/* black box, existing file */
				/* empty file, get append prototype */
    if (!sbuf.st_size) ds = default_proto (T);
				/* non-empty, get prototype from its data */
    else if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE)))
      fatal ("no INBOX prototype");
				/* error if unknown format */
    if (!strcmp (ds->dtb->name,"phile"))
      return fail ("unknown format INBOX",EX_UNAVAILABLE);
				/* otherwise can deliver to it */
    return deliver_safely (ds,&st,mailbox,path,tmp);
  }
  sprintf (tmp,"attempting to create mailbox %.80s path %.80s",mailbox,path);
  mm_dlog (tmp);
				/* supplicate to the Evil One */
  if (!path_create (ds,path)) return fail ("can't create INBOX",EX_CANTCREAT);
  sprintf (tmp,"created %.80s",path);
  mm_dlog (tmp);
				/* deliver the message */
  return deliver_safely (ds,&st,mailbox,path,tmp);
}
Esempio n. 17
0
File: syntax.c Progetto: E-LLP/VICAR
FUNCTION CODE getqlf 
(
    struct SYNBLK	*sb,		/* in/out: syntax block			*/
    TEXT		qualstr[]	/* out:  qualifier string		*/

 )
    {
    GENPTR		pos;
    CODE		toktyp;
    TEXT		token[TOKESIZ+1];
 

    pos = SAVPOS;			/* save position in case no quals found	*/
    if ((toktyp = gettok(sb, token)) == S_WHITE)	/* get token...		*/
	toktyp  = gettok(sb, token);	/* if white, get another		*/
    if (toktyp == S_SYNERR) goto syn_err;
    if (toktyp != QUAL_SYM)		/* if no qualifiers			*/
	{
	SETPOS(pos);			/* restore position			*/
	return(S_NONE);
	}

    /* The following checks are made to prevent improper syntax of 'proc a,|b|'
       or 'proc (a,b),|c|' from being processed identically to 'proc a|b|' or
       'proc (a,b)|c|', respectively.					*/

    pos = SAVPOS;			/* save pos as syntax check will change it	*/
    if ((*sb).lstcg == S_COMSEP)	/* if terminator char of last field was a comma */
        goto syn_err;
    else if ((*sb).lstcg == S_RPAREN)	/* since a comma separator isn't recorded... */
	{				/* check for one explicitly			*/
	SETPOS(pos-2);			/* back over current and '|' chars		*/
	while (*(*sb).curchr != ')')
	    {
	    if (*(*sb).curchr == ',')
		goto syn_err;
	    else
		(*sb).curchr--;
	    }
	SETPOS(pos);			/* restore position	*/
	}

    qualstr[0] = EOS;
    while (FOREVER)
	{
	if ((toktyp = gettok(sb, token)) == S_SYNERR) goto close_err;	/* get next token*/
	if (toktyp == QUAL_SYM)
	    break;			/* break if qualifiers done		*/
	if (toktyp == EOS) goto close_err;	/* syntax error if no closing "/"*/
	if (s_length(token) + s_length(qualstr) > CMDLINSIZ) goto close_err;	/* if no closing "/"*/
	s_append(token, qualstr);
	}
    return(SUCCESS);

syn_err:
    (*sb).curchr = (*sb).curchr - 1;	/* general syntax error			*/
    synerr(sb, "Incorrect format for qualifier");
    return(S_SYNERR);

close_err:
    (*sb).errchr = (*sb).curchr - 1;	/* point to error detection		*/
    synerr(sb, "No closing '|' in qualifier list");
    return(S_SYNERR);
    }
Esempio n. 18
0
void serverlogin(){
    int badserver;
    int field = 0, pos = 0, len = 0, addresslen = 0, usernamelen = 0, key = 0;

    char address[33] = "";
    int i;

    char username[17] = "";
    int j;

    while(1){

        i = strlen(address);
        j = strlen(username);

        if (field)
            len = usernamelen;
        else
            len = addresslen;

        xt_par0(XT_CH_NORMAL);
        SETPOS(ROWS / 2 - 3, COLS / 2 - 30);
        printf("%s                       Server Connect                       %s", XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 - 2, COLS / 2 - 30);
        printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 - 1, COLS / 2 - 30);
        printf("%s  %s  Address: %s                                %s             %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_UNDERLINE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);
        SETPOS(ROWS / 2 - 1, COLS / 2 - 17);
        xt_par0(XT_CH_UNDERLINE);
        printf("%s", address);
        xt_par0(XT_CH_NORMAL);

        SETPOS(ROWS / 2, COLS / 2 - 30);
        printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 1, COLS / 2 - 30);
        printf("%s  %s  Username: %s                %s                            %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);
        SETPOS(ROWS / 2 + 1, COLS / 2 - 16);
        xt_par0(XT_CH_UNDERLINE);
        printf("%s", username);
        xt_par0(XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 2, COLS / 2 - 30);
        printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

        SETPOS(ROWS / 2 + 3, COLS / 2 - 30);
        printf("%s Esc to go back, Enter to connect, Up/Down to switch fields %s", XT_CH_INVERSE, XT_CH_NORMAL);

        fflush(stdout);

        if (addresslen < 32) {
            xt_par0(XT_CH_NORMAL);
            if (pos < 32)
                xt_par0(XT_CH_UNDERLINE);
            SETPOS(ROWS / 2 - 1, COLS / 2 - 17 + addresslen);
            putchar(' ');
        }

        if (usernamelen < 16) {
            xt_par0(XT_CH_NORMAL);
            if (pos < 16)
                xt_par0(XT_CH_UNDERLINE);
            SETPOS(ROWS / 2 + 1, COLS / 2 - 16 + usernamelen);
            putchar(' ');
        }
        xt_par0(XT_CH_NORMAL);

        switch (field) {
            case 0:
                SETPOS(ROWS / 2 - 1, COLS / 2 - 17 + pos);
                break;
            case 1:
                SETPOS(ROWS / 2 + 1, COLS / 2 - 16 + pos);
                break;
        }

        while((key = getkey()) == KEY_NOTHING);


        switch(key){
            case KEY_ENTER: {
                if (i == 0 || j < 2)
                    break;
                badserver = 0;
                sockfd = make_connection(address);
                if (sockfd < 0)
                    badserver = 1;
                else if (transmit(sockfd, CMD_CONNECT, username) < 0)
                    badserver = 1;
                else {
                    int command;
                    char* buffer;
                    if (receive(sockfd, &command, &buffer) < 0)
                        badserver = 1;
                    else {
                        if (command == CMD_CONNECT)
                            our_id = atoi(buffer);
                        else
                            badserver = 1;
                        free(buffer);
                    }
                }

                if (badserver) {
                    xt_par0(XT_CH_NORMAL);
                    SETPOS(ROWS / 2 - 3, COLS / 2 - 30);
                    printf("%s                       Server Connect                       %s", XT_CH_INVERSE,XT_CH_NORMAL);

                    SETPOS(ROWS / 2 - 2, COLS / 2 - 30);
                    printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

                    SETPOS(ROWS / 2 - 1, COLS / 2 - 30);
                    printf("%s  %s  Address: %s%s%s             %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_UNDERLINE, address, XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

                    SETPOS(ROWS / 2, COLS / 2 - 30);
                    printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

                    SETPOS(ROWS / 2 + 1, COLS / 2 - 30);
                    printf("%s  %s           Server not found on this address.            %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

                    SETPOS(ROWS / 2 + 2, COLS / 2 - 30);
                    printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

                    SETPOS(ROWS / 2 + 3, COLS / 2 - 30);
                    printf("%s                       Esc to go back                       %s", XT_CH_INVERSE, XT_CH_NORMAL);
                    fflush(stdout);
                    break;
                }

                xt_par0(XT_CLEAR_SCREEN);
                lobby();
                close(sockfd);
                return;
            }
            case 27: //ESC
                xt_par0(XT_CLEAR_SCREEN);
                //return 0;
                return;
            case KEY_UP:
            case KEY_DOWN:
                field = !field;
                if (field)
                    len = usernamelen;
                else
                    len = addresslen;
                pos = 0;
                break;
            case KEY_LEFT:
                if (pos > 0){
                    pos--;
                }
                break;
            case KEY_RIGHT:
                if (pos < len){
                    pos++;
                }
                break;
            case KEY_BACKSPACE:
                if (field && pos > 0) {
                    username[--pos] = ' ';
                    username[usernamelen--] = '\0';
                    for (i = pos + 1; i <= usernamelen; i++) {
                        username[i-1] = username[i];
                    }
                } else if (!field && pos > 0) {
                    address[--pos] = ' ';
                    address[addresslen--] = '\0';
                    for (i = pos + 1; i <= addresslen; i++) {
                        address[i-1] = address[i];
                    }
                }
                break;
            default:
                if (key >= ' ' && key <= '~') {
                    if (field && usernamelen < 16) {
                        if (pos != usernamelen) {
                            for (i = usernamelen; i > pos; i--) {
                                username[i] = username[i-1];
                            }
                        }
                        username[pos] = key;
                        pos++;
                        putchar(key);
                        usernamelen++;
                    } else if (!field && addresslen < 32) {
                        if (pos != addresslen) {
                            for (i = addresslen; i > pos; i--) {
                                address[i] = address[i-1];
                            }
                        }
                        address[pos] = key;
                        pos++;
                        putchar(key);
                        addresslen++;
                    }
                }
                break;
        }
    }
}
Esempio n. 19
0
int confirm_request(char* username) {
    int choice = 0;

    int key = 0;

    xt_par0(XT_CH_NORMAL);
    SETPOS(ROWS / 2 - 3, COLS / 2 - 16);
    printf("%s                                %s", XT_CH_INVERSE, XT_CH_NORMAL);

    SETPOS(ROWS / 2 - 2, COLS / 2 - 16);
    printf("%s  %s                            %s  %s", XT_CH_INVERSE, XT_CH_NORMAL, XT_CH_INVERSE, XT_CH_NORMAL);

    SETPOS(ROWS / 2 - 1, COLS / 2 - 16);
    printf("%s  %s Let %16s join? %s  %s", XT_CH_INVERSE, XT_CH_NORMAL, username, XT_CH_INVERSE, XT_CH_NORMAL);

    SETPOS(ROWS / 2 + 0, COLS / 2 - 16);
    printf("%s  %s                            %s  %s", XT_CH_INVERSE, XT_CH_NORMAL, XT_CH_INVERSE, XT_CH_NORMAL);

    SETPOS(ROWS / 2 + 1, COLS / 2 - 16);
    printf("%s  %s       No         Yes       %s  %s", XT_CH_INVERSE, XT_CH_NORMAL, XT_CH_INVERSE, XT_CH_NORMAL);

    SETPOS(ROWS / 2 + 2, COLS / 2 - 16);
    printf("%s  %s                            %s  %s", XT_CH_INVERSE, XT_CH_NORMAL, XT_CH_INVERSE, XT_CH_NORMAL);

    SETPOS(ROWS / 2 + 3, COLS / 2 - 16);
    printf("%s                                %s", XT_CH_INVERSE, XT_CH_NORMAL);
    fflush(stdout);

    while (1){
        while ((key = getkey()) == KEY_NOTHING);

        switch (key) {
            case KEY_LEFT:
                choice = 0;
                break;
            case KEY_RIGHT:
                choice = 1;
                break;
            case KEY_ENTER:
                return choice;
        }

        if (choice) {
            SETPOS(ROWS / 2 + 1, COLS / 2 + 4);
            printf(XT_CH_INVERSE);
            printf(XT_CH_BOLD);
            printf("Yes");
            printf(XT_CH_NORMAL);
            SETPOS(ROWS / 2 + 1, COLS / 2 - 7);
            printf("No");
            fflush(stdout);
        } else {
            SETPOS(ROWS / 2 + 1, COLS / 2 - 7);
            printf(XT_CH_INVERSE);
            printf(XT_CH_BOLD);
            printf("No");
            printf(XT_CH_NORMAL);
            SETPOS(ROWS / 2 + 1, COLS / 2 + 4);
            printf("Yes");
            fflush(stdout);
        }
    }



}
Esempio n. 20
0
File: syntax.c Progetto: E-LLP/VICAR
FUNCTION CODE getval 
(
    FAST struct SYNBLK	*sb,		/* in/out: syntax block		*/
    FAST TEXT		*value[],	/* out: array of pointers to strings	*/
    FUNINT		maxval,		/* in:  dimension of value	*/
    COUNT		*count		/* out: actual number of values:*/
					/* -1 = no value, 0 = --	*/
 )
    {
    CODE	toktyp;			/* token type			*/
    FAST CODE	i;
    TEXT	field[TOKESIZ+1];	/* single value field		*/
    CODE	code, status;		/* return code			*/
    GENPTR	pos;
    TEXT	token[TOKESIZ+1];


    *count = 0;		
    code   = SUCCESS;
    pos    = SAVPOS;			/* save position for look-ahead	*/
    if (dash_dash(sb))
	{
	*count = 0;
	return (SUCCESS);		/* note *count is zero for --	*/
	}
    status = de_ref (sb, field);	/* look for de-reference syntax	*/
    if (status == SUCCESS)
        {
	value[0] = s_save (field);
	if (value[0] == NULL)
	    goto gv_merr;
	*count = 1;
	return (S_DEREF);
	}
    else if (status == S_SYNERR)
        return (status);

    if ((toktyp = gettok(sb, token)) == S_WHITE)	/* get token...		*/
	toktyp = gettok(sb, token);	/* if white, get another		*/
    if (toktyp == S_COMSEP)		/* if no value				*/
	*count = -1;
    else if (toktyp == S_SYNERR) goto gv_serr;	/* if syntax error		*/
    else if (toktyp == '(' )		/* left paren seen - assume multi-valued*/
	{
	igfdp(sb);			/* init block for getfld (w/in parens)	*/
	for (i = getfld(sb, field); i != S_RPAREN; i = getfld(sb, field))
	    {
	    if (i == S_SYNERR || i == EOS) goto gv_bval;
	    if (*count >= maxval) goto gv_mval;	/* error if max values reached	*/
	    value[*count] = s_save(field);	/*set value ptr to alloc values	*/
    	    if (value[*count] == NULL)
    		goto gv_merr;			/* no memory left		*/
	    (*count)++;
	    }
        if (*count == 0)
	    *count = -1;		/* flag 'no value'			*/
	(*sb).lstcg = S_RPAREN;	/* last terminator is right paren	*/
	}
    else				/* not multi-valued			*/
	{
	SETPOS(pos);			/* restore cmd stream position		*/
	if ((i = getfld(sb, field)) == S_SYNERR || i == S_RPAREN || i == '=')
	    goto gv_serr;
	else if (i == EOS)
	    code = EOS;
	else if (!NULLSTR(field) || i == S_QUOTED)
            {
	    value[0] = s_save(field);
	    if (value[0] == NULL) goto gv_merr;
	    *count = 1;
      	    }
        else if (NULLSTR(field))
	    *count = -1;		/* flag for 'no value'		*/
	}
    return(code);

gv_serr:
    (*sb).errchr = (*sb).curchr - 1;	/* point to error detection		*/
    synerr(sb, "Invalid value format");	/* put EM in block			*/
    code = S_SYNERR;
    return(code);
gv_bval:
    code = S_SYNERR;
    (*sb).errchr = (*sb).curchr - 1;	/* point to error detection		*/
    synerr(sb, "Missing value or invalid value format");
    free_val (value, *count);		/* free values allocated before error	*/
    *count = 0;
    return(code);
gv_mval:
    (*sb).errchr = (*sb).curchr - 1;	/* point to error detection		*/
    s_copy("Maximum number of values exceeded", (*sb).errmsg);
    code = S_SYNERR;
    free_val(value, *count);		/* free values allocated before error	*/
    *count = 0;
    return(code);
gv_merr:
    code = S_SYNERR;
    (*sb).errchr = (*sb).curchr - 1;	/* point to error detection		*/
    synerr(sb, "TAE Monitor internal memory overflow");
    free_val (value, *count);		/* free values allocated before error	*/
    *count = 0;
    return(code);
    }
Esempio n. 21
0
void game_wait(int created_game) {
    int key = 0;

    dispmultiframe();

    // this prints out current users in this game
    int i = created_game; // (which also needs to be integrated with server)
    // int onlinelistoffset = 0    ;

    int p_id;
    int foxes;
    int command;
    char* buffer;

    while (1) {
        int useroffset = 1;

        if (receive(sockfd, &command, &buffer) < 0) {
            if (errno != EWOULDBLOCK && errno != EAGAIN)
                return;
        }
        else {
            switch (command) {
                case CMD_NEW_REQUEST:
                    if (confirm_request(buffer))
                        transmit(sockfd, CMD_ACCEPT_REQ, buffer);
                    else
                        transmit(sockfd, CMD_REJECT_REQ, buffer);
                    dispmultiframe();
                    break;
                case CMD_CANCEL_REQ:
                    // TODO: implement
                    break;
                case CMD_PLAYER_JOIN:
                    sscanf(buffer, "%d", &p_id);
                    for (foxes = 0; foxes < games[i].slots_total; foxes++) {
                        if (games[i].players[foxes] == EMPTY_SLOT) {
                            games[i].players[foxes] = p_id;
                            break;
                        }
                    }
                    break;
                case CMD_PLAYER_PART:
                    sscanf(buffer, "%d", &p_id);
                    for (foxes = 0; foxes < games[i].slots_total; foxes++) {
                        if (games[i].players[foxes] == p_id) {
                            games[i].players[foxes] = EMPTY_SLOT;
                            break;
                        }
                    }
                    break;
                case CMD_GAME_START: {
                    game_t game;
                    setup_game(&game);
                    setup_multiplayer(&game, games[i].slots_total, atoi(buffer), sockfd);
                    while (game.running) {
                        update_game(&game);
                        usleep(1000000 / FPS);
                    }
                    return;
                }
                case CMD_QUIT:
                case CMD_ERROR:
                    return;
            }
            free(buffer);
        }

        switch ((key = getkey())) {
            case 'q':
            case 'Q':
            case 27: // esc
                transmit(sockfd, CMD_PLAYER_PART, NULL);
                xt_par0(XT_CLEAR_SCREEN);
                return;
        }

        for (foxes = 0; foxes < games[i].slots_total; foxes++) {
            SETPOS(6 + 2 * i + useroffset, 8);
            if (games[i].players[foxes] != EMPTY_SLOT) {
                printf("%d", games[i].players[foxes]);
                useroffset++;
            }
        }

        SETPOS(2,3);
        printf("%s", games[created_game].name);
        SETPOS(ROWS, COLS);

        fflush(stdout);
        usleep(1000000 / 20);
    }
}
Esempio n. 22
0
static int menu(void) {
    clear();
    drawmenu(0);
    star_t* stars = malloc(sizeof(star_t) * numstars);
    init(stars);

    int frame;
    int key, choice = 0;
    SETPOS(ROWS, COLS);
    while (1) {
        for (frame = 0; frame < fps / FPS; frame++)
            update(stars);
        display(stars);
        drawmenu(choice);
        switch ((key = getkey())) {
        case KEY_UP:
        case 'w':
            xt_par0(XT_CH_DEFAULT);
            switch (choice) { // makes the previous button 'normal'
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    printf("Settings");
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    break;
                case 1:
                    SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
            }
            if (choice > 0)
                choice--;
            else
                choice = 3;
            xt_par0(XT_CH_BOLD);
            xt_par0(XT_CH_INVERSE);
            switch (choice) { // makes the button highlighted
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    SETPOS(ROWS, COLS);
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    xt_par0(XT_CH_BOLD);
                    printf("Settings");
                    SETPOS(ROWS, COLS);
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    SETPOS(ROWS, COLS);
                    break;
                case 1:
                    SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
            }
            xt_par0(XT_CH_NORMAL);
            break;
        case KEY_DOWN:
        case 's':
            xt_par0(XT_CH_DEFAULT);
            switch (choice) { // makes the previous button 'normal'
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    printf("Settings");
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    break;
                case 1:
                    SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
            }
            if (choice < 3)
                choice++;
            else
                choice = 0;
            xt_par0(XT_CH_BOLD);
            xt_par0(XT_CH_INVERSE);
            switch (choice) { // makes the button highlighted
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    SETPOS(ROWS, COLS);
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    xt_par0(XT_CH_BOLD);
                    printf("Settings");
                    SETPOS(ROWS, COLS);
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    SETPOS(ROWS, COLS);
                    break;
                case 1:
                    SETPOS(ROWS / 2 + OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
                }
                xt_par0(XT_CH_NORMAL);
                break;
            case KEY_ENTER:
                return choice;
            case 'q':
                return MENU_QUIT;
        }
        fflush(stdout);
        usleep(1000000/FPS);

    }
}
Esempio n. 23
0
int join_popup (multiplayergame_t* game) {
    int key = 0;
    //int row = 0, col = 0;

    char tmpbuf[8];
    snprintf(tmpbuf, 8, "%d\n", game->id);
    transmit(sockfd, CMD_JOIN_GAME, tmpbuf);

    xt_par0(XT_CH_NORMAL);
    SETPOS(ROWS / 2 - 2, COLS / 2 - 30);
    printf("%s                         Join Game                          %s", XT_CH_INVERSE,XT_CH_NORMAL);

    SETPOS(ROWS / 2 - 1, COLS / 2 - 30);
    printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

    SETPOS(ROWS / 2 , COLS / 2 - 30);
    printf("%s  %s  Joining: %-41s    %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, game->name, XT_CH_INVERSE,XT_CH_NORMAL);

    SETPOS(ROWS / 2 + 1, COLS / 2 - 30);
    printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

    SETPOS(ROWS / 2 + 2, COLS / 2 - 30);
    printf("%s                            %sB%s%sack                            %s", XT_CH_INVERSE, XT_CH_UNDERLINE, XT_CH_NORMAL,XT_CH_INVERSE, XT_CH_NORMAL);
    fflush(stdout);
    usleep(1000000);
    int rejected = 0;
    while(1){

        int command;
        char* buffer;
        if (receive(sockfd, &command, &buffer) < 0) {
            if (errno != EWOULDBLOCK && errno != EAGAIN)
                return 0;
        }
        else {
            free(buffer);
            switch (command) {
                case CMD_ACCEPT_REQ:
                    rejected = -1;
                    break;
                case CMD_REJECT_REQ:
                    rejected = 1;
                    break;
                case CMD_QUIT:
                case CMD_ERROR:
                    return 0;
            }
        }

        if (rejected == 1) {
            xt_par0(XT_CH_NORMAL);
            SETPOS(ROWS / 2 - 2, COLS / 2 - 30);
            printf("%s                         Join Game                          %s", XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 - 1, COLS / 2 - 30);
            printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 , COLS / 2 - 30);
            printf("%s  %s Rejected by %-42s %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, game->name, XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 + 1, COLS / 2 - 30);
            printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 + 2, COLS / 2 - 30);
            printf("%s                            %sB%s%sack                            %s", XT_CH_INVERSE, XT_CH_UNDERLINE, XT_CH_NORMAL,XT_CH_INVERSE, XT_CH_NORMAL);
            fflush(stdout);
            usleep(1000000);
            return 0;
        } else if (rejected == -1) { // -1 symbolizes that they were ACCEPTED.
            SETPOS(ROWS / 2 - 2, COLS / 2 - 30);
            printf("%s                         Join Game                          %s", XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 - 1, COLS / 2 - 30);
            printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 , COLS / 2 - 30);
            printf("%s  %s Accepted by %-42s %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, game->name, XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 + 1, COLS / 2 - 30);
            printf("%s  %s                                                        %s  %s", XT_CH_INVERSE,XT_CH_NORMAL, XT_CH_INVERSE,XT_CH_NORMAL);

            SETPOS(ROWS / 2 + 2, COLS / 2 - 30);
            printf("%s                            %sB%s%sack                            %s", XT_CH_INVERSE, XT_CH_UNDERLINE, XT_CH_NORMAL,XT_CH_INVERSE, XT_CH_NORMAL);
            fflush(stdout);
            usleep(1000000 / 5);
            return 1;
        }

        key = getkey();
        switch(key){
            case 'q':
            case 'Q':
            case 'b':
            case 'B':
                transmit(sockfd, CMD_CANCEL_REQ, NULL);
                return 0;
        }
        fflush(stdout);
        usleep(1000000/2);
    }
}
Esempio n. 24
0
int game() {
    static int selected_game = 0;

    drawgames(selected_game);
    xt_par0(XT_CH_NORMAL);
    SETPOS(2, COLS - 18);
    draw_users();
    fflush(stdout);
    int key;
    if ((key = getkey()) == KEY_NOTHING)
        return 0;

    xt_par0(XT_CH_NORMAL);
    SETPOS(2, COLS - 18);
    // printf("Who's Online");
    // for (i = 0; i < numusers - onlinelistoffset; i++) {
    //     SETPOS(4 + i, COLS - 18);
    //     if (5 + i > ROWS)
    //         break;
    //     printf("%s", users[i + onlinelistoffset].username);

    // }
    switch(key) {
        // case '<':
        //     xt_par0(XT_CLEAR_SCREEN);
        //     drawgames(selected_game);
        //     dispmultiframe();
        //     if (onlinelistoffset > 0)
        //         onlinelistoffset--;
        //     xt_par0(XT_CH_NORMAL);
        //     SETPOS(2, COLS - 18);
        //     printf("Who's Online");
        //     for (i = 0; i < numusers - onlinelistoffset; i++) {
        //         SETPOS(4 + i, COLS - 18);
        //         if (5 + i > ROWS)
        //             break;
        //         if (users[i + onlinelistoffset].status != CLIENT_FREE)
        //             printf("%s", users[i + onlinelistoffset].username);
        //     }
        //     break;
        // case '>':
        //     xt_par0(XT_CLEAR_SCREEN);
        //     drawgames(selected_game);
        //     dispmultiframe();
        //     if (ROWS - 5 + onlinelistoffset < 64)
        //         onlinelistoffset++;
        //     xt_par0(XT_CH_NORMAL);
        //     SETPOS(2, COLS - 18);
        //     printf("Who's Online");
        //     for (i = 0; i < numusers - onlinelistoffset; i++) {
        //         SETPOS(4 + i, COLS - 18);
        //         if (5 + i > ROWS)
        //             break;
        //         if (users[i + onlinelistoffset].status != CLIENT_FREE)
        //             printf("%s", users[i + onlinelistoffset].username);
        //     }
        //     break;
        case 'q':
        case 'Q':
            xt_par0(XT_CLEAR_SCREEN);
            SETPOS(0,0);
            return MENU_QUIT;
        case 'w':
        case KEY_UP: {
            int i;
            for (i = selected_game - 1; i > 0; i--) {
                if (games[i].status != GAME_FREE) {
                    selected_game = i;
                    drawgames(selected_game);
                    xt_par0(XT_CH_NORMAL);
                    SETPOS(2, COLS - 18);
                    draw_users();
                    fflush(stdout);
                }
            }
            break;
        }
        case 's':
        case KEY_DOWN: {
            int i;
            for (i = selected_game + 1; i < MAX_GAMES; i++) {
                if (games[i].status != GAME_FREE) {
                    selected_game = i;
                    drawgames(selected_game);
                    xt_par0(XT_CH_NORMAL);
                    SETPOS(2, COLS - 18);
                    draw_users();
                    fflush(stdout);
                }
            }
            break;
        }
        case 'j':
        case 'J':
            if (join_popup(&games[selected_game]))
                game_wait(selected_game);
            drawgames(selected_game);
            xt_par0(XT_CH_NORMAL);
            SETPOS(2, COLS - 18);
            draw_users();
            break;
        case 'c':
        case 'C':
            if (create_popup()) // create_popup also includes the error message handling
                game_wait(numgames - 1);
            drawgames(selected_game);
            xt_par0(XT_CH_NORMAL);
            SETPOS(2, COLS - 18);
            draw_users();
            break;
        case 'h':
        case 'H':
            help_popup();
            break;
    }
    return 0;
}