예제 #1
0
void		cli_prend(t_request_data *rqd, t_server *t, t_world *w)
{
  int		index_item;
  char		out[ANSWER_SIZE];

  index_item = match_index(rqd->argv[0]);
  if (index_item < RES_TYPES_COUNT && index_item >= 0
      && (w->surface[rqd->user->posy][rqd->user->posx])
      .resources[index_item] > 0)
    {
      --((w->surface[rqd->user->posy][rqd->user->posx])
	 .resources[index_item]);
      ++(rqd->user->inventory[index_item]);
      sprintf(out, "pgt %d %d\n", rqd->user->number, index_item);
      cli_answer_to_all_graph(t, out);
      cli_pin(out, rqd->user);
      cli_answer_to_all_graph(t, out);
      cli_command_bct(out, rqd->user->posx, rqd->user->posy, w);
      cli_answer_to_all_graph(t, out);
      cli_answer(rqd->user, t, "ok\n");
      free(rqd->argv[0]);
      free(rqd->argv);
      return ;
    }
  error_show("cli_prend", "", "Invalid mineral requested from player %d",
	     rqd->user->number);
  cli_answer(rqd->user, t, "ko\n");
}
예제 #2
0
static unsigned char *SingleJokerSet(pMatchSets pMS, char ch){
  int i;

  if( !(i = match_index(ch)) )return NULL;
  i--;
  if( pMS->SetType[i] == SINGLEJOKER )return pMS->set[i];
  return NULL;
  }
예제 #3
0
static unsigned char *MultiJokerSet(pMatchSets pMS, char ch){
  int i;

  if( ! (i = match_index(ch)) )return NULL;
  i--;
  if( pMS->SetType[i] == MULTIJOKER )return pMS->set[i];
  return NULL;
  }
예제 #4
0
/*FUNCTION*/
int match_count(char *pszPattern,
                unsigned long cbPattern
  ){
/*noverbatim
CUT*/
  int iCounter = 0;

  while( cbPattern ){
    if( match_index(*pszPattern) )iCounter++;
    if( *pszPattern == ESCAPE_CHARACTER ){
      pszPattern++;
      cbPattern--;
      if( ! cbPattern )return iCounter;
      }
    pszPattern++;
    cbPattern--;
    }
  return iCounter;
  }
예제 #5
0
/*FUNCTION*/
void match_ModifySet(pMatchSets pMS,
                     char JokerCharacter,
                     int nChars,
                     unsigned char *pch,
                     int fAction
  ){
/*noverbatim
CUT*/
  int i,index,offset;
  unsigned char *set,mask;

  i = match_index(JokerCharacter);
  if( i == 0 )return;
  i--;
  if( fAction & MATCH_SNOJ )pMS->SetType[i] = NOJOKER;
  if( fAction & MATCH_SSIJ )pMS->SetType[i] = SINGLEJOKER;
  if( fAction & MATCH_SMUJ )pMS->SetType[i] = MULTIJOKER;

  set = pMS->set[i];
  if( fAction & MATCH_NULS )
    for( i=0 ; i<32 ; i++ )set[i] = 0;
  if( fAction & MATCH_FULS )
    for( i=0 ; i<32 ; i++ )set[i] = 0xFF;

  if( fAction & (MATCH_ADDC|MATCH_REMC) )
    while( nChars-- ){
      mask = 1;
      index = (*pch) >> 3;
      offset = (*pch) & 7;
      mask <<= offset;
      if( fAction & MATCH_ADDC )set[index] |= mask;
      if( fAction & MATCH_INVC )set[index] ^= mask;
      if( fAction & MATCH_REMC ){
        mask = ~mask;
        set[index] &= mask;
        }
      pch++;
      }
  return;
  }
예제 #6
0
int
main (int argc, char *argv[])
{
	int type;
	void *data = g_malloc0 (MAX_ENTRY_SIZE);
	int num_args = argc - 1;
	int num_nums = 0;
	int num_vtables = 0;
	int i;
	long nums [num_args];
	long vtables [num_args];
	gboolean dump_all = FALSE;
	gboolean pause_times = FALSE;
	gboolean pause_times_stopped = FALSE;
	gboolean pause_times_concurrent = FALSE;
	gboolean pause_times_finish = FALSE;
	gboolean color_output = FALSE;
	long long pause_times_ts = 0;
	const char *input_path = NULL;
	int input_file;
	EntryStream stream;
	unsigned long long entry_index;
	unsigned long long first_entry_to_consider = 0;

	for (i = 0; i < num_args; ++i) {
		char *arg = argv [i + 1];
		char *next_arg = argv [i + 2];
		if (!strcmp (arg, "--all")) {
			dump_all = TRUE;
		} else if (!strcmp (arg, "--pause-times")) {
			pause_times = TRUE;
		} else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
			vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
			++i;
		} else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
			first_entry_to_consider = strtoull (next_arg, NULL, 10);
			++i;
		} else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
			color_output = TRUE;
		} else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
			input_path = next_arg;
			++i;
		} else {
			nums [num_nums++] = strtoul (arg, NULL, 16);
		}
	}

	if (dump_all)
		assert (!pause_times);
	if (pause_times)
		assert (!dump_all);

	input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
	init_stream (&stream, input_file);
	entry_index = 0;
	while ((type = read_entry (&stream, data)) != SGEN_PROTOCOL_EOF) {
		if (entry_index < first_entry_to_consider)
			goto next_entry;
		if (pause_times) {
			switch (type) {
			case PROTOCOL_ID (binary_protocol_world_stopping): {
				PROTOCOL_STRUCT (binary_protocol_world_stopping) *entry = data;
				assert (!pause_times_stopped);
				pause_times_concurrent = FALSE;
				pause_times_finish = FALSE;
				pause_times_ts = entry->timestamp;
				pause_times_stopped = TRUE;
				break;
			}
			case PROTOCOL_ID (binary_protocol_concurrent_finish):
				pause_times_finish = TRUE;
			case PROTOCOL_ID (binary_protocol_concurrent_start):
			case PROTOCOL_ID (binary_protocol_concurrent_update):
				pause_times_concurrent = TRUE;
				break;
			case PROTOCOL_ID (binary_protocol_world_restarted): {
				PROTOCOL_STRUCT (binary_protocol_world_restarted) *entry = data;
				assert (pause_times_stopped);
				printf ("pause-time %d %d %d %lld %lld\n",
						entry->generation,
						pause_times_concurrent,
						pause_times_finish,
						entry->timestamp - pause_times_ts,
						pause_times_ts);
				pause_times_stopped = FALSE;
				break;
			}
			}
		} else {
			int match_indices [num_nums + 1];
			gboolean match = is_always_match (type);
			match_indices [num_nums] = num_nums == 0 ? match_index (NULL, type, data) : BINARY_PROTOCOL_NO_MATCH;
			match = match_indices [num_nums] != BINARY_PROTOCOL_NO_MATCH;
			for (i = 0; i < num_nums; ++i) {
				match_indices [i] = match_index ((gpointer) nums [i], type, data);
				match = match || match_indices [i] != BINARY_PROTOCOL_NO_MATCH;
			}
			if (!match) {
				for (i = 0; i < num_vtables; ++i) {
					if (is_vtable_match ((gpointer) vtables [i], type, data)) {
						match = TRUE;
						break;
					}
				}
			}
			if (match || dump_all)
				printf ("%12lld ", entry_index);
			if (dump_all)
				printf (match ? "* " : "  ");
			if (match || dump_all)
				print_entry (type, data, num_nums, match_indices, color_output);
		}
	next_entry:
		++entry_index;
	}
	close_stream (&stream);
	if (input_path)
		close (input_file);
	g_free (data);

	return 0;
}