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


C++ NetConnection::SetName方法代码示例

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


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

示例1: NetJoinRequestCallback

void NetJoinRequestCallback(NetSender* sender, NetMessage& msg) {
	//do nothing
	ConsolePrintString("\nNetJoinRequestCallback => ");

	BinaryBufferParser bp(&msg.messageBuffer[0], msg.curSize);
	std::string otherName = bp.ReadNextString();
	ConsolePrintString(otherName);

	if (NetworkSystem::s_gameSession->CanAddNewConn()) {
		Byte nextConnIndex = NetworkSystem::s_gameSession->GetNextJoinableConnIndex();
		NetworkSystem::s_gameSession->AddConnection(*sender->addr, 0xff, "client_"+ShortToString(nextConnIndex)+"(O.o)((_ | __ | _");

		//sender->conn = NetworkSystem::s_gameSession->FindConnectionInMap(nextConnIndex);
		NetConnection* newClientConnPtr = NetworkSystem::s_gameSession->FindConnectionInMap(0xff);
		if (newClientConnPtr) {
			NetMessage* joinAcceptMsg = new NetMessage(EN_MSG_ID_JOIN_ACCEPT);
			Byte myMaxConns = NetworkSystem::s_gameSession->GetMaxConnections();
			joinAcceptMsg->WRITE_BYTES(myMaxConns);
			joinAcceptMsg->WRITE_BYTES(nextConnIndex);

			if (NetworkSystem::s_gameSession->m_connSelf) {

				Byte myConnIndex = NetworkSystem::s_gameSession->m_connSelf->GetConnIndex();

				joinAcceptMsg->WRITE_BYTES(myConnIndex);
				//joinAcceptMsg->WriteMessageData(&myConnIndex, SIZE_OF(myConnIndex));

				//joinAcceptMsg->WriteMessageData(&std::string(AllocLocalHostName() + "__(O.o)((_|__|_\0"), SIZE_OF(std::string));
				std::string hostNameString = AllocLocalHostName();
				joinAcceptMsg->WRITE_BYTES(hostNameString);

			}//end of if my info exists

			//doing sender->conn causes system to spam new conns

			newClientConnPtr->SendNetMessage(*joinAcceptMsg);

			//newClientConnPtr->SetConnIndex(0xff);

			newClientConnPtr->SetName("client_" + ShortToString(nextConnIndex) + "(O.o)((_ | __ | _");
		}
		
	}
	else {
		NetMessage* joinDenyMsg = new NetMessage(EN_MSG_ID_JOIN_DENY);

		NetworkSystem::s_gameSession->SendNetMessage(*joinDenyMsg);
	}
	

}
开发者ID:achen889,项目名称:Warlockery_Engine,代码行数:51,代码来源:NetMessage.cpp


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