Example #1
0
// TODO : Rewrite this f***g ugly function
unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsigned int lvl, acetables *g_ape)
{
	RAW *newraw;
	userslist *user_passif_chan, *user_actif_chan;
	json_item *jlist;

	user_passif_chan = getuchan(user_passif, chan);
	
	if (user_actif != NULL) {
		user_actif_chan = getuchan(user_actif, chan);
		
		if (user_passif_chan == NULL || user_actif_chan == NULL || ((user_actif_chan->level < lvl || user_actif_chan->level < user_passif_chan->level) && !(user_actif->flags & FLG_AUTOOP)) || lvl < 1 || lvl > 32) {
			send_error(user_actif, "SETLEVEL_ERROR", "110", g_ape);
		
			return 0;
		}
		
		user_passif_chan->level = lvl;
		
		if (chan->interactive) {
			jlist = json_new_object();
			
			json_set_property_objN(jlist, "ope", 3, get_json_object_user(user_passif));
			json_set_property_objN(jlist, "oper", 4, get_json_object_user(user_actif));
			json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
			json_set_property_intN(jlist, "level", 5, lvl);
		
			newraw = forge_raw(RAW_SETLEVEL, jlist);
			post_raw_channel(newraw, chan, g_ape);
		}
		return 1;
	} else if (user_passif_chan != NULL && lvl > 0 && lvl < 32) {		
		user_passif_chan->level = lvl;
		
		if (chan->interactive) {
			jlist = json_new_object();

			json_set_property_objN(jlist, "ope", 3, get_json_object_user(user_passif));
			json_set_property_objN(jlist, "oper", 4, get_json_object_user(NULL));
			json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
			json_set_property_intN(jlist, "level", 5, lvl);

			newraw = forge_raw(RAW_SETLEVEL, jlist);
			post_raw_channel(newraw, chan, g_ape);
			
		}
		return 1;
	}
	return 0;
}
Example #2
0
unsigned int settopic(USERS *user, CHANNEL *chan, const char *topic, acetables *g_ape)
{
    RAW *newraw;
    userslist *list;
    json *jlist;

    list = getuchan(user, chan);

    if (list == NULL || list->level < 3 || strlen(topic)+1 > MAX_TOPIC_LEN) {

        send_error(user, "SETTOPIC_ERROR", "111", g_ape);

    } else {
        memcpy(chan->topic, topic, strlen(topic)+1);

        jlist = NULL;

        set_json("user", NULL, &jlist);
        json_attach(jlist, get_json_object_user(user), JSON_OBJECT);

        set_json("pipe", NULL, &jlist);
        json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

        newraw = forge_raw(RAW_SETTOPIC, jlist);
        post_raw_channel(newraw, chan, g_ape);

        return 1;
    }
    return 0;
}
Example #3
0
void send_msg_channel(CHANNEL *chan, const char *msg, const char *type, acetables *g_ape)
{
	RAW *newraw;
	json *jlist = NULL;
	
	set_json("value", msg, &jlist);
	
	newraw = forge_raw(type, jlist);
	
	post_raw_channel(newraw, chan, g_ape);
}
Example #4
0
void send_msg_channel(CHANNEL *chan, const char *msg, const char *type, acetables *g_ape)
{
	RAW *newraw;
	json_item *jlist = json_new_object();
	
	json_set_property_strZ(jlist, "value", msg);
	
	newraw = forge_raw(type, jlist);
	
	post_raw_channel(newraw, chan, g_ape);
}
Example #5
0
/* to manage subuser use post_to_pipe() instead */
void post_raw_pipe(RAW *raw, char *pipe, acetables *g_ape)
{
	transpipe *spipe;
	
	if ((spipe = get_pipe(pipe, g_ape)) != NULL) {
		if (spipe->type == CHANNEL_PIPE) {
			post_raw_channel(raw, spipe->pipe, g_ape);
		} else {
			post_raw(raw, spipe->pipe, g_ape);
		}
	}
}
Example #6
0
void left(USERS *user, CHANNEL *chan, acetables *g_ape) // Vider la liste chainée de l'user
{
	userslist *list, *prev;

	CHANLIST *clist, *ctmp;
	RAW *newraw;
	json_item *jlist;
	
	FIRE_EVENT_NULL(left, user, chan, g_ape);
	
	if (!isonchannel(user, chan)) {
		return;
	}
	
	list = chan->head;
	prev = NULL;
	
	clist = user->chan_foot;
	ctmp = NULL;
	
	while (clist != NULL) {
		if (clist->chaninfo == chan) {
			if (ctmp != NULL) {
				ctmp->next = clist->next;
			} else {
				user->chan_foot = clist->next;
			}
			free(clist);
			break;
		}
		ctmp = clist;
		clist = clist->next;
	}
	
	
	while (list != NULL && list->userinfo != NULL) {
		if (list->userinfo == user) {
			if (prev != NULL) {
				prev->next = list->next;
			} else {
				chan->head = list->next;
			}
			free(list);
			list = NULL;
			if (chan->head != NULL && chan->interactive) {
				jlist = json_new_object();
				
				json_set_property_objN(jlist, "user", 4, get_json_object_user(user));
				json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
				
				newraw = forge_raw(RAW_LEFT, jlist);
				post_raw_channel(newraw, chan, g_ape);
			} else if (chan->head == NULL) {
				rmchan(chan, g_ape);
			}
			break;
		}
		prev = list;
		list = list->next;
	}
	
}
Example #7
0
// TODO : Rewrite this f***g ugly function
unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsigned int lvl, acetables *g_ape)
{
    RAW *newraw;
    userslist *user_passif_chan, *user_actif_chan;
    json *jlist;

    char level[8];

    user_passif_chan = getuchan(user_passif, chan);

    if (user_actif != NULL) {
        user_actif_chan = getuchan(user_actif, chan);

        if (user_passif_chan == NULL || user_actif_chan == NULL || ((user_actif_chan->level < lvl || user_actif_chan->level < user_passif_chan->level) && !(user_actif->flags & FLG_AUTOOP)) || lvl < 1 || lvl > 32) {
            send_error(user_actif, "SETLEVEL_ERROR", "110", g_ape);

            return 0;
        }

        user_passif_chan->level = lvl;

        if (chan->interactive) {
            jlist = NULL;

            set_json("ope", NULL, &jlist);
            json_attach(jlist, get_json_object_user(user_passif), JSON_OBJECT);

            set_json("opeur", NULL, &jlist);
            json_attach(jlist, get_json_object_user(user_actif), JSON_OBJECT);

            set_json("level", itos(lvl, level), &jlist);
            set_json("pipe", NULL, &jlist);
            json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

            newraw = forge_raw(RAW_SETLEVEL, jlist);
            post_raw_channel(newraw, chan, g_ape);
        }
        return 1;
    } else if (user_passif_chan != NULL && lvl > 0 && lvl < 32) {
        user_passif_chan->level = lvl;

        if (chan->interactive) {
            jlist = NULL;

            set_json("ope", NULL, &jlist);
            json_attach(jlist, get_json_object_user(user_passif), JSON_OBJECT);

            set_json("opeur", NULL, &jlist);
            json_attach(jlist, get_json_object_user(NULL), JSON_OBJECT);

            set_json("level", itos(lvl, level), &jlist);
            set_json("pipe", NULL, &jlist);
            json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

            newraw = forge_raw(RAW_SETLEVEL, jlist);
            post_raw_channel(newraw, chan, g_ape);

        }
        return 1;
    }
    return 0;
}