Beispiel #1
0
void check_botinfo(BotInfo *binfo, const char *channel)
{
	Chan	*chan;
	ChanUser *cu;
	Mech	*backup;
	char	*userhost;

	userhost = getuh(binfo->nuh);

	backup = current;
	for(current=botlist;current;current=current->next)
	{
		for(chan=current->chanlist;chan;chan=chan->next)
		{
			if (channel && Strcasecmp(channel,chan->name))
				continue;
			if ((cu = find_chanbot(chan,binfo->nuh)) == NULL)
				continue;
			if (!Strcasecmp(cu->userhost,userhost))
			{
				cu->flags |= CU_NEEDOP;
				send_mode(chan,50,QM_CHANUSER,'+','o',(void*)cu);
			}
		}
	}
	current = backup;
}
Beispiel #2
0
void check_botjoin(Chan *chan, ChanUser *cu)
{
	BotNet	*bn;
	BotInfo *binfo;

#ifdef DEBUG
	debug("(check_botjoin) chan = %s; cu = %s!%s\n",chan->name,cu->nick,cu->userhost);
#endif /* DEBUG */

	for(bn=botnetlist;bn;bn=bn->next)
	{
		if (bn->status != BN_LINKED)
			continue;

		for(binfo=bn->botinfo;binfo;binfo=binfo->next)
		{
			if (!nickcmp(cu->nick,binfo->nuh) &&
				!Strcasecmp(cu->userhost,getuh(binfo->nuh)))
			{
				if ((cu = find_chanbot(chan,binfo->nuh)) == NULL)
					return;
				cu->flags |= CU_NEEDOP;
				send_mode(chan,50,QM_CHANUSER,'+','o',(void*)cu);
#ifdef DEBUG
				debug("(check_botjoin) CU_NEEDOP set, mode pushed\n");
#endif /* DEBUG */
				return;
			}
		}
	}
}
static void automated_send_recv()
{
	int sk;
	char device[18];

	if (fork()) {
		if (!savefile) {
			do_listen(recv_mode);
			return;
		}

		save_fd = open(savefile, O_CREAT | O_WRONLY,
						S_IRUSR | S_IWUSR);
		if (save_fd < 0)
			syslog(LOG_ERR, "Failed to open file to save data");

		do_listen(save_mode);

		close(save_fd);
	} else {
		ba2str(&bdaddr, device);

		sk = do_connect(device);
		if (sk < 0)
			exit(1);
		send_mode(sk);
	}
}
Beispiel #4
0
void check_kicksay(Chan *chan, ChanUser *doer, char *text)
{
	KickSay *kick,*save;
	char *mask;
	int action;

	save = NULL;
	action = -1;
	for(kick=current->kicklist;kick;kick=kick->next)
	{
		if (*kick->chan == '*' || !Strcasecmp(chan->name,kick->chan))
		{
			if (!matches(kick->mask,text))
			{
				if (kick->action > action)
				{
					action = kick->action;
					save = kick;
				}
			}
		}
	}
	if (save)
	{
		if (!action)
		{
			if (doer->flags & CU_KSWARN)
				action = 1;
			if (!(doer->flags & CU_KSWARN))
			{
				doer->flags |= CU_KSWARN;
				to_server("NOTICE %s :%s\n",doer->nick,save->reason);
			}
		}
		if (action > 1)
		{
			mask = format_uh(get_nuh(doer),FUH_USERHOST);
			if (action > 2)
			{
				add_shit("Auto KS",chan->name,mask,save->reason,2,now+3600);
			}
			if (!(doer->flags & CU_BANNED))
			{
				doer->flags |= CU_BANNED;
				send_mode(chan,90,QM_RAWMODE,'+','b',mask);
			}
		}
		if (action && !(doer->flags & CU_KICKED))
		{
			doer->flags |= CU_KICKED;
			send_kick(chan,CurrentNick,FMT_PLAIN,save->reason);
		}
	}
}
Beispiel #5
0
void shit_action(Chan *chan, ChanUser *cu)
{
	Shit	*shit;
	const char *nick;
	char	*fromnick;
	char	*userhost;

	if (!chan->setting[TOG_SHIT].int_var || !chan->bot_is_op || cu->user)
		return;

	userhost = get_nuh(cu);
	if ((cu->shit = find_shit(userhost,chan->name)) == NULL)
		return;

	shit = cu->shit;

	if (shit->action == SHIT_KB || shit->action == SHIT_PERMABAN)
	{
		nick = cu->nick;

		send_mode(chan,85,QM_CHANUSER,'-','o',cu);
		send_mode(chan,90,QM_RAWMODE,'+','b',shit->mask);

		fromnick = nickcpy(NULL,shit->from);
		send_kick(chan,nick,"%s %s: %s",time2small(shit->time),fromnick,
			(shit->reason) ? shit->reason : "GET THE HELL OUT!!!");
		return;
	}
	else
	/*
	 *  shitlevel 1: not allowed to be chanop
	 */
	if (shit->action == SHIT_CHANOP)
	{
		send_mode(chan,160,QM_CHANUSER,'-','o',(void*)cu);
	}
}
Beispiel #6
0
/*
  send_hub_frame - send frame1 and frame2 when protocol is FrSkyDPORT
  frame 1 is sent every 200ms with baro alt, nb sats, batt volts and amp, control_mode
  frame 2 is sent every second with gps position data
*/
void AP_Frsky_Telem::send_hub_frame()
{
    uint32_t now = hal.scheduler->millis();

    // send frame1 every 200ms
    if (now - _last_frame1_ms > 200) {
        _last_frame1_ms = now;
        calc_gps_sats();
        send_gps_sats();
        send_mode();

        calc_battery();
        send_batt_remain();
        send_batt_volts();
        send_current();

        calc_baro_alt();
        send_baro_alt_m();
        send_baro_alt_cm();
    }
    // send frame2 every second
    if (now - _last_frame2_ms > 1000) {
        _last_frame2_ms = now;
        send_heading();
        calc_gps_position();
        if (_pos_gps_ok) {
            send_gps_lat_dd();
            send_gps_lat_mm();
            send_gps_lat_ns();
            send_gps_lon_dd();
            send_gps_lon_mm();
            send_gps_lon_ew();
            send_gps_speed_meter();
            send_gps_speed_cm();
            send_gps_alt_meter();
            send_gps_alt_cm();
        }
    }
}
int main(int argc ,char *argv[])
{
	struct sigaction sa;
	int opt, sk, mode = RECV;

	while ((opt=getopt(argc,argv,"rdscmnb:p:")) != EOF) {
		switch(opt) {
		case 'r':
			mode = RECV;
			break;

		case 's':
			mode = SEND;
			break;

		case 'd':
			mode = DUMP;
			break;

		case 'c':
			mode = RECONNECT;
			break;

		case 'm':
			mode = MULTY;
			break;

		case 'n':
			mode = CONNECT;
			break;

		case 'b':
			data_size = atoi(optarg);
			break;

		case 'p':
			if (sscanf(optarg, "0x%4hx", &pkt_type) != 1) {
				usage();
				exit(1);
			}
			break;

		default:
			usage();
			exit(1);
		}
	}

	if (!(argc - optind) && (mode != RECV && mode != DUMP)) {
		usage();
		exit(1);
	}

	if (!(buf = malloc(data_size))) {
		perror("Can't allocate data buffer");
		exit(1);
	}

	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = SIG_IGN;
	sa.sa_flags   = SA_NOCLDSTOP;
	sigaction(SIGCHLD, &sa, NULL);

	openlog("scotest", LOG_PERROR | LOG_PID, LOG_LOCAL0);

	switch( mode ){
		case RECV:
			do_listen(recv_mode);
			break;

		case DUMP:
			do_listen(dump_mode);
			break;

		case SEND:
			send_mode(argv[optind]);
			break;

		case RECONNECT:
			reconnect_mode(argv[optind]);
			break;

		case MULTY:
			multy_connect_mode(argv[optind]);
			break;

		case CONNECT:
			sk = do_connect(argv[optind]);
			if (sk < 0)
				exit(1);
			dump_mode(sk);
			break;
	}

	syslog(LOG_INFO, "Exit");

	closelog();

	return 0;
}
Beispiel #8
0
/*
  sport_tick - main call to send updates to transmitter when protocol is FrSkySPORT
  called by scheduler at a high rate
*/
void AP_Frsky_Telem::sport_tick(void)
{
    // check UART has been initialised
    if (!_initialised_uart) {
        init_uart_for_sport();
    }

    int16_t numc;
    numc = _port->available();

    // check if available is negative
    if (numc < 0) {
        return;
    }

    // this is the constant for hub data frame
    if (_port->txspace() < 19) {
        return;
    }

    for (int16_t i = 0; i < numc; i++) {
        int16_t readbyte = _port->read();
        if (_sport_status == 0) {
            if  (readbyte == SPORT_START_FRAME) {
                _sport_status = 1;
            }
        } else {
            switch (readbyte) {
            case DATA_ID_FAS:
                if (_battery_data_ready) {
                    switch (_fas_call) {
                    case 0:
                        send_batt_volts();
                        break;
                    case 1:
                        send_current();
                        break;
                    }
                    _fas_call++;
                    if (_fas_call > 1) {
                        _fas_call = 0;
                    }
                    _battery_data_ready = false;
                }
                break;
            case DATA_ID_GPS:
                if (_gps_data_ready) {
                    switch (_gps_call) {
                    case 0:
                        send_gps_lat_dd();
                        break;
                    case 1:
                        send_gps_lat_mm();
                        break;
                    case 2:
                        send_gps_lat_ns();
                        break;
                    case 3:
                        send_gps_lon_dd();
                        break;
                    case 4:
                        send_gps_lon_mm();
                        break;
                    case 5:
                        send_gps_lon_ew();
                        break;
                    case 6:
                        send_gps_speed_meter();
                        break;
                    case 7:
                        send_gps_speed_cm();
                        break;
                    case 8:
                        send_gps_alt_meter();
                        break;
                    case 9:
                        send_gps_alt_cm();
                        break;
                    case 10:
                        send_heading();
                        break;
                    }

                    _gps_call++;
                    if (_gps_call > 10) {
                        _gps_call = 0;
                        _gps_data_ready = false;
                    }
                }
                break;
            case DATA_ID_VARIO:
                if (_baro_data_ready) {
                    switch (_vario_call) {
                    case 0 :
                        send_baro_alt_m();
                        break;
                    case 1:
                        send_baro_alt_cm();
                        break;
                    }
                    _vario_call ++;
                    if (_vario_call > 1) {
                        _vario_call = 0;
                        _baro_data_ready = false;
                    }
                }
                break;
            case DATA_ID_SP2UR:
                switch (_various_call) {
                case 0 :
                    if ( _sats_data_ready ) {
                        send_gps_sats();
                        _sats_data_ready = false;
                    }
                    break;
                case 1:
                    if ( _mode_data_ready ) {
                        send_mode();
                        _mode_data_ready = false;
                    }
                    break;
                }
                _various_call++;
                if (_various_call > 1) {
                    _various_call = 0;
                }
                break;
            }
            _sport_status = 0;
        }
    }
}
int main(int argc, char *argv[])
{
	struct sigaction sa;
	int opt, sk, mode = RECV, need_addr = 0;

	bacpy(&bdaddr, BDADDR_ANY);
	bacpy(&auto_bdaddr, BDADDR_ANY);

	while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:O:N:MAESL:W:C:D:Y:T")) != EOF) {
		switch (opt) {
		case 'r':
			mode = RECV;
			break;

		case 's':
			mode = SEND;
			need_addr = 1;
			break;

		case 'w':
			mode = LSEND;
			break;

		case 'u':
			mode = CRECV;
			need_addr = 1;
			break;

		case 'd':
			mode = DUMP;
			break;

		case 'c':
			mode = RECONNECT;
			need_addr = 1;
			break;

		case 'n':
			mode = CONNECT;
			need_addr = 1;
			break;

		case 'm':
			mode = MULTY;
			need_addr = 1;
			break;

		case 'a':
			mode = AUTO;

			if (!strncasecmp(optarg, "hci", 3))
				hci_devba(atoi(optarg + 3), &auto_bdaddr);
			else
				str2ba(optarg, &auto_bdaddr);
			break;

		case 'b':
			data_size = atoi(optarg);
			break;

		case 'i':
			if (!strncasecmp(optarg, "hci", 3))
				hci_devba(atoi(optarg + 3), &bdaddr);
			else
				str2ba(optarg, &bdaddr);
			break;

		case 'P':
			channel = atoi(optarg);
			break;

		case 'U':
			if (!strcasecmp(optarg, "spp"))
				uuid = SERIAL_PORT_SVCLASS_ID;
			else if (!strncasecmp(optarg, "0x", 2))
				uuid = strtoul(optarg + 2, NULL, 16);
			else
				uuid = atoi(optarg);
			break;

		case 'M':
			master = 1;
			break;

		case 'A':
			auth = 1;
			break;

		case 'E':
			encr = 1;
			break;

		case 'S':
			secure = 1;
			break;

		case 'L':
			linger = atoi(optarg);
			break;

		case 'W':
			defer_setup = atoi(optarg);
			break;

		case 'B':
			filename = strdup(optarg);
			break;

		case 'O':
			savefile = strdup(optarg);
			break;

		case 'N':
			num_frames = atoi(optarg);
			break;

		case 'C':
			count = atoi(optarg);
			break;

		case 'D':
			delay = atoi(optarg) * 1000;
			break;

		case 'Y':
			priority = atoi(optarg);
			break;

		case 'T':
			timestamp = 1;
			break;

		default:
			usage();
			exit(1);
		}
	}

	if (need_addr && !(argc - optind)) {
		usage();
		exit(1);
	}

	if (!(buf = malloc(data_size))) {
		perror("Can't allocate data buffer");
		exit(1);
	}

	memset(&sa, 0, sizeof(sa));
	if (mode == AUTO)
		sa.sa_handler = sig_child_exit;
	else
		sa.sa_handler = SIG_IGN;
	sa.sa_flags   = SA_NOCLDSTOP;
	sigaction(SIGCHLD, &sa, NULL);

	openlog("rctest", LOG_PERROR | LOG_PID, LOG_LOCAL0);

	switch (mode) {
		case RECV:
			do_listen(recv_mode);
			break;

		case CRECV:
			sk = do_connect(argv[optind]);
			if (sk < 0)
				exit(1);
			recv_mode(sk);
			break;

		case DUMP:
			do_listen(dump_mode);
			break;

		case SEND:
			sk = do_connect(argv[optind]);
			if (sk < 0)
				exit(1);
			send_mode(sk);
			break;

		case LSEND:
			do_listen(send_mode);
			break;

		case RECONNECT:
			reconnect_mode(argv[optind]);
			break;

		case MULTY:
			multi_connect_mode(argc - optind, argv + optind);
			break;

		case CONNECT:
			sk = do_connect(argv[optind]);
			if (sk < 0)
				exit(1);
			dump_mode(sk);
			break;

		case AUTO:
			automated_send_recv();
			break;
	}

	syslog(LOG_INFO, "Exit");

	closelog();

	return 0;
}