bool upb_sink_startmsg(upb_sink *s) { const upb_handlers *h = s->top->h; upb_startmsg_handler *startmsg = (upb_startmsg_handler *)upb_handlers_gethandler(h, UPB_STARTMSG_SELECTOR); if (startmsg) { const void *hd = upb_handlers_gethandlerdata(h, UPB_STARTMSG_SELECTOR); bool ok = startmsg(s->top->closure, hd); if (!ok) return false; } return true; }
void handle_player(int sock) { int z, prevx, prevy; struct plyr *p = malloc(sizeof(struct plyr)); p->fd = sock; p->x = p->y = p->lastdump = 0; p->worldx = p->worldy = 0; p->location = NULL; p->location = (struct loc *) get_world(p, 0,0); if(p->location == NULL) { printf("FAILED TO GET WORLD!\n"); close(p->fd); return; } startmsg(p->fd); while( read_byte(p->fd) == 0); dump_world(p); while(1){ prevx = p->x; prevy = p->y; //handle input if(handle_input(p)){ printf("disconnecting client\n"); break; } //display if(p->x != prevx || p->y != prevy) { //printf("trying to display @ %d, %d: %d\n", prevx, prevy, CHARAT(p,prevx, prevy)); write_byte(p->fd, CHARAT(p,prevx, prevy)); move_cursor(p->fd, p->x, p->y); //printf("now at %d,%d: %d\n",p->x,p->y, CHARAT(p,p->x,p->y)); } check_updates(p); } send(p->fd, "Goodbye\n", 8, 0); close(p->fd); }