本文整理汇总了C++中raknet::SystemAddress类的典型用法代码示例。如果您正苦于以下问题:C++ SystemAddress类的具体用法?C++ SystemAddress怎么用?C++ SystemAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SystemAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TServerDetails
void
CRakMasterServer::RegisterServer(RakNet::SystemAddress& _rServerAddress, RakNet::RakNetGUID& _rServerGuid, uchar* _ucpData, uint _uiLength)
{
std::map<uint64, TServerDetails*>::iterator Entry = m_mRegisteredServers.find(_rServerGuid.g);
if (Entry == m_mRegisteredServers.end())
{
TServerDetails* tpServerDetails = new TServerDetails();
char sServerIp[256];
_rServerAddress.ToString_Old(false, sServerIp);
tpServerDetails->tAddress = _rServerAddress;
tpServerDetails->tGuid = _rServerGuid;
tpServerDetails->fUnregisterTimer = s_kfRegistrationTimeout;
m_mRegisteredServers.insert( std::pair<uint64, TServerDetails*>(_rServerGuid.g, tpServerDetails) );
LOG_MESSAGE("Registered Server. IP(%s) GUID(%llu)", _rServerAddress.ToString(), _rServerGuid.g);
}
else
{
Entry->second->fUnregisterTimer = s_kfRegistrationTimeout;
LOG_MESSAGE("Re-registered Server. IP(%s) GUID(%llu)", _rServerAddress.ToString(), _rServerGuid.g);
}
}
示例2: 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;
}
示例3: is_in_same_network
bool Network::is_in_same_network(std::string const& other) const {
RakNet::SystemAddress o;
RakNet::SystemAddress self;
if (o.FromString(other.c_str()) && self.FromString(external_id_.c_str())) {
if (o.EqualsExcludingPort(self)) {
return true;
}
}
return false;
}
示例4: switch
// Returning false prevents the proxy from forwarding current packet to the client
bool
CProxy::HandleLoginSrvPacket(RakNet::Packet* pPacket, RakNet::SystemAddress& clientAddr, RakNet::BitStream& inStr, uchar opCode)
{
uint off = inStr.GetReadOffset();
switch (opCode)
{
case Opcodes::OP_LOGIN:
bool bLoggedIn = false;
inStr.Read(bLoggedIn);
if (bLoggedIn)
{
ff::fmt(pan::debug, "({0}) Player successfully logged in.", clientAddr.ToString(false));
// Do the switch to Area server here
}
break;
}
inStr.SetReadOffset(off);
return true;
}
示例5: canConnected
bool NetworkEngine::canConnected(RakNet::SystemAddress id)
{
RakNet::SystemAddress connecteds[MAX_PLAYERS];
unsigned short size = MAX_PLAYERS;
//unsigned short pos = peer->NumberOfConnections();
//peer->GetConnectionList(connecteds,&pos);
peer->GetConnectionList((RakNet::SystemAddress*) &connecteds,&size);
if(disconnecteds.size() > 0)
{
std::vector<RakNet::SystemAddress>::iterator it = disconnecteds.begin();
do
{
if(id.EqualsExcludingPort(*it))
{
disconnecteds.erase(it);
return true;
}
it++;
}while(it != disconnecteds.end());
}
for(int i=0;i<MAX_PLAYERS;i++)
{
if(connecteds[i].EqualsExcludingPort(id))
{
return false;
}
}
return false;
}
示例6: connect
void Connector::connect( RakNet::SystemAddress server ){
if (raknetInterface == nullptr){
LOG("Client is not started!");
return;
}
char * ip = new char[64]; // must be new char[]! Not char ip[], BAD_ACCESS!!
for(int i=0; i<64; i++){ ip[i] = 0; }
server.ToString(false, ip);
int result = raknetInterface->Connect(ip, server.GetPort(), RAKNET_PASSWORD, (int)strlen(RAKNET_PASSWORD));
LOG("[Connector] Connecting to %s", ip);
if(result == RakNet::CONNECTION_ATTEMPT_STARTED)
{
LOG("[Connector] Connecting to %s started.", ip);
}
else if (result == RakNet::INVALID_PARAMETER)
{
LOG("[Connector] INVALID_PARAMETER");
}
else if (result == RakNet::CANNOT_RESOLVE_DOMAIN_NAME)
{
LOG("[Connector] CANNOT_RESOLVE_DOMAIN_NAME");
}
else if (result == RakNet::ALREADY_CONNECTED_TO_ENDPOINT)
{
LOG("[Connector] ALREADY_CONNECTED_TO_ENDPOINT");
}
else if (result == RakNet::CONNECTION_ATTEMPT_ALREADY_IN_PROGRESS)
{
LOG("[Connector] CONNECTION_ATTEMPT_ALREADY_IN_PROGRESS");
}
else if (result == RakNet::SECURITY_INITIALIZATION_FAILED)
{
LOG("[Connector] SECURITY_INITIALIZATION_FAILED");
}
else{
LOG("[Connector] connecting atempt failed for unknown reason!!!");
}
delete [] ip;
}
示例7: sendMessagePlayerReconnected
void NetworkEngine::sendMessagePlayerReconnected(RakNet::SystemAddress systemAddress)
{
//Envia un ID_SERVER_MESSAGE con un RakNet::String;
RakNet::BitStream bitStream;
RakNet::RakString string("Player %s has reconnected to the game\n", systemAddress.ToString());
bitStream.Write((unsigned char)ID_SERVER_STRING_MESSAGE);
bitStream.Write(string);
peer->Send(&bitStream, HIGH_PRIORITY, RELIABLE, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);
}
示例8: sendData
void ClientChatNetPackageSender::sendData( const char* data, int lenght )
{
const NetworkAddress& networkAddress(getPeer()->getNetworkAddress());
RakNet::SystemAddress target;
target.FromStringExplicitPort(networkAddress.getServerIp(),networkAddress.getServerPort());
// 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
// target.FromStringExplicitPort created the address to send the data to
// false means send the message to the given target address
RakNet::RakPeerInterface* rakNetPeer(getPeer()->accessRakNetPeer());
// note: better check if the peer is connected in the first place
if(rakNetPeer != nullptr) {
rakNetPeer->Send(data, lenght,
HIGH_PRIORITY, RELIABLE_ORDERED, 0, target, false);
}
}
示例9: addReceiveMessage
///加条发送的消息
void SimulateClientMainFrame::addReceiveMessage(const std::string& message,const RakNet::SystemAddress& Address)
{
wxString tem;
tem+=Address.ToString();
tem+=": ";
tem+=message;
tem+="\n";
m_receiveText->AppendText(tem);
}
示例10: processDatabasePlayer
//------------------------------------------------------------------------------------
void PlayerManager::processDatabasePlayer(NetPack* pPack)
{
///把数据转发给客户端
Tag_PlayerCollect* players=static_cast<Tag_PlayerCollect*>(pPack->getData());
if(players->m_Count==0)///表示这个帐号还没有新建角色
{
}else ///把所有角色发给客户端
{
}
RakNet::SystemAddress address;
address.SetBinaryAddress(players->m_ip);
NetWorkServer::getSingleton().send(GM_REQUEST_PLAYERS,(const char*)pPack->getData(),pPack->getDataLength(),address);
return ;
}
示例11:
void
CProxy::OnClosedConnection(const RakNet::SystemAddress& systemAddress,
RakNet::RakNetGUID rakNetGUID,
RakNet::PI2_LostConnectionReason lostConnectionReason)
{
ff::fmt(pan::notice, "({0}) Closed connection", systemAddress.ToString(false));
s_clientInfos* pInfos = m_mapClientAddr[systemAddress];
m_mapClientAddr.erase(systemAddress);
std::map<uint, s_clientInfos*>::iterator it = m_mapClientId.find(pInfos->m_uID);
if (it != m_mapClientId.end())
m_mapClientId.erase(it);
}
示例12: run
void Network_module::run()
{
print_config();
using namespace RakNet;
RakNet::RakPeerInterface* l_rakpeer = RakNet::RakPeerInterface::GetInstance();
int l_addr_count = l_rakpeer->GetNumberOfAddresses();
NET_MOD_INFO("获取到本机IP数量%d个", l_addr_count);
for (int i = 0; i < l_addr_count; i++)
{
RakNet::SystemAddress addr = l_rakpeer->GetLocalIP(i);
NET_MOD_INFO("第%d个IP地址为:%s", i + 1, addr.ToString(false));
}
RakNet::SocketDescriptor l_socket_descriptor;
l_socket_descriptor.port = m_local_port;
if (l_rakpeer->Startup(m_max_connection, &l_socket_descriptor, 1) != RakNet::RAKNET_STARTED)
{
NET_MOD_ERROR("启动网络引擎失败");
RakNet::RakPeerInterface::DestroyInstance(l_rakpeer);
return;
}
l_rakpeer->SetMaximumIncomingConnections(m_max_income_connection);
NET_MOD_INFO("启动网络引擎成功,监控地址为%s", l_rakpeer->GetMyBoundAddress().ToString(false));
NET_MOD_INFO("开始载入打孔插件");
m_punch_proxy = new NatPunchProxy;
m_punch_proxy->init_proxy(l_rakpeer);
start_network_loop(l_rakpeer);
}
示例13: main
//.........这里部分代码省略.........
// You won't see these unless you modified CloudServer
printf("Server rejected the connection.\n");
return 1;
case ID_INCOMPATIBLE_PROTOCOL_VERSION:
printf("Server is running an incompatible RakNet version.\n");
return 1;
case ID_NO_FREE_INCOMING_CONNECTIONS:
printf("Server has no free connections\n");
return 1;
case ID_IP_RECENTLY_CONNECTED:
printf("Recently connected. Retrying.");
rakPeer->Connect(serverAddress, serverPort, 0, 0);
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
printf("Connected to server.\n");
UploadInstanceToCloud(&cloudClient, packet->guid);
GetClientSubscription(&cloudClient, packet->guid);
GetServers(&cloudClient, packet->guid);
break;
case ID_CLOUD_GET_RESPONSE:
{
RakNet::CloudQueryResult cloudQueryResult;
cloudClient.OnGetReponse(&cloudQueryResult, packet);
unsigned int rowIndex;
const bool wasCallToGetServers=cloudQueryResult.cloudQuery.keys[0].primaryKey=="CloudConnCount";
printf("\n");
if (wasCallToGetServers)
printf("Downloaded server list. %i servers.\n", cloudQueryResult.rowsReturned.Size());
else
printf("Downloaded client list. %i clients.\n", cloudQueryResult.rowsReturned.Size());
unsigned short connectionsOnOurServer=65535;
unsigned short lowestConnectionsServer=65535;
RakNet::SystemAddress lowestConnectionAddress;
for (rowIndex=0; rowIndex < cloudQueryResult.rowsReturned.Size(); rowIndex++)
{
RakNet::CloudQueryRow *row = cloudQueryResult.rowsReturned[rowIndex];
if (wasCallToGetServers)
{
unsigned short connCount;
RakNet::BitStream bsIn(row->data, row->length, false);
bsIn.Read(connCount);
printf("%i. Server found at %s with %i connections\n", rowIndex+1, row->serverSystemAddress.ToString(true), connCount);
unsigned short connectionsExcludingOurselves;
if (row->serverGUID==packet->guid)
connectionsExcludingOurselves=connCount-1;
else
connectionsExcludingOurselves=connCount;
// Find the lowest load server (optional)
if (packet->guid==row->serverGUID)
{
connectionsOnOurServer=connectionsExcludingOurselves;
}
else if (connectionsExcludingOurselves < lowestConnectionsServer)
{
lowestConnectionsServer=connectionsExcludingOurselves;
lowestConnectionAddress=row->serverSystemAddress;
}
}
else
{
printf("%i. Client found at %s", rowIndex+1, row->clientSystemAddress.ToString(true));
示例14: ban
void Player::ban() const
{
auto netCtrl = mwmp::Networking::getPtr();
RakNet::SystemAddress addr = netCtrl->getSystemAddress(guid);
netCtrl->banAddress(addr.ToString(false));
}
示例15: OnSendAborted
virtual void OnSendAborted( RakNet::SystemAddress systemAddress )
{
char str[32];
systemAddress.ToString(true, (char*) str);
RAKNET_DEBUG_PRINTF("Send aborted to %s\n", str);
}