当前位置: 首页>>代码示例>>C++>>正文


C++ Ref::GetID方法代码示例

本文整理汇总了C++中Ref::GetID方法的典型用法代码示例。如果您正苦于以下问题:C++ Ref::GetID方法的具体用法?C++ Ref::GetID怎么用?C++ Ref::GetID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ref的用法示例。


在下文中一共展示了Ref::GetID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SendDeletePacket

void SendDeletePacket(RakPeerInterface *rakServer, SystemAddress& systemAddress, Ref<User> user, uchar *packetData, uint length) {
	if (length < 8) return; // If packet data is less than 8 bytes long (counting byte 0), then return as it only contains the packet header

	// User ID stringstream
	stringstream usrId;
	usrId << user->GetID();

	// Get the User ID into a string
	string usrIDString = usrId.str();

	// Get the objectID from the packets
	unsigned long long objectID;
	memcpy(&objectID, packetData + 0x08, 8);

	cout << "Deleting character with ID: " << objectID << " from account: " << usrIDString << endl;

	// Query to delete char from database
	stringstream query;
	query << "DELETE FROM `characters` WHERE `objectID` = '" << objectID << "';";

	// Get number of characters the user has
	uchar usrNumChars = user->userChars;

	// Query to subtract one character from user
	stringstream query2;
	query2 << "UPDATE `accounts` SET `numChars` = '" << usrNumChars - 1 << "' WHERE `id` = '" << usrIDString << "';";

	// Change front character to 0
	stringstream query3;
	query3 << "UPDATE `accounts` SET `frontChar` = '0' WHERE `id` = '" << usrIDString << "';";

	// Query the database with the above 3 queries...
	Database::Query(query.str()); // Delete char...
	Database::Query(query2.str()); // ... Update account numChars...
	Database::Query(query3.str()); // ... and finish by setting front char to 0

	// Set local user's numChars and frontChar
	user->userChars = usrNumChars - 1;
	user->userFrontChar = 0;

	// Create the packet that will be used to send that char deletion
	// packet to the client
	RakNet::BitStream bitStream;

	CreatePacketHeader(ID_USER_PACKET_ENUM, 5, 12, &bitStream);
	bitStream.Write((uchar)1); // Success?

	rakServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, systemAddress, false);
}
开发者ID:Caboose1543,项目名称:LUNIServerProject,代码行数:49,代码来源:CharPackets.cpp

示例2: AddCharToDatabase

void AddCharToDatabase(RakPeerInterface *rakServer, SystemAddress& systemAddress, uchar *packetData, uint length, Ref<User> usr) {
	if (length < 8) return;

	// Get the ID out the user logged in (from User.h)
	stringstream usrId;
	usrId << usr->GetID();

	// Convert it to a string to use with the queries.
	string usrIDString = usrId.str();

	// Create the variables to hold the char items
	ulong shirtColor;
	ulong shirtStyle;
	ulong pantsColor;
	ulong hairStyle;
	ulong hairColor;
	ulong lh;
	ulong rh;
	ulong eyebrows;
	ulong eyes;
	ulong mouth;

	// Copy the char items from the creation packet
	// to their variables
	memcpy(&shirtColor, packetData + 0x5F, 4);
	memcpy(&shirtStyle, packetData + 0x63, 4);
	memcpy(&pantsColor, packetData + 0x67, 4);
	memcpy(&hairStyle, packetData + 0x6B, 4);
	memcpy(&hairColor, packetData + 0x6F, 4);
	memcpy(&lh, packetData + 0x73, 4);
	memcpy(&rh, packetData + 0x77, 4);
	memcpy(&eyebrows, packetData + 0x7B, 4);
	memcpy(&eyes, packetData + 0x7F, 4);
	memcpy(&mouth, packetData + 0x83, 4);

	// Print to the console the char items... (these
	// will also be in the database to view later)
	cout << "Shirt color is: " << shirtColor << endl;
	cout << "Shirt style is: " << shirtStyle << endl;
	cout << "Pants color is: " << pantsColor << endl;
	cout << "Hair style is: " << hairStyle << endl;
	cout << "Hair color is: " << hairColor << endl;
	cout << "LH is: " << lh << endl;
	cout << "RH is: " << rh << endl;
	cout << "Eyebrows are: " << eyebrows << endl;
	cout << "Eyes are: " << eyes << endl;
	cout << "Mouth is: " << mouth << endl;

	// Figure out the pants and shirt IDs that the
	// char starts with...
	ulong shirtID = FindCharShirtID(shirtColor, shirtStyle);
	ulong pantsID = FindCharPantsID(pantsColor);
	
	// Initialize username string...
	string username;

	// Read the string from the packet
	int i = 8;
	while (true) {
		username.push_back(packetData[i++]);
		if (packetData[++i] == 0) break;
	}
	username.push_back(0);
	i++;

	// Print the username to the console
	cout << "Username is: " << username << endl;

	// Get the line numbers from the packet for the character
	// premade name (in minifigname_first.txt, _middle.txt, and
	// _last.txt)
	ulong firstLineNum;
	ulong middleLineNum;
	ulong lastLineNum;

	// Copy the data into the variables
	memcpy(&firstLineNum, packetData + 0x4A, 4);
	memcpy(&middleLineNum, packetData + 0x4E, 4);
	memcpy(&lastLineNum, packetData + 0x52, 4);

	// Now, figure out the unapproved name and store it as
	// as string
	string unapprovedName = GetUnapprovedUsername(firstLineNum, middleLineNum, lastLineNum);
	

	// Save character into the database
	uchar creationStatus = 0;

	// Get the strings of the username
	string usernameStr = string(username.c_str());
	string unapprovedUserStr = string(unapprovedName.c_str());

	// Prepare the first query to check to see if username
	// already exists
	stringstream query1;
	query1 << "SELECT `id` FROM `characters` WHERE `name` = '" << usernameStr << "' LIMIT 1;";

	cout << "Query is: " << query1.str() << endl;

	// Query the database...
//.........这里部分代码省略.........
开发者ID:Caboose1543,项目名称:LUNIServerProject,代码行数:101,代码来源:CharPackets.cpp

示例3: SendCharPacket

void SendCharPacket(RakPeerInterface *rakServer, SystemAddress& systemAddress, Ref<User> usr) {
	RakNet::BitStream bitStream;

	CreatePacketHeader(ID_USER_PACKET_ENUM, 5, 6, &bitStream);
	
	if (usr == NULL) {
		cout << "Usr is null!!! ERROR!" << endl;
	}

	uchar charactersLength = (uchar)usr->userChars;
	uchar frontChar = (uchar)usr->userFrontChar;

	bitStream.Write(charactersLength);
	bitStream.Write(frontChar);

	ostringstream userId;
	userId << usr->GetID();

	cout << userId.str() << endl;

	string userIdStr = userId.str();

	// This loop perhaps is very inefficient, but it makes sure
	// 4 chars are loaded (or, if they don't exist, fill with 0x00)
	for (uint i = 0; i <= charactersLength; i++) {
		CharactersPacket charData = CharactersPacket();

		ostringstream loopSS;
		loopSS << i;
		string loopStr = loopSS.str(); //loopSS.str();

		// Connect to the database and retrieve character info
		auto qr = Database::Query("SELECT * FROM `characters` WHERE `id` = '" + loopStr + "' AND `accountID` = '" + userIdStr + "';");

		// If the number of rows equals 0 from database (character doesn't exist), print it
		if (mysql_num_rows(qr) == 0) {
			cout << "Char " << loopStr <<  " doesn't exist yet.";
		} else {
			// Otherwise, fetch the data in the row
			auto ftc = mysql_fetch_row(qr);

			charData.objectID = (ulonglong)atoi(ftc[2]); // This is the character ID... ftc[1] is the user id
			charData.unknown1 = 0; // Dunno what this is...

			string sCharName = (string)ftc[3]; // This is the character name
			string sUnapprovedName = (string)ftc[4]; // This is the pre-defined (unapproved) name

			/*wstringstream swCharName; // Create a wstringstream for the char name
			swCharName << sCharName.c_str(); // Add the char name to it

			wstringstream swUnapprovedName; // Create a wstringstream for the unapproved name
			swUnapprovedName << sUnapprovedName.c_str(); // Add the unapproved name to it

			wstring wCharName = swCharName.str(); // Create a wstring from the wstringstream
			wstring wUnapprovedName = swUnapprovedName.str(); // Create a wstring from the wstringstream

			wCharName.resize(66);
			wUnapprovedName.resize(66);*/

			wstring wCharName = StringToWString(sCharName, 66);
			wstring wUnapprovedName = StringToWString(sUnapprovedName, 66);
			
			charData.charName = wCharName; // This is the name of the character
			charData.unapprovedName = wUnapprovedName; // This is the unapproved name of the character			
			
			charData.nameRejected = (uchar)atoi(ftc[5]); // This determines whether the user's name is approved
			charData.freeToPlay = (uchar)atoi(ftc[6]); // This determines whether the user if Free to Play
			charData.unknown2 = "";
			charData.shirtColor = (ulong)atoi(ftc[7]); // The shirt color
			charData.shirtStyle = (ulong)atoi(ftc[8]); // Possibly the shirt style... ?
			charData.pantsColor = (ulong)atoi(ftc[9]); // The pants color
			charData.hairStyle = (ulong)atoi(ftc[10]); // Hair style
			charData.hairColor = (ulong)atoi(ftc[11]); // Hair color
			charData.lh = 0; (ulong)atoi(ftc[12]); // This is the left hand item?
			charData.rh = 0; (ulong)atoi(ftc[13]); // This is the right hand item?
			charData.eyebrows = (ulong)atoi(ftc[14]); // Eyebrows
			charData.eyes = (ulong)atoi(ftc[15]); // Eyes
			charData.mouth = (ulong)atoi(ftc[16]); // Mouth
			charData.unknown4 = 0; // Dunno what this is...
			charData.lastZoneId = (ulong)atoi(ftc[25]); // The last world ID the user was in...
			charData.mapInstance = (ushort)atoi(ftc[26]); // The map instance
			charData.mapClone = (ulong)atoi(ftc[27]); // The map clone
			charData.lastLogout = 0; // Last logout in seconds (useless until we get world server working)
			//charData.equippedItemsLength = CharSpecialItemsCount(charData.objectID); // The items length

			charData.WriteDataToBitstream(&bitStream, i);

			GetCharSpecialItems(charData.objectID, &bitStream);
		}
	}	

	rakServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, systemAddress, false);
	SavePacket("char_creation.bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
}
开发者ID:Caboose1543,项目名称:LUNIServerProject,代码行数:94,代码来源:CharPackets.cpp


注:本文中的Ref::GetID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。