void ironSwordUseCallback(struct item_use_t* data){ if(data==NULL){ quit("Error: Cannot use item on NULL"); } //If the item was used on a player if(data->type == CALLBACK_TYPE_PLAYER){ damage_creature(player, data->item->name, data->item->damage, 2); } //If it was used on a creature else if(data->type == CALLBACK_TYPE_CREATURE){ damage_creature(data->creature, data->item->name, data->item->damage, DMG_PIERCING); } //If it was used on another item else if(data->type==CALLBACK_TYPE_ITEM){ if(data->item == NULL){quit("Error: Cannot damage NULL item");} if(data->caller==NULL){quit("Error: Item_Use caller is NULL");} if(data->caller->material > data->item->material){ free(data->item); msg_add("The blade completely destroys it!"); } else{msg_add("The blade glances off, barely scratching it.");} } //Otherwise, error else if(data->type<0 || data->type>CALLBACK_TYPE_MAX){ quit("Error: Invalid target type"); } }
static void *transmit_start(void *arg) { int fd = (unsigned long)arg; struct msg *msg; ssize_t res; while (1) { msg = opt_master ? msg_gen(-opt_msglen) : msg_get(); if (opt_verbose) msg_dump(msg); res = write(fd, msg->buf, msg->len); if (res < 0) { pr_error("Write error %d\n", errno); exit(-1); } if (res < msg->len) { pr_error("Short write %zd < %u\n", res, msg->len); exit(-1); } tx_bytes += res; if (opt_master && opt_chain) msg_add(msg); else free(msg); } return NULL; }
static void *receive_start(void *arg) { int fd = (unsigned long)arg; struct msg *msg; ssize_t res; unsigned int avail = 0; static unsigned char buf[MAX_MAX_MSG_LEN]; unsigned long long delay; while (1) { msg = opt_master ? msg_get() : msg_gen(-opt_msglen); while (avail < msg->len) { res = read(fd, buf + avail, sizeof(buf) - avail); if (res < 0) { pr_error("Read error %d\n", errno); exit(-1); } avail += res; rx_bytes += res; } if (!msg_verify(msg, buf)) { pr_error("Data mismatch\n"); cmp_buffer(buf, msg->buf, msg->len); print_stats(); exit(-1); } delay = get_timestamp() - msg->stamp; if (!delay) delay = 1; pr_debug(ESC_GREEN "OK %u bytes in %llu us (%llu bps)\n", msg->len, delay, msg->len * 8000000 / delay); avail -= msg->len; if (avail > 0) { pr_debug("Keeping %u bytes\n", avail); memmove(buf, buf + msg->len, avail); } if (!opt_master && opt_chain) { msg_inc(msg); msg_add(msg); } else { free(msg); } } return NULL; }
/* Begins recording a new macro. If we're currently playing one back, * or already recording another one, then this does nothing. */ void start_recording(){ if(!playing_macro && !recording_macro){ int new_macro = msg_promptchar("Press a key to bind to new macro"); //ERR means that ESC was pressed if(new_macro == ERR || new_macro == cmd_data[CMD_MACRO]){ recording_macro = false; msg_add("Canceled"); return; } while(get_macro_by_cmd(new_macro) != NULL || cmd_exists(new_macro)){ new_macro = msg_promptchar("Key in use. Press a key to bind to new macro"); if(new_macro == ERR){ recording_macro = false; msg_add("Canceled"); return; } } //Set up the macro reclist_t *new_reclist = Calloc(1, sizeof(reclist_t)); new_reclist->bind = new_macro; new_reclist->next = macros; macros = new_reclist; recording_macro = true; msg_add("Recording has started."); next_cmd = NULL; } else if(playing_macro){ msg_add("Cannot start recording while playback is happening."); } else{ msg_add("Cannot start recording while recording."); } }
//-------------------------------------------- void msg_mqtt_udp_add(msg_mqtt_udp_t *ms) { msg_add(&queue, (msg_t *)ms); }
void defaultZapCallback(struct item_zap_t* data){ msg_add("Nothing happened!");}
void defaultConsumeCallback(struct item_consume_t* data){ msg_add("Nothing happened!");}
void defaultUseCallback(struct item_use_t* data){ msg_add("Nothing happened!");}