Ejemplo n.º 1
0
/// \brief  Print welcome message and input the size of the board
/// \return void
void welcome(){
    clear();
    char mesg[]=":2o48_Network";
    getmaxyx(stdscr,row,col);
    mvprintw(row/2,(col-strlen(mesg))/2,mesg);
    int ver=c_version();
    char verstr[100];
    char infostr[100]="Press N to connect to server,S to be a server";
    sprintf(verstr,"version %X",ver);
    mvprintw(row/2+1,(col-strlen(verstr))/2,verstr);
    mvprintw(row/2+2,(col-strlen(infostr))/2,infostr);
    mvprintw(row-3,0,"Welcome to :2048 by Librazy\n");
    printw("Enter a number<=9 that you want the board be:");
    int inpN=4+'0';
    while(1){
        inpN=getch();
        if((inpN==3)||(inpN==KEY_F(1)))c_forceQuit();
        if(inpN>'0'&&inpN<='9')break;
        if(inpN=='n'||inpN=='N'){
            mvprintw(row-3,0,"Networking mode now,enter ip you want to connect\n");clrtoeol();move(row-2,0);echo();
            char ipstr[130]={0};
            while(scanw("%127s",ipstr)!=1){mvprintw(row-3,0,"Networking mode now,enter ip you want to connect!\n");clrtoeol();move(row-2,0);}
            noecho();
            SClient = dyad_newStream();
            printw(ipstr);
            printw(",Enter a number<=9 that you want the board be:");
            while(1){
                inpN=getch();
                if(inpN>'0'&&inpN<='9'){
                    N=(char)(inpN-'0');printw("%d",N);refresh();break;
                }
            }
            pthread_create (&TInfo, &AThread, t_Info, NULL);
            pthread_mutex_lock(&MNetC);
            connecting=true;
            isnetworking=true;
            dyad_addListener(SClient, DYAD_EVENT_DATA, n_Data, NULL);
            dyad_addListener(SClient, DYAD_EVENT_ERROR, g_Error, NULL);
            dyad_connect(SClient,ipstr, 2048);
            return;
        }
        if(inpN=='s'||inpN=='S'){
            move(row-3,0);clrtoeol();move(row-2,0);clrtoeol();
            SServ = dyad_newStream();
            pthread_create (&TInfo, &AThread, t_Info, NULL);
            pthread_mutex_lock(&MNetC);
            connecting=true;
            isnetworking=true;
            dyad_addListener(SServ, DYAD_EVENT_ERROR, g_Error, NULL);
            dyad_addListener(SServ, DYAD_EVENT_ACCEPT, s_Accept, NULL);
            dyad_listenEx(SServ, "0.0.0.0",2048,1);//Force IPv4
			mvprintw(row-3,0,"Serving mode now,listening port 2048\n"); refresh();
            return;
        }
    }
    N=(char)(inpN-'0');
    printw("%d\nThe board will be %d.Press any key and rock on!",N,N);
    getch();
    pthread_create (&TInfo, &AThread, t_Info, NULL);
}
Ejemplo n.º 2
0
int main(void) {
  dyad_Stream *s;
  dyad_init();

  s = dyad_newStream();
  dyad_addListener(s, DYAD_EVENT_CONNECT, onConnect, NULL);
  dyad_addListener(s, DYAD_EVENT_ERROR,   onError,   NULL);
  dyad_addListener(s, DYAD_EVENT_DATA,    onData,    NULL);
  dyad_connect(s, "time-nw.nist.gov", 13);

  while (dyad_getStreamCount() > 0) {
    dyad_update();
  }
  
  dyad_shutdown();
  return 0;
}
Ejemplo n.º 3
0
		int connect(const char *host, int port) {
			return dyad_connect(m_wrap, host, port);
		}