Пример #1
0
void room_del_character(room *r, character *ch, int reason_code)
{
	table_iterator *t;

	/* Remove our character from the room */
	table_del(r->chars, character_username(ch));

	/* Broadcast to each character in the room that a
	 * new character has left the room.
	 */
	t = table_iterate_over(r->chars);
	while(1)
	{
		character *tc;
		const char *name, *reason;

		tc = table_iterate(t);
		if(!tc)
			break;

		name = character_username(ch);
		reason = reasons[reason_code];
		chprintf(tc, "\r\n%s left the room via %s.\r\n",
			name, reason );
		character_prompt(tc);
	}

}
Пример #2
0
static void
rmuser(struct user *usr, struct channel *chan)
{

        list_remove(usr, &chan->users);
        if (SLIST_EMPTY(&chan->users)) {
                table_del(channels, chan->name, chan->len);
                free_channel(chan);
        }
}
/* Função para remover um par chave valor da tabela, especificado pela
 * chave key.
 * Devolve: 0 (OK) ou -1 em caso de erros
 */
int ptable_del(struct ptable_t *ptable, char *key)
{
    int result,size;
    result = -1;
	if(ptable->isOpen)
	{
		struct message_t *msg;
		char *msg_buffer,*pmanager_buffer;
		result = table_del(ptable->table,key);
	    if(result == 0)
		{	
			msg = (struct message_t*) malloc(sizeof(struct message_t));
			if(msg == NULL)
			{
				perror("Out of memory");
				return -1;
			}
			msg->opcode = OC_DEL;
			msg->c_type = CT_KEY;
			msg->content.key = strdup(key);
			size = message_to_buffer(msg,&msg_buffer);
			//Alocar memoria
			pmanager_buffer = (char *) malloc(size+sizeof(uint16_t));
			//Copiar o tamanho da mensagem
			memcpy(pmanager_buffer,&size,sizeof(uint16_t));
			//Copiar a mensagem
			memcpy(pmanager_buffer+sizeof(uint16_t),msg_buffer,size);
			//Escrever mensagem
			if(pmanager_log(ptable->pmanager,pmanager_buffer)==-1)
			{
				printf("Falha na escrita\n");
			}
			//Free
			free(pmanager_buffer);
			free_message(msg);
			free(msg_buffer);
		}
	}
	return result;
}