static void remove_word(t_tout *tout) { remove_from_array(tout->word_cursor, (void*)tout->words , sizeof(char*), tout->word_count); remove_from_array(tout->word_cursor, (void*)tout->white , sizeof(int), tout->word_count); tout->word_count--; if (tout->word_count <= 0) abort_exit(0); if (tout->word_cursor >= tout->word_count) tout->word_cursor = 0; }
void remove_opener_floor (struct opener_floor *o) { size_t i = o - opener_floor; opener_floor = remove_from_array (opener_floor, &opener_floor_nmemb, i, 1, sizeof (*o)); }
void remove_door (struct door *d) { size_t i = d - door; door = remove_from_array (door, &door_nmemb, i, 1, sizeof (*d)); }
void remove_loose_floor (struct loose_floor *l) { size_t i = l - loose_floor; loose_floor = remove_from_array (loose_floor, &loose_floor_nmemb, i, 1, sizeof (*l)); }
void remove_spikes_floor (struct spikes_floor *s) { size_t i = s - spikes_floor; spikes_floor = remove_from_array (spikes_floor, &spikes_floor_nmemb, i, 1, sizeof (*s)); }
void remove_chopper (struct chopper *c) { size_t i = c - chopper; chopper = remove_from_array (chopper, &chopper_nmemb, i, 1, sizeof (*c)); }
void remove_closer_floor (struct closer_floor *c) { size_t i = c - closer_floor; closer_floor = remove_from_array (closer_floor, &closer_floor_nmemb, i, 1, sizeof (*c)); }
void add_new_fset(char *name, char *args) { if (args && *args) { IrcVariable *tmp = NULL; int cnt, loc; tmp = (IrcVariable *)find_array_item((Array *)&ext_fset_list, name, &cnt, &loc); if (!tmp || cnt >= 0) { tmp = new_malloc(sizeof(IrcVariable)); tmp->name = m_strdup(name); tmp->type = STR_TYPE_VAR; add_to_array((Array *)&ext_fset_list, (Array_item *)tmp); } malloc_strcpy(&tmp->string, args); } else { IrcVariable *tmp; if ((tmp = (IrcVariable *)remove_from_array((Array *)&ext_fset_list, name))) { new_free(&tmp->name); new_free(&tmp->string); new_free(&tmp); } } }
void remove_changed_pos (struct pos *p) { size_t i = p - changed_pos; changed_pos = remove_from_array (changed_pos, &changed_pos_nmemb, i, 1, sizeof (*p)); }
array_item *array_lookup (array *a, const char *name, int wild, int rem) { int count, location; if (rem) return remove_from_array(a, name); else return find_array_item(a, name, &count, &location); }
void process_line(SOCKET socket, char* msg) { // V3: //@color=#0000FF;emotes=;subscriber=0;turbo=0;user_type= :bomb_mask!bomb_mask@bomb_mask.tmi.twitch.tv PRIVMSG #bomb_mask :Yo thanks //:[email protected] PRIVMSG #channel :message that was sent if(strncmp(msg, "PING", 4) == 0) { printf("\n\n\n###########PING###########\n\n\n"); int len = strlen("PONG"); send_msg(socket, "PONG tmi.twitch.tv", &len); return; } /* see if message contains tags */ char* tags = strtok(msg, " "); array_t tags_arr; int r = parse_tags(tags, &tags_arr); char* prefix = strtok(NULL, " "); char* cmd = strtok(NULL, " "); //printf("prefix and cmd read\n"); //printf("stuff parsed\n"); if(strcmp(cmd, "PRIVMSG") == 0) { //printf("private message\n"); char* username = calloc(32, sizeof(char)); char* channel = strtok(NULL, " ")+1; char* bot_command = strtok(NULL, " "); sscanf(bot_command, ":%s", bot_command); if(bot_command[0] != '!') { free(username); return; } array_t params; init_array(¶ms, 1); char* temp_tok = NULL; while(temp_tok = strtok(NULL, " \r\n")) { insert_array(¶ms, temp_tok); } int res = sscanf(prefix, "%*[^!]!%[^@]@%*", username); char* usertype = get_value(&tags_arr, "user_type"); //printf("usertype: %s\n", usertype); for(int i = 0; i < command_count; i++) { if(strcmp(registered_commands[i]->name, bot_command+1) == 0) { char* response = NULL; hackerbot_command_args args = {username, usertype, channel, NULL, socket}; if(registered_commands[i]->argcount == 0) { response = registered_commands[i]->function(&args); } else { if(params.used < registered_commands[i]->argcount) response = registered_commands[i]->usage; /* if the user supplies too many arguments, we will just merge all the "unnecessarry" ones into one string to make the last argument */ else if(params.used > registered_commands[i]->argcount) { /* ...-1 is perfectly fine because we never hit this code path if argcount == 0 */ char* merged = strdup(params.array[registered_commands[i]->argcount-1]); int msg_len = 0; for(int j = registered_commands[i]->argcount; j < params.used; j++) { msg_len = strlen(merged); char* temp_buf = calloc(msg_len + 1 + strlen(params.array[j]) + 1, sizeof(char)); memcpy(temp_buf, merged, msg_len); memcpy(temp_buf + msg_len, " ", 1); memcpy(temp_buf + msg_len + 1, params.array[j], strlen(params.array[j]) + 1); free(merged); merged = calloc(msg_len + 1 + strlen(params.array[j]) + 1, sizeof(char)); memcpy(merged, temp_buf, msg_len + 1 + strlen(params.array[j]) + 1); free(temp_buf); } int used = params.used; for(int j = registered_commands[i]->argcount; j < used; j++) remove_from_array(¶ms); params.array[registered_commands[i]->argcount-1] = merged; args.params = ¶ms; response = registered_commands[i]->function(&args); free(merged); } else { args.params = ¶ms; response = registered_commands[i]->function(&args); } } if(!response) response = "There was an error while processing your request BibleThump"; send_irc_message(socket, response, username, args.channel); goto cleanup; } } send_irc_message(socket, "I don't know that command", username, channel); cleanup: free_array(&tags_arr); free_array(¶ms); free(username); } }