コード例 #1
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asetrealname
 *
 * Usage:  asetrealname user newname
 *
 *   This command sets the user's real name (as displayed to admins on finger
 *   notes) to "newname".
 */
int com_asetrealname(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int p1, connected;

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;

  if (!check_admin2(p, p1)) {
    pprintf(p, "You can only set real names for players below your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (player_globals.parray[p1].fullName)
    free(player_globals.parray[p1].fullName);
  if (param[1].type == TYPE_NULL) {
    player_globals.parray[p1].fullName = NULL;
    pprintf(p, "Real name for %s removed\n", player_globals.parray[p1].name);
  } else {
    player_globals.parray[p1].fullName = strdup(param[1].val.word);
    pprintf(p, "Real name of %s changed to \"%s\".\n", player_globals.parray[p1].name, param[1].val.word);
  }
  player_save(p1);
  if (connected) {
    if (param[1].type == TYPE_NULL) {
      pprintf_prompt(p1, "\n\n%s has removed your real name.\n\n", pp->name);
    } else {
      pprintf_prompt(p1, "\n\n%s has changed your real name.\n\n", pp->name);
    }
  } else {
    player_remove(p1);
  }
  return COM_OK;
}
コード例 #2
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asethandle
 *
 * Usage: asethandle oldname newname
 *
 *   This command changes the handle of the player from oldname to
 *   newname.  The various player information, messages, logins, comments
 *   and games should be automatically transferred to the new account.
 */
int com_asethandle(int p, param_list param)
{
  char *player = param[0].val.word;
  char *newplayer = param[1].val.word;
  char playerlower[MAX_LOGIN_NAME], newplayerlower[MAX_LOGIN_NAME];
  int p1;

  strcpy(playerlower, player);
  stolower(playerlower);
  strcpy(newplayerlower, newplayer);
  stolower(newplayerlower);
  if (player_find_bylogin(playerlower) >= 0) {
    pprintf(p, "A player by that name is logged in.\n");
    return COM_OK;
  }
  if (player_find_bylogin(newplayerlower) >= 0) {
    pprintf(p, "A player by that new name is logged in.\n");
    return COM_OK;
  }
  p1 = player_new();
  if (player_read(p1, playerlower)) {
    pprintf(p, "No player by the name %s is registered.\n", player);
    player_remove(p1);
    return COM_OK;
  } else {
	  if (!check_admin2(p, p1)) {
		  pprintf(p, "You can't set handles for an admin with a level higher than or equal to yourself.\n");
		  player_remove(p1);
		  return COM_OK;
	  }
  }
  player_remove(p1);

  p1 = player_new();
  if ((!player_read(p1, newplayerlower)) && (strcmp(playerlower, newplayerlower))) {
    pprintf(p, "Sorry that handle is already taken.\n");
    player_remove(p1);
    return COM_OK;
  }
  player_remove(p1);

  if ((!player_rename(playerlower, newplayerlower)) && (!player_read(p1, newplayerlower))) {
    pprintf(p, "Player %s renamed to %s.\n", player, newplayer);
    free(player_globals.parray[p1].name);
    player_globals.parray[p1].name = strdup(newplayer);
    player_save(p1);
    /*if (player_globals.parray[p1].s_stats.rating > 0)
      UpdateRank(TYPE_STAND, newplayer, &player_globals.parray[p1].s_stats, player);
    if (player_globals.parray[p1].z_stats.rating > 0)
      UpdateRank(TYPE_CRAZYHOUSE, newplayer, &player_globals.parray[p1].z_stats, player);
    if (player_globals.parray[p1].w_stats.rating > 0)
      UpdateRank(TYPE_WILD, newplayer, &player_globals.parray[p1].w_stats, player);*/
  } else {
    pprintf(p, "Asethandle failed.\n");
  }
  player_remove(p1);
  return COM_OK;
}
コード例 #3
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asetpasswd
 *
 * Usage: asetpasswd player {password,*}
 *
 *   This command sets the password of the player to the password given.
 *   If '*' is specified then the player's account is locked, and no password
 *   will work until a new one is set by asetpasswd.
 *
 *   If the player is connected, he is told of the new password and the name
 *   of the admin who changed it, or likewise of his account status.  An
 *   email message is mailed to the player's email address as well.
 */
int com_asetpasswd(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int p1, connected;
  char subject[400], text[10100];
  char salt[3];

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;

  if (!check_admin2(p, p1)) {
    pprintf(p, "You can only set password for players below your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (!CheckPFlag(p1, PFLAG_REG)) {
    pprintf(p, "You cannot set the password of an unregistered player!\n");
    return COM_OK;
  }
  if (player_globals.parray[p1].passwd)
    free(player_globals.parray[p1].passwd);
  if (param[1].val.word[0] == '*') {
    player_globals.parray[p1].passwd = strdup(param[1].val.word);
    pprintf(p, "Account %s locked!\n", player_globals.parray[p1].name);
    sprintf(text, "Password of %s is now useless.  Your account at our"
                  " BICS has been locked.\n", player_globals.parray[p1].name);
      pprintf(p, "Please leave a comment to explain why %s's account"
                 " was locked.\n", player_globals.parray[p1].name);
      pcommand(p, "addcomment %s Account locked.\n", player_globals.parray[p1].name);
  } else {
    salt[0] = 'a' + random() % 26;
    salt[1] = 'a' + random() % 26;
    salt[2] = '\0';
    player_globals.parray[p1].passwd = strdup(chessd_crypt(param[1].val.word, salt));
    sprintf(text, "Password of %s changed to \"%s\".\n", player_globals.parray[p1].name, param[1].val.word);
    pprintf(p, "%s", text);
  }
  if (param[1].val.word[0] == '*') {
    sprintf(subject, "CHESSD: %s has locked your account.", pp->name);
    if (connected)
      pprintf_prompt(p1, "\n%s\n", subject);
  } else {
    sprintf(subject, "CHESSD: %s has changed your password.", pp->name);
    if (connected)
      pprintf_prompt(p1, "\n%s\n", subject);
  }
  mail_string_to_address(player_globals.parray[p1].emailAddress, subject, text);
  player_save(p1);
  if (!connected)
    player_remove(p1);
  return COM_OK;
}
コード例 #4
0
ファイル: save.c プロジェクト: isfos/naev
/**
 * @brief Saves all the player's game data.
 *
 *    @param writer XML writer to use.
 *    @return 0 on success.
 */
static int save_data( xmlTextWriterPtr writer )
{
   /* the data itself */
   if (diff_save(writer) < 0) return -1; /* Must save first or can get cleared. */
   if (player_save(writer) < 0) return -1;
   if (missions_saveActive(writer) < 0) return -1;
   if (var_save(writer) < 0) return -1;
   if (pfaction_save(writer) < 0) return -1;
   if (hook_save(writer) < 0) return -1;
   if (space_sysSave(writer) < 0) return -1;

   return 0;
}
コード例 #5
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * addcomment
 *
 * Usage: addcomment user comment
 *
 *   Places "comment" in the user's comments.  If a user has comments, the
 *   number of comments is indicated to admins using the "finger" command.
 *   The comments themselves are displayed by the "showcomments" command.
 */
int com_addcomment(int p, param_list param)
{
  int p1, connected;

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;

  if (player_add_comment(p, p1, param[1].val.string)) {
    pprintf(p, "Error adding comment!\n");
  } else {
    pprintf(p, "Comment added for %s.\n", player_globals.parray[p1].name);
    player_save(p1);
  }
  if (!connected)
    player_remove(p1);
  return COM_OK;
}
コード例 #6
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asetemail
 *
 * Usage: asetemail player [address]
 *
 *   Sets the email address of the player to the address given.  If the
 *   address is omited, then the player's email address is cleared.  The
 *   person's email address is revealed to them when they use the "finger"
 *   command, but no other users -- except admins -- will have another
 *   player's email address displayed.
 */
int com_asetemail(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int p1, connected;
  char *oldemail;

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;

  if (!check_admin2(p, p1)) {
    pprintf(p, "You can only set email addr for players below your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (player_globals.parray[p1].emailAddress) {
    oldemail = strdup(player_globals.parray[p1].emailAddress);
    free(player_globals.parray[p1].emailAddress);
  } else {
    oldemail = strdup("");
  }

  if (param[1].type == TYPE_NULL) {
    player_globals.parray[p1].emailAddress = NULL;
    pprintf(p, "Email address for %s removed\n", player_globals.parray[p1].name);
    pcommand(p, "addcomment %s Email address removed.\n", player_globals.parray[p1].name);

  } else {
    player_globals.parray[p1].emailAddress = strdup(param[1].val.word);
    pprintf(p, "Email address of %s changed to \"%s\".\n", player_globals.parray[p1].name, param[1].val.word);
    pcommand(p, "addcomment %s Email address changed from %s to %s.\n", player_globals.parray[p1].name, oldemail, player_globals.parray[p1].emailAddress);
  }
  free(oldemail);
  player_save(p1);
  if (connected) {
    if (param[1].type == TYPE_NULL) {
      pprintf_prompt(p1, "\n\n%s has removed your email address.\n\n", pp->name);
    } else {
      pprintf_prompt(p1, "\n\n%s has changed your email address.\n\n", pp->name);
    }
  } else {
    player_remove(p1);
  }
  return COM_OK;
}
コード例 #7
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asetbug
 *
 * Usage: asetbug handle rating won lost drew RD
 *
 *   This command allows admins to set a user's statistics for Bughouse
 *   games.  The parameters are self-explanatory: rating, # of wins,
 *   # of losses, # of draws, and ratings deviation.
 */
int com_asetbug(int p, param_list param)
{
  int p1, connected;

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;

  if (CheckPFlag(p1, PFLAG_REG)) {
    SetRating(p1, param, &player_globals.parray[p1].bug_stats);
    player_save(p1);
    pprintf(p, "Bughouse rating for %s modified.\n", player_globals.parray[p1].name);
  } else
    pprintf(p, "%s is unregistered. Can't modify rating.\n", player_globals.parray[p1].name);

  if (!connected)
    player_remove(p1);
  return COM_OK;
}
コード例 #8
0
ファイル: save.c プロジェクト: Kinniken/NoxImperii
/**
 * @brief Saves all the player's game data.
 *
 *    @param writer XML writer to use.
 *    @return 0 on success.
 */
static int save_data( xmlTextWriterPtr writer )
{
   /* the data itself */
   if (diff_save(writer) < 0) return -1; /* Must save first or can get cleared. */
   if (player_save(writer) < 0) return -1;
   if (missions_saveActive(writer) < 0) return -1;
   if (events_saveActive(writer) < 0) return -1;
   if (news_saveArticles( writer ) < 0) return -1;
   if (var_save(writer) < 0) return -1;
   if (pfaction_save(writer) < 0) return -1;
   if (hook_save(writer) < 0) return -1;

   if (space_transientAssetsSave(writer) < 0) return -1;
   if (space_transientSystemsSave(writer) < 0) return -1;
   if (space_transientJumpsSave(writer) < 0) return -1;
   if (space_customData(writer) < 0) return -1;
   if (space_sysSave(writer) < 0) return -1;
   return 0;
}
コード例 #9
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asetblitz
 *
 * Usage: asetblitz handle rating won lost drew RD
 *
 *   This command allows admins to set a user's statistics for Blitz games.
 *   The parameters are self-explanatory: rating, # of wins, # of losses,
 *   # of draws, and ratings deviation.
 */
int com_asetzh(int p, param_list param)
{
  int p1, connected;

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;

  if (CheckPFlag(p1, PFLAG_REG)) {
      SetRating(p1, param, &player_globals.parray[p1].z_stats);
      player_save(p1);
      UpdateRank(TYPE_CRAZYHOUSE, player_globals.parray[p1].name, &player_globals.parray[p1].z_stats,
	     player_globals.parray[p1].name);
  } else
    pprintf(p, "%s is unregistered. Can't modify rating.\n", player_globals.parray[p1].name);

  if (!connected)
    player_remove(p1);
  return COM_OK;
}
コード例 #10
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * asetadmin
 *
 * Usage: asetadmin player AdminLevel
 *
 *   Sets the admin level of the player with the following restrictions.
 *   1. You can only set the admin level of players lower than yourself.
 *   2. You can only set the admin level to a level that is lower than
 *      yourself.
 */
int com_asetadmin(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int p1, connected, oldlevel;

  if (!FindPlayer(p, param[0].val.word,&p1, &connected))
    return COM_OK;

  if (!check_admin2(p, p1)) {
    pprintf(p, "You can only set adminlevel for players below your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (!strcmp(player_globals.parray[p1].login, pp->login)) {
    pprintf(p, "You can't change your own adminlevel.\n");
    return COM_OK;
  }
  if (!check_admin(p, param[1].val.integer+1)) {
    pprintf(p, "You can't promote someone to or above your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (param[1].val.integer < 0)
  {
    pprintf(p, "Level must be positive.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  oldlevel = player_globals.parray[p1].adminLevel;
  player_globals.parray[p1].adminLevel = param[1].val.integer;
  pprintf(p, "Admin level of %s set to %d.\n", player_globals.parray[p1].name, player_globals.parray[p1].adminLevel);
  player_save(p1);
  if (connected) {
    pprintf_prompt(p1, "\n\n%s has set your admin level to %d.\n\n", pp->name, player_globals.parray[p1].adminLevel);
  } else {
    player_remove(p1);
  }
  return COM_OK;
}
コード例 #11
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * 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;
}
コード例 #12
0
ファイル: adminproc.c プロジェクト: SKAcz/bics-current
/*
 * 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
}
コード例 #13
0
ファイル: main.c プロジェクト: chadhao/Programming1
int main(int argc, char* argv[])
{
	struct deck thisDeck;
	struct player thisPlayer;
	struct game thisGame;
	int inputValidity;
	int menu;
	int game;
	int load = 0;
	
	//Not Working!!! card_init_deck(&thisDeck);
	
	//This is the exact same algorithm used in card.c and it works great here!!! Why!!!
	for (int k = 0; k < 4; k++)
	{
		for (int i = 0; i < 13; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				strcpy(thisDeck.oneCard[k*52+i*4+j].rank, ranks[i]);
				strcpy(thisDeck.oneCard[k*52+i*4+j].suit, suits[j]);
				thisDeck.oneCard[k*52+i*4+j].value = value[i];
			}
		}
	}
	
	card_shuffle(&thisDeck);
	thisPlayer.chip = 0;
	
	system("clear");
		
	while (1)
	{
		printf("\n\n**********BlackJack**********\n\n");
		printf(" 1. Play\n");
		printf(" 2. Load\n");
		printf(" 3. Player status\n");
		printf(" 4. Exit\n\n");
		printf("*****************************\n\n");
		while(1)
		{
			printf("Please enter menu number: ");
			inputValidity = scanf("%d", &menu);
			while(getchar()!='\n'){}
			if (inputValidity)
			{
				if (menu < 1 || menu > 4)
				{
					printf("Please select from menu!\n");
				}
				else
				{
					break;
				}
			}
			else
			{
				printf("Please enter a NUMBER!\n");
			}
		}
		
		if (menu == 4)
		{
			player_save(&thisPlayer);
			printf("Thanks for playing! Bye!\n");
			break;
		}
		else if (menu == 3)
		{
			if (thisPlayer.name == NULL)
			{
				printf("No player record.\n");
				continue;
			}
			player_status(&thisPlayer);
			continue;
		}
		else if (menu == 2)
		{
			player_load(&thisPlayer);
			continue;
		}
		else
		{
			if (thisPlayer.chip == 0)
			{
				player_name(&thisPlayer);
				player_chip(&thisPlayer);
			}
			printf("Welcome %s!\nHave fun!\n\n", thisPlayer.name);
			
			while(1)
			{
				//Deal initial cards
				game_init(&thisGame);
				if (thisDeck.cardNow > 180)
				{
					printf("\n\nShuffling...\n\n");
					card_shuffle(&thisDeck);
				}
				if (thisPlayer.chip <= 0)
				{
					printf("You are penniless!\n");
					thisPlayer.win = 0;
					thisPlayer.lose = 0;
					thisPlayer.push = 0;
					break;
				}
				game_bet(1, &thisPlayer, &thisGame);
				printf("\nDealer is dealing the cards...\n\n");
				game_deal_card(2, &thisGame, &thisDeck);
				game_deal_card(1, &thisGame, &thisDeck);
				game_deal_card(2, &thisGame, &thisDeck);
				game_deal_card(1, &thisGame, &thisDeck);
				printf("Dealer shows %s of %s\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].rank, thisDeck.oneCard[thisGame.dealer_inhand[0]].suit);
				printf("Dealer\'s point is %d\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].value);
				printf("Your cards: ");
				game_print_card(2, &thisGame, &thisDeck);
				printf("\n");
				printf("Your point is %d\n", game_totalvalue(2, &thisGame, &thisDeck));
				
				//Check if dealer shows an Ace
				if (thisDeck.oneCard[thisGame.dealer_inhand[0]].value == 11)
				{
					game_bet(2, &thisPlayer, &thisGame);
					if (game_totalvalue(1, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) != 4)
					{
						if (thisGame.is_insured)
						{
							thisPlayer.chip += thisGame.bet;
						}
						thisPlayer.lose++;
						printf("Dealer\'s cards: ");
						game_print_card(1, &thisGame, &thisDeck);
						printf("\n");
						printf("Dealer\'s point is %d\n", game_totalvalue(1, &thisGame, &thisDeck));
						printf("Dealer is BlackJack!\n");
						if (game_end())
						{
							break;
						}
						else
						{
							continue;
						}
					}
					else if (game_totalvalue(2, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) == 4)
					{
						thisPlayer.chip += thisGame.bet;
						thisPlayer.push++;
						printf("Push!\n");
					}
				}
				
				game_play(&thisPlayer, &thisDeck, &thisGame);
				if (game_end())
				{
					break;
				}
				continue;
			}
			continue;
		}
	}
	
	return 0;
}
コード例 #14
0
ファイル: lists.c プロジェクト: SKAcz/bics-current
/* add or subtract something to/from a list */
int list_addsub(int p, char* list, char* who, int addsub)
{
  struct player *pp = &player_globals.parray[p];
  int p1, connected, loadme, personal, ch;
  char *listname, *member, junkChar;
  struct List *gl;
  char *yourthe, *addrem;

  gl = list_findpartial(p, list, addsub);
  if (!gl)
    return COM_OK;

  personal = ListArray[gl->which].rights == P_PERSONAL;
  loadme = (gl->which != L_FILTER) && (gl->which != L_REMOVEDCOM) && (gl->which != L_CHANNEL);
  listname = ListArray[gl->which].name;
  yourthe = personal ? "your" : "the";
  addrem = (addsub == 1) ? "added to" : "removed from";

  if (loadme) {
    if (!FindPlayer(p, who, &p1, &connected)) {
      if (addsub == 1)
        return COM_OK;
      member = who;		/* allow sub removed/renamed player */
      loadme = 0;
    } else
      member = player_globals.parray[p1].name;
  } else {
    member = who;
  }

  if (addsub == 1) {		/* add to list */

   if (gl->which == L_CHANNEL) {

     if (sscanf (who,"%d%c",&ch, &junkChar) == 1 && ch >= 0 && ch < 255) {
       if ((ch == 0) && (!in_list(p,L_ADMIN,pp->name))) {
         pprintf(p, "Only admins may join channel 0.\n");
         return COM_OK;
       }
     } else {
         pprintf (p,"The channel to add must be a number between 0 and %d.\n",MAX_CHANNELS - 1);
         return COM_OK;
  	}
  }
  if (in_list(p, gl->which, member)) {
     pprintf(p, "[%s] is already on %s %s list.\n", member, yourthe, listname);
     if (loadme && !connected)
       player_remove(p1);
     return COM_OK;
    }
    if (list_add(p, gl->which, member)) {
      pprintf(p, "Sorry, %s %s list is full.\n", yourthe, listname);
      if (loadme && !connected)
	player_remove(p1);
      return COM_OK;
    }
  } else if (addsub == 2) {	/* subtract from list */
    if (!in_list(p, gl->which, member)) {
      pprintf(p, "[%s] is not in %s %s list.\n", member, yourthe, listname);
      if (loadme && !connected)
	player_remove(p1);
      return COM_OK;
    }
    list_sub(p, gl->which, member);
  }
  pprintf(p, "[%s] %s %s %s list.\n", member, addrem, yourthe, listname);

  if (!personal) {
    FILE *fp;
    char filename[MAX_FILENAME_SIZE];

    switch (gl->which) {
    case L_MUZZLE:
    case L_CMUZZLE:
    case L_C1MUZZLE:
    case L_C24MUZZLE:
    case L_C46MUZZLE:
    case L_C49MUZZLE:
    case L_C50MUZZLE:
    case L_C51MUZZLE:
    case L_ABUSER:
    case L_BAN:
    case L_NOTEBAN:
    case L_RATEBAN:
      pprintf(p, "Please leave a comment to explain why %s was %s the %s list.\n", member, addrem, listname);
      pcommand(p, "addcomment %s %s %s list.\n", member, addrem, listname);
      break;
    case L_COMPUTER:
      /*if (player_globals.parray[p1].z_stats.rating > 0)
	UpdateRank(TYPE_CRAZYHOUSE, member, &player_globals.parray[p1].z_stats, member);
      if (player_globals.parray[p1].s_stats.rating > 0)
	UpdateRank(TYPE_STAND, member, &player_globals.parray[p1].s_stats, member);
      if (player_globals.parray[p1].w_stats.rating > 0)
	UpdateRank(TYPE_WILD, member, &player_globals.parray[p1].w_stats, member);*/
      break;
    case L_ADMIN:
      if (addsub == 1) {	/* adding to list */
	player_globals.parray[p1].adminLevel = 10;
	pprintf(p, "%s has been given an admin level of 10 - change with asetadmin.\n", member);
      } else {
	player_globals.parray[p1].adminLevel = 0;
      }
      break;
    case L_FILTER:
    case L_REMOVEDCOM:
    default:
      break;
    }

    if (loadme && connected)
        pprintf_prompt(p1, "You have been %s the %s list by %s.\n",
                                    addrem, listname, pp->name);

    sprintf(filename, "%s/%s", LISTS_DIR, listname);
    fp = fopen_s(filename, "w");
    if (fp == NULL) {
      d_printf( "Couldn't save %s list.\n", listname);
    } else {
      int i;
      for (i = 0; i < gl->numMembers; i++)
	fprintf(fp, "%s\n", gl->m_member[i]);
      fclose(fp);
    }
  }
  if (loadme || (gl->which == L_ADMIN)) {
    player_save(p1);
  }
  if (loadme && !connected) {
    player_remove(p1);
  }
  return COM_OK;
}