// cPlayerInfo.cpp: implementation of the cPlayerInfo class.
//
//////////////////////////////////////////////////////////////////////

#include <string.h>
#include "cPlayerInfo.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

cPlayerInfo::cPlayerInfo(){

}

cPlayerInfo::~cPlayerInfo(){

}

bool cPlayerInfo::Load(FILE *fp){
	return fread(this, sizeof(cPlayerInfo), 1, fp) == 1;
}

bool cPlayerInfo::Save(FILE *fp){
	return fwrite(this, sizeof(cPlayerInfo), 1, fp) == 1;
}

bool cPlayerInfo::SetName(char *pName){
	// 먼저 이름으로 사용해도 좋을 것인지를 검사한다.
	int len;

	if(pName == NULL) return false;
	len = strlen(pName);
	if(len < 1 || len > 12) return false;

	strncpy(Name, pName, 12);
	return true;
}

bool cPlayerInfo::SetPassword(char *pPassword){
	// 암호로 적당하다면 기록한다.
	int len;
	if(pPassword == NULL) return false;
	len = strlen(pPassword);
	if(len < 4 || len > 12) return false;

	strncpy(Password, pPassword, 12);
	return true;
}

bool cPlayerInfo::IsSameName(char *p){
	return strncmp(Name, p, 12) == 0;
}

bool cPlayerInfo::IsSamePassword(char *p){
	return strncmp(Password, p, 12) == 0;
}
