Exemple #1
0
void conn_delete_by_desc(DESC_DATA *d)
{
	CONN_MAP::iterator	iter, cur_iter;

	for (iter = s_conn_map.begin(); iter != s_conn_map.end(); )
	{
		cur_iter = iter; iter++;

		CONN_DATA	*conn = cur_iter->second;

		if (GET_DESC(conn) == d)
		{
			s_conn_map.erase(cur_iter);
			account_logout(conn);


			if (GET_EVENT(conn))
			{
				event_cancel(GET_EVENT(conn));
				GET_EVENT(conn) = NULL;
			}
			SAFE_FREE(conn);
		}
	}
}
Exemple #2
0
void send_force_logout(CONN_DATA *conn)
{
	DESC_DATA	*desc = GET_DESC(conn);
	if (NULL==desc) return;

	sys_log("FORCE_LOGOUT : %d, %s", GET_ID(conn), GET_LOGIN(conn)?GET_LOGIN(conn):"null");
	packet_force_logout(desc, conn);
}
Exemple #3
0
void packet_login_notice(CONN_DATA *conn)
{
	DESC_DATA	*desc = GET_DESC(conn);
	if (NULL==desc)	return;
	PACKET_DATA	*buf = &desc->packet_buffer;

	packet_header(buf, HEADER_TG_LOGIN_NOTICE, desc->desc_num);
	packet(buf, GET_LOGIN(conn), MAX_LOGIN_LEN);
	packet(buf, encode_4bytes(GET_ON_TIME(conn)), 4);
	packet(buf, encode_4bytes(GET_OFF_TIME(conn)), 4);
}
Exemple #4
0
void packet_teen_notice(CONN_DATA *conn, int hour)
{
	DESC_DATA	*desc = GET_DESC(conn);
	PACKET_DATA	*buf = &desc->packet_buffer;

	packet_header(buf, HEADER_TG_TEEN_NOTICE, desc->desc_num);
	packet(buf, GET_LOGIN(conn), MAX_LOGIN_LEN);
	packet(buf, encode_4bytes(hour), 4);

	sys_log("NOTICE: (login,hour) = (%s, %d)", GET_LOGIN(conn), hour);
}
Exemple #5
0
/*
 * Save a character and inventory.
 * Would be cool to save NPC's too for quest purposes,
 *   some of the infrastructure is provided.
 */
bool save_char_obj( struct char_data *ch )
{
    FILE *fp;
    char  buf     [ MAX_STRING_LENGTH ];
    char  strsave [ MAX_INPUT_LENGTH  ];
    bool  rval = FALSE;

    if ( IS_NPC( ch ) ) // || GET_LEVEL( ch ) < 2 )
      return rval;

    if ( GET_DESC(ch) && GET_DESC(ch)->original )
      ch = GET_DESC(ch)->original;

    // GET_SAVED(ch) = time( 0 );
    /* close down the reserve descriptor -- don't forget to reopen it */
    fclose( fpReserve );

    sprintf( strsave, "%s/%s/%s", PLAYER_DIR,
             player_dir( GET_NAME( ch ) ),
             capitalize( GET_NAME( ch ) ) );

    if ( !( fp = fopen( strsave, "w" ) ) ) {
      sprintf( buf, "save_char_obj: fopen %s: ", GET_NAME( ch ) );
      log( buf );
      perror( strsave );
      rval = FALSE;
    } else {
      fwrite_char( ch, fp );
      if ( ch->carrying )
        fwrite_obj_char( ch, ch->carrying, fp, 0 );
      if ( GET_ALIASES(ch) )
        fwrite_alias( ch, GET_ALIASES(ch), fp );
      fprintf( fp, "#END\n" );
      fclose( fp );
      rval = TRUE;
    }
    fpReserve = fopen( NULL_FILE, "r" );
    return rval;
}
Exemple #6
0
/*
 * Load a char and inventory into a new ch structure.
 */
bool load_char_obj( struct descriptor_data * d, const char * name )
{
  FILE      *fp;
  struct char_data *ch;
  char       strsave [ MAX_INPUT_LENGTH ];
  bool       found;
  char       sorry_player [] =
    "********************************************************\n\r"
    "** One or more of the critical fields in your player  **\n\r"
    "** file were corrupted since you last played.  Please **\n\r"
    "** contact an administrator or programmer to          **\n\r"
    "** investigate the recovery of your characters.       **\n\r"
    "********************************************************\n\r";
  char       sorry_object [] =
    "********************************************************\n\r"
    "** One or more of the critical fields in your player  **\n\r"
    "** file were corrupted leading to the loss of one or  **\n\r"
    "** more of your possessions.                          **\n\r"
    "********************************************************\n\r";
  char       sorry_alias [] =
    "********************************************************\n\r"
    "** One or more of the critical fields in your player  **\n\r"
    "** file were corrupted leading to the loss of one or  **\n\r"
    "** more of your aliases.                              **\n\r"
    "********************************************************\n\r";
  
  ch  				= new_character( TRUE );
  
  d->character			= ch;
  GET_DESC(ch)			= d;
  ch->player.name   = str_dup( name );
  /*
  ch->pcdata->prompt                  = str_dup( daPrompt );
  ch->last_note                       = 0;
  */
  strcpy( GET_PASSWD(ch), "" );
  POOFIN(ch)			= str_dup( "" );
  POOFOUT(ch)			= str_dup( "" );
  GET_TITLE(ch)			= str_dup( "" );
  GET_STR(ch)			= 10;
  GET_ADD(ch)			= 10; 
  GET_INT(ch)			= 10; 
  GET_WIS(ch)			= 10; 
  GET_DEX(ch)			= 10; 
  GET_CON(ch)			= 10; 
  GET_CHA(ch)			= 10; 
  GET_WILL(ch)			= 10; 
  GET_COND(ch, DRUNK)	= 48;
  GET_COND(ch, FULL)	= 48;
  GET_COND(ch, THIRST)	= 48;
  GET_COND(ch, TIRED)	= 48;
  
  // ch->pcdata->switched                = FALSE;
  
  found = FALSE;
  fclose( fpReserve );
  
  /* parsed player file directories by Yaz of 4th Realm */
  /* decompress if .gz file exists - Thx Alander */
  sprintf( strsave, "%s/%s/%s%s", PLAYER_DIR,
           player_dir( GET_NAME(ch) ),
           capitalize( GET_NAME(ch) ), ".gz" );
  
    if ( ( fp = fopen( strsave, "r" ) ) ) {
      char       buf     [ MAX_STRING_LENGTH ];
      
      fclose( fp );
      sprintf( buf, "gzip -dfq %s", strsave );
      system( buf );
    }

    sprintf( strsave, "%s/%s/%s", PLAYER_DIR,
             player_dir( GET_NAME(ch) ),
             capitalize( GET_NAME(ch) ) );

    if ( ( fp = fopen( strsave, "r" ) ) ) {
	char buf[ MAX_STRING_LENGTH ];
	int iNest;

	for ( iNest = 0; iNest < MAX_NEST; iNest++ )
	    rgObjNest[iNest] = NULL;

	found = TRUE;
	for ( ; ; )
	{
	    char *word;
	    char  letter;
	    int   status;

	    letter = fread_letter( fp );
	    if ( letter == '*' )
	    {
		fread_to_eol( fp );
		continue;
	    }

	    if ( letter != '#' )
	    {
              log( "Load_char_obj: # not found." );
              break;
	    }

	    word = fread_word_stat( fp, &status );

	    if ( !str_cmp( word, "PLAYER" ) )
	    {
	        if ( fread_char ( ch, fp ) )
		{
		    sprintf( buf,
			    "Load_char_obj:  %s section PLAYER corrupt.\n\r",
			    name );
		    log( buf );
		    SEND_TO_Q( sorry_player, d );

		    /* 
		     * In case you are curious,
		     * it is ok to leave ch alone for close_socket
		     * to free.
		     * We want to now kick the bad character out as
		     * what we are missing are MANDATORY fields.  -Kahn
		     */
		    SET_BIT( PRF_FLAGS(ch), PLR_DELETED );
		    return TRUE;
		}
	    }
	    else if ( !str_cmp( word, "OBJECT" ) )
	    {
	        if ( !fread_obj_char( ch, fp ) )
		{
		    sprintf( buf,
			    "Load_char_obj:  %s section OBJECT corrupt.\n\r",
			    name );
		    log( buf );
		    SEND_TO_Q( sorry_object, d );
		    return FALSE;
		}
	    }
	    else if ( !str_cmp( word, "ALIAS"    ) ) {
              if ( !fread_alias( ch, fp ) )
              {
                sprintf( buf,
                         "Load_char_obj: %s section ALIAS corrupt.\n\r",
                         name );
                log( buf );
                SEND_TO_Q( sorry_alias, d );
                return FALSE;
              }
            }
	    else if ( !str_cmp( word, "END"    ) ) break;
	    else
	    {
		log( "Load_char_obj: bad section." );
		break;
	    }
	} /* for */

	fclose( fp );
    }

    fpReserve = fopen( NULL_FILE, "r" );

    if ( found )
      rent_adjust( d->character );
    
    return found;
}
Exemple #7
0
int input_login(DESC_DATA *d, const char *data, int plen)
{
	const int	PACKET_LENGTH = 4;

	if (plen < PACKET_LENGTH)
		return 0;

	DWORD	account_id = decode_4bytes((const BYTE*)data);

//	sys_log("LOGIN: %u", account_id);

	/* 기존 정보가 있으면 접속을 끊으라고 알려줌 */
	CONN_DATA	*conn = conn_find(account_id);
	if (conn)
	{
		send_force_logout(conn);
		//conn_delete(GET_ID(conn));

		// 새로운 접속자도 접속을 끊는다.
		{
			PACKET_DATA	*buf = &d->packet_buffer;

			packet_header(buf, HEADER_TG_FORCE_LOGOUT, d->desc_num);
			packet(buf, GET_LOGIN(conn), MAX_LOGIN_LEN);
		}
		return PACKET_LENGTH;
	}

	conn = (CONN_DATA*) calloc(1, sizeof(CONN_DATA));
	GET_ID(conn)	= account_id;
	GET_DESC(conn)	= d;
	GET_EVENT(conn)	= NULL;


	int login_succ = FALSE;
	if (teen_all_flag)
		login_succ = account_login_teen_all(account_id, conn);
	else
		login_succ = account_login(account_id, conn);

	if (FALSE==login_succ)
	{
		//conn_delete(GET_ID(conn));
		SAFE_FREE(conn);
		return PACKET_LENGTH;
	}

	conn_insert(conn);

	if (YES==GET_TEENAGE(conn))
	{
		conn_event_info	*info = (conn_event_info*) calloc(1, sizeof(conn_event_info));
		info->conn = conn;
		GET_EVENT(conn) = event_create(conn_event_func, info, (CHECK_TIME_SEC * PASSES_PER_SEC));
	}
	else
	{
		GET_EVENT(conn) = NULL;
	}

	if (YES==GET_TEENAGE(conn))
	{
		send_login_notice(conn);
		set_notice_step(conn);
		send_notice(conn);
	}

	sys_log("CONN_INSERT : %u, %s", GET_ID(conn), GET_LOGIN(conn));

	return PACKET_LENGTH;
} /* end of input_login() */