void handle_shop_event(POINT p) { short i,store_what_picked; p.x -= 5; p.y -= 5; if (PtInRect(&talk_help_rect,p)) { click_shop_rect(talk_help_rect); party.help_received[26] = 0; give_help(226,27,0); return; } if (PtInRect(&shop_done_rect, p)) { click_shop_rect(shop_done_rect); end_shop_mode(); return; } for (i = 0; i < 8; i++) { store_what_picked = i + GetScrollPos(shop_sbar,SB_CTL); if ((PtInRect(&shopping_rects[i][1],p)) && (store_shop_items[store_what_picked] >= 0)) { click_shop_rect(shopping_rects[i][1]); handle_sale(store_shop_items[store_what_picked],store_shop_costs[store_what_picked]); } if ((PtInRect(&shopping_rects[i][6],p)) && (store_shop_items[store_what_picked] >= 0) && (store_shop_type != SHOP_HEALER) && (store_shop_type != SHOP_FOOD)){ click_shop_rect(shopping_rects[i][6]); handle_info_request(store_shop_items[store_what_picked]); } } }
static void client_input(struct socket_info *si) { struct client_connection *c = si->udata; char buf[1500]; int n; int got = 0; int ok; if (!c) croak(1, "client_input: no client_connection information"); if ( (n = read(si->fd, buf, 1500)) == -1) { switch (errno) { case EPIPE: client_gone(si); return; case ECONNRESET: client_gone(si); return; } croak(1, "client_input: read error"); } if (n == 0) { client_gone(si); return; } msgpack_unpacker_reserve_buffer(&c->unpacker, n); memcpy(msgpack_unpacker_buffer(&c->unpacker), buf, n); msgpack_unpacker_buffer_consumed(&c->unpacker, n); while (msgpack_unpacker_next(&c->unpacker, &c->input)) { msgpack_object *o; uint32_t cid; uint32_t type; got = 1; ok = -1; PS.client_requests++; si->PS.client_requests++; //if (!opt_quiet) { // printf("got client input: "); // msgpack_object_print(stdout, c->input.data); // printf("\n"); //} o = &c->input.data; if (o->type != MSGPACK_OBJECT_ARRAY) { error_reply(si, RT_ERROR, 0, "Request is not an array"); goto end; } if (o->via.array.size < 1) { error_reply(si, RT_ERROR, 0, "Request is an empty array"); goto end; } if (o->via.array.size < 2) { error_reply(si, RT_ERROR, 0, "Request without an id"); goto end; } if (o->via.array.ptr[RI_CID].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { error_reply(si, RT_ERROR, 0, "Request id is not a positive integer"); goto end; } cid = o->via.array.ptr[RI_CID].via.u64; if (o->via.array.ptr[RI_TYPE].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { error_reply(si, RT_ERROR, cid, "Request type is not a positive integer"); goto end; } type = o->via.array.ptr[RI_TYPE].via.u64; switch (type) { case RT_SETOPT: ok = handle_setopt_request(si, cid, o); break; case RT_GETOPT: ok = handle_getopt_request(si, cid, o); break; case RT_INFO: ok = handle_info_request(si, cid, o); break; case RT_DEST_INFO: ok = handle_dest_info_request(si, cid, o); break; case RT_GET: ok = handle_get_request(si, cid, o); break; case RT_GETTABLE: ok = handle_gettable_request(si, cid, o); break; default: error_reply(si, type|RT_ERROR, cid, "Unknown request type"); } end: if (ok < 0) { PS.invalid_requests++; si->PS.invalid_requests++; } } if (got) { msgpack_unpacker_expand_buffer(&c->unpacker, 0); } }