本文整理汇总了C++中raknet::SystemAddress::IsLANAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ SystemAddress::IsLANAddress方法的具体用法?C++ SystemAddress::IsLANAddress怎么用?C++ SystemAddress::IsLANAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::SystemAddress
的用法示例。
在下文中一共展示了SystemAddress::IsLANAddress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintStatus
void PrintStatus( void ) {
// enumerate local addresses
size_t numAddresses = peer->GetNumberOfAddresses();
if ( numAddresses ) {
console.Print( PrintLevel::Normal, "Network primed on:\n" );
for ( size_t i = 0u; i < numAddresses; i++ ) {
Indent indent( 1u );
console.Print( PrintLevel::Normal, "%i. %s\n",
i + 1,
peer->GetLocalIP( i )
);
}
}
else {
console.Print( PrintLevel::Normal, "Network primed on %s\n",
peer->GetMyBoundAddress().ToString()
);
}
console.Print( PrintLevel::Normal, "GUID: %" PRIX64 "\n",
myGUID
);
// get a list of remote connections
uint16_t numRemoteSystems;
peer->GetConnectionList( nullptr, &numRemoteSystems );
RakNet::SystemAddress *remoteSystems = new RakNet::SystemAddress[numRemoteSystems];
peer->GetConnectionList( remoteSystems, &numRemoteSystems );
console.Print( PrintLevel::Normal, "%i connections (max: %i)\n",
numRemoteSystems,
peer->GetMaximumIncomingConnections()
);
if ( numRemoteSystems ) {
console.Print( PrintLevel::Normal, "Listing active connections...\n" );
for ( size_t i = 0u; i < numRemoteSystems; i++ ) {
RakNet::SystemAddress *sa = &remoteSystems[i];
Indent indent( 1u );
std::string type;
if ( sa->IsLANAddress() ) {
type = " LAN";
}
else if ( sa->IsLoopback() ) {
type = "LOOP";
}
else {
type = "INET";
}
console.Print( PrintLevel::Normal, "%s: %s - %s\n",
type.c_str(),
sa->ToString(),
connectionStateMessages[peer->GetConnectionState( *sa )]
);
}
}
delete[] remoteSystems;
}
示例2: main
_CONSOLE_2_SetSystemProcessParams
#endif
int main(void)
{
// Pointers to the interfaces of our server and client.
// Note we can easily have both in the same program
RakNet::RakPeerInterface *server=RakNet::RakPeerInterface::GetInstance();
RakNet::RakNetStatistics *rss;
server->SetIncomingPassword("Rumpelstiltskin", (int)strlen("Rumpelstiltskin"));
server->SetTimeoutTime(30000,RakNet::UNASSIGNED_SYSTEM_ADDRESS);
// RakNet::PacketLogger packetLogger;
// server->AttachPlugin(&packetLogger);
#if LIBCAT_SECURITY==1
cat::EasyHandshake handshake;
char public_key[cat::EasyHandshake::PUBLIC_KEY_BYTES];
char private_key[cat::EasyHandshake::PRIVATE_KEY_BYTES];
handshake.GenerateServerKey(public_key, private_key);
server->InitializeSecurity(public_key, private_key, false);
FILE *fp = fopen("publicKey.dat","wb");
fwrite(public_key,sizeof(public_key),1,fp);
fclose(fp);
#endif
// Holds packets
RakNet::Packet* p;
// GetPacketIdentifier returns this
unsigned char packetIdentifier;
// Record the first client that connects to us so we can pass it to the ping function
RakNet::SystemAddress clientID=RakNet::UNASSIGNED_SYSTEM_ADDRESS;
// Holds user data
char portstring[30];
printf("This is a sample implementation of a text based chat server.\n");
printf("Connect to the project 'Chat Example Client'.\n");
printf("Difficulty: Beginner\n\n");
// A server
puts("Enter the server port to listen on");
Gets(portstring,sizeof(portstring));
if (portstring[0]==0)
strcpy(portstring, "1234");
puts("Starting server.");
// Starting the server is very simple. 2 players allowed.
// 0 means we don't care about a connectionValidationInteger, and false
// for low priority threads
// I am creating two socketDesciptors, to create two sockets. One using IPV6 and the other IPV4
RakNet::SocketDescriptor socketDescriptors[2];
socketDescriptors[0].port=atoi(portstring);
socketDescriptors[0].socketFamily=AF_INET; // Test out IPV4
socketDescriptors[1].port=atoi(portstring);
socketDescriptors[1].socketFamily=AF_INET6; // Test out IPV6
bool b = server->Startup(4, socketDescriptors, 2 )==RakNet::RAKNET_STARTED;
server->SetMaximumIncomingConnections(4);
if (!b)
{
printf("Failed to start dual IPV4 and IPV6 ports. Trying IPV4 only.\n");
// Try again, but leave out IPV6
b = server->Startup(4, socketDescriptors, 1 )==RakNet::RAKNET_STARTED;
if (!b)
{
puts("Server failed to start. Terminating.");
exit(1);
}
}
server->SetOccasionalPing(true);
server->SetUnreliableTimeout(1000);
DataStructures::List< RakNet::RakNetSocket2* > sockets;
server->GetSockets(sockets);
printf("Socket addresses used by RakNet:\n");
for (unsigned int i=0; i < sockets.Size(); i++)
{
printf("%i. %s\n", i+1, sockets[i]->GetBoundAddress().ToString(true));
}
printf("\nMy IP addresses:\n");
for (unsigned int i=0; i < server->GetNumberOfAddresses(); i++)
{
RakNet::SystemAddress sa = server->GetInternalID(RakNet::UNASSIGNED_SYSTEM_ADDRESS, i);
printf("%i. %s (LAN=%i)\n", i+1, sa.ToString(false), sa.IsLANAddress());
}
printf("\nMy GUID is %s\n", server->GetGuidFromSystemAddress(RakNet::UNASSIGNED_SYSTEM_ADDRESS).ToString());
puts("'quit' to quit. 'stat' to show stats. 'ping' to ping.\n'pingip' to ping an ip address\n'ban' to ban an IP from connecting.\n'kick to kick the first connected player.\nType to talk.");
char message[2048];
// Loop for input
while (1)
{
// This sleep keeps RakNet responsive
RakSleep(30);
//.........这里部分代码省略.........
示例3: Init
bool TetrisServer::Init()
{
m_interface = RakNet::RakPeerInterface::GetInstance();
RakNet::RakNetStatistics *rss;
m_interface->SetIncomingPassword("Rumpelstiltskin", (int)strlen("Rumpelstiltskin"));
m_interface->SetTimeoutTime(30000, RakNet::UNASSIGNED_SYSTEM_ADDRESS);
// Record the first client that connects to us so we can pass it to the ping function
m_clientID = RakNet::UNASSIGNED_SYSTEM_ADDRESS;
// Holds user data
char* portstring = "1234";
printf("This is a sample implementation of a text based chat server.\n");
printf("Connect to the project 'Chat Example Client'.\n");
printf("Difficulty: Beginner\n\n");
printf("Starting server.\n");
// Starting the server is very simple. 2 players allowed.
// 0 means we don't care about a connectionValidationInteger, and false
// for low priority threads
// I am creating two socketDesciptors, to create two sockets. One using IPV6 and the other IPV4
RakNet::SocketDescriptor socketDescriptors[2];
socketDescriptors[0].port = atoi(portstring);
socketDescriptors[0].socketFamily = AF_INET; // Test out IPV4
socketDescriptors[1].port = atoi(portstring);
socketDescriptors[1].socketFamily = AF_INET6; // Test out IPV6
bool b = m_interface->Startup(4, socketDescriptors, 2) == RakNet::RAKNET_STARTED;
m_interface->SetMaximumIncomingConnections(4);
if (!b)
{
printf("Failed to start dual IPV4 and IPV6 ports. Trying IPV4 only.\n");
// Try again, but leave out IPV6
b = m_interface->Startup(4, socketDescriptors, 1) == RakNet::RAKNET_STARTED;
if (!b)
{
printf("Server failed to start. Terminating.\n");
return false;
}
}
m_interface->SetOccasionalPing(true);
m_interface->SetUnreliableTimeout(1000);
DataStructures::List< RakNet::RakNetSocket2* > sockets;
m_interface->GetSockets(sockets);
printf("Socket addresses used by RakNet:\n");
for (unsigned int i = 0; i < sockets.Size(); i++)
{
printf("%i. %s\n", i + 1, sockets[i]->GetBoundAddress().ToString(true));
}
printf("\nMy IP addresses:\n");
for (unsigned int i = 0; i < m_interface->GetNumberOfAddresses(); i++)
{
RakNet::SystemAddress sa = m_interface->GetInternalID(RakNet::UNASSIGNED_SYSTEM_ADDRESS, i);
printf("%i. %s (LAN=%i)\n", i + 1, sa.ToString(false), sa.IsLANAddress());
}
printf("\nMy GUID is %s\n", m_interface->GetGuidFromSystemAddress(RakNet::UNASSIGNED_SYSTEM_ADDRESS).ToString());
return true;
}