コード例 #1
0
void CharacterCreationThread::onCheckNameAvailabilityRequest(const mp::Request *request)
{
	mp::Console::debugprintln("Received CheckNameAvailability request");
	ASSERT(request->getType() == mp::RequestType::CHECK_NAME_AVAILABILITY);
	const mp::RequestCheckNameAvailability *checkRequest = dynamic_cast<const mp::RequestCheckNameAvailability *>(request);
	ASSERT(checkRequest != NULL);
	if (isNameAvailable(checkRequest->getFirstName(), checkRequest->getLastName()))
	{
		mp::Console::debugprintln("Name available");
		mp::ResponseCheckNameAvailability::ResponseBody checkBody;
		checkBody.isAvailable = true;
		mp::Response *response = mp::Response::create(mp::ResponseType::CHECK_NAME_AVAILABILITY, &checkBody);
		mClient->tcpSocket()->sendResponse(response);
		mp::Response::destroy(response);
	}
	else
	{
		mp::Console::debugprintln("Name unavailable");
		mp::ResponseCheckNameAvailability::ResponseBody checkBody;
		checkBody.isAvailable = false;
		mp::Response *response = mp::Response::create(mp::ResponseType::CHECK_NAME_AVAILABILITY, &checkBody);
		mClient->tcpSocket()->sendResponse(response);
		mp::Response::destroy(response);
	}
}
コード例 #2
0
void MaterialManager::addMaterialsFrom(std::string materialFileName)
{
	std::ifstream materialFile(materialFileName);

	ErrorLog * elInst = ErrorLog::getInstance();

	if (!materialFile.good())
	{
		elInst->logFatalError("Couldn't open: " + materialFileName);
	}

	// TextureManager * tmInstance = TextureManager::getInstance();

	// No Textures!


	std::string currentBit = "";
	NamedMaterial * tmpM = nullptr;
	while (!materialFile.eof())
	{
		materialFile >> currentBit;
		if (currentBit == "newmtl")
		{
			if (tmpM != nullptr)
			{
				m_materials.push_back(tmpM);
			}
			tmpM = new NamedMaterial();
			materialFile >> tmpM->Name;

			if (!isNameAvailable(tmpM->Name))
			{
				// message box about the name conflict
				
				elInst->logMinorError("Material name conflict, " + tmpM->Name + " already defined in the material manager (this is to be expected if the models use the same material, the first difinition encountered will be used)");


				std::string skipedData = "";
				while (skipedData != "newmtl")
				{
					materialFile >> skipedData;
					// could resch the end of the file
					if (materialFile.eof())
					{
						delete tmpM;
						tmpM = nullptr;
						break;
						break;
					}
				}

				delete tmpM;
				tmpM = nullptr;


				tmpM = new NamedMaterial();
				materialFile >> tmpM->Name;
			}
		}
		else if (currentBit == "Ka")
コード例 #3
0
void CharacterCreationThread::onCreateCharacterRequest(const mp::Request *request)
{
	mp::Console::debugprintln("Received CreateCharacter request");
	ASSERT(request->getType() == mp::RequestType::CREATE_CHARACTER);
	const mp::RequestCreateCharacter *createRequest = dynamic_cast<const mp::RequestCreateCharacter *>(request);
	ASSERT(createRequest != NULL);
	if (isNameAvailable(createRequest->getFirstName(), createRequest->getLastName()))
	{
		mp::Console::debugprintln("Name available, creating character");

		// Check if max
		bool isFull = false;
		std::stringstream checkMax;
		checkMax << "SELECT COUNT(ID_CHAR) AS NB_CHAR FROM T_EO_CHAR WHERE ID_USER = "******" LIMIT 1";
		MysqlResult *checkRes = mSQLManager->query(checkMax.str().c_str());
		checkRes->first();
		int nbChars = checkRes->getInt("NB_CHAR");
		mSQLManager->clearResult(checkRes);
		if (nbChars >= MAX_CHARACTERS)
			isFull = true;

		if (!isFull)
		{
			// Create character
			std::stringstream query;
			if (::strlen(createRequest->getLastName()) == 0)
			{
				query << "INSERT INTO T_EO_CHAR(ID_USER, ID_CHAR_POS, CHAR_FNAME, CHAR_LNAME, BO_MALE, "
					<< "CHAR_SIZE, HAIR_TYPE, HEAD_TYPE, BODY_TYPE, CHAR_ORDER) "
					<< "VALUES(" << mAccountId << ",  NULL, '" << createRequest->getFirstName() << "', NULL, "
					<< (createRequest->isMale() ? "TRUE" : "FALSE") << ", " << createRequest->getCharacterSize() << ", " << createRequest->getHairType() << ", "
					<< createRequest->getHeadType() << ", " << createRequest->getBodyType() << ", " << mNbChars << ")";
			}
			else
			{
				query << "INSERT INTO T_EO_CHAR(ID_USER, ID_CHAR_POS, CHAR_FNAME, CHAR_LNAME, BO_MALE, "
					<< "CHAR_SIZE, HAIR_TYPE, HEAD_TYPE, BODY_TYPE, CHAR_ORDER) "
					<< "VALUES(" << mAccountId << ",  NULL, '" << createRequest->getFirstName() << "', '" << createRequest->getLastName() << "', "
					<< (createRequest->isMale() ? "TRUE" : "FALSE") << ", " << createRequest->getCharacterSize() << ", " << createRequest->getHairType() << ", "
					<< createRequest->getHeadType() << ", " << createRequest->getBodyType() << ", " << mNbChars << ")";
			}
			bool isCreated = mSQLManager->oneWayQuery(query.str().c_str(), mSQLLink);
			if (isCreated)
			{
				mp::ResponseCreateCharacter::ResponseBody createBody;
				createBody.isCreated = true;
				createBody.internalError = false;
				createBody.isFull = false;
				mp::Response *response = mp::Response::create(mp::ResponseType::CREATE_CHARACTER, &createBody);
				mClient->tcpSocket()->sendResponse(response);
				mp::Response::destroy(response);
				mThread->start(new CharacterSelectionThread(mClient, mAccountId));
				mIsFinished = true;
			}
			else
			{
				mp::ResponseCreateCharacter::ResponseBody createBody;
				createBody.isCreated = false;
				createBody.internalError = true;
				createBody.isFull = false;
				mp::Response *response = mp::Response::create(mp::ResponseType::CREATE_CHARACTER, &createBody);
				mClient->tcpSocket()->sendResponse(response);
				mp::Response::destroy(response);
			}
		}
		else // is full
		{
			mp::Console::debugprintln("Max characters reached for account, not creating");
			mp::ResponseCreateCharacter::ResponseBody createBody;
			createBody.isCreated = false;
			createBody.internalError = false;
			createBody.isFull = true;
			mp::Response *response = mp::Response::create(mp::ResponseType::CREATE_CHARACTER, &createBody);
			mClient->tcpSocket()->sendResponse(response);
			mp::Response::destroy(response);
		}
	}
	else // not available
	{
		mp::Console::debugprintln("Name unavailable, not creating");
		mp::ResponseCreateCharacter::ResponseBody createBody;
		createBody.isCreated = false;
		createBody.internalError = false;
		createBody.isFull = false;
		mp::Response *response = mp::Response::create(mp::ResponseType::CREATE_CHARACTER, &createBody);
		mClient->tcpSocket()->sendResponse(response);
		mp::Response::destroy(response);
	}
}