Example #1
0
/*
 * 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;
}
Example #2
0
/*
 * 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;
}
Example #3
0
int player_hit(struct player *p, struct game *g) {
	if (player_remove(p, g)) {
		ERR_TRACE();
		return -1;
	}
	if (!p->lives) {
		player_respawn(p);
		if (player_add(p, g)) {
			ERR_TRACE();
			return -1;
		}
	} else {
		if (!--p->lives) {
			SDLNet_TCP_Send(p->client->s, "\11", 1);
			player_free(p);
		} else {
			player_respawn(p);
			if (player_add(p, g)) {
				ERR_TRACE();
				return -1;
			}
		}
	}
	return 0;
}
Example #4
0
/** Stop the server.
 * @param game A game
 * @return TRUE if the game changed from running to stopped
*/
gboolean server_stop(Game * game)
{
	GList *current;

	if (!server_is_running(game))
		return FALSE;

	meta_unregister();

	game->is_running = FALSE;
	if (game->accept_tag) {
		driver->input_remove(game->accept_tag);
		game->accept_tag = 0;
	}
	if (game->accept_fd >= 0) {
		close(game->accept_fd);
		game->accept_fd = -1;
	}

	playerlist_inc_use_count(game);
	current = game->player_list;
	while (current != NULL) {
		Player *player = current->data;
		player_remove(player);
		player_free(player);
		current = g_list_next(current);
	}
	playerlist_dec_use_count(game);

	return TRUE;
}
Example #5
0
/*
 * 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;
}
Example #6
0
/*
 * 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;
}
Example #7
0
/*
 * showcomment
 *
 * Usage: showcomment user
 *
 *   This command will display all of the comments added to the user's account.
 */
int com_showcomment(int p, param_list param)
{
  int p1, connected;

  if (!FindPlayer(p, param[0].val.word, &p1, &connected))
    return COM_OK;
  player_show_comments(p, p1);
  if (!connected)
    player_remove(p1);
  return COM_OK;
}
Example #8
0
/*
 * 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;
}
Example #9
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;
}
Example #10
0
int com_players_rewrite(int p, param_list param)
{

	int pT;
	int c;
	time_t t = time(0);
	DIR *dirp;
	char dname[MAX_FILENAME_SIZE];
	struct dirent *dp;
	d_printf("BICS: Rewriting players data at %s\n", strltime(&t));
	for (c = 'a'; c <= 'z'; c++)
	{
		sprintf(dname, "%s/%c", PLAYER_DIR, c);
		dirp = opendir(dname);
		if (!dirp)
			continue;
		for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
		{

			if (dp->d_name[0] == '.')
				continue;

			pprintf(p, "%s\n", dp->d_name);

				{
				pT = player_new();
				if (player_read(pT, dp->d_name) == 0)
				{


					//player_save_DB(pT);
					pprintf(p,"BICS: Player %s saved.\n", player_globals.parray[pT].login);

				}
				else
				{
					pprintf(p,"BICS: Problem reading player %s.\n", dp->d_name);
				}
					player_remove(pT);
				}

		}

		closedir(dirp);
	}
	return COM_OK;
}
Example #11
0
/*
 * 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;
}
Example #12
0
/*
 * 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;
}
Example #13
0
/*
 * 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;
}
Example #14
0
static void Add__to__queue(void **queue, void **player){
    struct command com;
    queue_t * q = queue_new();
    player_t * pl[1];
    pl[0] = player_new('w', 's', 'd', 'a', 'f');
    char index = 'w';
    char * moves;
    moves = player_get_moves(pl[0]);
    for (int i = 0; i < 5; i++){
    if (moves[i] == index)
                    {
                        i++;
                        com.command = i;
                        com.players = pl[i];
                        assert_int_equal(queue_add(q, com),KK);
                    }
    }
    queue_remove(&q);
    player_remove(&pl);
}
Example #15
0
static void Player__command__ErrorCommand(void **queue, void **player){
    struct command com;
    queue_t * q = queue_new();
    player_t * pl[1];
    pl[0] = player_new('w', 's', 'd', 'a', 'f');
    char index = 'y';
    char * moves;
    moves = player_get_moves(pl[0]);
    for (int i = 0; i < 5; i++){
    if (moves[i] == index)
                    {
                        i++;
                        com.command = i;
                        com.players = pl[i];
                        queue_add(q, com);
                        //assert_int_equal(i,);
                    }
    }
    assert_int_equal(queue_size(q),0);
    queue_remove(&q);
    player_remove(&pl);
}
Example #16
0
void RaptorServer::DroppedClient( ConnectedClient *client )
{
	client->Synchronized = false;
	
	Player *player = Data.GetPlayer( client->PlayerID );
	
	// Tell other clients about the removed player.
	Packet player_remove( Raptor::Packet::PLAYER_REMOVE );
	player_remove.AddUShort( client->PlayerID );
	Net.SendAllExcept( &player_remove, client );
	
	if( player )
	{
		// Tell other players to display a message about the removed player.
		Packet message( Raptor::Packet::MESSAGE );
		message.AddString( (player->Name + " has left the game.").c_str() );
		Net.SendAllExcept( &message, client );
	}
	
	player = NULL;
	Data.RemovePlayer( client->PlayerID );
}
Example #17
0
static void Double__queue(void **queue, void **player){
    struct command com;
    queue_t * q = queue_new();
    player_t * pl[1];
    pl[0] = player_new('w', 's', 'd', 'a', 'f');
    char index = 'w';
    char * moves;
    moves = player_get_moves(pl[0]);
    for (int a = 0; a < 200; a++){
    for (int i = 0; i < 5; i++){
    if (moves[i] == index)
                    {
                        i++;
                        com.command = i;
                        com.players = pl[i];
                        queue_add(q, com);
                    }
    }
    }
    assert_int_equal(queue_size(q),200);
    queue_remove(&q);
    player_remove(&pl);
}
Example #18
0
/*thread responsible for receiving data*/
DWORD WINAPI gs_listener(void *data){
	int iResult;
	int iSendResult;
	int recvbuflen;

	SOCKET ConnectSocket2 = (SOCKET)data; //////////////////////////////////////doesnt work?!!!

	/*receive until connection closure*/
	while(1){
		//if(ConnectSocket2==ConnectSocket) printf("yes"); //!!!!!!!!!!!!prints "yes"
		//else printf("no");
		//Sleep(500);
		//to solve this:
		//1. move this swtich to main()
		//2. use non-blocking mode
		//3. use this thread to pass input to global buffor
		//4. read in main() from global buffor and send it from there
		//5. now both sending and receiving works
		//OR SIMPLY
		//somehow make this thread to be able to use this socket
		iResult = recv(ConnectSocket2, recvbuf, recvbuflen, 0);
		if(iResult>0){
			switch(recvbuf[0]){
				case 0x00:
					printf("Couldnt move to %d %d, try once again.\n", recvbuf[1], recvbuf[2]);
					break;
				case 0x01:
					printf("Player %d has made a move.\n", gamerooms[0].canmove);
					gamerooms[0].board[recvbuf[1]*M+recvbuf[2]] = gamerooms[0].players[gamerooms[0].canmove].mark;
					gamerooms[0].canmove = (gamerooms[0].canmove+1)%gamerooms[0].playersnum;
					board_print();
					dead_marks_delete(recvbuf);
					board_print();
					break;
				case 0x02:
					printf("Player %d got a point.\n", gamerooms[0].canmove);
					gamerooms[0].board[recvbuf[1]*M+recvbuf[2]] = gamerooms[0].players[gamerooms[0].canmove].mark;
					++gamerooms[0].players[gamerooms[0].canmove].points;
					gamerooms[0].canmove = (gamerooms[0].canmove+1)%gamerooms[0].playersnum;
					board_print();
					dead_marks_delete(recvbuf);
					board_print();
					break;
				case 0x06:
					printf("A new player has connected to the gameroom.\n");
					newplayer_get(recvbuf);
					break;
				case 0x07:
					printf("Connected to a new gameroom!\n");
					gameroom_get(recvbuf);
					break;
				case 0x08:
					printf("Player %d has disconnected.\n", recvbuf[1]);
					player_remove(0, recvbuf[1]);
					break;
				case 0x09:
					printf("Couldn't move to %d gameroom.\n", recvbuf[1]);
					break;
				default: break;
			}
		}else{
			printf("\n\nconnection error\n");
			break;
		}//else printf("socket failed with error: %ld\n", WSAGetLastError());
	}

	gs_alive = 0;
	/* cleanup will be handled by main() */
	return 0;
}
Example #19
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;
}
Example #20
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
}
Example #21
0
/*
 * adjudicate
 *
 * Usage: adjudicate white_player black_player result
 *
 *   Adjudicates a saved (stored) game between white_player and black_player.
 *   The result is one of: abort, draw, white, black.  "Abort" cancels the game
 *   (no win, loss or draw), "white" gives white_player the win, "black" gives
 *   black_player the win, and "draw" gives a draw.
 */
int com_adjudicate(int p, param_list param)
{
  int wp, wconnected, bp, bconnected, g, inprogress, confused = 0;

  if (!FindPlayer(p, param[0].val.word, &wp, &wconnected))
    return COM_OK;
  if (!FindPlayer(p, param[1].val.word, &bp, &bconnected)) {
    if (!wconnected)
     player_remove(wp);
    return COM_OK;
  }

  inprogress = ((player_globals.parray[wp].game >=0) &&(player_globals.parray[wp].opponent == bp));

  if (inprogress) {
    g = player_globals.parray[wp].game;
  } else {
    g = game_new();
    if (game_read(g, wp, bp) < 0) {
      confused = 1;
      pprintf(p, "There is no stored game %s vs. %s\n", player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else {
      game_globals.garray[g].white = wp;
      game_globals.garray[g].black = bp;
    }
  }
  if (!confused) {
    if (strstr("abort", param[2].val.word) != NULL) {
      game_ended(g, WHITE, END_ADJABORT);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been aborted.",
	       player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been aborted.",
	       player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else if (strstr("draw", param[2].val.word) != NULL) {
      game_ended(g, WHITE, END_ADJDRAW);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a draw", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a draw", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else if (strstr("white", param[2].val.word) != NULL) {
      game_ended(g, WHITE, END_ADJWIN);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a win", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a loss", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else if (strstr("black", param[2].val.word) != NULL) {
      game_ended(g, BLACK, END_ADJWIN);
      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a loss", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a win", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else {
      confused = 1;
      pprintf(p, "Result must be one of: abort draw white black\n");
    }
  }
  if (!confused) {
    pprintf(p, "Game adjudicated.\n");
    if (!inprogress) {
      game_delete(wp, bp);
    } else {
      return (COM_OK);
    }
  }
  game_remove(g);
  if (!wconnected)
    player_remove(wp);
  if (!bconnected)
    player_remove(bp);
  return COM_OK;
}
Example #22
0
/* 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;
}