/* -------------------------------------------------------------------------- * * Add dlink node to the dlink list after the specified node. * * * * <list> - list to add node to * * <node> - the node to add * * <after> - add the new node after this node * * <ptr> - a user-defined pointer * * -------------------------------------------------------------------------- */ void dlink_add_after(struct list *lptr, struct node *nptr, struct node *after, void *ptr) { /* If <after> is the list tail, then a dlink_add_tail() does the job */ if(after == lptr->tail) { dlink_add_tail(lptr, nptr, ptr); return; } /* Set the data pointer */ nptr->data = ptr; /* Make references on the new node */ nptr->next = after->next; nptr->prev = after; /* Update prev-reference of the node after the <after> node */ after->next->prev = nptr; /* Update next-reference of the <after> node */ after->next = nptr; /* Update list size */ lptr->size++; }
/* -------------------------------------------------------------------------- * * Create a game. * * -------------------------------------------------------------------------- */ struct player *player_new(const char *name, int team, int accepted) { struct player *player; /* allocate, zero and link game struct */ player = mem_static_alloc(&player_heap); memset(player, 0, sizeof(struct player)); /* initialize the struct */ strlcpy(player->name, name, sizeof(player->name)); player->hash = strihash(player->name); player->refcount = 1; player->serial = player_serial; player->team = team; player->accepted = accepted; dlink_list_zero(&player->cards); dlink_add_tail(&player_list, &player->node, player); debug(player_log, "Created player block: %s", player->name); return player; }
/* -------------------------------------------------------------------------- * * -------------------------------------------------------------------------- */ void player_schupf(struct player *from, struct player *to, int mode) { struct card *card; if((card = card_by_mode(&from->cards, mode))) { dlink_find_delete(&from->cards, card); dlink_add_tail(&to->cards, &card->pnode, card); log(player_log, L_status, "Karte %s geschupft an %s.", card->name, to->name); bot_send("SCHUPFE %s %s", to->name, card->name); } }
/* -------------------------------------------------------------------------- * * -------------------------------------------------------------------------- */ struct chanmodechange *chanmode_change_add(struct list *list, int what, char mode, char *arg, struct chanuser *acuptr) { struct chanmodechange *cmcptr = NULL; if(chanmode_table[(uint32_t)mode - 0x40].type) { cmcptr = mem_static_alloc(&chanmode_heap); cmcptr->bounced = 0; cmcptr->mode = &chanmode_table[(uint32_t)mode - 0x40]; cmcptr->what = what; cmcptr->nmask = NULL; cmcptr->umask = NULL; cmcptr->hmask = NULL; if(acuptr) { cmcptr->acptr = acuptr->client; cmcptr->target = acuptr; } else { cmcptr->acptr = NULL; cmcptr->target = NULL; } cmcptr->ihash = 0; cmcptr->info[0] = '\0'; cmcptr->ts = 0L; if(arg) strlcpy(cmcptr->arg, arg, sizeof(cmcptr->arg)); else cmcptr->arg[0] = '\0'; dlink_add_tail(list, &cmcptr->node, cmcptr); } return cmcptr; }
/* -------------------------------------------------------------------------- * * Hook before user/nick is validated * * -------------------------------------------------------------------------- */ static void lc_cookie_hook(struct lclient *lcptr) { struct lc_cookie *cookie; cookie = mem_static_alloc(&lc_cookie_heap); /* Add to pending cookie list */ if(lcptr->plugdata[LCLIENT_PLUGDATA_COOKIE]) mem_static_free(&lc_cookie_heap, lcptr->plugdata); lcptr->plugdata[LCLIENT_PLUGDATA_COOKIE] = cookie; cookie->lclient = lcptr; dlink_add_tail(&lc_cookie_list, &cookie->node, cookie); /* Build cookie data */ lc_cookie_build(cookie); /* Now send the cookie */ lclient_send(cookie->lclient, "PING :%s", cookie->data); }