本文整理汇总了C++中raknet::RakPeerInterface::GetInternalID方法的典型用法代码示例。如果您正苦于以下问题:C++ RakPeerInterface::GetInternalID方法的具体用法?C++ RakPeerInterface::GetInternalID怎么用?C++ RakPeerInterface::GetInternalID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::RakPeerInterface
的用法示例。
在下文中一共展示了RakPeerInterface::GetInternalID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
case ID_CONNECTION_REQUEST_ACCEPTED:
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
break;
case ID_NEW_INCOMING_CONNECTION:
printf("ID_NEW_INCOMING_CONNECTION from %s\n", packet->systemAddress.ToString());
break;
case ID_DISCONNECTION_NOTIFICATION:
printf("ID_DISCONNECTION_NOTIFICATION\n");
break;
case ID_CONNECTION_LOST:
printf("ID_CONNECTION_LOST\n");
break;
case ID_ADVERTISE_SYSTEM:
// The first conditional is needed because ID_ADVERTISE_SYSTEM may be from a system we are connected to, but replying on a different address.
// The second conditional is because AdvertiseSystem also sends to the loopback
if (rakPeer->GetSystemAddressFromGuid(packet->guid)==RakNet::UNASSIGNED_SYSTEM_ADDRESS &&
rakPeer->GetMyGUID()!=packet->guid)
{
printf("Connecting to %s\n", packet->systemAddress.ToString(true));
rakPeer->Connect(packet->systemAddress.ToString(false), packet->systemAddress.GetPort(),0,0);
}
break;
case ID_SND_RECEIPT_LOSS:
case ID_SND_RECEIPT_ACKED:
{
uint32_t msgNumber;
memcpy(&msgNumber, packet->data+1, 4);
DataStructures::List<Replica3*> replicaListOut;
replicaManager.GetReplicasCreatedByMe(replicaListOut);
unsigned int idx;
for (idx=0; idx < replicaListOut.Size(); idx++)
{
((SampleReplica*)replicaListOut[idx])->NotifyReplicaOfMessageDeliveryStatus(packet->guid,msgNumber, packet->data[0]==ID_SND_RECEIPT_ACKED);
}
}
break;
}
}
if (kbhit())
{
ch=getch();
if (ch=='q' || ch=='Q')
{
printf("Quitting.\n");
quit=true;
}
if (ch=='c' || ch=='C')
{
printf("Objects created.\n");
if (topology==SERVER||topology==CLIENT)
{
replicaManager.Reference(new ClientCreatible_ClientSerialized);
replicaManager.Reference(new ServerCreated_ClientSerialized);
replicaManager.Reference(new ClientCreatible_ServerSerialized);
replicaManager.Reference(new ServerCreated_ServerSerialized);
}
else
{
// for (int i=0; i < 20; i++)
replicaManager.Reference(new P2PReplica);
}
}
if (ch=='r' || ch=='R')
{
DataStructures::List<Replica3*> replicaListOut;
replicaManager.GetReplicasCreatedByMe(replicaListOut);
unsigned int idx;
for (idx=0; idx < replicaListOut.Size(); idx++)
{
((SampleReplica*)replicaListOut[idx])->RandomizeVariables();
}
}
if (ch=='d' || ch=='D')
{
printf("My objects destroyed.\n");
DataStructures::List<Replica3*> replicaListOut;
// The reason for ClearPointers is that in the sample, I don't track which objects have and have not been allocated at the application level. So ClearPointers will call delete on every object in the returned list, which is every object that the application has created. Another way to put it is
// A. Send a packet to tell other systems to delete these objects
// B. Delete these objects on my own system
replicaManager.GetReplicasCreatedByMe(replicaListOut);
replicaManager.BroadcastDestructionList(replicaListOut, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
for (unsigned int i=0; i < replicaListOut.Size(); i++)
RakNet::OP_DELETE(replicaListOut[i], _FILE_AND_LINE_);
}
}
RakSleep(30);
for (int i=0; i < 4; i++)
{
if (rakPeer->GetInternalID(RakNet::UNASSIGNED_SYSTEM_ADDRESS,0).GetPort()!=SERVER_PORT+i)
rakPeer->AdvertiseSystem("255.255.255.255", SERVER_PORT+i, 0,0,0);
}
}
rakPeer->Shutdown(100,0);
RakNet::RakPeerInterface::DestroyInstance(rakPeer);
}
示例2: main
//.........这里部分代码省略.........
printf("Enter IP to ban. You can use * as a wildcard\n");
Gets(message, sizeof(message));
server->AddToBanList(message);
printf("IP %s added to ban list.\n", message);
continue;
}
// Message now holds what we want to broadcast
char message2[2048];
// Append Server: to the message so clients know that it ORIGINATED from the server
// All messages to all clients come from the server either directly or by being
// relayed from other clients
message2[0] = 0;
const static char prefix[] = "Server: ";
strncpy(message2, prefix, sizeof(message2));
strncat(message2, message, sizeof(message2) - strlen(prefix) - 1);
// message2 is the data to send
// strlen(message2)+1 is to send the null terminator
// HIGH_PRIORITY doesn't actually matter here because we don't use any other priority
// RELIABLE_ORDERED means make sure the message arrives in the right order
// We arbitrarily pick 0 for the ordering stream
// RakNet::UNASSIGNED_SYSTEM_ADDRESS means don't exclude anyone from the broadcast
// true means broadcast the message to everyone connected
server->Send(message2, (const int)strlen(message2) + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);
}
// Get a packet from either the server or the client
for (p = server->Receive(); p; server->DeallocatePacket(p), p = server->Receive())
{
// We got a packet, get the identifier with our handy function
packetIdentifier = GetPacketIdentifier(p);
// Check if this is a network message packet
switch (packetIdentifier)
{
case ID_DISCONNECTION_NOTIFICATION:
// Connection lost normally
printf("ID_DISCONNECTION_NOTIFICATION from %s\n", p->systemAddress.ToString(true));;
break;
case ID_NEW_INCOMING_CONNECTION:
// Somebody connected. We have their IP now
printf("ID_NEW_INCOMING_CONNECTION from %s with GUID %s\n", p->systemAddress.ToString(true), p->guid.ToString());
clientID = p->systemAddress; // Record the player ID of the client
printf("Remote internal IDs:\n");
for (int index = 0; index < MAXIMUM_NUMBER_OF_INTERNAL_IDS; index++)
{
RakNet::SystemAddress internalId = server->GetInternalID(p->systemAddress, index);
if (internalId != RakNet::UNASSIGNED_SYSTEM_ADDRESS)
{
printf("%i. %s\n", index + 1, internalId.ToString(true));
}
}
break;
case ID_INCOMPATIBLE_PROTOCOL_VERSION:
printf("ID_INCOMPATIBLE_PROTOCOL_VERSION\n");
break;
case ID_CONNECTED_PING:
case ID_UNCONNECTED_PING:
printf("Ping from %s\n", p->systemAddress.ToString(true));
break;
case ID_CONNECTION_LOST:
// Couldn't deliver a reliable packet - i.e. the other system was abnormally
// terminated
printf("ID_CONNECTION_LOST from %s\n", p->systemAddress.ToString(true));;
break;
default:
// The server knows the static data of all clients, so we can prefix the message
// With the name data
printf("%s\n", p->data);
// Relay the message. We prefix the name for other clients. This demonstrates
// That messages can be changed on the server before being broadcast
// Sending is the same as before
sprintf(message, "%s", p->data);
server->Send(message, (const int)strlen(message) + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, p->systemAddress, true);
break;
}
}
}
server->Shutdown(300);
// We're done with the network
RakNet::RakPeerInterface::DestroyInstance(server);
}