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


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

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


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

示例1: CharactersLoop

void CharactersLoop(CONNECT_INFO* cfg, Ref< UsersPool > OnlineUsers, Ref< CrossThreadQueue< string > > OutputQueue) {
	RakPeerInterface* rakServer = RakNetworkFactory::GetRakPeerInterface();

	PacketFileLogger* msgFileHandler = NULL;
	if (cfg->logFile) {
		msgFileHandler = new PacketFileLogger();
		rakServer->AttachPlugin(msgFileHandler);
	}

	InitSecurity(rakServer, cfg->useEncryption);
	SocketDescriptor socketDescriptor(cfg->listenPort, 0);

	if (rakServer->Startup(8, 30, &socketDescriptor, 1)) {
		stringstream s;
		s << "characters started! Listening on: " << cfg->listenPort << "\n";
		OutputQueue->Insert(s.str());
	} else exit(2);
	rakServer->SetMaximumIncomingConnections(8);

	if (msgFileHandler != NULL) msgFileHandler->StartLog(".\\logs\\char");

	Packet* packet;

	while (!LUNIterminate) {
		RakSleep(30);	// This sleep keeps RakNet responsive
		packet = rakServer->Receive();
		if (packet == NULL) continue;
		PrintPacketInfo(packet, msgFileHandler);
		// create and send packets back here according to the one we got

		switch (packet->data[0]) {
			case ID_LEGO_PACKET:

				switch (packet->data[1]) {
					case LUNI_INITAW:
						if (packet->data[3] == 0) {	// thats just a formality so far since no other numbers occured for this case
							auto v = OpenPacket(".\\char\\init_aw.bin");
							ServerSendPacket(rakServer, v, packet->systemAddress);
						}
						break;

					case LUNI_CHARACTER:

						switch (packet->data[3]) {
							case LUNI_CHARACTER_CHARSDATA: // char response: 05, 06
								// char traffic only - byte 8 defines number of characters, if there are no characters the user automatically gets to the character creation screen
							{
								//giving client characters list
								auto v = OpenPacket(".\\char\\char_aw2.bin");
								ServerSendPacket(rakServer, v, packet->systemAddress);

							#ifdef DEBUG
								/*StringCompressor* sc = StringCompressor::Instance();
								Ref<char> output = new char[256];
								RakNet::BitStream* bs = new RakNet::BitStream(v.data(), v.size(), false);
								if (sc->DecodeString(output.Get(), 256, bs))
									cout << ("\n the TEST: " + RawDataToString((uchar*)output.Get(), 256) + "\n");
								else cout << ("\n the Test failure :(\n");*/
								RakNet::BitStream bs(v.data(), v.size(), false);
								vector< uchar > out(v.size() *2);
								bs.ReadCompressed(out.data(), out.size(), true);
								//cout << "\n the Test: " << RawDataToString( s.Get(), v.size() ) << endl;
								//SavePacket("theTest.bin", out);
							#endif
							}
								break;

							case LUNI_CHARACTER_CREATEDNEW:
							{
								CharacterCreation cc(CleanPacket(packet->data, packet->length));

								stringstream s;
								s << "\nSomebody wants to create a character with name: " << cc.GetName() << endl;
								s << "re-Serialization: " << RawDataToString(cc.Serialize(), cc.GetGeneratedPacketSize()) << endl;
								OutputQueue->Insert(s.str());
								// response: 05, 06
								// since we can't build our own packets yet we can't send a response here (because it is dependent on the user input)
								vector< uchar > reply(2);
								reply.push_back(5);
								reply.push_back(6);
								ServerSendPacket(rakServer, reply, packet->systemAddress);
							}
								break;

							case 4: // is this sent from the client once the user wants to enter world?
							{
								auto usr = OnlineUsers->Find(packet->systemAddress);
								if (usr != NULL) {
									usr->numredir++;
									//character id is received
									vector< uchar > t;
									for (int i = 8; i <= 11; i++) t.push_back(packet->data[i]);
									usr->nextcid = *(ulong*)t.data();

								#ifdef DEBUG
									stringstream s;
									s << "\nCharacter logging in world with id: " << usr->nextcid;
									if ( usr->nextcid == 2397732190 ) s << " CheekyMonkey!\n";
									else if ( usr->nextcid == 2444680020 ) s << " monkeybrown!\n";
									else if ( usr->nextcid == 1534792735 ) s << " GruntMonkey!\n";
//.........这里部分代码省略.........
开发者ID:Caboose1543,项目名称:LUNIServerProject,代码行数:101,代码来源:CharactersLoop.cpp

示例2: CharactersLoop

void CharactersLoop(CONNECT_INFO* cfg, Ref< UsersPool > OnlineUsers, Ref< CrossThreadQueue< string > > OutputQueue) {
    // Initialize the RakPeerInterface used throughout the entire server
    RakPeerInterface* rakServer = RakNetworkFactory::GetRakPeerInterface();

    // Initialize the PacketFileLogger plugin (for the logs)
    PacketFileLogger* msgFileHandler = NULL;
    if (cfg->logFile) {
        msgFileHandler = new PacketFileLogger();
        rakServer->AttachPlugin(msgFileHandler);
    }

    // Initialize security IF user has enabled it in config.ini
    InitSecurity(rakServer, cfg->useEncryption);

    // Initialize the SocketDescriptor
    SocketDescriptor socketDescriptor(cfg->listenPort, 0);

    // If the startup of the server is successful, print it to the console
    // Otherwise, quit the server (as the char server is REQUIRED for the
    // server to function properly)
    if (rakServer->Startup(8, 30, &socketDescriptor, 1)) {
        stringstream s;
        s << "Characters started! Listening on: " << cfg->listenPort << "\n";
        OutputQueue->Insert(s.str());
    } else exit(2);

    // Set max incoming connections to 8
    rakServer->SetMaximumIncomingConnections(8);

    // If msgFileHandler is not NULL, save logs of char server
    if (msgFileHandler != NULL) msgFileHandler->StartLog(".\\logs\\char");

    // Initialize the Packet class for the packets
    Packet* packet;

    // This will be used in the saving of packets below...
    int i = 0;

    while (!LUNIterminate) {
        RakSleep(30);	// This sleep keeps RakNet responsive
        packet = rakServer->Receive(); // Recieve the packets from the server
        if (packet == NULL) continue; // If packet is NULL, just continue without processing anything
        PrintPacketInfo(packet, msgFileHandler); // Save packet info

        // This will save all packets recieved from the client if running from DEBUG
#ifdef DEBUG
        stringstream packetName;
        packetName << ".//Saves//Packet" << i << ".bin";

        SavePacket(packetName.str(), (char *)packet->data, packet->length);
        i++;
#endif

        switch (packet->data[0]) {
        case ID_LEGO_PACKET:

            switch (packet->data[1]) {
            case GENERAL:
                if (packet->data[3] == VERSION_CONFIRM) {	// thats just a formality so far since no other numbers occured for this case
                    SendInitPacket(rakServer, packet->systemAddress, false);
                }
                break;

            case SERVER:

                switch (packet->data[3]) {
                case CLIENT_VALIDATION:
                {
                    cout << "Recieved client validation..." << endl;
                    break;
                }

                case CLIENT_CHARACTER_LIST_REQUEST:
                {
                    auto usr = OnlineUsers->Find(packet->systemAddress);
                    if (usr->nameInUse == 0) {
                        cout << "Sending char packet...";
                        SendCharPacket(rakServer, packet->systemAddress, usr);
                    }
                    break;
                }

                case CLIENT_CHARACTER_CREATE_REQUEST:
                {
                    // Find online user by systemAddress
                    auto usr = OnlineUsers->Find(packet->systemAddress);

                    // Make SURE user is not null!!!!!!
                    if (usr != NULL) {
                        AddCharToDatabase(rakServer, packet->systemAddress, packet->data, packet->length, usr);
                    }
                    else {
                        cout << "ERROR SAVING USER: User is null." << endl;
                    }

                    // If the username is in use, do NOT send the char packet. Otherwise, send it
                    if (usr->nameInUse == 0) {
                        SendCharPacket(rakServer, packet->systemAddress, usr);
                    }
                }
//.........这里部分代码省略.........
开发者ID:TheThunderBird,项目名称:LUNIServerProject,代码行数:101,代码来源:CharactersLoop.cpp

示例3: WorldLoop

void WorldLoop(CONNECT_INFO* cfg, Ref< UsersPool > OnlineUsers, Ref< CharactersPool> OnlineCharacters, Ref< CrossThreadQueue< string > > OutputQueue) {
	// Initialize the RakPeerInterface used throughout the entire server
	rakServer = RakNetworkFactory::GetRakPeerInterface();

	// Initialize the PacketFileLogger plugin (for the logs)
	PacketFileLogger* msgFileHandler = NULL;
	if (cfg->logFile) {
		msgFileHandler = new PacketFileLogger();
		rakServer->AttachPlugin(msgFileHandler);
	}

	// Initialize security IF user has enabled it in config.ini
	InitSecurity(rakServer, cfg->useEncryption);

	// Initialize the SocketDescriptor
	SocketDescriptor socketDescriptor(cfg->listenPort, 0);

	// If the startup of the server is successful, print it to the console
	// Otherwise, quit the server (as the char server is REQUIRED for the
	// server to function properly)
	if (rakServer->Startup(8, 30, &socketDescriptor, 1)) {
		stringstream s;
		s << "world started! Listening on: " << cfg->listenPort << "\n";
		OutputQueue->Insert(s.str());
	} else exit(2);

	rakServer->SetNetworkIDManager(&networkIdManager);

	rakServer->AttachPlugin(&replicaManager);
	networkIdManager.SetIsNetworkIDAuthority(true);

	// Attach the ReplicaManager2
	replicaManager.SetAutoSerializeInScope(true);
	replicaManager.SetAutoParticipateNewConnections(true);
	replicaManager.SetAutoConstructToNewParticipants(true);

	// Set max incoming connections to 8
	rakServer->SetMaximumIncomingConnections(8);

	// If msgFileHandler is not NULL, save logs of char server
	if (msgFileHandler != NULL) msgFileHandler->StartLog(".\\logs\\world");

	// Initialize the Packet class for the packets
	Packet* packet;

	// This will be used in the saving of packets below
	int i = 0;

	ZoneId zone = NIMBUS_ISLE;

	// This will be used in the saving of packets below...
	while (!LUNIterminate) {
		RakSleep(30);	// This sleep keeps RakNet responsive
		packet = rakServer->Receive(); // Recieve the packets from the server
		if (packet == NULL) continue; // If packet is NULL, just continue without processing anything

		// This will save all packets recieved from the client if running from DEBUG
		#ifdef DEBUG
			stringstream packetName;
			packetName << ".//Saves//World_Packet" << i << ".bin";

			if (packet->data[3] != 22) {
				SavePacket(packetName.str(), (char*)packet->data, packet->length);
				i++;
			}
		#endif

		// Create and send packets back here according to the one we got
			switch (packet->data[0]) {
			case ID_USER_PACKET_ENUM:
				switch (packet->data[1]) {
				case GENERAL:
					if (packet->data[3] == 0) {	// thats just a formality so far since no other numbers occured for this case
						auto v = OpenPacket(".\\worldTest\\init_aw2.bin");
						ServerSendPacket(rakServer, v, packet->systemAddress);
					}
					break;

				case WORLD:

					switch (packet->data[3]) {
					case CLIENT_VALIDATION:
					{
											  auto usr = OnlineUsers->Find(packet->systemAddress);
											  //this packets contains ZoneId and something else... but what?
											  // it starts whit: 53 05 00 02 00 00 00 00 -- -- (<-ZoneId) ?? ?? ??
											  vector< uchar > v;
											  /*if (usr != NULL && usr->nextcid == 2444680020) { //monkeybrown
												  v = OpenPacket(".\\world\\monkeybrown\\char_aw2.bin");
												  }
												  else if (usr != NULL && usr->nextcid == 1534792735) { //gruntmonkey
												  v = OpenPacket(".\\world\\gruntmonkey\\char_aw2.bin");
												  }
												  else if (usr != NULL && usr->nextcid == 1457240027) { //shafantastic
												  v = OpenPacket(".\\world\\shastafantastic\\char_aw22.bin");
												  }
												  else { //cheekymonkey
												  v = OpenPacket(".\\world\\char_aw2.bin");
												  }*/

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

示例4: WorldLoop

void WorldLoop(CONNECT_INFO* cfg, Ref< UsersPool > OnlineUsers, Ref< CrossThreadQueue< string > > OutputQueue) {
	// Initialize the RakPeerInterface used throughout the entire server
	RakPeerInterface* rakServer = RakNetworkFactory::GetRakPeerInterface();

	// Initialize the PacketFileLogger plugin (for the logs)
	PacketFileLogger* msgFileHandler = NULL;
	if (cfg->logFile) {
		msgFileHandler = new PacketFileLogger();
		rakServer->AttachPlugin(msgFileHandler);
	}

	// Initialize security IF user has enabled it in config.ini
	InitSecurity(rakServer, cfg->useEncryption);

	// Initialize the SocketDescriptor
	SocketDescriptor socketDescriptor(cfg->listenPort, 0);

	// If the startup of the server is successful, print it to the console
	// Otherwise, quit the server (as the char server is REQUIRED for the
	// server to function properly)
	if (rakServer->Startup(8, 30, &socketDescriptor, 1)) {
		stringstream s;
		s << "world started! Listening on: " << cfg->listenPort << "\n";
		OutputQueue->Insert(s.str());
	} else exit(2);

	// Set max incoming connections to 8
	rakServer->SetMaximumIncomingConnections(8);

	// If msgFileHandler is not NULL, save logs of char server
	if (msgFileHandler != NULL) msgFileHandler->StartLog(".\\logs\\world");

	// Initialize the Packet class for the packets
	Packet* packet;

	// This will be used in the saving of packets below
	int i = 0;

	// This will be used in the saving of packets below...
	while (!LUNIterminate) {
		RakSleep(30);	// This sleep keeps RakNet responsive
		packet = rakServer->Receive(); // Recieve the packets from the server
		if (packet == NULL) continue; // If packet is NULL, just continue without processing anything

		// This will save all packets recieved from the client if running from DEBUG
		#ifdef DEBUG
			stringstream packetName;
			packetName << ".//Saves//World_Packet" << i << ".bin";

			SavePacket(packetName.str(), (char*)packet->data, packet->length);
			i++;
		#endif

		// Create and send packets back here according to the one we got
		switch (packet->data[0]) {
			case ID_USER_PACKET_ENUM:
				switch (packet->data[1]) {
					case GENERAL:
						if (packet->data[3] == 0) {	// thats just a formality so far since no other numbers occured for this case
							auto v = OpenPacket(".\\world\\init_aw.bin");
							ServerSendPacket(rakServer, v, packet->systemAddress);
						}
						break;

					case SERVER:

						switch (packet->data[3]) {
							case CLIENT_VALIDATION:
							{ 
								auto usr = OnlineUsers->Find(packet->systemAddress);
								//this packets contains ZoneId and something else... but what?
								// it starts whit: 53 05 00 02 00 00 00 00 -- -- (<-ZoneId) ?? ?? ??
								vector< uchar > v;
								if (usr != NULL && usr->nextcid == 2444680020) { //monkeybrown
									v = OpenPacket(".\\world\\monkeybrown\\char_aw2.bin");
								}
								else if (usr != NULL && usr->nextcid == 1534792735) { //gruntmonkey
									v = OpenPacket(".\\world\\gruntmonkey\\char_aw2.bin");
								}
								else if (usr != NULL && usr->nextcid == 1457240027) { //shafantastic
									v = OpenPacket(".\\world\\shastafantastic\\char_aw22.bin");
								}
								else { //cheekymonkey
									v = OpenPacket(".\\world\\char_aw2.bin");
								}

								#ifdef DEBUG
								if (v.size() > 0) {
									RakNet::BitStream bs( CleanPacket(v.data(), v.size()), v.size()-8, false );
									ZoneId zid;
									bs.Read(zid);
									stringstream s;
									s << "\nLoading world: " << zid << endl;
									OutputQueue->Insert(s.str());
								} else OutputQueue->Insert("\nWorld Error: can't load char_aw2.bin\n");
								#endif

								ServerSendPacket(rakServer, v, packet->systemAddress);
							}
								break;
//.........这里部分代码省略.........
开发者ID:Caboose1543,项目名称:LUNIServerProject,代码行数:101,代码来源:WorldLoop.cpp


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