Esempio n. 1
11
int main(int argc, char *argv[])
{
    clock_t start, end, elapsed;
    FILE *entrada, *entrada2, *copia, *consulta, *saida;
    Words *words=NULL, *aux=NULL;
    char linha[1024],linha2[1024];
    char delimiters[] = " .,;:!?'\n'-*";
    char *token=NULL, *cp, c, n,aspas=(char)39,tab=(char)9;
    int i=0, ok=0,okay=0;



    if (argc != 5)         //numero de parametros corretos
    {
        printf("Numero incorreto de parametros.\n Sintaxe: copia arq_origem arq_destino\n");
        return 1;
    }

    entrada = fopen(argv[1], "r");       //abre o primeiro arquivo (arquivo de entrada)
    copia = fopen("facil.txt", "w");     //arquivo auxiliar
    consulta = fopen(argv[2], "r");      //abre o arquivo de consulta
    saida = fopen (argv[3], "w");        //abre ou cria ou arquivo de saida

    if(!entrada)                         //caso arquivos não existam
    {
        printf("ERRO\n");
        return 1;
    }
    if(!consulta)
    {
        printf("ERRO\n");
        return 1;
    }

    while(!feof(entrada))                //cria arquivo auxiliar a ser usado sem pontos, e caracteres separadores especiais
    {
        c=fgetc(entrada);
        if((c==',')||(c==':')||(c==';')||(c=='.')||(c=='-')||(c==EOF)||(c=='!')||(c=='?')||(c=='"')||(c=='*')||(c==aspas)||(c=='(')||(c==')')||(c=='_') || c==tab)
            c=' ';

        fputc(tolower(c),copia);
    }

    fclose(entrada);
    fclose(copia);


    entrada = fopen("facil.txt", "r");
    entrada2 = fopen("facil.txt", "r");

    if(!entrada)
        printf("ERRO\n");

    ///AQUI COLOCA OS ELEMENTOS NA ABP
    else
    {
        while(fgets(linha,1024, entrada))
        {

            stolower(linha);   //função que transforma tudo para minusculo

            cp = strdup(linha);

            token = strtok (cp, delimiters);    //pega tokens (usa cp como auxiliar para caso o ponteiro fique iinvalido em algum momento)
            while(token!=NULL)
            {
                words = abp(words,token);          //insere na abp
                token = strtok (NULL, delimiters); //pega proximo token

            }
        }
    }
    words = abp(words, "(NULL)");  //insere a palavra "(NULL)" na abp, para ser apontada pela ultima palavra do texto


    aux = words;                   //ponteiro aux fixo no inicio da ABP
    fseek(entrada, 0, SEEK_SET);
    n=fscanf(entrada2,"%s",linha2);//inicia o arquivo auxiliar uma palavra na frente


    ///AQUI COLOCA OS ELEMTTOS NO CAMPO LISTA DO NÓ DA ABP
    while(n != EOF)
    {
        words = aux;

        n=fscanf(entrada2,"%s",linha2);
        c=fscanf(entrada,"%s",linha);

        if(n == EOF)
        {
            words=busca(words,linha);                               //caso seja a ultima palavra do texto, busca ela na árvore
            words->vizinhos=insere_lista(words->vizinhos,"(NULL)"); //insere ela apontando também para ("NULL")
            break;
        }

        words=busca(words,linha);                             //busca a palavra no texto

        words->vizinhos=insere_lista(words->vizinhos,linha2); //insere ela apontando para sua sucessora
    }

   // printf("iuti");
    fclose(entrada2);
    fclose(entrada);
    moda(aux,aux);  //calcula a medida estatística para cada elemento da lista
    ordena(aux);    //ordena a lista pelo valor de sua "moda"

    ///AQUI FAZ A BUSCA E GERA SAIDA
    start=clock();
    fseek(consulta,0,SEEK_SET);
    while(fgets(linha,1023,consulta))
    {

        words=aux;                     //volta para o inicio da árvore
        strcpy(linha, strtok(linha,delimiters)); //paga pegar a linha correta
        words=busca(words,linha);      //vai para o lugar da arvore daquela palavra

        if(words!=NULL)
        {
            fputs("Consulta: ", saida);
            fputs(words->id, saida);
            fputs("\n", saida);

            i=0;
            while(words->vizinhos!=NULL && i<atoi(argv[4]))
            {
                fprintf(saida,"Sugestao: %s",words->vizinhos->id);  //printa tudo bonitinho
                okay=strlen(words->vizinhos->id);
                for(ok=0; ok<30-okay; ok++)
                    fprintf(saida," ");
                fprintf(saida,"(%lf)\n",words->vizinhos->moda);
                words->vizinhos = words->vizinhos->prox;
                i++;
            }
            fputs("\n", saida);

        }
    }

    fputs("\n", saida);
    end=clock(); //lê o tempo final
    elapsed = 1000 * (end - start) / (CLOCKS_PER_SEC);
    fprintf(saida,"Gasto: %ld ms", elapsed); //mostra o tempo final em ms

    fclose(consulta);
    fclose(saida);

    //Desenha(aux,1);

    deltree(aux);

    return 0;
}
Esempio n. 2
0
int
pr_SNameToId(char name[PR_MAXNAMELEN], afs_int32 *id)
{
    namelist lnames;
    idlist lids;
    register afs_int32 code;

    lids.idlist_len = 0;
    lids.idlist_val = 0;
    lnames.namelist_len = 1;
    lnames.namelist_val = malloc(PR_MAXNAMELEN);
    stolower(name);
    strncpy(lnames.namelist_val[0], name, PR_MAXNAMELEN);
    code = ubik_PR_NameToID(pruclient, 0, &lnames, &lids);
    if (lids.idlist_val) {
	*id = *lids.idlist_val;
	xdr_free((xdrproc_t) xdr_idlist, &lids);
    }
    if (lnames.namelist_val)
	free(lnames.namelist_val);
    return code;
}
Esempio n. 3
0
int
pr_CreateGroup(char name[PR_MAXNAMELEN], char owner[PR_MAXNAMELEN], afs_int32 *id)
{
    afs_int32 code;
    afs_int32 oid = 0;
    afs_int32 flags = 0;

    stolower(name);
    if (owner) {
	code = pr_SNameToId(owner, &oid);
	if (code)
	    return code;
	if (oid == ANONYMOUSID)
	    return PRNOENT;
    }
    flags |= PRGRP;
    if (*id) {
	code = ubik_PR_INewEntry(pruclient, 0, name, *id, oid);
	return code;
    } else {
	code = ubik_PR_NewEntry(pruclient, 0, name, flags, oid, id);
	return code;
    }
}
Esempio n. 4
0
/*
 * remplayer
 *
 * Usage:  remplayer name
 *
 *   Removes an account.  A copy of its files are saved under .rem.* which can
 *   be found in the appropriate directory (useful in case of an accident).
 *
 *   The account's details, messages, games and logons are all saved as
 *   'zombie' files.  These zombie accounts are not listed in handles or
 *   totals.
 */
int com_remplayer(int p, param_list param)
{
	char *player = param[0].val.word;
	char playerlower[MAX_LOGIN_NAME];
	int p1, lookup;

	strcpy(playerlower, player);
	stolower(playerlower);
	p1 = player_new();
	lookup = player_read(p1, playerlower);
	if (!lookup) {
		if (!check_admin2(p, p1)) {
			pprintf(p, "You can't remove an admin with a level higher than or equal to yourself.\n");
			player_remove(p1);
			return COM_OK;
		}
	}
	player_remove(p1);
	if (lookup) {
		pprintf(p, "No player by the name %s is registered.\n", player);
		return COM_OK;
	}
	if (player_find_bylogin(playerlower) >= 0) {
		pprintf(p, "A player by that name is logged in.\n");
		return COM_OK;
	}
	if (!player_kill(playerlower)) {
		pprintf(p, "Player %s removed.\n", player);
		//UpdateRank(TYPE_CRAZYHOUSE, NULL, NULL, player);
		//UpdateRank(TYPE_STAND, NULL, NULL, player);
		//UpdateRank(TYPE_WILD, NULL, NULL, player);
	} else {
		pprintf(p, "Remplayer failed.\n");
	}
	return COM_OK;
}
Esempio n. 5
0
/**
 * Main!  Handles program arguments and general execution
 *
 * @param argc the number of program arguments
 * @param argv the program arguments
 * @return 0 for success, any other value indicates failure
 */
int main(int argc, char **argv) {
	bool errors = false;

	bool encrypt = false;
	bool decrypt = false;
	bool passThroughInvalidInput = false;
	bool toUpper = false;
	bool toLower = false;
	char alphabet[MAX_STRING_SIZE + 1] = "";
	char key[MAX_STRING_SIZE] = "";
	static struct option long_options[] = { { "alphabet", required_argument, 0,
			'a' }, { "encrypt", no_argument, 0, 'e' }, { "decrypt", no_argument,
			0, 'd' }, { "help", no_argument, 0, 'h' }, { "key",
	required_argument, 0, 'k' }, { "lower", no_argument, 0, 'l' }, { "passthru",
			no_argument, 0, 'p' }, { "predefined-alpha",
	required_argument, 0, 'q' }, { "upper", no_argument, 0, 'u' }, { "version",
			no_argument, 0, 'v' }, { 0, 0, 0, 0 } };
	// Handle command line options
	while (true) {
		int option_index = 0;

		int option = getopt_long(argc, argv, "a:edhk:lpq:uv", long_options,
				&option_index);
		if (option == -1)
			break;
		switch (option) {
		case 'a':
			if (strnlen(optarg, MAX_STRING_SIZE + 1) > MAX_STRING_SIZE) {
				fprintf(stderr,
						"Alphabet is longer than max supported size of %d.\n",
						MAX_STRING_SIZE);
				errors = true;
			}
			strncpy(alphabet, optarg, MAX_STRING_SIZE);
			break;
		case 'e':
			encrypt = true;
			break;
		case 'd':
			decrypt = true;
			break;
		case 'h':
			// Print help
			puts(HELP);
			return (EXIT_SUCCESS);
			break;
		case 'k':
			strncpy(key, optarg, MAX_STRING_SIZE);
			break;
		case 'l':
			toLower = true;
			break;
		case 'p':
			passThroughInvalidInput = true;
			break;
		case 'q':
			if (0 == strncmp("UC", optarg, MAX_STRING_SIZE)) {
				strncpy(alphabet, UC_ALPHA, MAX_STRING_SIZE);
			} else if (0 == strncmp("LC", optarg, MAX_STRING_SIZE)) {
				strncpy(alphabet, LC_ALPHA, MAX_STRING_SIZE);
			} else if (0 == strncmp("AC", optarg, MAX_STRING_SIZE)) {
				strncpy(alphabet, AC_ALPHA, MAX_STRING_SIZE);
			} else if (0 == strncmp("PRINT", optarg, MAX_STRING_SIZE)) {
				strncpy(alphabet, PRINTABLE, MAX_STRING_SIZE);
			} else {
				fprintf(stderr, "There is no predefined alphabet \"%s\"\n",
						optarg);
				fputs("Please run with --help for usage options.\n", stderr);
				errors = true;
			}
			break;
		case 'u':
			toUpper = true;
			break;
		case 'v':
			printf("%s\n", VERSION);
			return (EXIT_SUCCESS);
		case '?':
			fputs("Please run with --help for usage options.\n", stderr);
			errors = true;
			break;
		default:
			abort();
			break;
		}
	}

	// Check for input errors before trying to apply cipher
	if (optind < argc) {
		fputs("Non-option arguments are not supported.\n", stderr);
		fputs("Please run with --help for usage options.\n", stderr);
		errors = true;
	}
	if (false == encrypt && false == decrypt) {
		fputs("Specify if you would like to encrypt or decrypt.\n", stderr);
		return (EXIT_FAILURE);
	} else if (true == encrypt && true == decrypt) {
		fputs("You cannot both encrypt and decrypt.\n", stderr);
		return (EXIT_FAILURE);
	}
	if (NULL == alphabet || 0 == strnlen(alphabet, MAX_STRING_SIZE)) {
		fputs("No alphabet provided.\n", stderr);
		errors = true;
	} else {
		for (short i = 0; 0 != key[i]; i++) {
			if (0 > findChar(alphabet, key[i])) {
				fprintf(stderr,
						"Key has character '%c' that is not in the alphabet.\n",
						key[i]);
				errors = true;
			}
		}
	}
	if (NULL == key || 0 == strnlen(key, MAX_STRING_SIZE)) {
		fputs("No key provided.\n", stderr);
		errors = true;
	}
	if (true == toUpper && true == toLower) {
		fputs("You cannot convert output to both upper case and lower case.\n",
		stderr);
		errors = true;
	} else if (true == toUpper) {
		stoupper(alphabet);
		stoupper(key);
	} else if (true == toLower) {
		stolower(alphabet);
		stolower(key);
	}
	if (doesAlphabetHaveDuplicates(alphabet)) {
		fputs("Alphabet cannot have duplicate characters.\n", stderr);
		errors = true;
	}

	// If there are no detected errors, attempt to apply the cipher on STDIN
	if (false == errors) {
		applyCipher(alphabet, key, encrypt && !decrypt, passThroughInvalidInput,
				toUpper, toLower);
	} else {
		return (EXIT_FAILURE);
	}
	return (EXIT_SUCCESS);
}
Esempio n. 6
0
int
main(int argc, char **argv)
{
    afs_int32 code;
    char name[PR_MAXNAMELEN];
    char gname[PR_MAXNAMELEN];
    char owner[PR_MAXNAMELEN];
    afs_int32 id;
    char buf[3000];
    FILE *fp;
    char *ptr;
    char *tmp;
    char *cellname;
    namelist lnames;
    afs_int32 i;
    afs_int32 fail = 0;

    if (argc < 2) {
	fprintf(stderr, "Usage: readgroup [-v] [-c cellname] groupfile.\n");
	exit(0);
    }
    cellname = 0;
    for (i = 1; i < argc; i++) {
	if (!strcmp(argv[i], "-v"))
	    verbose = 1;
	else {
	    if (!strcmp(argv[i], "-c")) {
		cellname = (char *)malloc(100);
		strncpy(cellname, argv[++i], 100);
	    } else
		strncpy(buf, argv[i], 150);
	}
    }
    code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
    free(cellname);
    if (code) {
	fprintf(stderr, "pr_Initialize failed .. exiting.\n");
	fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
	exit(1);
    }

    if ((fp = fopen(buf, "r")) == NULL) {
	fprintf(stderr, "Couldn't open %s.\n", argv[1]);
	exit(1);
    }

    while ((tmp = fgets(buf, 3000, fp)) != NULL) {
	/* group file lines must either have the name of a group or a tab or blank space at beginning */
	if (buf[0] == '\n')
	    break;
	if (buf[0] != ' ' && buf[0] != '\t') {
	    /* grab the group name */
	    memset(gname, 0, PR_MAXNAMELEN);
	    memset(owner, 0, PR_MAXNAMELEN);
	    sscanf(buf, "%s %d", gname, &id);
	    tmp = buf;
	    skip(&tmp);
	    skip(&tmp);
	    stolower(gname);
	    ptr = strchr(gname, ':');
	    strncpy(owner, gname, ptr - gname);
	    if (strcmp(owner, "system") == 0)
		strncpy(owner, "system:administrators", PR_MAXNAMELEN);
	    fail = 0;
	    if (verbose)
		printf("Group is %s, owner is %s, id is %d.\n", gname, owner,
		       id);
	    code = pr_CreateGroup(gname, owner, &id);
	    if (code != 0) {
		if (code != PRIDEXIST) {	/* already exists */
		    fprintf(stderr, "Failed to create group %s with id %d!\n",
			    gname, id);
		    fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
		}
		if (code != PREXIST && code != PRIDEXIST) {	/* we won't add users if it's not there */
		    fail = 1;
		}
	    }
	    if (!fail) {
		/* read members out of buf and add to the group */
		memset(name, 0, PR_MAXNAMELEN);
		while (sscanf(tmp, "%s", name) != EOF) {
		    if (strchr(name, ':') == NULL) {
			/* then it's not a group */
			code = pr_AddToGroup(name, gname);
			report_error(code, name, gname);
		    } else {
			/* add the members of a group to the group */
			if (verbose)
			    printf("Adding %s to %s.\n",
				   lnames.namelist_val[i], gname);
			code = pr_ListMembers(name, &lnames);
			if (code) {
			    fprintf(stderr,
				    "Couldn't get the members for %s to add to %s.\n",
				    name, gname);
			    fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code),
				    code);
			}
			for (i = 0; i < lnames.namelist_len; i++) {
			    code =
				pr_AddToGroup(lnames.namelist_val[i], gname);
			    report_error(code, lnames.namelist_val[i], gname);
			}
			if (lnames.namelist_val)
			    free(lnames.namelist_val);
		    }
		    memset(name, 0, PR_MAXNAMELEN);
		    skip(&tmp);
		}
	    }
	} else {		/* must have more names to add */
	    /* if we couldn't create the group, and it wasn't already there, don't try to add more users */
	    if (fail)
		continue;
	    /* read members out of buf and add to the group */
	    memset(name, 0, PR_MAXNAMELEN);
	    tmp = buf;
	    tmp++;
	    while (sscanf(tmp, "%s", name) != EOF) {
		if (strchr(name, ':') == NULL) {
		    /* then it's not a group */
		    code = pr_AddToGroup(name, gname);
		    report_error(code, name, gname);
		} else {
		    /* add the members of a group to the group */
		    code = pr_ListMembers(name, &lnames);
		    if (code) {
			fprintf(stderr,
				"Couldn't get the members for %s to add to %s.\n",
				name, gname);
			fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code),
				code);
		    }
		    for (i = 0; i < lnames.namelist_len; i++) {
			if (verbose)
			    printf("Adding %s to %s.\n",
				   lnames.namelist_val[i], gname);
			code = pr_AddToGroup(lnames.namelist_val[i], gname);
			report_error(code, lnames.namelist_val[i], gname);
		    }
		    if (lnames.namelist_val)
			free(lnames.namelist_val);
		}
		memset(name, 0, PR_MAXNAMELEN);
		skip(&tmp);
	    }
	}
    }
    return 0;
}
Esempio n. 7
0
/*
 * addplayer
 *
 * Usage: addplayer playername emailaddress realname
 *
 *   Adds a local player to the server with the handle of "playername".  For
 *   example:
 *
 *      addplayer Hawk [email protected] Henrik Gram
 */
int com_addplayer(int p, param_list param)
{
    char text[2048];
    char *newplayer = param[0].val.word;
    char *newname = param[2].val.string;
    char *newemail = param[1].val.word;
    char password[PASSLEN + 1];
    char newplayerlower[MAX_LOGIN_NAME];
    char salt[3];
    int p1, lookup;
    int i;

    if (strlen (newplayer) >= MAX_LOGIN_NAME) {
        pprintf (p, "Player name is too long\n");
        return COM_OK;
    }

    if (strlen (newplayer) < 3) {
        pprintf(p, "Player name is too short\n");
        return COM_OK;
    }

    if (!alphastring (newplayer)) {
        pprintf (p, "Illegal characters in player name. Only A-Za-z allowed.\n");
        return COM_OK;
    }

    strcpy (newplayerlower, newplayer);
    stolower (newplayerlower);
    p1 = player_new ();
    lookup = player_read (p1, newplayerlower);

    if (!lookup) {
        pprintf (p, "A player by the name %s is already registered.\n", newplayerlower);
        player_remove (p1);
        return COM_OK;
    }

    player_globals.parray[p1].name = strdup (newplayer);
    player_globals.parray[p1].login = strdup (newplayerlower);
    player_globals.parray[p1].fullName = strdup (newname);
    player_globals.parray[p1].emailAddress = strdup (newemail);

    for (i = 0; i < PASSLEN; i++) {
        password[i] = 'a' + random() % 26;
    }

    password[i] = '\0';
    salt[0] = 'a' + random() % 26;
    salt[1] = 'a' + random() % 26;
    salt[2] = '\0';
    player_globals.parray[p1].passwd = strdup (chessd_crypt (password, salt));


    PFlagON (p1, PFLAG_REG);
    PFlagON (p1, PFLAG_RATED);
    player_add_comment (p, p1, "Player added by addplayer.");
        player_globals.parray[p1].timeOfReg = (int) time (0);
	player_save (p1);
	player_remove (p1);

    if ( (p1 = player_find_part_login(newplayer)) >= 0) {
        sprintf (text, "\nYour player account has been created.\n\n"
                  "Login Name: %s\nFull Name: %s\nEmail Address: %s\nInitial Password: %s\n\n"
                  "If any of this information is incorrect, please contact the administrator\n"
                  "to get it corrected.\n\n"
                  "You may change your password with the password command on the the server.\n"
                  "\nPlease be advised that if this is an unauthorized duplicate account for\n"
                  "you, by using it you take the risk of being banned from accessing this\n"
                  "chess server.\n\n"
                  "Regards,\n\nThe BICS admins\n",
                  newplayer, newname, newemail, password);

        pprintf_prompt (p1, "%s", text);
	player_read (p1, newplayer);
        player_globals.parray[p1].timeOfReg = player_globals.parray[p1].logon_time;
    }


    pprintf (p, "Added: >%s< >%s< >%s< \n", newplayer, newname, newemail);
    pprintf (p, "Password %s\n", password);

    return COM_OK;
}
Esempio n. 8
0
/*
 * raisedead
 *
 * Usage:  raisedead oldname [newname]
 *
 *   Restores an account that has been previously removed using "remplayer".
 *   The zombie files from which it came are removed.  Under most
 *   circumstances, you restore the account to the same handle it had
 *   before (oldname).  However, in some circumstances you may need to
 *   restore the account to a different handle, in which case you include
 *   "newname" as the new handle.  After "raisedead", you may need to use the
 *   "asetpasswd" command to get the player started again as a registered
 *   user, especially if the account had been locked
 *   by setting the password to *.
 */
int com_raisedead(int p, param_list param)
{
  char *player = param[0].val.word;
  char *newplayer = (param[1].type == TYPE_NULL  ?  player  :  param[1].val.word);
  char playerlower[MAX_LOGIN_NAME], newplayerlower[MAX_LOGIN_NAME];
  char plrFile[MAX_FILENAME_SIZE];

  int p2, lookup;

  strcpy(playerlower, player);
  stolower(playerlower);
  strcpy(newplayerlower, newplayer);
  stolower(newplayerlower);

  /* First make sure we have a player to raise. */
  sprintf (plrFile, "%s/%c/.rem.%s", PLAYER_DIR, playerlower[0], playerlower);
  if (!file_exists (plrFile)) {
    pprintf(p, "No deleted player %s.\n", player);
    return COM_OK;
  }

  /* Now check for registered player. */
  sprintf (plrFile, "%s/%c/%s", PLAYER_DIR, newplayerlower[0], newplayerlower);
  if (file_exists (plrFile)) {
    pprintf(p, "A player named %s is already registered.\n", newplayerlower);
    pprintf(p, "Obtain a new handle for the dead person.\n");
    pprintf(p, "Then use raisedead [oldname] [newname].\n");
    return COM_OK;
  }

  /* Don't raise over a logged in user. */
  if (player_find_bylogin(newplayerlower) >= 0) {
    pprintf(p, "A player named %s is logged in.\n", newplayerlower);
    pprintf(p, "Can't raise until that person leaves.\n");
    return COM_OK;
  }

  /* OK, ready to go. */
  if (!player_reincarn(playerlower, newplayerlower)) {
    if (param[1].type == TYPE_WORD)
      pprintf(p, "Player %s reincarnated to %s.\n", player, newplayer);
    else
      pprintf(p, "Player %s raised.\n", player);
    p2 = player_new();
    if (!(lookup = player_read(p2, newplayerlower))) {
      if (param[1].type == TYPE_WORD) {
        free(player_globals.parray[p2].name);
        player_globals.parray[p2].name = strdup(newplayer);
        player_save(p2);
      }
      /*if (player_globals.parray[p2].s_stats.rating > 0)
        UpdateRank(TYPE_STAND, newplayer, &player_globals.parray[p2].s_stats, newplayer);
      if (player_globals.parray[p2].z_stats.rating > 0)
        UpdateRank(TYPE_CRAZYHOUSE, newplayer, &player_globals.parray[p2].z_stats, newplayer);
      if (player_globals.parray[p2].w_stats.rating > 0)
        UpdateRank(TYPE_WILD, newplayer, &player_globals.parray[p2].w_stats, newplayer);*/
    }
    player_remove(p2);
  } else {
    pprintf(p, "Raisedead failed.\n");
  }
  return COM_OK;
#if 0
 if (param[1].type == TYPE_NULL) {
    if (!player_raise(playerlower)) {
      pprintf(p, "Player %s raised from dead.\n", player);

      p1 = player_new();
      if (!(lookup = player_read(p1, playerlower))) {
	/*if (player_globals.parray[p1].s_stats.rating > 0)
	  UpdateRank(TYPE_STAND, player, &player_globals.parray[p1].s_stats, player);
	if (player_globals.parray[p1].z_stats.rating > 0)
	  UpdateRank(TYPE_CRAZYHOUSE, player, &player_globals.parray[p1].z_stats, player);
	if (player_globals.parray[p1].w_stats.rating > 0)
	  UpdateRank(TYPE_WILD, player, &player_globals.parray[p1].w_stats, player);*/
      }
      player_remove(p1);
    } else {
      pprintf(p, "Raisedead failed.\n");
    }
    return COM_OK;
  } else {
    if (player_find_bylogin(newplayerlower) >= 0) {
      pprintf(p, "A player by the requested name is logged in.\n");
      pprintf(p, "Can't reincarnate until they leave.\n");
      return COM_OK;
    }
    p2 = player_new();
    lookup = player_read(p2, newplayerlower);
    player_remove(p2);
    if (!lookup) {
      pprintf(p, "A player by the name %s is already registered.\n", player);
      pprintf(p, "Obtain another new handle for the dead person.\n");
      return COM_OK;
    }
    if (!player_reincarn(playerlower, newplayerlower)) {
      pprintf(p, "Player %s reincarnated to %s.\n", player, newplayer);
      p2 = player_new();
      if (!(lookup = player_read(p2, newplayerlower))) {
	free(player_globals.parray[p2].name);
	player_globals.parray[p2].name = strdup(newplayer);
	player_save(p2);
	/*if (player_globals.parray[p2].s_stats.rating > 0)
	  UpdateRank(TYPE_STAND, newplayer, &player_globals.parray[p2].s_stats, newplayer);
	if (player_globals.parray[p2].z_stats.rating > 0)
	  UpdateRank(TYPE_CRAZYHOUSE, newplayer, &player_globals.parray[p2].z_stats, newplayer);
	if (player_globals.parray[p2].w_stats.rating > 0)
	  UpdateRank(TYPE_WILD, newplayer, &player_globals.parray[p2].w_stats, newplayer);*/
      }
      player_remove(p2);
    } else {
      pprintf(p, "Raisedead failed.\n");
    }
  }
  return COM_OK;
#endif
}
Esempio n. 9
0
int asign_dir(struct ut_cache *file)
{
	char ext[5]; /* allow for 4 char extentions */
	memset(ext, 0, sizeof(ext));
	char *pdot=NULL;

	if( (pdot=strrchr(file->gfile, '.')) != NULL)
		memcpy(ext, (pdot+1), sizeof(char)*3);

	stolower(ext);

	/* Match extentions to game directory */

	/* Animations */
	if(!strcmp( ext, UT_UKX ) )
		memcpy(file->gdir, ANIMATIONS, sizeof(ANIMATIONS));
	/* Force Feedback */
	else if( !strcmp(ext, UT_IFR) )
		memcpy(file->gdir, FORCE_FEEDBACK, sizeof(FORCE_FEEDBACK));
	/* Karma Data */
	else if( !strcmp(ext, UT_KA) )
		memcpy(file->gdir, KARMA_DATA, sizeof(KARMA_DATA));
	/* Maps */
	else if( !strcmp(ext, UT_UNR) )
		memcpy(file->gdir, MAPS, sizeof(MAPS));
	else if( !strcmp(ext, UT_UT2) )
		memcpy(file->gdir, MAPS, sizeof(MAPS));
	/* Music */
	else if( !strcmp(ext, UT_UMX) )
		memcpy(file->gdir, MUSIC, sizeof(MUSIC));
	else if( !strcmp(ext, UT_OGG) )
		memcpy(file->gdir, MUSIC, sizeof(MUSIC));
	/* Saves */
	else if( !strcmp(ext, UT_UVX) )
		memcpy(file->gdir, SAVES, sizeof(SAVES));
	/* Sounds */
	else if( !strcmp(ext, UT_UAX) )
		memcpy(file->gdir, SOUND, sizeof(SOUND));
	/* Speech */
	else if( !strcmp(ext, UT_XML) )
		memcpy(file->gdir, SPEECH, sizeof(SPEECH));
	/* Static Meshes */
	else if( !strcmp(ext, UT_USX) )
		memcpy(file->gdir, STATIC_MESHES, sizeof(STATIC_MESHES));
	/* System */
	else if( !strcmp(ext, UT_U ))
		memcpy(file->gdir, SYSTEM, sizeof(SYSTEM));
	else if( !strcmp(ext, UT_UCL) )
		memcpy(file->gdir, SYSTEM, sizeof(SYSTEM));
	else if( !strcmp(ext, UT_INI) )
		memcpy(file->gdir, SYSTEM, sizeof(SYSTEM));
	else if( !strcmp(ext, UT_INT) )
		memcpy(file->gdir, SYSTEM, sizeof(SYSTEM));
	else if( !strcmp(ext, UT_UPL) )
		memcpy(file->gdir, SYSTEM, sizeof(SYSTEM));
	/* Textures */
	else if( !strcmp(ext, UT_UTX) )
		memcpy(file->gdir, TEXTURES, sizeof(TEXTURES));
	else
		memset(file->gdir, 0, sizeof(file->gdir));

	return 0;
}
static int process_wordzones (struct dirinfo *dip, char *path, char *basename)
{
    static char *ext = "linlist";
    static char tmp1[BUFSIZE];
    static char tmp2[BUFSIZE];

    char *cp, *distp, *navi = dip->dat[0];
    int   ch, sepcnt, nlen = strlen (navi);
    FILE *fp;

    strcpy (tmp1, basename);

    cp = strchr (tmp1, '.');
    if (cp == NULL) return 0;

    *cp++ = '\0';

    if (strcmp (cp, ext)) return 0;

    fp = fopen (path, "r");
    if (fp == NULL) return -1;

    sepcnt = 0;
    cp     = tmp2;
    distp  = NULL;
    for (;;) {
        ch = fgetc (fp);
        if (ch == '\n' || ch == EOF) {
            *cp++ = '\0';
            if (sepcnt == 1 && tmp1[0] != '\0') {
                char *splitp = navi_split (tmp2, 0);
                float dist = atof (distp);

                if (splitp && (splitp[0] == 'H' || dist < 0.4) && prefix_match (navi, nlen, tmp2)) {
/* Temporary suppress distp */
/* distp = ""; */
/*
printf ("[%d]W\t%s\t%s\t%s\t%s\t%s\t%s[%d]\n", p, tmp1, ctx[2], ctx[1], splitp, tmp2, distp, p);
*/
                    printf ("W\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", stolower (tmp1), dip->dat[1], dip->dat[2], splitp + 1, tmp1, tmp2, distp);
                    TESTABORT ();
                }
            }
            if (ch == EOF) break;
            sepcnt = 0;
            cp     = tmp2;
            distp  = NULL;
        } else {
            if (ch == ' ') {
                *cp++ = '\0';
                distp = cp;
                sepcnt++;
            } else {
                *cp++ = ch;
            }
        }
    }

    fclose (fp);

    return 0;
}
static int process_linpag (struct dirinfo *dip, char typ, char *path, char *basename, char *tail)
{
    char *bp, *tp, *ep = NULL;
    int ch, lno = 0;
    FILE *fp;
    char *navi = dip->dat[0];
    int   nlen = strlen (navi);

    tp = basename + strlen (basename) - strlen (tail);
    if (tp < basename) return 0;
    if (strcmp (tp, tail)) return 0;

    fp = fopen (path, "r");
    if (fp == NULL) return 0;

    ch = fgetc (fp);
    while  (ch != EOF && ep == NULL) {
         lno++;
         bp = id_buffer;
         while (ch != EOF && ch != '\n' && ch != ' ') {
             *bp++ = ch;
             ch = fgetc (fp);
         }
         if (ch != ' ') {
             ep = "Bad navis ID";
             break;
         }
         *bp = 0;
         while (ch == ' ') ch = fgetc (fp);
         tp = "<txt>";
         while (*tp && (ch == *tp++)) ch = fgetc (fp);
         if (*tp) {
             ep = "bad <txt> tag";
             break;
         }
         bp = txt_buffer;
         while (ch != EOF && ch != '\n') {
             *bp++ = ch;
             ch = fgetc (fp);
         }
         bp--;
         tp = ">txt/<";
         while (*tp && (bp >= txt_buffer) && *tp == *bp) {
             tp++;
             bp--;
         }
         if (*tp) {
             ep = "bad </txt> tag";
             break;
         }
         *++bp = 0;
         {
             char *splitp = navi_split (id_buffer, 0);
             if (splitp && prefix_match (navi, nlen, id_buffer)) {
/*
printf ("[%d]%c\t%s\t%s\t%s\t%s\t%s[%d]\n", p, typ, txt_buffer, ctx[2], ctx[1], splitp, id_buffer, p);
*/
                 printf ("%c\t%s\t%s\t%s\t%s\t%s\t%s\n", typ, stolower (txt_buffer), dip->dat[1], dip->dat[2], splitp, txt_buffer, id_buffer);
                 TESTABORT ();
             }
         }
         if (ch == '\n') ch = fgetc (fp);
    } 
    fclose (fp);

    if (ep) {
        fprintf (stderr, "Error at line %d: %s\n", lno, ep);
    }
    return (ep != NULL);
}
Esempio n. 12
0
bool IsVortec(void)
{
  return !strcmp("vortec", stolower(pDTS_Color->Service));
}
Esempio n. 13
0
bool IsPirch(void)
{
  return !strcmp("pirch", stolower(pDTS_Color->Service));
}
Esempio n. 14
0
bool PrintString(int Time)
// Purpose: Convert data from GlobalString into
//    a file-play command-string to send to
//    client via ether DDE or Tcl.
// Globals Used: GlobalString, String
// Shared Memory Vars: pDTS_Color->Channel
{
  UINT length = strlen(GlobalString);

  if (length == 0)
    length = sprintf(GlobalString, "\r\n");

  char *tString;

  // Allocate a buffer large enough to handle a case where every
  // char was a " or a \ (requiring insertion of \ escape chars
  // plus a NULL
  if ((tString = (char*)malloc(2*length+1)) == NULL)
  {
    ErrorHandler("Error allocating command buffer");
    return false;
   }

  char* FileNameBuf;

  // Allocate file-name buffer
  if ((FileNameBuf = (char*)malloc(MAX_PATH)) == NULL)
  {
    ErrorHandler("Error creating filename buffer");
    return false;
  }

  UINT ii,jj;

  // Scan string for " characters or \ characters
  // \\ and \" are needed for text between quotes in C
  for (ii = 0, jj = 0 ; ii < length ; ii++, jj++)
  {
    if (!pDTS_Color->bUseDDE)
    {
      if (GlobalString[ii] == '"' || GlobalString[ii] == '\x5c')
        // allow " and \ chars
        tString[jj++] = '\x5c';

      tString[jj] = GlobalString[ii];
    }
    else // mIRC will interpret $# as a parameter! (replace with ' ')
    {
      if (ii+1 < length && GlobalString[ii] == '$' &&
                                            isdigit(GlobalString[ii+1]))
        tString[jj] = ' ';
      else
        tString[jj] = GlobalString[ii];
    }
  }

  tString[jj] = NULLCHAR;

  if (!strcmp("status", stolower(pDTS_Color->Channel)))
  {
    if (pDTS_Color->bUseDDE) // echo to mIRC
    {
      // Writing one line to a file and using the /play command
      // eliminates the mIRC bug of stripping out spaces...
      //
      // ORIGINALLY, setting UseFile triggered mode of writing to a
      // temp-file... but NOW, YahCoLoRiZe can locally do /msg driven
      // playback or send just the /play file command when UseDll is
      // unchecked.  When UseDll is checked, we want to have two modes
      // in the dll.  If UseFile is checked, we want to play data
      // from the file written by YahCoLoRiZe (a full file), one line
      // at a time via /play and through a temp-file here.
      //
      // If UseFile us NOT checked, YahCoLoRiZe does not write a
      // big file for us to play here, instead it used a "one-line"
      // mode (via setting PlayTime < 0)... but HERE, we still
      // want to buffer that text through a temp-file to keep
      // mIRC/PIRCH from stripping spaces out...
      //if (pDTS_Color->bUseFile)

      if (IsPirchVortec())
      {
        // Pirch bug seems to require a leading CTRL_K or else the first
        // color-sequence CTRL_K is skipped...
        for (int ii = strlen(tString) ; ii >= 0  ; ii--)
          tString[ii+1] = tString[ii];
        tString[0] = '\003'; // leading CTRL_K
      }

      if (DTS_WriteLineToFile(FileNameBuf, tString) == false)
      {
        ErrorHandler("Error writing main temp file");
        free(FileNameBuf);
        return false;
      }

      // send to status window
      if (IsPirchVortec())
        // this won't work - pirch has no switch for status...
        sprintf(GlobalString, "/playfile -s %s", FileNameBuf);
      else // we only play a one-line file, NOTE: DO NOT USE -p!
        sprintf(GlobalString, "/play -s %s %i", FileNameBuf, Time);

//      if (IsPirchVortec())
        // Pirch bug seems to require a leading CTRL_K
        // or else the first color-sequence CTRL_K is skipped
//        sprintf(GlobalString, "/display %c%s",'\003',tString);
//      else
//        sprintf(GlobalString, "/echo -s %s",tString);
    }
    else // echo to XiRCON
      sprintf(GlobalString, "echo \"%s\" status",tString);
  }
  else // not to status window
  {
    if (pDTS_Color->bUseDDE) // msg to mIRC via file
    {
      // Writing one to a temp file and using the /play command
      // eliminates the mIRC bug of stripping out spaces...
      if (DTS_WriteLineToFile(FileNameBuf, tString) == false)
      {
        ErrorHandler("Error writing mIRC temp file");
        free(FileNameBuf);
        return false;
      }

      if (IsPirchVortec())
        sprintf(GlobalString, "/playfile %s %s", pDTS_Color->Channel,
                                                          FileNameBuf);
      else // we only play a one-line file, NOTE: DO NOT USE -p!
        sprintf(GlobalString, "/play %s %s %i", pDTS_Color->Channel,
                                                   FileNameBuf, Time);
    }
    else // msg to XiRCON
      sprintf(GlobalString, "/msg %s \"%s\"",pDTS_Color->Channel,tString);
  }

  free(tString);
  free(FileNameBuf);
  return true;
}
Esempio n. 15
0
int com_match(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int adjourned;                /* adjourned game? */
  int g;                        /* more adjourned game junk */
  int p1;
  int bh = 0, partner = 0, pp1 = 0;
  struct pending* pendfrom;
  struct pending* pendto;
  struct pending* pend;
  int wt = -1;                  /* white start time */
  int winc = -1;                /* white increment */
  int bt = -1;                  /* black start time */
  int binc = -1;                /* black increment */
  int rated = -1;               /* 1 = rated, 0 = unrated */
  int white = -1;               /* 1 = want white, 0 = want black */
  char category[100], board[100];
  textlist *clauses = NULL;
  int type = 0;

  category[0] ='\0';
  board[0] ='\0';

  if ((pp->game >= 0) && ((game_globals.garray[pp->game].status == GAME_EXAMINE)
|| (game_globals.garray[pp->game].status == GAME_SETUP))) {

    pprintf(p, "You can't challenge while you are examining a game.\n");
    return COM_OK;
  }

  if (pp->game >= 0) {
    pprintf(p, "You can't challenge while you are playing a game.\n");
    return COM_OK;
  }

  /* Makes sure that the user has not been ratebanned - Added by johnthegreat*/
  if (in_list(p, L_RATEBAN, player_globals.parray[p].name))
  {
  	pprintf_prompt(p,"You are banned from playing rated games.");
   	return COM_OK;
  }

  stolower(param[0].val.word);
  p1 = player_find_part_login(param[0].val.word);
  if (p1 < 0) {
    pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
    return COM_OK;
  }

  if (p1 == p) {                /* Allowing to match yourself to enter
                                   analysis mode */
    //ExamineScratch (p, param, 0);
    	pprintf(p, "Your can not match yourself.\n");
	return COM_OK;
  }

  if (!CheckPFlag(p1, PFLAG_OPEN)) {
    pprintf(p, "Player \"%s\" is not open to match requests.\n", player_globals.parray[p1].name);
    return COM_OK;
  }

  if (player_globals.parray[p1].game >= 0) {
    pprintf(p, "Player \"%s\" is playing a game.\n", player_globals.parray[p1].name);    return COM_OK;
  }

  if (CheckPFlag(p, PFLAG_TOURNEY) && !CheckPFlag(p1, PFLAG_TOURNEY)) {
    pprintf(p, "You may only match players with their tournament variable set.\n");
    return COM_OK;
  }

  if (!CheckPFlag(p, PFLAG_TOURNEY) && CheckPFlag(p1, PFLAG_TOURNEY)) {
    pprintf(p, "%s is in a tournament, and cannot accept other challenges.\n", player_globals.parray[p1].name);
    return COM_OK;
  }

	if (!net_globals.con[pp->socket]->timeseal)
	{
		return COM_OK;

	}
  if (!CheckPFlag(p, PFLAG_OPEN)) {
    PFlagON(p, PFLAG_OPEN);
    pprintf(p, "Setting you open for matches.\n");
  }


/* look for an adjourned game between p and p1 */
  g = game_new();
  adjourned = (game_read(g, p, p1) >= 0) || (game_read(g, p1, p) >= 0);
  if (adjourned) {
    type = game_globals.garray[g].type;
    wt = game_globals.garray[g].wInitTime / 60000;
    bt = game_globals.garray[g].bInitTime / 60000;
    winc = game_globals.garray[g].wIncrement / 1000;
    binc = game_globals.garray[g].bIncrement / 1000;
    rated = game_globals.garray[g].rated;
  }
  game_remove(g);

  pendto = find_pend(p, p1, PEND_MATCH);

  pendfrom = find_pend(p1, p, PEND_MATCH);

  if (!adjourned) {
      if (player_censored(p1, p))
        {
          pprintf(p, "Player \"%s\" is censoring you.\n",
              player_globals.parray[p1].name);
          return COM_OK;
        }
      if (player_censored(p, p1))
        {
          pprintf(p, "You are censoring \"%s\".\n",
              player_globals.parray[p1].name);
          return COM_OK;
        }
    if (in_list(p1, L_NOPLAY, pp->name)) {
      pprintf(p, "You are on %s's noplay list.\n", player_globals.parray[p1].name);
      return COM_OK;
    }
    if (in_list(p, L_NOPLAY, player_globals.parray[p1].name)) {
      pprintf(p, "You have %s on your noplay list.\n", player_globals.parray[p1].name);
      return COM_OK;
    }

    /* Makes sure that the opponent has not been ratebanned - Added by johnthegreat*/
    if (in_list(p1, L_RATEBAN, player_globals.parray[p1].name))
    {
    	pprintf(p,"%s has been banned from playing rated games.",player_globals.parray[p1].name);
    	return COM_OK;
    }

    if (CheckPFlag(p1, PFLAG_WHITELIST) && !player_isAllowedPlay(p1, p)) {
        struct player *pp2 = player_getStruct(p1);
        pprintf(p, "%s is not allowing requests from you.\n", pp2->name);
        return COM_OK;
    }

    if (param[1].type != TYPE_NULL) {
      if (!parse_match_string(p, &wt,&bt,&winc,&binc,&white,&rated,category,
                                                  board,param[1].val.string))

	  return COM_OK; /* couldn't parse */
    }

    if (rated == -1)
      rated = BoolCheckPFlag(p, PFLAG_RATED);
    if (!CheckPFlag(p, PFLAG_REG) || !CheckPFlag(p1, PFLAG_REG))
      rated = 0;

    if (winc == -1)
      winc = (wt == -1) ? pp->d_inc : 0;  /* match 5 == match 5 0 */

    if (wt == -1)
      wt = pp->d_time;

    if (bt == -1)
      bt = wt;

    if (binc == -1)
      binc = winc;

    if (category[0])
	{
			if (!board[0] && strcmp(category,"bughouse") && strcmp(category,"zh"))
			{
				pprintf(p, "You must specify a board and a category.\n");
				return COM_OK;
			} else if (board[0])
			{
				char fname[MAX_FILENAME_SIZE];

				if (!strcmp(board,"FR"))
					sprintf(fname, "%s/%s", BOARD_DIR, board);
				else
					sprintf(fname, "%s/%s/%s", BOARD_DIR, category, board);

				if (!file_exists(fname))
				{
					pprintf(p, "No such category/board: %s/%s\n", category, board);
					return COM_OK;
				}
			}
    }
    type = game_isblitz(category,board);

    if (type == TYPE_BUGHOUSE) {
      if (rated && pp->partner >= 0 && player_globals.parray[p1].partner >= 0) {
        if (!CheckPFlag(pp->partner, PFLAG_REG)
              || !CheckPFlag(player_globals.parray[p1].partner, PFLAG_REG))
          rated = 0;
      }
    }
    if (rated && (type == TYPE_NONSTANDARD)) {
      pprintf(p, "Game is non-standard - reverting to unrated\n");
      rated = 0;
    }
    if (rated && (type == TYPE_UNTIMED)) {
      pprintf(p, "Game is untimed - reverting to unrated\n");
      rated = 0;
    }
    if ((pendfrom == NULL) && !CheckPFlag(p1, PFLAG_ROPEN)
        && (rated != BoolCheckPFlag(p1, PFLAG_RATED))) {
      pprintf(p, "%s only wants to play %s games.\n", player_globals.parray[p1].name,
              rstr[!rated]);
      pprintf_highlight(p1, "Ignoring");
      pprintf(p1, " %srated match request from %s.\n",
              (rated ? "" : "un"), pp->name);
      return COM_OK;
    }

    /* Now check formula. */
    if (!adjourned
        && !GameMatchesFormula(p,p1, wt,winc,bt,binc, rated, type, &clauses)) {
      pprintf(p, "Match request does not fit formula for %s:\n",
              player_globals.parray[p1].name);
      pprintf(p, "%s's formula: %s\n", player_globals.parray[p1].name, player_globals.parray[p1].formula);
      ShowClauses (p, p1, clauses);
      ClearTextList(clauses);
      pprintf_highlight(p1, "Ignoring");
      pprintf_prompt(p1, " (formula): %s (%d) %s (%d) %s.\n",
                     pp->name,
                     GetRating(&player_globals.parray[p], type),
                     player_globals.parray[p1].name,
                     GetRating(&player_globals.parray[p1], type),
            game_str(rated, wt * 60, winc, bt * 60, binc, category, board));
      return COM_OK;
    }

    if (type == TYPE_BUGHOUSE) {
      bh = 1;
      partner = pp->partner;
      pp1 = player_globals.parray[p1].partner;

      if (pp < 0) {
        pprintf(p, "You have no partner for bughouse.\n");
        return COM_OK;
      }
      if (pp1 < 0) {
        pprintf(p, "Your opponent has no partner for bughouse.\n");
        return COM_OK;
      }
      if (partner == pp1) { /* should be an impossible case - DAV */
        pprintf(p, "You and your opponent both chose the same partner!\n");
        return COM_OK;
      }
      if (partner == p1 || pp1 == p) {
        pprintf(p, "You and your opponent can't choose each other as partners!\n");
        return COM_OK;
      }
      if (player_globals.parray[partner].partner != p) { /* another impossible case - DAV */
        pprintf(p, "Your partner hasn't chosen you as his partner!\n");
        return COM_OK;
      }
      if (player_globals.parray[pp1].partner != p1) { /* another impossible case - DAV */
        pprintf(p, "Your opponent's partner hasn't chosen your opponent as his partner!\n");
        return COM_OK;
      }
      if (!CheckPFlag(partner, PFLAG_OPEN) || player_globals.parray[partner].game >= 0) {
        pprintf(p, "Your partner isn't open to play right now.\n");
        return COM_OK;
      }
      if (!CheckPFlag(pp1, PFLAG_OPEN) || player_globals.parray[pp1].game >= 0) {
        pprintf(p, "Your opponent's partner isn't open to play right now.\n");
        return COM_OK;
      }

      /* Bypass NOPLAY lists, censored lists, ratedness, privacy, and formula for now */
      /*  Active challenger/ee will determine these. */
    }
    /* Ok match offer will be made */

  }                             /* adjourned games shouldn't have to worry
                                   about that junk? */
				/* keep incase of adjourned bughouse in future*/

  if (pendto != NULL) {
    pprintf(p, "Updating offer already made to \"%s\".\n", player_globals.parray[p1].name);
  }

  if (pendfrom != NULL) {
    if (pendto != NULL) {
      pprintf(p, "Pending list error!.\n");
      d_printf( "CHESSD: This shouldn't happen. You can't have a match pending from and to the same person.\n");
      return COM_OK;
    }

    if (adjourned || ((wt == pendfrom->btime) &&
                      (winc == pendfrom->binc) &&
                      (bt == pendfrom->wtime) &&
                      (binc == pendfrom->winc) &&
                      (rated == pendfrom->rated) &&
                      ((white == -1) || (white + pendfrom->seek_color == 1)) &&
               (!strcmp(category, pendfrom->category)) &&
                 (!strcmp(board, pendfrom->board_type)))) {
      /* Identical match, should accept! */
      accept_match(pendfrom,p, p1);
      return COM_OK;

    } else {
      delete_pending(pendfrom);
    }
  }

  if (pendto == NULL)
    pend = add_pending(p,p1,PEND_MATCH);
  else
    pend = pendto;

  pend->wtime = wt;
  pend->winc = winc;
  pend->btime = bt;
  pend->binc = binc;
  pend->rated = rated;
  pend->seek_color = white;
  pend->game_type = type;
  pend->category = strdup(category);
  pend->board_type = strdup (board);

  if (pendfrom != NULL) {
    pprintf(p, "Declining offer from %s and offering new match parameters.\n", player_globals.parray[p1].name);
    pprintf(p1, "\n%s declines your match offer a match with these parameters:", pp->name);
  }

  if (pendto != NULL) {
    pprintf(p, "Updating match request to: ");
    pprintf(p1, "\n%s updates the match request.\n", pp->name);
  } else {
    pprintf(p, "Issuing: ");
    pprintf(p1, "\n");
  }

  pprintf(p, "%s (%s) %s", pp->name,
          ratstrii(GetRating(&player_globals.parray[p], type), p),
          colorstr[white + 1]);
  pprintf_highlight(p, "%s", player_globals.parray[p1].name);
  pprintf(p, " (%s) %s%s.\n",
          ratstrii(GetRating(&player_globals.parray[p1], type), p1),
          game_str(rated, wt , winc, bt , binc, category, board),
          adjustr[adjourned]);
  pprintf(p1, "Challenge: ");
  pprintf_highlight(p1, "%s", pp->name);
  pprintf(p1, " (%s) %s",
          ratstrii(GetRating(&player_globals.parray[p], type), p),
          colorstr[white + 1]);
  pprintf(p1, "%s (%s) %s%s.\n", player_globals.parray[p1].name,
          ratstrii(GetRating(&player_globals.parray[p1], type), p1),
          game_str(rated, wt , winc, bt , binc, category, board),
          adjustr[adjourned]);
  Bell (p1);

  if (bh) {

    pprintf(partner, "\nYour bughouse partner issuing %s (%s) %s",
            pp->name, ratstrii(GetRating(&player_globals.parray[p], type), p),
            colorstr[white + 1]);
    pprintf_highlight(partner, "%s", player_globals.parray[p1].name);
    pprintf(partner, " (%s) %s.\n",
            ratstrii(GetRating(&player_globals.parray[p1], type), p1),
            game_str(rated, wt , winc, bt , binc, category, board));
    pprintf(partner, "Your game would be ");
    pprintf_highlight(partner, "%s", player_globals.parray[pp1].name);
    pprintf_prompt(partner, " (%s) %s%s (%s) %s.\n",
          ratstrii(GetRating(&player_globals.parray[pp1], type), pp1),
          colorstr[white + 1], player_globals.parray[partner].name,
          ratstrii(GetRating(&player_globals.parray[partner], type), partner),
          game_str(rated, wt , winc, bt , binc, category, board));
    Bell (partner);

    pprintf(pp1, "\nYour bughouse partner was challenged ");
    pprintf_highlight(pp1, "%s", pp->name);
    pprintf(pp1, " (%s) %s", ratstrii(GetRating(&player_globals.parray[p], type), p),
                             colorstr[white + 1]);
    pprintf(pp1, "%s (%s) %s.\n", player_globals.parray[p1].name,
            ratstrii(GetRating(&player_globals.parray[p1], type), p1),
            game_str(rated, wt , winc, bt , binc, category, board));
    pprintf(pp1, "Your game would be %s (%s) %s", player_globals.parray[pp1].name,
          ratstrii(GetRating(&player_globals.parray[pp1], type), pp1),
          colorstr[white + 1]);
    pprintf_highlight(pp1, "%s", player_globals.parray[partner].name);
    pprintf_prompt(pp1, " (%s) %s.\n",
          ratstrii(GetRating(&player_globals.parray[partner], type), partner),
          game_str(rated, wt , winc, bt , binc, category, board));
    Bell(pp1);
  }

  check_lists_match (p,p1);

  print_match_rating_info (p,p1,type,rated);

  pprintf_prompt(p1, "You can \"accept\" or \"decline\", or propose different parameters.\n");

  return COM_OK;
}
Esempio n. 16
0
int main(int argc, char *argv[])
{
  struct stat	ffstat;
  char  *inputstr = NULL;
  char  *inbuf = NULL;
  char  *tracktype_str=NULL;
  char  tmpbuf[4096];
  int   inlen = 0, err=0, c=0;
  int   limit_arg = 0;

  if (argc < 2)
    usage(argv[0]);

  while ((c = getopt(argc, argv,"befjt:To:cl:n:s")) != -1)
  {
    switch (c)
    {
    case 'b':
      print_byte_offset=1;
      break;
    case 'e':
      print_epoch_time=1;
      break;
    case 'f':
      print_filename_only=1;
      break;
    case 'j':
      print_julian_time=1;
      break;
    case 'o':
      logfilename=optarg;
      break;
    case 't':
      tracksrch=1;
      tracktype_str=optarg;
      if (atoi(tracktype_str)==1)
        tracktype1=1;
      else if (atoi(tracktype_str)==2)
        tracktype2=1;
      else
        usage(argv[0]);
      break;
    case 'T':
      tracksrch=1;
      tracktype1=1;
      tracktype2=1;
      break;
    case 'c':
    	print_file_hit_count=1;
    	break;
    case 'l':
    	limit_arg = atoi(optarg);
    	if (limit_arg > 0)
    	  limit_file_results = limit_arg;
    	else
    		usage(argv[0]);
    	break;
    case 'n':
    	exclude_extensions = stolower(optarg);
    	break;
    case 's':
    	newstatus = 1;

    	break;
    case 'h':
    default:
      usage(argv[0]);
      break;
    }
  } 

  //do some cleanup to make sure that invalid options don't get combined
  if (logfilename != NULL)
  {
    if (newstatus == 1)
    {
    	print_file_hit_count = 0;
    }
  }
  else
  {
  	newstatus = 0;
  	print_file_hit_count = 0;
  }

  inputstr = argv[optind];
  if (inputstr == NULL)
    usage(argv[0]);

  inlen = strlen(inputstr) + 1;

  if (open_logfile() < 0)
    exit(-1);

  inbuf = (char *)malloc(inlen + 1);

  memset(inbuf, '\0', inlen+1);
  strncpy(inbuf, inputstr, inlen);

  signal_proc();

  init_time = time(NULL);
  printf("\n%s\n", PROG_VER);
  printf("\nLocal start time: %s\n",ctime((time_t *)&init_time));
  if (check_dir(inbuf)) 
  {
#ifdef WINDOWS
    if ((inbuf[strlen(inbuf) - 1]) != '\\')
      inbuf[strlen(inbuf)] = '\\';
#else
    if ((inbuf[strlen(inbuf) - 1]) != '/')
      inbuf[strlen(inbuf)] = '/';
#endif
    proc_dir_list(inbuf);
  }
  else
  {
    err = get_file_stat(inbuf, &ffstat);
    if (err == -1)
    {
      if (errno == ENOENT)
        fprintf(stderr, "File %s not found, can't stat\n", inbuf);
      else
        fprintf(stderr, "Cannot stat file %s; errno=%d\n", inbuf, errno);
      exit (-1);
    }

    if ((ffstat.st_size > 0) && ((ffstat.st_mode & S_IFMT) == S_IFREG))
    {
      memset(&tmpbuf, '\0', 4096);
      if (escape_space(inbuf, tmpbuf) == 0)
      {
        if (logfilename != NULL)
          if (strstr(inbuf, logfilename) != NULL)
          fprintf(stderr, "main: We seem to be hitting our log file, so we'll leave this out of the search -> %s\n", inbuf);
          else
          {
#ifdef DEBUG
            printf("Processing file %s\n",inbuf);
#endif
            ccsrch(inbuf);
          }
        else
        {
#ifdef DEBUG
          printf("Processing file %s\n",inbuf);
#endif
          ccsrch(inbuf);
        }
      }
    }
    else if ((ffstat.st_mode & S_IFMT) == S_IFDIR)
    {
#ifdef WINDOWS
      if ((inbuf[strlen(inbuf) - 1]) != '\\')
        inbuf[strlen(inbuf)] = '\\';
#else
      if ((inbuf[strlen(inbuf) - 1]) != '/')
        inbuf[strlen(inbuf)] = '/';
#endif
      proc_dir_list(inbuf);
    }
    else
      fprintf(stderr, "main: Unknown mode returned-> %x\n", ffstat.st_mode);
  }

  cleanup_shtuff();
  free(inbuf);

  return (0);
}