void Draft::pick(Team &user, vector<NodeData*>& a, WINDOW **board, const int &pickN){ char num[3]; int rank = 0; int temp = pickN; //for some reason mvwgetstr resets pickN, solved nextTen(a, board); while(true){ do{ mvwprintw(board[32], 1, 1, "Enter rank of desired player(1-300): "); wrefresh(board[32]); mvwgetstr(board[32], 1, 38, num); sscanf(num, "%d", &rank); } while(rank < 1 || rank > 300); if(!a[rank - 1]->getTaken()) break; else if(a[rank - 1]->getTaken()){ mvwprintw(board[32], 2, 1, "Already taken, pick again"); wrefresh(board[32]); } } a[rank - 1]->setTaken(true); insertEnd(a[rank - 1]); user.roster.add(a[rank - 1], board[31]); user.roster.displayRoster(board[31]); toBoard(a[rank - 1], board, temp); }
main() { //printf("网络初始化成功!\n"); initUI(); r=initSocket(); if(r==-1) exit(-1); signal(SIGCHLD,handle); if(fork()) { //输入,发送 char buf[256]; while(1) { mvwgetstr(wmsg,1,1,buf); //buf[r]=0; send(fd,buf,strlen(buf),0); //wclear(wmsg); //box(wmsg,0,0); refresh(); wrefresh(wmsg); wrefresh(winfo); } } else { //接收,显示 char buf[256]; int line=1; while(1) { r=recv(fd,buf,255,0); if(r==-1) break; if(r==0) break; buf[r]=0; mvwaddstr(winfo,line,1,buf); line++; if(line>=(LINES-3)) { wclear(winfo); line=1; box(winfo,0,0); } wmove(wmsg,1,1); touchwin(wmsg); refresh(); wrefresh(winfo); wrefresh(wmsg); } exit(-1); } destroy(); }
int main(){ signal(SIGCHLD,handle); r = initSocket(); if(r == -1){ printf("init socket :%m\n"); exit(-1); } printf("Init socket success.....\n"); initUI(); if(fork()){ //input ,send char buf[256]; while(1){ r = mvwgetstr(wmsg,1,1,buf); send(fd,buf,strlen(buf),0); wclear(wmsg); box(wmsg,'|','-'); refresh(); wrefresh(wmsg); } }else{ //receive ,show char buf[256]; int line = 1; while(1){ r = recv(fd,buf,255,0); if(r == -1)break; buf[r] = 0; mvwaddstr(winfo,line,1,buf); line++; if(line >= (LINES-6)){ wclear(winfo); line = 1; box(winfo,'|','-'); } wmove(wmsg,1,1); touchwin(wmsg); refresh(); wrefresh(winfo); wrefresh(wmsg); } exit(0); } destroy(); return 0; }
void open_dir(WINDOW * win) { int row,col,fd; getmaxyx(win,row,col); start_color(); init_pair(3,COLOR_BLACK,COLOR_BLUE); WINDOW * local_win; delwin(win); refresh(); { win = newwin(LINES-3,COLS,0,0); box(win,0,0); wbkgd(win,COLOR_PAIR(1)); mvwprintw(win,0,(COLS - 14)/2,"MY TEXT-EDITOR"); wrefresh(win); } local_win = subwin(win,4,COLS/3,row/2,(col - COLS/3)/2); box(local_win,0,0); wbkgd(local_win,COLOR_PAIR(3)); getmaxyx(win,row,col); mvwprintw(local_win,1,2,"TYPE IN FILE LOCATION:"); wmove(local_win,2,2); wrefresh(local_win); wrefresh(win); echo(); curs_set(1); mvwgetstr(local_win,2,2,dir); wclear(local_win); werase(local_win); wrefresh(local_win); { int ptr=1,ptrcol=1; long int res; char ch; if ((fd = open(dir,O_RDWR|O_CREAT,S_IRWXO|S_IRWXU|S_IRWXG)) == -1) { perror("Can't open!"); exit(1); } while((res = read(fd,&ch,1)) > 0) { if (ch == '\n') { ptrcol++; ptr = 1; continue; } mvwprintw(win,ptrcol,ptr++,"%c",ch); } wrefresh(win); } close(fd); delwin(local_win); }
void sendwmsg() { while(1) { char buf[256]; mvwgetstr(wmsg,1,1,buf); send(fd,buf,strlen(buf),0); wclear(wmsg); box(wmsg,0,0); refresh(); wrefresh(wmsg); wrefresh(win); } }
void recv_nth(WINDOW *recv_menu, int starty, int startx) { char input_n[128]; WINDOW *recv_nth_input_menu; WINDOW *recv_nth_show_email; int x = 1; int y = 1; recv_nth_show_email = newwin(HEIGHT, WIDTH, 1, 1); // Get the email id from the user. recv_nth_input_menu = newwin(3, 18, starty, startx); box(recv_nth_input_menu, 0, 0); wrefresh(recv_nth_input_menu); mvwprintw(recv_nth_input_menu, y, x, "email id = "); wrefresh(recv_nth_input_menu); mvwgetstr(recv_nth_input_menu, y, x + strlen("email id = "), input_n); wrefresh(recv_nth_input_menu); // Create command to receive the email using PyMail char *cmd_part_1 = " receive "; char *cmd_part_2 = " > pymail_cli_recv.tmp"; char cmd[2048]; strcpy(cmd, pymail_install_dir); strcat(cmd, cmd_part_1); strcat(cmd, input_n); strcat(cmd, cmd_part_2); // Get the email by executing the previously made command. printw("Loading email..."); refresh(); system(cmd); // Clear the screen werase(recv_nth_input_menu); wrefresh(recv_nth_input_menu); erase(); refresh(); // Read the mail char *email_buffer = read_tmp_email_file(); // TODO: Fix the way the email is displayed. show_email(recv_nth_show_email, email_buffer); free(email_buffer); return; }
int start_server( char *err ) { // our username char *uname = "server"; // First call to socket() function sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if( sockfd < 0 ) { sprintf( err, "ERROR opening socket" ); return 1; } // Initialize socket structure bzero((char*) &serv_addr, sizeof( serv_addr ) ); portno = SERVER_PORT; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons( portno ); // Now bind the host address using bind() call if( bind( sockfd, (struct sockaddr *) &serv_addr, sizeof( serv_addr ) ) < 0 ) { sprintf( err, "ERROR on binding" ); return 1; } // Now start listening for the clients, here process will // go into sleep mode and will wait for the incoming connection listen( sockfd, 5 ); while( 1 ) { clilen = sizeof( cli_addr ); // Accept actual connection from the client newsockfd = accept( sockfd, (struct sockaddr *)&cli_addr, &clilen ); if( newsockfd < 0 ) { sprintf( err, "ERROR on accept" ); return 1; } ipa = (char *)inet_ntoa( cli_addr.sin_addr ); // get the name of the user that connected, and send ours send( newsockfd, uname, strlen(uname), 0 ); int n = recv( newsockfd, oname, 1024, 0 ); // store length of my name and other user's name oname_len = strlen(oname); uname_len = strlen( uname ); //init_win(); start_thread(); line++; mvwprintw( chatw, line, 1, "Connection from %s [%s]\n", oname, ipa ); wrefresh(chatw); while( 1 ) { mvwgetstr( inputw, 1, 1, send_data ); wrefresh( inputw ); if( strcmp( send_data, "Q" ) == 0 ) { quit = true; send( newsockfd, send_data, strlen( send_data ), 0 ); close( newsockfd ); break; } else { line++; wattron( chatw, COLOR_PAIR(1) ); mvwprintw( chatw, line, 1, "%s: ", uname ); wattroff( chatw, COLOR_PAIR(1) ); mvwprintw( chatw, line, uname_len+3, "%s", send_data ); wrefresh( chatw ); refresh(); clean_input(); send( newsockfd, send_data, strlen( send_data ), 0 ); } } //shutdown_win(); } pthread_exit( NULL ); close( sockfd ); return 0; }
int main(int argc, char *argv[]){ int sockfd, numbytes, childproc; int y, x , i , L, index; char *msg, *user, *buffer = (char*) malloc((USERNAMESIZE + MAXDATASIZE + 4)*sizeof(char)); char *addr = NULL; if(argc >= 2){ addr=argv[1]; } sockfd=socksetup(addr); user=startscreen(); L=strlen(user); // SETTING UP ncurses WINDOWS WINDOW *in, *out; initscr(); cbreak(); echo(); in = newwin(4, 0, LINES-4, 0); out = newwin(LINES-4, 0, 0, 0); scrollok(in, TRUE); scrollok(out, TRUE); childproc = fork(); if(childproc >= 0){ if(childproc > 0){ //RECEIVING MESSAGES while((numbytes = recv(sockfd, buffer, (USERNAMESIZE + MAXDATASIZE + 4), 0)) >0) { if(0 < strlen(buffer)){ index=getuser(buffer); wattron(out, A_BOLD); for(i=0;i<index;i++) wprintw(out, "%c", buffer[i]); wattroff(out, A_BOLD); wprintw(out, "%s\n", buffer + index); } wrefresh(out); wrefresh(in); wmove(in, 0, 0); } } else //SENDING MESSAGES while(1){ mvwgetstr(in,0, 0, buffer); wmove(in, 0, 0); werase(in); wrefresh(in); msg=parsemsg(user, buffer, L); if (send(sockfd, msg, MAXDATASIZE + USERNAMESIZE + 4, 0) == -1) close(sockfd); } } wgetch(in); delwin(in); delwin(out); endwin(); close(sockfd); free(buffer); return 0; }
int mvgetstr(int y, int x, char *str) { return mvwgetstr(stdscr, y, x, str); }