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); }
static void n_Init(dyad_Event *e) { if (!memcmp(e->data, "INCOMP", 6)) { c_warning("Incompatiable version!Quit."); dyad_end(e->stream); dyad_shutdown(); pthread_cancel(TInfo); pthread_cond_signal (&CInfo); pthread_join(TInfo, NULL); getch(); c_forceQuit(); }else{ SGaming=e->stream; 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); } }
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); } }
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); }
void removeAllListeners(int event) { dyad_removeAllListeners(m_wrap, event); }