Exemplo n.º 1
0
/**
 * Envoi du gagnant a tous les participants
 * @param the_players Liste des joueurs
 * @param uid Identifiant du gagnant
 */
void send_death(Players the_players, uint16_t uid) {
    Frame death_frame = create_death(uid);
    send_broadcast(the_players, death_frame);
    
    /* Desinscription du perdant */
    remove_player_by_id(uid, the_players, 0);
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;
 
  PROCESS_BEGIN();
//set_global_address();
 udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),NULL);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("NUC E\n");
        PROCESS_EXIT();
    }

  etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
    printf("Sending broadcast\n");
    send_broadcast("hi",sizeof("hi"));
  }

  PROCESS_END();
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
	int ret;
	// create server
	ret = create_server();
	if(ret != 0)
	{
		printf("create server error\n");
		return -1;
	}

	// send broad cast
	ret = send_broadcast();
	if(ret != 0)
	{
		printf("send broadcast error\n");
		return -2;
	}

	// accept client
	ret = accept_client();
	if(ret != 0)
	{
		printf("accept_client error\n");
		return -3;
	}

	return 0;
}
Exemplo n.º 4
0
/**
 * Envoi de la trame Death contenant les 2 perdants en broadcast
 * @param the_players Liste des joueurs
 * @param uid1 Identifiant d'un survivant mort
 * @param uid2 Identifiant d'un survivant mort
 */
void send_two_deaths(Players the_players, uint16_t uid1, uint16_t uid2) {
    Frame death_frame = create_two_deaths(uid1, uid2);
    send_broadcast(the_players, death_frame);
    
    /* Desinscription des perdants */
    remove_player_by_id(uid1, the_players, 0);
    remove_player_by_id(uid2, the_players, 0);    
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static void
send(mac_callback_t sent, void *ptr)
{
  if(packetbuf_holds_broadcast()) {
    send_broadcast(sent, ptr);
  } else {
    NETSTACK_MAC.send(sent, ptr);
  }
}
Exemplo n.º 6
0
/**
 * Envoi du gagnant a tous les participants
 * @param the_players Liste des joueurs
 * @param uid Identifiant du gagnant
 */
void send_win(Players the_players, uint16_t uid) {
    Player winner = get_player_by_id(uid, the_players);
    Frame win_frame = create_win(uid);
    send_broadcast(the_players, win_frame);
    
    /* Changement de statut du gagnant */
    winner->is_winner = 1;
    
    /* Desinscription du gagnant */
    remove_player_by_id(uid, the_players, 0);
}
Exemplo n.º 7
0
    /**
     * Broadcasts the specified message as a WebSocket frame to every specified connection.
     * 
     * Thread-safe: may be called concurrently from any thread.
     * 
     * May cause the broadcast message
     * to interleave with other frames (put in the middle of continuation sequence, or
     * in the middle to TCP fragmented sequence), if target connection is used for
     * outbound traffic at the the time of broadcast.
     * 
     * @param connections list of connections to broadcast
     * @param msg message to broadcast
     * @param msg_type frame type (opcode) to use
     */
    static void broadcast(std::vector<std::shared_ptr<tcp_connection>>& connections,
            sl::io::span<const char> msg,
            sl::websocket::frame_type msg_type = sl::websocket::frame_type::text) {
        // prepare message
        auto holder = std::make_shared<std::vector<char>>();
        auto hbuf = std::array<char, 10>();
        auto header = sl::websocket::frame::make_header(hbuf, msg_type, msg.size());
        holder->resize(header.size() + msg.size());
        std::memcpy(holder->data(), header.data(), header.size());
        std::memcpy(holder->data() + header.size(), msg.data(), msg.size());

        // broadcast message
        for (auto& el : connections) {
            send_broadcast(std::move(el), holder);
        }
    }
Exemplo n.º 8
0
PROCESS_THREAD(monitor_process, ev, data)
{
    static uint8_t a;
    static int n;
    static unsigned char *buf_p, buf[10];
    static struct etimer wait_timer;
    static short int code=3;	//victim code
    PROCESS_BEGIN();

    a=monitor_target;

    if(a==0)
        PROCESS_EXIT();

    buf_p = buf;//code+dest+collouge
    MAPPER_ADD_PACKETDATA(buf_p,code);
    MAPPER_ADD_PACKETDATA(buf_p,a);
    MAPPER_ADD_PACKETDATA(buf_p,myip.u8[15]); // sending to parent its child node and it is victim


    if(last_target==a)
    {
        printf("last mntr %u same ret\n",last_target);
        PROCESS_EXIT();
    }

    printf("Monitoring for %u last target %u \n",monitor_target,last_target);
    monitor=1;

    last_target=a;

    reset_timer_flag = send_timer_flag=1;

    for(n=0; n<9; n++) {

        send_broadcast(buf,sizeof(buf));

        etimer_set(&wait_timer, CLOCK_SECOND*2);
        PROCESS_WAIT_UNTIL(etimer_expired(&wait_timer));

        printf("packet sent to %u last_target %u\n",monitor_target,last_target);

    }
    //printf("Monitor process exit\n");
    PROCESS_EXIT();
    PROCESS_END();
}
Exemplo n.º 9
0
/*---------------------------------------------------------------------------*/
void ntp_server_send(struct uip_udp_conn *udpconn) {
	struct ntp_msg *pkt;
#ifndef BROADCAST_MODE
	struct time_spec rects;
#endif
	struct time_spec xmtts;

	struct ntp_msg server_msg;
#ifndef BROADCAST_MODE
	if(uip_newdata()) {
		 // get receive timestamp (t2)
		 clock_get_time(&rects);

		// check if received packet is complete
		if ((uip_datalen() != NTP_MSGSIZE_NOAUTH)
		   && (uip_datalen() != NTP_MSGSIZE)) {
			PRINTF("Received malformed NTP packet\n");
			return;
		}
		PRINTF ("Received correct packet !!! \n");
		pkt = uip_appdata;

		server_msg.status = MODE_SERVER | (NTP_VERSION << 3) | LI_ALARM;
		server_msg.orgtime.int_partl=pkt->xmttime.int_partl;
		server_msg.orgtime.fractionl=pkt->xmttime.fractionl;
		server_msg.rectime.int_partl=uip_htonl(rects.sec + JAN_1970);
		server_msg.rectime.fractionl=uip_htonl(rects.nsec);
		clock_get_time(&xmtts);
		server_msg.xmttime.int_partl = uip_htonl(xmtts.sec + JAN_1970);
		server_msg.xmttime.fractionl = uip_htonl(xmtts.nsec);

		send_unicast(udpconn,&UIP_IP_BUF->srcipaddr,&server_msg,sizeof (struct ntp_msg));
		//uip_ipaddr_copy(&udpconn->ripaddr, &UIP_IP_BUF->srcipaddr);
		//uip_udp_packet_send(udpconn, &server_msg, sizeof(struct ntp_msg));
		//uip_create_unspecified(&udpconn->ripaddr);
	}
#else
	server_msg.status = MODE_BROADCAST | (NTP_VERSION << 3) | LI_ALARM;
	
	clock_get_time(&xmtts);
 	server_msg.xmttime.int_partl = uip_htonl(xmtts.sec + JAN_1970);
  	server_msg.xmttime.fractionl = uip_htonl(xmtts.nsec);
  	
  	send_broadcast(udpconn, &server_msg, sizeof(struct ntp_msg));
#endif
}
Exemplo n.º 10
0
int		broadcast_ia(t_server *server, t_player *player)
{
  t_list	tmp;
  t_task	*current;

  if (!server || !player)
    {
      fprintf(stderr, INTERNAL_ERR);
      return (-1);
    }
  if ((current = list_get_elem_at_position(player->queue_tasks, 0)) == NULL)
    return (-1);
  if (current->params == NULL || strlen(current->params) > 512)
    return (store_answer_p(player, strdup(KO), 0));
  else if (store_answer_p(player, strdup(OK), 0) == -1)
    return (fprintf(stderr, ERR_BUFFER), -1);
  tmp = server->all_players;
  return (send_broadcast(server, player, tmp, current->params));
}
Exemplo n.º 11
0
/*
 * Envoi de la liste des joueurs en broadcast
 * @param the_players Liste des joueurs
 */
void send_user(Players the_players) {
    size_t i = 0;
    Frame user_frame;
    Player current_player;
    
    /* Envoi a tous les clients de la trame User 
     * qui decrit chaque joueur connecte 
     */
    for(i=0; i < the_players->size; i++) {
        current_player = the_players->player[i];
        
        if(current_player->is_connected) {
            user_frame = create_user(current_player);
            send_broadcast(the_players, user_frame);
        }
    }
    
    /* Fin de la liste de joueurs */
    send_end(the_players);
}
Exemplo n.º 12
0
void	user_receive(t_who *group, t_who *user)
{
	int		response;
	char	str[1024];

	(void)group;
	ft_bzero(str, 1024);
	response = recv(user->fd, str, BUF_SIZE, 0);
	ft_strcat(user->buffer, str);
	if (response && ft_strchr(user->buffer, '\n') != NULL)
	{
		if (user->buffer[0] == '/')
			user_command(group, user);
		else
			send_channel(group, user);
		ft_bzero(user->buffer, sizeof(user->buffer));
	}
	else if (response == 0)
	{
		sprintf(str, MSG_USER_QUIT, user->user.name);
		close_connection(user);
		send_broadcast(group, str);
	}
}
Exemplo n.º 13
0
void *client_thread(void *arg)
{
	cJSON *root = NULL;
	char buffer[512] = {0};
	dev_tt dev;
	DEV_ADD_RETURN ret_add_dev = DEV_ADD_OK;
	BOOL ret = FALSE;
	char cityid[20] = {0};
	fd_set pending_data;
	struct timeval block_time;
	if (arg == NULL) {
		return NULL;
	}
	int *fd = arg;

	FD_ZERO(&pending_data);
	FD_SET(*fd,&pending_data);
	block_time.tv_sec = 5;
	block_time.tv_usec = 0;

	/*if client connect and not send message in 5 seconds,we will close the connection*/
	if (select((*fd) + 1, &pending_data, NULL, NULL, &block_time) > 0) {
		if (FD_ISSET(*fd, &pending_data)) {
			if (read(*fd, buffer, sizeof(buffer)) < 0) {
				close(*fd);
				return NULL;
			}
		}
	} 
	
	led_flash(LED_FOR_NETWORK, 1, 3);
	DEBUG_MSG("Network receive:%s\n", buffer);
	root = cJSON_Parse(buffer);//parse json
	if (root == NULL) {
		return NULL;
	}
	memset(&dev, 0, sizeof(dev_tt));
	char *who			= cJSON_GetObjectItem(root, "param0")->valuestring;
	dev.user_action 		= cJSON_GetObjectItem(root, "param1")->valuestring;
	dev.basic_info.mac		= cJSON_GetObjectItem(root, "param2")->valuestring;
	dev.basic_info.name 		= cJSON_GetObjectItem(root, "param3")->valuestring;
	dev.type 				= cJSON_GetObjectItem(root, "param4")->valuestring;
	dev.dev_cmd 			= cJSON_GetObjectItem(root, "param5")->valuestring;
	dev.basic_info.groupname	= cJSON_GetObjectItem(root, "param6")->valuestring;
	char *param1			= cJSON_GetObjectItem(root, "param7")->valuestring;
	char *param2			= cJSON_GetObjectItem(root, "param8")->valuestring;
	
	if (who == NULL || dev.user_action == NULL || dev.basic_info.mac==NULL ||dev.basic_info.name== NULL||dev.dev_cmd==NULL||dev.basic_info.groupname==NULL) {
		close(*fd);
		return NULL;
	}
	USER_ACTION user_action_type = (USER_ACTION)atoi(dev.user_action);
	switch (user_action_type) {
	case ACTION_DEV_ADD:
		dev.basic_info.name 		= strtok(dev.basic_info.name,":");//contains unicode
		dev.basic_info.unicode 	= strtok(NULL,":");
		dev.type = param2;
		if (dev.basic_info.name == NULL ||dev.basic_info.unicode == NULL) {
			break;
		}
		DEBUG_MSG("ADD:name= %s,unicode= %s\n",dev.basic_info.name,dev.basic_info.unicode);
		ret_add_dev = AddDevToStaticTable(dev.basic_info.mac,dev.basic_info.name,dev.basic_info.unicode,dev.basic_info.groupname,atoi(param1),atoi(dev.type));
		if (ret_add_dev==DEV_ADD_OK) {
			write(*fd, SOCKET_RESPONSE_YES, strlen(SOCKET_RESPONSE_YES));
			send_broadcast(who, user_action_type, dev.basic_info.name);
		} else if (ret_add_dev == DEV_MAC_EXIST) {
			write(*fd,SOCKET_RESPONSE_MAC_EXIST, strlen(SOCKET_RESPONSE_MAC_EXIST));
		} else if (ret_add_dev == DEV_NAME_EXIST) {
			write(*fd,SOCKET_RESPONSE_NAME_EXIST, strlen(SOCKET_RESPONSE_NAME_EXIST));
		}
		break;
	case ACTION_DEV_REMOVE:
		ret = RemoveDevFromStaticTable(dev.basic_info.mac,dev.basic_info.name);
		if (ret) {
			send_broadcast(who,user_action_type,dev.basic_info.name);
		}
		goto response_client;
		break;
	case ACTION_DEV_ADD_GROUP:
		ret = AddDevGroupName(dev.basic_info.groupname);
		goto response_client;
		break;
	case ACTION_DEV_EDIT:
		{
			char *oldname = param1;
			dev.basic_info.name = strtok(dev.basic_info.name,":");
			dev.basic_info.unicode = strtok(NULL,":");
			if (dev.basic_info.name == NULL ||dev.basic_info.unicode == NULL||oldname==NULL) {
				break;			
			}
			DEBUG_MSG("UPDATE:oldname = %s newname= %s,unicode= %s\n",oldname,dev.basic_info.name,dev.basic_info.unicode);
			ret = UpdateDevDisplayName(dev.basic_info.mac, oldname,dev.basic_info.name,dev.basic_info.unicode);
			if (ret) {
				send_broadcast(who,user_action_type,dev.basic_info.name);
			}
			goto response_client;
		}
		break;
	case ACTION_GET_ALARM_LIST:
		GetAlarmAllList();
		write(*fd,get_alarm_alllist(),strlen(get_alarm_alllist()));
		break;
	case ACTION_GET_DEV_LIST:
		GetDeviceList();
		write(*fd,get_dev_list(),strlen(get_dev_list()));
		break;
	case ACTION_GET_CITY_ID:
		//char *name = dev.basic_info.name;
		memset(cityid,0,sizeof(cityid));
		if (GetCityIDByName(dev.basic_info.name, cityid)) {
			write(*fd,cityid,strlen(cityid));
		} else {
			write(*fd,SOCKET_RESPONSE_NO,strlen(SOCKET_RESPONSE_NO));
		}
		break;
	case ACTION_DEV_CONTROL:
		if (app_status.is_uart_ok) {
			ret = ForwardControlToUart(dev.basic_info.mac,dev.basic_info.name,(DEV_TYPE_INDEX)(atoi(dev.type)),atoi(dev.dev_cmd),atoi(param1));
		} else {
			ret = FALSE;
		}
		goto response_client;
		break;
	case ACTION_SEND_MSG:
		if (app_status.is_sms_ok) {
			ret = sms.send(dev.basic_info.mac,dev.basic_info.name);
		} else {
			ret = FALSE;
		}
		goto response_client;
		break;
	case ACTION_ALARM_ADD:
		//mac as the value(email or mobile value)
		ret = AddAlarmItem((ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_ALARM_LOCK:
		ret = ChangeAlarmItemToState(ALARM_LOCK,(ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_ALARM_UNLOCK:
		ret = ChangeAlarmItemToState(ALARM_UNLOCK,(ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_ALARM_DELETE:
		ret = DeleteFromAlarmTable((ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_GET_ALL_GROUP_NAME:
		GetAllGroupName();
		write(*fd , get_group_list(), strlen(get_group_list()));
		break;
	case ACTION_UPDATE_DEV_GROUP:
		ret = UpdateDevGroupName(dev.basic_info.mac,dev.basic_info.name,dev.basic_info.groupname);
		goto response_client;
		break;
	case ACTION_SET_GROUP_ID:
		{
			groupInfo_t group_info;
			memset(&group_info,0,sizeof(&group_info));
			strcpy(group_info.group_id,dev.basic_info.mac);
			strcpy(group_info.group_name,dev.basic_info.name);
			ret = SetFamilyGroupInfo(group_info);
			goto response_client;
		}
		break;
	case ACTION_GET_GROUP_ID:
		{
			groupInfo_t group_info;
			memset(&group_info,0,sizeof(&group_info));
			if (GetFamilyGroupInfo(&group_info)) {
					char buf[1024] = {0};
					sprintf(buf,"%s,%s,",group_info.group_id,group_info.group_name);
					write(*fd,buf,strlen(buf));
			} else {
				write(*fd,"_FAIL_",strlen("_FAIL_"));
			}
		}
		break;
	case ACTION_ADD_TIMERTASK:
		{
			timertask_item_t item;
			DEBUG_MSG("add timertask!\n");
			memset(&item,0,sizeof(&item));
			strcpy(item.dev_mac,dev.basic_info.mac);
			strcpy(item.dev_name,dev.basic_info.name);
			strcpy(item.happen_time ,param1);
			item.period		=	atoi(dev.type);
			item.action		=	atoi(dev.dev_cmd);
			item.tipinfo		=	atoi(dev.basic_info.groupname);
			item.howlong		=	atoi(param2);
			DEBUG_MSG("action = %d, howlong = hour:%2d,minute:%2d\n",item.action,(item.howlong)/100,(item.howlong)%100);
			ret = AddOneTimerTask(item);
			if (ret && item.howlong > 0) {
				TimeAdd(item.happen_time,item.howlong/100, item.howlong%100, item.happen_time);
				if (item.action == CMD_SW_OPEN) {
					item.action = CMD_SW_CLOSE;
				} else {
					item.action = CMD_SW_OPEN;
				}
				item.howlong = 0;//avoid repeat
				ret = AddOneTimerTask(item);
			}
			goto response_client;
		}
		break;
	case ACTION_DELETE_TIMERTASK:
		{
			int timertask_id = 0;
			ret = DeleteOneTimerTaskByID(timertask_id);
			goto response_client;
		}
		break;
	case ACTION_GET_TIMERTASK_INFO:
		GetAllTimerTaskInfo();
		write(*fd,g_timertask_info,strlen(g_timertask_info));
		break;
	case ACTION_SW_GET_STATE:
		{
			char buffer[10] = {0};
			enum control_cmd state = SWGetCurrentState(dev.basic_info.mac,dev.basic_info.name,atoi(param1));
			sprintf(buffer,"%d", state);
			write(*fd,buffer,strlen(buffer));
		}
		break;
	case ACTION_QUIT:
		close(*fd);
		return NULL;
	default:
		break;
	}
	close(*fd);
	return NULL;
response_client:
	if (ret) {
		write(*fd, SOCKET_RESPONSE_YES, strlen(SOCKET_RESPONSE_YES));
	} else {
		write(*fd, SOCKET_RESPONSE_NO, strlen(SOCKET_RESPONSE_NO));
	}
	close(*fd);
	return NULL;
}
Exemplo n.º 14
0
/*
 * Envoi d'un message Start a tous les joueurs encore connectes (broadcast)
 * @param the_players Liste des joueurs
 * @param msg Message a envoyer
 */
void send_start(Players the_players, const char* msg) {
    Frame start_frame = create_start(msg);
    send_broadcast(the_players, start_frame);    
}
Exemplo n.º 15
0
int main(void)
{
    char buffer[1024] = {0};
    FILE *file = NULL;
	int port=1001;
	int count=0,count1=0;
    int g_song_type = 0;
	//read_files("/mnt/ntfs/file_bak/songs/9/07/95009.mpg");
	//return;

	//recv_broadcast(&port);
	//g_external_data_flag=1;

	while(0)
	{
		if(count1 % 3 == 0)
			send_broadcast("eth0",port,"TEST BROADCAST",10);
		count1++;
		clear_data();

		if(g_external_data_flag != 0)
		{
			count++;
			g_external_data_flag=0;
			print_msg("hava data=%d\n",count);
		}
		else
		{
			//print_msg("no data\n");
		}
		//if(count == 10) break;
	}
	//return;
    //print_msg("%s\n",__FILE__);
    int i = 0;
    g_SongData=(SongData_t *)malloc(65535*sizeof(SongData_t));
    g_TotalSong = 0;
    file = fopen ("song.txt", "rb");
    if (file)
    {
        while (1)
        {
            memset (buffer, 0, 1024);
            if ((fgets (buffer, 1024, file)) == NULL)
            {   
                break;
            }   
            else
            {   
                if(strlen(buffer)==65 && 
                    isdigit(buffer[0]) && 
                    isdigit(buffer[1]) && 
                    isdigit(buffer[2]) && 
                    isdigit(buffer[3]) && 
                    isdigit(buffer[4]))
                {
                    memcpy (&(g_SongData[g_TotalSong]), buffer, 65);
                    g_TotalSong++;   
                }   
            }   
            if (g_TotalSong >= 65535)
            {   
                break;
            }   
        }
        fclose (file);
    }
    print_msg("g_TotalSong=%d %d\n",g_TotalSong,sizeof(SongData_t));
	print_msg("g_TotalSong=%d %d\n",g_TotalSong,sizeof(SongData1_t));
	
    file = fopen ("song1.txt", "w+");
    for(i=0;i<g_TotalSong;i++)
    {
        g_SongData1=g_SongData[i];
        memset(&g_SongData2,0x20,sizeof(SongData1_t));
        
        memcpy(g_SongData2.SongNo,g_SongData1.SongNo,SONG_NO_LENGTH);//1
        //unsigned char SongNo[SONG_NO_LENGTH];
        
        //g_SongData2.Tracks=g_SongData1.SongType;
        if ((g_song_type == SONG_TYPE_MPEG1_RC_VOCAL) || 
        (g_song_type == SONG_TYPE_MPEG2_RC_VOCAL) || 
        (g_song_type == SONG_TYPE_MPEG12_0X81_VOCAL) || 
        (g_song_type == SONG_TYPE_MPEG12_0XC1_VOCAL) || 
        (g_song_type == SONG_TYPE_MPEG12_0X89_VOCAL) || 
        (g_song_type == SONG_TYPE_MPEG12_0XA1_VOCAL) || 
        (g_song_type == SONG_TYPE_MPEG4_RC_VOCAL) || 
        (g_song_type == SONG_TYPE_MP3))
        {
            g_SongData2.Tracks = '2'; //�˜�(��•������•)
        }
        else
        {
            g_SongData2.Tracks = '1';  //�෴(��•������•)
        }
        //unsigned char SongType;
    
        g_SongData2.Language=g_SongData1.Language;//2
        //unsigned char Language;
    
        memcpy(g_SongData2.SongName,g_SongData1.SongName,SONG_NAME_MAXIMUM);//3
        //unsigned char SongName[SONG_NAME_MAXIMUM];
    
        memcpy(g_SongData2.SongWord,g_SongData1.SongWord,10);//4
        //unsigned char SongWord[10];
        
        g_SongData2.SongCnt=g_SongData1.SongCnt;//5
        //unsigned char SongCnt;
    
        g_SongData2.Dance=g_SongData1.Dance;
        
        memcpy(g_SongData2.Singer,g_SongData1.Singer,SINGER_NAME_LENGTH);//6
        //unsigned char Singer[SINGER_NAME_LENGTH];
    
        
        if(g_SongData1.SongMode=='1')//6140a785 239
        {
            g_SongData2.SongType='6';
        }
        if(g_SongData1.SongMode=='2')
        {
            g_SongData2.SongType='1';
        }
        else if(g_SongData1.SongMode=='3')
        {
            g_SongData2.Film='1';
        }
        else if(g_SongData1.SongMode=='4')
        {
            g_SongData2.SongType='4';
        }
        else if(g_SongData1.SongMode=='5')
        {
            g_SongData2.SongType='0';
        }
        else if(g_SongData1.SongMode=='6')
        {
            g_SongData2.SongType='a';
        }
        else if(g_SongData1.SongMode=='7')
        {
            g_SongData2.SongType='7';
        }
        else if(g_SongData1.SongMode=='8')
        {
            g_SongData2.SongType='8';
        }
        else if(g_SongData1.SongMode=='9')
        {
            g_SongData2.SongType='5';
        }
        //"1.�ϳ�����X", "2.���ո���X", "4.����СƷX",
        //"5.��������X", "6.���ɸ���",  "7.ϲ�����X", 
        //"8.Ϸ������X", "9.��ͯ����X", "3.��Ӱ"
        
        //��������                    //
        //1.���ո���X.      2.�������.
        //3.��������.       4.����.(����СƷ)X
        //5.��ͯ����X.      6.�ϳ�����X.
        //7.ϲ�����X.      8.Ϸ��X.
        //9.�����.       0.��������X.
        //a.���ɸ���.
        
        //unsigned char Singer2[SINGER_NAME_LENGTH];
        g_SongData2.LF[0]='\r';
        g_SongData2.LF[1]='\n';
        //unsigned char LF[2];
        fwrite(&g_SongData2,1,sizeof(SongData1_t),file);
    }
    print_msg("g_TotalSong=%d %d\n",g_TotalSong,i);
    if(file) fclose(file);
    return 0;
}
Exemplo n.º 16
0
/**
 * Determines the command to be executed by parsing the user input
 * @param String entered by the user
 */
void comm_process(char *comm_line){

    char *comm_args[257];                    //Stores tokenized arguments of the input command
    char temp[999];                         //Create a copy of entered command line value
    int i=0,j;                                //Counter
    unsigned int arguments=0;               //Stores no of command line arguments


    //Set all elements of temp array to '\0'
    memset((char *)&temp,'\0',sizeof(temp));

    //Set all elements of char array to '\0'
    memset((char *)&comm_args,'\0',sizeof(comm_args));

    //Copy input string
    strcpy(temp,comm_line);

    //Extract command from the user entered string
    comm_args[0]=strtok(comm_line," ");

    //printf("\nDEBUG: comm_args[0] is : %s",comm_args[0]);

    //Extract arguments
    while(comm_args[i]){

        comm_args[++i]=strtok(NULL," ");

        //printf("\nDEBUG: comm_args[%D] : %s",i,comm_args[i]);

        if(i==5 || comm_args[i]==NULL)
        {
            arguments=i-1;
            break;
        }
        //vprintf("\nDEBUG: comm_args[%d] is :%s",i,comm_args[i]);
    }

	comm_line=temp;

    //Common commands
    if (strncmp("AUTHOR",comm_args[0],sizeof("AUTHOR")-1)==0 && arguments==0)
    {

        success(comm_args[0]);
        cse4589_print_and_log("I, alizisha, have read and understood the course academic integrity policy.\n");
        end_(comm_args[0]);

    }
    else if( strncmp("PORT",comm_args[0],sizeof("PORT")-1)==0 && arguments==0 && isLoggedIn==TRUE)
    {

        if(my_port>=0 && my_port<=65536){
            success(comm_args[0]);
            cse4589_print_and_log("PORT:%d\n", my_port);
        }else{
            error_(comm_args[0]);
        }

        end_(comm_args[0]);
    }
    else if( strncmp("IP",comm_args[0],sizeof("IP")-1)==0 && arguments==0 && isLoggedIn==TRUE)
    {

        if(getPublicIP()>=0){
           success(comm_args[0]);
           cse4589_print_and_log("IP:%s\n", my_ip);
        }else{
            error_(comm_args[0]);
        }
        end_(comm_args[0]);
    }
    else if( strncmp("LIST",comm_args[0],sizeof("LIST")-1)==0 && arguments==0 && isLoggedIn==TRUE)
    {
        char *ip_addr=(char *)calloc(INET_ADDRSTRLEN+1,sizeof(char));
        char *host_name=(char *)calloc(50,sizeof(char));

        int list_id;

        if(mode==CLIENT)
        {
            success(comm_args[0]);
            for(i=0,list_id=1;i<=3;i++)
            {
                if(clients[i].port!=NOT_CONNECTED)
                {
                    //printf("\nDEBUG: 1");
                    memset(host_name,'\0',50);
                    memset(ip_addr,'\0',INET_ADDRSTRLEN+1);
                    //printf("\nDEBUG: 2");
                    //printf("\nIP before ntop is: %d",clients[i].ip);
                    inet_ntop(AF_INET,&(clients[i].ip),ip_addr,INET_ADDRSTRLEN);
                    //printf("\nDEBUG: 3");
                    get_name(host_name,clients[i].ip);
                    //printf("\nDEBUG: 4");
                    cse4589_print_and_log("%-5d%-35s%-20s%-8d\n", list_id++, host_name, ip_addr, clients[i].port);
                    //printf("\nDEBUG: 5");
                }
            }
        }else if(mode==SERVER)
        {
            success(comm_args[0]);
            //memset(host_name,'\0',50);
            //memset(ip_addr,'\0',INET_ADDRSTRLEN+1);

            /*

            for(i=0,j=1;i<=3;i++,j++)
                printf("\n%d\tIP: %d\tPort: %d",j,client_list[i].nodeinfo.ip,client_list[i].nodeinfo.port);

            fflush(stdout);*/

            for(i=0,list_id=1;i<=3;i++)
            {
                if(client_list[i].isOnline==TRUE)
                {
                    memset(host_name,'\0',50);
                    memset(ip_addr,'\0',INET_ADDRSTRLEN+1);
                    //printf("\nDEBUG: 2");
                    inet_ntop(AF_INET,&(client_list[i].nodeinfo.ip),ip_addr,INET_ADDRSTRLEN);
                    //printf("\nDEBUG: 3");
                    get_name(host_name,client_list[i].nodeinfo.ip);
                    //printf("\nDEBUG: 4");
                    cse4589_print_and_log("%-5d%-35s%-20s%-8d\n", list_id++, host_name, ip_addr, client_list[i].nodeinfo.port);
                }
            }

            /*

            printf("\nAfter listing!");
            for(i=0,j=1;i<=3;i++,j++)
                printf("\n%d\tIP: %d\tPort: %d",j,client_list[i].nodeinfo.ip,client_list[i].nodeinfo.port);

            fflush(stdout);
            */
        }else
        {
            error_(comm_args[0]);
        }

        free(ip_addr);
        free(host_name);

        end_(comm_args[0]);

    }
    else if( strncmp("EXIT",comm_args[0],sizeof("EXIT")-1)==0 && arguments==0)
    {
        //Insert method to logout

        success(comm_args[0]);
        end_(comm_args[0]);

        exit(0);
    }
    //Server Commands
    else if( strncmp("STATISTICS",comm_args[0],sizeof("STATISTICS")-1)==0 && arguments==0 && mode==SERVER)
    {
        success(comm_args[0]);
        serv_stats();
        end_(comm_args[0]);

    }
    else if( strncmp("BLOCKED",comm_args[0],sizeof("BLOCKED")-1)==0 && arguments==1 && mode==SERVER)
    {
        command_blocked(comm_args[1]);
        end_(comm_args[0]);
    }
    //Client Commands
    else if( strncmp("BLOCK",comm_args[0],sizeof("BLOCK")-1)==0 && arguments==1 && mode==CLIENT && isLoggedIn==TRUE
        && strncmp("BLOCKED",comm_args[0],sizeof("BLOCKED")-1)!=0)
    {
        //printf("\nDEBUG: Extracted IP is : %s",comm_args[1]);
        //fflush(stdout);

        if(client_block(comm_args[1])==TRUE)
        {
            success(comm_args[0]);
        }else
        {
            error_(comm_args[0]);
        }
        end_(comm_args[0]);
    }
    else if( strncmp("LOGIN",comm_args[0],sizeof("LOGIN")-1)==0 && arguments==2 && mode==CLIENT &&isLoggedIn==FALSE )
    {
        if(client_login(comm_args[1],atoi(comm_args[2]))==TRUE)
        {
            success(comm_args[0]);
            isLoggedIn=TRUE;
            isLoggedOut=FALSE;
            FD_SET(client_sock, &master);                   //Add client_socket to client's master FD list
            //FD_SET(client_sock, &read_fds);
            if(client_sock>fdmax)
                fdmax=client_sock;
            //printf("\nDebug: Client_socket successfully added to list!");
            //fflush(stdout);
        }else
        {
            error_(comm_args[0]);
        }

        end_(comm_args[0]);

    }
    else if( strncmp("REFRESH",comm_args[0],sizeof("REFRESH")-1)==0 && arguments==0 && mode==CLIENT && isLoggedIn==TRUE)
    {
        int i,list_id;
        char *ip_addr=(char *)calloc(INET_ADDRSTRLEN+1,sizeof(char));
        char *host_name=(char *)calloc(50,sizeof(char));

        if(client_refresh()==TRUE)
        {
            success(comm_args[0]);
            for(i=0,list_id=1;i<=3;i++)
            {
                if(clients[i].port!=NOT_CONNECTED)
                {
                    //printf("\nDEBUG: 1");
                    memset(host_name,'\0',50);
                    memset(ip_addr,'\0',INET_ADDRSTRLEN+1);
                    //printf("\nDEBUG: 2");
                    //printf("\nIP before ntop is: %d",clients[i].ip);
                    inet_ntop(AF_INET,&(clients[i].ip),ip_addr,INET_ADDRSTRLEN);
                    //printf("\nDEBUG: 3");
                    get_name(host_name,clients[i].ip);
                    //printf("\nDEBUG: 4");
                    cse4589_print_and_log("%-5d%-35s%-20s%-8d\n", list_id++, host_name, ip_addr, clients[i].port);
                    //printf("\nDEBUG: 5");
                }
            }

        }
        else{
            error_(comm_args[0]);
        }

        free(ip_addr);
        free(host_name);

        end_(comm_args[0]);

    }
    else if( strncmp("SEND",comm_args[0],sizeof("SEND")-1)==0 && isLoggedIn==TRUE&& mode==CLIENT && arguments>=2)
    {
        char *ip,*msg;//comm_args[1];
        strtok(comm_line," ");
        ip=strtok(NULL," ");
        msg=strtok(NULL,"\n");

        if(send_message_client(ip,msg)==TRUE)
        {
            success(comm_args[0]);
        }else
        {
            error_(comm_args[0]);
        }
        end_(comm_args[0]);
    }
    else if( strncmp("BROADCAST",comm_args[0],sizeof("BROADCAST")-1)==0  && isLoggedIn==TRUE && mode==CLIENT &&arguments>=1)
    {
        char *msg;

        /* Extract message from the entire command */
        strtok(comm_line," ");                          //Separate command string
        msg=strtok(NULL,"\n");

        if(send_broadcast(msg)==TRUE)
            success(comm_args[0]);
        else
            error_(comm_args[0]);

        end_(comm_args[0]);

    }
    else if( strncmp("UNBLOCK",comm_args[0],sizeof("UNBLOCK")-1)==0 && arguments==1 && mode==CLIENT && isLoggedIn==TRUE)
    {
        if(client_unblock(comm_args[1])==TRUE)
        {
            success(comm_args[0]);
        }else{
            error_(comm_args[0]);
        }

        end_(comm_args[0]);
    }
    else if( strncmp("LOGOUT",comm_args[0],sizeof("LOGOUT")-1)==0 && arguments==0 && mode==CLIENT && isLoggedIn==TRUE)
    {
        if(client_logout()==TRUE)
        {
            success(comm_args[0]);
            isLoggedIn=FALSE;
            isLoggedOut=TRUE;
            //Stop listening on client_sock
            FD_CLR(client_sock, &master);

        }else
        {
            error_(comm_args[0]);
        }

        end_(comm_args[0]);
    }
    else if( strncmp("SENDFILE",comm_args[0],sizeof("SENDFILE")-1)==0 && arguments==2 && mode==CLIENT && isLoggedIn==TRUE){
    }else{
    }
}
Exemplo n.º 17
0
PROCESS_THREAD(udp_client_process, ev, data)
{
    static struct etimer start_timer, send_timer;
    static int flag=1;int i=0;
    static struct mt_thread sending_thread, attackinit_thread;	

    PROCESS_BEGIN();

    SENSORS_ACTIVATE(button_sensor);
    SENSORS_ACTIVATE(radio_sensor);

    set_global_address();

    printf("UDP client process started\n");

    print_local_addresses();

	myip=uip_ds6_get_link_local(ADDR_PREFERRED)->ipaddr;

    /* new connection with remote host */
    client_conn = udp_new(NULL, NULL, NULL);
    if(client_conn == NULL) {
        printf("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(client_conn, UIP_HTONS(10000+(int)myip.u8[15]));

    udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),tcpip_handler);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("No UDP broadcast connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
	
    printf("Created a connection with the server ");
    PRINT6ADDR(&client_conn->ripaddr);
    printf(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

    etimer_set(&start_timer, 60 * CLOCK_SECOND);//network setting time
    etimer_set(&send_timer, CLOCK_SECOND * ((int)myip.u8[15]+60+40));//node check/send parent info
    char buf[3]="hi";


    mt_init();
    mt_start(&sending_thread, sendpacket, 0);
    mt_start(&attackinit_thread, attack_init, NULL);	
    while(1) {

        PROCESS_YIELD();

        //NETSTACK_RDC.off(0);
        //NETSTACK_MAC.off(0);
        //NETSTACK_RADIO.off();
        //button_sensor::value(0);

        if(ev==tcpip_event)
        {
			
	    tcpip_handler();	                  
        }
	if(rssi_stored==5)// if got 5 rssi value from parent or child
	{
		monitor=0;
		monitor_target=0;
		for(i=0;i<5;i++)
			printf("Monitered value %d \n",mrssi[i]);
		rssi_stored=0;
	}
        if((ev==sensors_event) && (data == &button_sensor)) {            
	if(attack_flag)      
	{
		printf("Attack deactivated\n");   
		attack_flag=0;
		attacker=0;
		attacker_set=0;
		dis_output(NULL);
	}else {
		printf("Attack activated\n");   
		mt_exec(&attackinit_thread);
	}	
        }
        if((ev==sensors_event) && (data == &radio_sensor))
        {
            printf("Radio value %d",radio_sensor.value(0));
        }
        if(etimer_expired(&send_timer))
	{
		//uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345));
		//uip_create_unspecified(&client_conn->ripaddr); 
		//if(myip.u8[15]==4)
		//sendpacket(0);
		etimer_set(&send_timer, CLOCK_SECOND*(myip.u8[15]+60));
		if(parent_change)        // send only at parent change event
		{	            
	            if(!attack_flag)	//  this is not attacker and
		    {	
			mt_exec(&sending_thread);
			//sendpacket(0);	//  send nbr info by broadcast 0 for broadcast 
			parent_change=0;
			printf("Thread initiated\n");
		    }
	        }
	}
        if(etimer_expired(&start_timer) && flag==1)
        {
            flag=0;
            send_xy();
	    etimer_set(&start_timer, CLOCK_SECOND*(myip.u8[15]+1));
	    PROCESS_WAIT_UNTIL(etimer_expired(&start_timer));
	    send_broadcast("hi",sizeof("hi"));	
	    sendpacket(1);	// 0 means send by unicast	
	    	
        }
    }

    PROCESS_END();
}
Exemplo n.º 18
0
/**
 * Envoi des positions et directions de tous les participants
 * encore vivants en broadcast
 * 
 * @param the_players Liste des joueurs
 * @param elapsed_time Temps ecoule depuis le debut de la partie
 */
void send_turn(Players the_players, uint32_t elapsed_time) {
    Frame turn_frame = create_turn(elapsed_time, the_players); 
    send_broadcast(the_players, turn_frame);
}
Exemplo n.º 19
0
/**
 * Envoi de la trame End precisant la fin de la liste des joueurs
 * @param the_players Liste des joueurs
 */
void send_end(Players the_players) {
    Frame end_frame = create_end();
    send_broadcast(the_players, end_frame);
}
Exemplo n.º 20
0
/*
 * Envoi d'un message Pause a tous les joueurs encore connectes (broadcast)
 * @param the_players Liste des joueurs
 * @param msg Message a envoyer
 */
void send_pause(Players the_players, const char* msg) {
    Frame pause_frame = create_pause(msg);
    send_broadcast(the_players, pause_frame);
}