Beispiel #1
0
void init_new_game(table *t)
{
	int i;
	player *p;

	t->state = IN_PROGRESS;
	t->current_player = 0;
	t->card_deck = NULL;

	logging_debug("A game has started on table: %s!", t->name);
	table_broadcast(t, "The game has started!!!\n");
	table_broadcast(t, "\n-- BEGIN LIST OF PLAYERS --\n");
	
	for (i = 0; i < t->num_players; i++)
	{
		p = t->players[i];
		table_broadcast(t, "%d: %s\n", (i + 1), p->name);
	}

	table_broadcast(t, "-- END LIST OF PLAYERS --\n");

	//print the game rules
	table_broadcast(t, "Hopefully you already know how to play\n");
	table_broadcast(t, "Texas Hold'em Poker. You will be dealt\n");
	table_broadcast(t, "Your two cards and you make your choices\n");
	table_broadcast(t, "(when prompted to) of\n");
	table_broadcast(t, "b <<amount>> to bet or raise\n");
	table_broadcast(t, "c            to call\n");
	table_broadcast(t, "f            to fold\n");

	deal_out_new_cards(t);

	t->deck = generate_new_deck();
	
	//deal out the cards
	for (i = 0; i < t->num_players; i++)
	{
		p = t->players[i];
		p->card_one = (card*) stack_pop(t->deck);
		send_str(t->players[i]->socket, "Your first card is a %s\n", card_tostring(p->card_one));
		logging_info("%s dealt %s", t->players[i]->name, card_tostring(p->card_one));
	}

	for (i = 0; i < t->num_players; i++)
	{
		p = t->players[i];
		p->card_two = (card*) stack_pop(t->deck);
		send_str(t->players[i]->socket, "Your second card is a %s\n", card_tostring(p->card_two));
		logging_info("%s dealt %s", t->players[i]->name, card_tostring(p->card_two));
	}

}
Beispiel #2
0
int dl_file_input(int sensor_id, float temp, float rel_hum, int flags) {
  /* output into octave readable file */
  /* decorate with timestamp and seconds since start of program */
  
  time_t cur_time;
  struct tm ts;
  if ((time( &cur_time ) == 0) || (localtime_r(&cur_time, &ts) == 0)) {
    logging_error( "Could not get current time.\n" );
    ts.tm_year = 0; ts.tm_mon = 0; ts.tm_mday = 0;
    ts.tm_hour = 0; ts.tm_min = 0; ts.tm_sec = 0;
  } 
  double time_sec = difftime( cur_time, dl_file_start );

  logging_info( "%04i-%02i-%02i %02i:%02i:%02i, %lli, %i, %1.2f, %1.2f, %i.\n", ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, (long long int)cur_time, sensor_id, temp, rel_hum, flags );
  fprintf( dl_file_out, "%04i-%02i-%02i %02i:%02i:%02i, %lli, %i, %1.2f, %1.2f, %i.\n", ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, (long long int)cur_time, sensor_id, temp, rel_hum, flags );
  fflush( dl_file_out );
  
  logging_status( 3, "%i -> %1.1f°C, %1.1f%%", sensor_id, temp, rel_hum );
  return 0; // ok :-)
}
Beispiel #3
0
int main (int argc, char **argv) {

  char* filename = 0;
  char* outfilename = 0;
  int c;
  
  logging_init();
  
  opterr = 0;
  
  while ((c = getopt (argc, argv, "vqf:o:")) != -1)
    switch (c)
    {
      case 'v':
        verbose++;
        break;
      case 'q':
        verbose--;
        break;
      case 'f':
        if (filename != 0) {
          logging_info( "Overriding previous -f flag '%s' with '%s'.\n", filename, optarg );
        }
        filename = optarg;
        break;
      case 'o':
        if (outfilename != 0) {
          logging_info( "Overriding previous -o flag '%s' with '%s'.\n", outfilename, optarg );
        }
        outfilename = optarg;
        break;
      case '?':
        if ((optopt == 'f') || (optopt == 'o') || (optopt == 'd'))
          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
        else if (isprint (optopt))
          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        else
          fprintf (stderr,
                   "Unknown option character `\\x%x'.\n",
                   optopt);
        fprintf( stderr,
          "rtl_868, Copyright (C) 2015 Clemens Helfmeier\n"
          "rtl_868 comes with ABSOLUTELY NO WARRANTY; for details see the\n"
          "LICENSE file distributed with the program.\n"
          "This is free software, and you are welcome to redistribute it\n"
          "under certain conditions; see the LICENSE file for details.\n"
          "\n"
          "Usage: \n" 
          " rtl_868 [PARAMETERS] [FILENAME]\n"
          "   [FILENAME]     read input data from there. Defaults to stdin.\n"
          "   [PARAMETERS]   Unix style parameters with possible values:\n"
          "      -v          be more verbose. accumulates when given multiple times.\n"
          "      -q          be less verbose.\n"
          "      -f file     open file instead of stdin.\n"
          "      -o file     open file instead of stdout.\n"
          "\n"
        );
        return 1;
      default:
        abort ();
    }
  
  if ((argc - 1 == optind) && (filename == 0)) {
    logging_verbose( "Using positional argument '%s' as input filename.\n", argv[optind] );
    // if there is a single remaining argument, use it as filename
    filename = argv[optind];
  } else {
    int index;
    for (index = optind; index < argc; index++) {
      logging_error( "Unkown non-option argument %s\n", argv[index] );
      return 1;
    }
  }

  if (filename == 0) {
    filename = "-";
  }
  if (outfilename == 0){
    outfilename = "-";
  }
  logging_verbose( "decode.c version 0, verbose %i, filename %s -> %s.\n", verbose, filename, outfilename );
  logging_info(
     "rtl_868, Copyright (C) 2015 Clemens Helfmeier\n"
     "rtl_868 comes with ABSOLUTELY NO WARRANTY; for details see the\n"
     "LICENSE file distributed with the program.\n"
     "This is free software, and you are welcome to redistribute it\n"
     "under certain conditions; see the LICENSE file for details.\n"
  );
  
  FILE *in, *out;
  if ((filename == 0) || (strcmp( filename, "-" ) == 0))
    in = stdin;
  else
    in = fopen( filename, "r" );
  if (in == 0) {
    if (filename == 0) {
      logging_error( "Could not open stdin as input file.\n" );
    } else {
      logging_error( "Could not open input file '%s'.\n", filename );
    }
    return 1;
  }

  if ((outfilename == 0) || (strcmp( outfilename, "-" ) == 0))
    out = stdout;
  else
    out = fopen( outfilename, "a" );
  if (out == 0) {
    if (outfilename == 0) {
      logging_error( "Could not open stdout as output file.\n" );
    } else {
      logging_error( "Could not open output file '%s'.\n", outfilename );
    }
    return 1;
  }

  int duplicate_stream_input( int transmission[], unsigned int length ) {
    if ((ws300.input( transmission, length) == 0) ||
      (tx29.input(transmission, length) == 0))
      return 0;
    else if (verbose > 1) {
      if (length < 6) return -1;
      fprintf( out, "__, %i, ", length );
      while (length-- > 0)
        fprintf( out, "%02x ", *transmission++ );
      fprintf( out, "\n" );
      fflush(out);
      return 0;
    } else {
      return 0;
    }
  }
  stream_decoder_t mysd = { .init = 0, .input = &duplicate_stream_input };
  
  // construct the signal chain
  /* transmission decoder */
  td.init( &nrz );
  /* nrz */
  nrz.init( &mysd );
  /* ws300 and tx29 */
  ws300.init( &dl_file );
  tx29.init( &dl_file );
  /* dl_file */
  dl_file.init( out );
  
  uint16_t d[1024];
  unsigned long long int ndata = 0;
  unsigned long long int last_ndata = 0;
  
  struct timespec last_status;
  clock_gettime( CLOCK_MONOTONIC, &last_status );
  
  // read from stdin S16LE data
  while (1) {
    /* read a chunk */
    int n = fread( d, sizeof(d[0]), sizeof(d)/sizeof(d[0]), in );
    if (n != sizeof(d)/sizeof(d[0])) {
      logging_error( "\nError during read: %x.\n", n );
      break;
    } else {
      ndata += n;
    }

    struct timespec now;
    clock_gettime( CLOCK_MONOTONIC, &now );
    // if time is over, redisplay status
    float dt = 1.0 * (now.tv_sec - last_status.tv_sec) + 1.0 * (now.tv_nsec - last_status.tv_nsec) / 1e9;
    if (dt > 1) {
      // calculate new throughput
      float throughput = (ndata - last_ndata) / dt;
      last_ndata = ndata;
    
      /* update status display */
      char nd_e;
      float nd_b;
      data_to_string( (float)ndata, &nd_b, &nd_e );
      char tp_e;
      float tp_b;
      data_to_string( throughput, &tp_b, &tp_e );
      logging_status( 0, "%s -> %s, %1.1f%c, %1.1f%c", filename, outfilename, nd_b, nd_e, tp_b, tp_e );
    
      logging_restatus();
      last_status.tv_sec = now.tv_sec;
      last_status.tv_nsec = now.tv_nsec;
    }
    
    /* and put the chunk into the transmission decoder */
    int i;
    for (i = 0; i<sizeof(d)/sizeof(d[0]); i++) {
      td.input( d[i] );
    }
  }

  fclose(in);
}
Beispiel #4
0
int dl_file_init( FILE *out ) {
  time( &dl_file_start );
  dl_file_out = out;
  logging_info( "Data_Logger initialized.\n" );
}