Пример #1
0
void x_right(){
	pthread_mutex_lock(&MNet);
	attack[0][attacktimes[0]++]=5;
	dyad_writef(SGaming, "RIGHT\n");
	dyad_update();
	pthread_mutex_unlock(&MNet);
}
Пример #2
0
static void n_Data(dyad_Event *e) {
    connecting=false;
    int ver=c_version();
    dyad_writef(e->stream, "VERSION %X %d\n",ver,N);dyad_update();
    dyad_removeAllListeners(e->stream, DYAD_EVENT_CONNECT);
    dyad_addListener(e->stream, DYAD_EVENT_DATA, n_Init, NULL);
}
Пример #3
0
void x_down(){
	pthread_mutex_lock(&MNet);
	attack[0][attacktimes[0]++]=3;
	dyad_writef(SGaming, "DOWN\n");
	dyad_update();
	pthread_mutex_unlock(&MNet);
}
Пример #4
0
void x_left(){
	pthread_mutex_lock(&MNet);
	attack[0][attacktimes[0]++]=4;
	dyad_writef(SGaming, "LEFT\n");
	dyad_update();
	pthread_mutex_unlock(&MNet);
}
Пример #5
0
void x_del(int arg,int arg2){
	pthread_mutex_lock(&MNet);
	attack[0][attacktimes[0]++]=1;
	dyad_writef(SGaming, "DEL %d %d\n",arg,arg2);
	dyad_update();
	pthread_mutex_unlock(&MNet);
}
Пример #6
0
void x_boom(int arg,int arg2){
	pthread_mutex_lock(&MNet);
	attack[0][attacktimes[0]++]=6;
	dyad_writef(SGaming, "BOOM %d %d\n",arg,arg2);
	dyad_update();
	pthread_mutex_unlock(&MNet);
}
Пример #7
0
/// \brief  The thread to print Board to screen
/// \param  arg Void
/// \return void* NULL
void* t_NetworkSend(void* arg){
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS , NULL);
    int oldtype;
    while(1){
        pthread_testcancel();
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
        pthread_mutex_lock(&MNet);
        pthread_cond_wait (&CNet, &MNet);
        pthread_testcancel();
        pthread_mutex_lock(&MBoard);
        c_writeBoardToDisk(0,false);
        FILE *fp;
        char name[20];
        int ver=c_version();
        sprintf(name,"2048.0.%X.save",ver);
        if((fp=fopen(name,"r"))) {
            int c;
            int count = 500;
            while (count--) {
                if ((c = fgetc(fp)) != EOF) {
                    dyad_write(SGaming, &c, 1);
                } else {
                    dyad_update();
                    break;
                }
            }
        }else{
            dyad_writef(SGaming, "ERR");
        }
        pthread_mutex_unlock(&MBoard);
        pthread_mutex_unlock(&MNet);
        pthread_setcanceltype(oldtype, NULL);
    }
    return NULL;
}
Пример #8
0
static void s_Init(dyad_Event *e) {
    int cliver=0,val=0,cliN;
    val=sscanf(e->data,"VERSION %X %d",&cliver,&cliN);
    if(cliver!=c_version()||val!=2){
        dyad_writef(e->stream,"INCOMP\n");
        c_warning("Incompatiable version!Quit.");
        dyad_update();
        dyad_end(SServ);
        getch();
        c_forceQuit();
    }else{
        SGaming=e->stream;
        N=cliN;
        dyad_writef(e->stream,"OK\n");dyad_update();
        dyad_removeAllListeners(e->stream, DYAD_EVENT_DATA);
        dyad_addListener(e->stream, DYAD_EVENT_DATA, g_Data, NULL);
        dyad_addListener(e->stream, DYAD_EVENT_CLOSE, g_Close, NULL);
        pthread_mutex_unlock(&MNetC);
    }
}
Пример #9
0
static void s_Accept(dyad_Event *e) {
    connecting=false;
    dyad_writef(e->remote,"ACC\n");
    dyad_removeAllListeners(SServ, DYAD_EVENT_ACCEPT);
    dyad_addListener(e->remote, DYAD_EVENT_DATA, s_Init, NULL);
}
Пример #10
0
static void onAccept(dyad_Event *e) {
  dyad_addListener(e->remote, DYAD_EVENT_DATA, onData, NULL);
  dyad_writef(e->remote, "echo server\r\n");
}
Пример #11
0
		void writef(const char *fmt, ...) {
			dyad_writef(m_wrap, fmt);
		}