Exemple #1
0
void DataHandler(SDMData& dat,long length)
{
	unsigned int total_recd = 0;
	unsigned int lastsec_recd = 0;
	unsigned int total_sent = 0;
	unsigned int lastsec_sent = 0;

	total_recd = GET_UINT(&dat.msg[0]);
	lastsec_recd = GET_UINT(&dat.msg[4]);
	total_sent = GET_UINT(&dat.msg[8]);
	lastsec_sent = GET_UINT(&dat.msg[12]);


	if(dat.source.getPort() == PORT_DM)
	{
	 	printf("DM ::  Total messages recd = %u, Messages last second recd= %u, Total messages sent = %u, Messages last second sent = %u\n", total_recd, lastsec_recd, total_sent, lastsec_sent);
	}
	else if (dat.source.getPort() == PORT_TM)
        {
	  	printf("TM ::  Total messages recd = %u, Messages last second recd= %u, Total messages sent = %u, Messages last second sent = %u\n", total_recd, lastsec_recd, total_sent, lastsec_sent);
        } 
	else if (dat.source.getPort() == PORT_PM)
	{
	  	printf("PM ::  Total messages recd = %u, Messages last second recd= %u, Total messages sent = %u, Messages last second sent = %u\n", total_recd, lastsec_recd, total_sent, lastsec_sent);
	}
	else if (dat.source.getPort() == PORT_SM)
	{
		printf("SM ::  Total messages recd = %u, Messages last second recd= %u, Total messages sent = %u, Messages last second sent = %u\n", total_recd, lastsec_recd, total_sent, lastsec_sent);
	}
	else
		printf("Unknown sender. %ld:%hd\n", dat.source.getAddress(), dat.source.getPort());
}
Exemple #2
0
void Settings::load(const QString &filePath)
{
    settingsPath = filePath;

    //if no settings file exist -- use the default one and save it on disc
    QFile file(settingsPath);
    if (!file.exists()) {
        if (!QFile::copy(":/texts/" + FILENAME, settingsPath)) {
            qWarning("Failed to save default settings in %s, please check user permissions.", qPrintable(settingsPath));
            settingsPath = ":/texts/" + FILENAME;
        }
    }

    QSettings s(settingsPath, QSettings::IniFormat);
    bool ok;
    s.beginGroup("Network");
        address = s.value("address", "127.0.0.1").toString();

        GET_UINT(port, "port", 10003, ok)
        GET_INT(maxClients, "maxClients", 1024, ok);
        GET_INT(maxSimultaneousConnectionsFromSingleIp, "maxSimultaneousConnectionsFromSingleIp", 10, ok);
    s.endGroup();

    s.beginGroup("Penalty");
        enablePenalty = s.value("enable", true).toBool();

        GET_INT(maxPenaltyPoints, "maxPenaltyPoints", 85, ok)
        GET_UINT(penaltyPeriodSeconds, "penaltyPeriodSeconds", 10, ok)

        disconnectClientOnMaxPenaltyPointsReached = s.value("disconnectClientOnMaxPenaltyPointsReached", true).toBool();
        ignoreClientCommandsOnMaxPenaltyPointsReached = s.value("ignoreClientCommandsOnMaxPenaltyPointsReached", true).toBool();
        blacklistIpOnMaxPenaltyPointsReached = s.value("blacklistIpOnMaxPenaltyPointsReached", true).toBool();

        GET_INT(versionRequestPenalty, "versionRequestPenalty", 1, ok)
        GET_INT(serverListRequestPenalty, "serverListRequestPenalty", 3, ok)
        GET_INT(serverRegistrationPenalty, "serverRegistrationPenalty", 5, ok)
        GET_INT(setServerNamePenalty, "setServerNamePenalty", 3, ok)
        GET_INT(setServerMapPenalty, "setServerMapPenalty", 3, ok)
        GET_INT(setPlayersCountPenalty, "setPlayersCountPenalty", 3, ok)
        GET_INT(setMaxPlayersCountPenalty, "setMaxPlayersCountPenalty", 3, ok)
        GET_INT(setGameTypePenalty, "setGameTypePenalty", 3, ok)
        GET_INT(numberOfClientsRequestPenalty, "numberOfClientsRequestPenalty", 2, ok)
        GET_INT(pingRequestPenalty, "pingRequestPenalty", 1, ok)
        GET_INT(inviteRequestPenalty, "inviteRequestPenalty", 3, ok)
    s.endGroup();

    int blacklistSize = s.beginReadArray("Blacklist");
        while (blacklistSize) {
            s.setArrayIndex(--blacklistSize);
            blacklistedIpSet.insert(s.value("IP", "none").toString());
        }
}
Exemple #3
0
/** Read data from connected ASIM.
 *
 *  Read attempts to read data from the connected ASIM.  If the message is data,
 *  it is published to all interested subscribers, otherwise
 *  the message received is printed to the screen (if debug is high enough).
 *
 * INPUTS:
 * @param buf    [output] - The buffer in which to store the message.
 * @param length [output] - The number of bytes stored in buf.
 *
 * RETURNS:
 * @return char - The type of ASIM message received.
 */
char Sensor::Read(unsigned short& length, unsigned char* buf, int bufsize)
{
  char msg_type;
  int error_code;
  char error_str[80];
  int i;

  if(!connected)
    return ASIM_ERROR;

  memset(buf, 0, bufsize);	//Clear out the message buffer
  msg_type = device.Read(length,buf,bufsize);
  error_code = errno;

  switch(msg_type)
  {
  case ASIM_STATUS:
    if (buf[0]&0x80) //first bit is set for an error
    {
      if(debug_level>=0)
      {
	printf("ASIM %s status ERROR: %hhd\n",device_name,buf[0]);
      }
      if(debug_level>=2)
      {
	if(buf[0]&0x40) //illegal command bit
	{
	  printf("\tIllegal or unrecognized command\n");
	}
	if(buf[0]&0x20) //self test failure bit
	{
	  printf("\tSelf Test failed\n");
	}
      }
    }
    else
    {
      if(debug_level>=1)
      {
	printf("ASIM %s status OK: %hhd\n",device_name,buf[0]);
      }
    }
    if(debug_level>=2)
    {
      if(buf[0]&0x10) //mode bit
      {
	printf("\tASIM mode: operational\n");
      }
      else
      {
	printf("\tASIM mode: idle\n");
      }
    }
    break;

  case ASIM_XTEDS:
    if(debug_level>=1)
    {
      printf("%s xTEDS (%d)\n",device_name,length);
      fflush(NULL);
      if(debug_level>=2)
      {
	for(i=0;i<length;++i)
	{
	  if(isprint(buf[i])||isspace(buf[i]))
	  {
	    printf("%c",buf[i]);
	  }
	  else
	  {
	    printf("\nERROR %s xTEDS contains invalid character 0x%x\n",
		   device_name,buf[i]);
	  }
	}
      }
    }
    break;

  case ASIM_XTEDS_ID_PAIR:
    if(debug_level>=1)
    {
      printf("%s xTEDS_PID (%d)\n",device_name,length);
      fflush(NULL);
      if(debug_level>=2)
      {
	printf(" (ID=0x");
	for(i = 0; i < (length > 4 ? 4 : length);++i)
	  printf("%x",buf[i]);
	printf(")\n");
	for( ;i<length;++i)
	{
	  if(isprint(buf[i])||isspace(buf[i]))
	  {
	    printf("%c",buf[i]);
	  }
	  else
	  {
	    printf("\nWARNING: %s xTEDS contains invalid character 0x%x\n",
		   device_name,buf[i]);
	  }
	}
      }
    }
    break;

  case ASIM_DATA:
    if(debug_level>=2)
    {
      printf("%s produced message %hhd\n",device_name,buf[0]);
    }
    pthread_mutex_lock(&sensor_mutex);
    if(!subscriptions.Publish(buf[0],buf[1],(char*)(buf+2),length-2))
    {
      if(debug_level>=1)
      {
	printf("\t%s:%hhd had no subscribers\n",device_name,buf[0]);
	printf("\tCanceling %s:%hhd\n",device_name,buf[0]);
      }
      device.Cancel(buf[0], buf[1]);
    }
    else
    {
      MessageSent(subscriptions.GetLastPublished());
    }
    pthread_mutex_unlock(&sensor_mutex);
    break;

  case ASIM_TIME_AT_TONE:
  {
    // A modification for Fronterhouse.  The ASI protocol doesn't define an 
    // ASIM producing a Time-At-Tone, however, the GPS SPA-U ASIM will.  This 
    // will send it to the SM, which will in turn send it to all ASIMs connected
    // to the SM.

    SDMTat TATMsg;
    char SendBuffer[BUFSIZE];

    TATMsg.destination.setSensorID(0);	// Send to all ASIMs
    TATMsg.seconds = GET_UINT(buf);
    TATMsg.useconds = GET_UINT(buf+4);

    int TATLength = TATMsg.Marshal(SendBuffer);
    if (TATLength < 0)
    {
      printf("Error marshalling TAT message.\n");
      return ASIM_ERROR;
    }

    // Send to the SensorManager listen thread
    if (UDPsendto("127.0.0.1", PORT_SM, SendBuffer, TATLength) < 0)
    {
      printf("Error sending TAT message.\n");
      return ASIM_ERROR;
    }
  }
  break;

  case ASIM_VERSION:
    if(debug_level>=1)
      printf("%s running ASIM version %hhd\n",device_name,buf[0]);
    break;

  case ASIM_ERROR:
    if(debug_level>=0)	//display errors
    {
      printf("%s read error: %s\n",device_name,strerror_r(error_code,error_str,80));
    }
    break;

  case ASIM_TIMEOUT:
    if(debug_level>=3)	//only display timeout errors on debug 3
    {
      printf("%s read timeout: %s\n",
	     device_name,strerror_r(error_code,error_str,80));
    }
    break;

#ifdef WIN32
  case NULL:	/*Default return for no message available in Win32*/
    usleep(10000);		/*Give time for a message to be produced*/
    break;
#endif
  default:
    if(debug_level>=0)
      printf("%s produced an undefined message 0x%x\n",device_name,msg_type);
    break;
  }
  return msg_type;
}
// process an incoming multi options packet
void multi_options_process_packet(unsigned char *data, header *hinfo)
{
	ubyte code;	
	multi_local_options bogus;
	int idx,player_index;
	char str[255];
	int offset = HEADER_LENGTH;

	// find out who is sending this data	
	player_index = find_player_id(hinfo->id);

	if (player_index < 0) {
		nprintf(("Network", "Received packet from unknown player!\n"));
		return;
	}

	// get the packet code
	GET_DATA(code);
	switch(code){
	// get the start game options
	case MULTI_OPTION_START_GAME:
		Assert(Game_mode & GM_STANDALONE_SERVER);

		// get the netgame name
		GET_STRING(Netgame.name);		

		// get the netgame mode
		GET_INT(Netgame.mode);

		// get the security #
		GET_INT(Netgame.security);

		// get mode specific data
		switch(Netgame.mode){
		case NG_MODE_PASSWORD:
			GET_STRING(Netgame.passwd);
			break;
		case NG_MODE_RANK_ABOVE:
		case NG_MODE_RANK_BELOW:
			GET_INT(Netgame.rank_base);
			break;
		}

		// update standalone stuff
		std_connect_set_gamename(Netgame.name);
		std_multi_update_netgame_info_controls();
		break;

	// get mission choice options
	case MULTI_OPTION_MISSION:
		netgame_info ng;
		char title[NAME_LENGTH+1];
		int campaign_type,max_players;
		
		memset(&ng,0,sizeof(netgame_info));

		Assert(Game_mode & GM_STANDALONE_SERVER);

		// coop or team vs. team mode
		GET_INT(ng.type_flags);
		if((ng.type_flags & NG_TYPE_TEAM) && !(Netgame.type_flags & NG_TYPE_TEAM)){
			multi_team_reset();
		}
		// if squad war was switched on
		if((ng.type_flags & NG_TYPE_SW) && !(Netgame.type_flags & NG_TYPE_SW)){
			mprintf(("STANDALONE TURNED ON SQUAD WAR!!\n"));
		}
		Netgame.type_flags = ng.type_flags;

		// new respawn count
		GET_UINT(Netgame.respawn);

		// name string
		memset(str,0,255);

		GET_DATA(code);
		// campaign mode
		if(code){
			GET_STRING(ng.campaign_name);

			// set the netgame max players here if the filename has changed
			if(strcmp(Netgame.campaign_name,ng.campaign_name) != 0){				
				memset(title,0,NAME_LENGTH+1);			
				if(!mission_campaign_get_info(ng.campaign_name,title,&campaign_type,&max_players)){
					Netgame.max_players = 0;
				} else {
					Netgame.max_players = max_players;
				}

				strcpy_s(Netgame.campaign_name,ng.campaign_name);
			}

			Netgame.campaign_mode = 1;

			// put brackets around the campaign name
			if(Game_mode & GM_STANDALONE_SERVER){
				strcpy_s(str,"(");
				strcat_s(str,Netgame.campaign_name);
				strcat_s(str,")");
				std_multi_set_standalone_mission_name(str);
			}
		}
		// non-campaign mode
		else {
			GET_STRING(ng.mission_name);

			if(strcmp(Netgame.mission_name,ng.mission_name) != 0){
				if(strlen(ng.mission_name)){
					Netgame.max_players = mission_parse_get_multi_mission_info( ng.mission_name );
				} else {
					// setting this to -1 will prevent us from being seen on the network
					Netgame.max_players = -1;				
				}
				strcpy_s(Netgame.mission_name,ng.mission_name);
				strcpy_s(Game_current_mission_filename,Netgame.mission_name);				
			}			

			Netgame.campaign_mode = 0;
            
			// set the mission name
			if(Game_mode & GM_STANDALONE_SERVER){
				std_multi_set_standalone_mission_name(Netgame.mission_name);			
			}
		}

		// update FS2NetD as well
		if (MULTI_IS_TRACKER_GAME) {
			fs2netd_gameserver_update(true);
		}

		send_netgame_update_packet();	   
		break;

	// get the netgame options
	case MULTI_OPTION_SERVER:		
		get_server_options(data, &offset, &Netgame.options);

		// if we're a standalone set for no sound, do so here
		if((Game_mode & GM_STANDALONE_SERVER) && !Multi_options_g.std_voice){
			Netgame.options.flags |= MSO_FLAG_NO_VOICE;
		} else {
			// maybe update the quality of sound
			multi_voice_maybe_update_vars(Netgame.options.voice_qos,Netgame.options.voice_record_time);
		}

		// set the skill level
		Game_skill_level = Netgame.options.skill_level;		

		if((Game_mode & GM_STANDALONE_SERVER) && !(Game_mode & GM_CAMPAIGN_MODE)){
			Netgame.respawn = Netgame.options.respawn;
		}

		// if we have the "temp closed" flag toggle
		if(Netgame.options.flags & MLO_FLAG_TEMP_CLOSED){
			Netgame.flags ^= NG_FLAG_TEMP_CLOSED;
		}
		Netgame.options.flags &= ~(MLO_FLAG_TEMP_CLOSED);

		// if i'm the standalone server, I should rebroadcast to all other players
		if(Game_mode & GM_STANDALONE_SERVER){
			for(idx=0;idx<MAX_PLAYERS;idx++){
				if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx]) && (&Net_players[idx] != &Net_players[player_index]) ){
					multi_io_send_reliable(&Net_players[idx], data, offset);
				}
			}

			send_netgame_update_packet();
		}
		break;
	
	// local netplayer options
	case MULTI_OPTION_LOCAL:
		if(player_index == -1){
			get_local_options(data, &offset, &bogus);
		} else {
			get_local_options(data, &offset, &Net_players[player_index].p_info.options);

			//If the client has sent an object update higher than that which the server allows, reset it
			if (Net_player->flags & NETINFO_FLAG_AM_MASTER) {
				if (Net_players[player_index].p_info.options.obj_update_level > Cmdline_objupd) {
					Net_players[player_index].p_info.options.obj_update_level = Cmdline_objupd;
				}
			}
		}		
		break;
	}
	PACKET_SET_SIZE();
}