本文整理汇总了C++中NetConnection类的典型用法代码示例。如果您正苦于以下问题:C++ NetConnection类的具体用法?C++ NetConnection怎么用?C++ NetConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
void GUIApplication::consoleConnect(const std::vector<String>& params, String& output)
{
if (!m_userCreated)
{
output = "\nThis command is only available after log-in";
return;
}
if (params.size() < 3)
{
output = "\nExpected more parameters: connect <address> <tcp_port>";
return;
}
unsigned int tcpPort = 0;
try {
tcpPort = boost::lexical_cast<unsigned int>(params[2]);
}
catch (boost::bad_lexical_cast)
{
output = "\nBad parameter types. Expected: connect <address> <tcp_port>";
return;
}
NetConnection* newConnection = new NetConnection(*m_networkService);
RemoteMessagePeer* myPeer = new RemoteMessagePeer(newConnection, false, *m_networkService);
newConnection->connectTo(params[1].c_str(), tcpPort);
if (!m_networkThread.isRunning())
m_networkThread.start();
output = "\ncommand accepted.";
}
示例2: NetConnection
bool GUIApplication::onJoinServerClicked(const CEGUI::EventArgs&)
{
String playerName = m_guiContext->getRootWindow()->getChild("JoinServer/playerName")->getText();
String serverIp = m_guiContext->getRootWindow()->getChild("JoinServer/serverIp")->getText();
m_userName = playerName;
m_userListensUdpPort = 11223;
m_userCreated = true;
RemotePeersManager::getManager()->setMyName(m_userName.c_str());
RemotePeersManager::getManager()->setMyUdpPort(m_userListensUdpPort);
// TODO: start listening at given UDP port.
std::string errStr;
if (!m_networkThread.startUdpListener(m_userListensUdpPort, errStr))
{
return true;
}
NetConnection* newConnection = new NetConnection(*m_networkService);
RemoteMessagePeer* myPeer = new RemoteMessagePeer(newConnection, false, *m_networkService);
newConnection->connectTo(serverIp.c_str(), 1778);
if (!m_networkThread.isRunning())
m_networkThread.start();
return true;
}
示例3: AckCallback
void AckCallback(net_sender_t& from, NetMessage* msg) {
DevConsole::ConsolePrintf("%s", RGBA(0, 0, 255, 255), "Received ack");
NetConnection* connection = from.connection;
if (connection == nullptr) {
return;
}
size_t byteAt = 0;
unsigned char* messageData = msg->GetBuffer();
uint8_t numAcks = *(uint8_t*)(messageData + byteAt);
byteAt += sizeof(uint8_t);
for (int ack = 0; ack < numAcks; ack++) {
uint16_t ackID = *(uint16_t*)(messageData + byteAt);
byteAt += sizeof(uint16_t);
ReliableTracker *tracker = connection->FindAndRemoveTracker(ackID);
if (tracker != nullptr) {
for (uint16_t reliable_id : tracker->m_reliableIDs) {
connection->MarkReliableAsReceived(reliable_id);
}
}
}
}
示例4: findConnection
void NetInterface::handleDisconnect(const Address &address, BitStream *stream)
{
NetConnection *conn = findConnection(address);
if(!conn)
return;
ConnectionParameters &theParams = conn->getConnectionParameters();
Nonce nonce, serverNonce;
char reason[256];
nonce.read(stream);
serverNonce.read(stream);
if(nonce != theParams.mNonce || serverNonce != theParams.mServerNonce)
return;
U32 decryptPos = stream->getBytePosition();
stream->setBytePosition(decryptPos);
if(theParams.mUsingCrypto)
{
SymmetricCipher theCipher(theParams.mSharedSecret);
if(!stream->decryptAndCheckHash(NetConnection::MessageSignatureBytes, decryptPos, &theCipher))
return;
}
stream->readString(reason);
conn->setConnectionState(NetConnection::Disconnected);
conn->onConnectionTerminated(NetConnection::ReasonRemoteDisconnectPacket, reason);
removeConnection(conn);
}
示例5: HashNetAddress
NetConnection *NetConnection::lookup(const NetAddress *addr)
{
U32 hashIndex = HashNetAddress(addr);
for(NetConnection *walk = mHashTable[hashIndex]; walk; walk = walk->mNextTableHash)
if(Net::compareAddresses(addr, walk->getNetAddress()))
return walk;
return NULL;
}
示例6: esp8266_connectCallback
void ICACHE_FLASH_ATTR esp8266_connectCallback(void* arg)
{
uart0_tx_buffer("connected\r\n", 11);
struct espconn* conn = (struct espconn*)arg;
NetConnection* netConn = (NetConnection*)conn->reverse;
netConn->connectCallback(netConn->userData, net_ok);
}
示例7: VSoundEffectNetEvent
VTorque::SoundSourceType *VTorque::playSound( SoundEffectType *pSoundProfile, SceneObjectType *pObject, const U32 &pPosition, const F32 &pPitch )
{
if ( !pSoundProfile )
{
// Sanity!
return NULL;
}
#ifdef VT_EDITOR
// Fetch Reference Transform.
const MatrixF &transform = pObject->getTransform();
// Play Sound.
SFXSound *source = ( SFXSound* )SFX->playOnce( pSoundProfile, &transform );
if ( source )
{
// Set Position.
source->setPosition( pPosition );
// Set Pitch.
source->setPitch( pPitch );
}
// Return Source.
return source;
#else
// Fetch Client Group.
SimGroup* clientGroup = Sim::getClientGroup();
for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ )
{
NetConnection *connection = static_cast<NetConnection*>( *itr );
if ( connection )
{
// Create Event.
VSoundEffectNetEvent *event = new VSoundEffectNetEvent();
// Setup Event.
event->mProfile = pSoundProfile;
event->mPosition = pPosition;
event->mPitch = pPitch;
event->mIs3D = true;
event->mTransform = pObject->getTransform();
// Post Event.
connection->postNetEvent( event );
}
}
return NULL;
#endif
}
示例8: esp8266_disconnectCallback
void ICACHE_FLASH_ATTR esp8266_disconnectCallback(void* arg)
{
uart0_tx_buffer("disconnected\r\n", 14);
struct espconn* conn = (struct espconn*)arg;
NetConnection* netConn = (NetConnection*)conn->reverse;
esp8266_destroyConnection(netConn);
netConn->disconnectCallback(netConn->userData, net_ok);
}
示例9: esp8266_resolveCallback
void ICACHE_FLASH_ATTR esp8266_resolveCallback(const char* name, ip_addr_t* ip, void* arg)
{
struct espconn* conn = (struct espconn*)arg;
NetConnection* netConn = (NetConnection*)conn->reverse;
uart0_tx_buffer("get conn\r\n", 10);
HTTPESP8266ConnectionData* driver = esp8266_getConnection(netConn);
uart0_tx_buffer("check ip\r\n", 10);
if(!ip)
{ // failed to lookup the hostname
uart0_tx_buffer("bad ip\r\n", 8);
esp8266_destroyConnection(netConn);
netConn->readCallback(netConn->userData, NULL, 0, net_error);
return;
}
char pageBuffer[20];
ets_sprintf(pageBuffer, "r: %d.%d.%d.%d\r\n", IP2STR(ip));
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
uart0_tx_buffer("set tcp callbacks\r\n", 19);
espconn_regist_connectcb(conn, esp8266_connectCallback);
espconn_regist_disconcb(conn, esp8266_disconnectCallback);
espconn_regist_reconcb(conn, esp8266_reconnectCallback);
uart0_tx_buffer("set callbacks\r\n", 15);
espconn_regist_recvcb(conn, esp8266_recvCallback);
espconn_regist_sentcb(conn, esp8266_sendCallback);
uart0_tx_buffer("set ip\r\n", 8);
ets_memcpy(&conn->proto.tcp->remote_ip, ip, 4);
if(driver->secure)
{
uart0_tx_buffer("async sconnect\r\n", 16);
conn->proto.tcp->remote_port = 443;
ets_sprintf(pageBuffer, "port: %d\r\n", conn->proto.tcp->remote_port);
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
sint8 r = espconn_secure_connect(conn);
ets_sprintf(pageBuffer, "c_conn: %d\r\n", r);
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
}
else
{
uart0_tx_buffer("async connect\r\n", 15);
conn->proto.tcp->remote_port = 80;
ets_sprintf(pageBuffer, "port: %d\r\n", conn->proto.tcp->remote_port);
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
sint8 r = espconn_connect(conn);
ets_sprintf(pageBuffer, "c_conn: %d\r\n", r);
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
}
}
示例10: esp8266_recvCallback
void ICACHE_FLASH_ATTR esp8266_recvCallback(void* arg, char* buffer, unsigned short size)
{
char pageBuffer[20];
ets_sprintf(pageBuffer, "rx: %d\r\n", size);
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
struct espconn* conn = (struct espconn*)arg;
NetConnection* netConn = (NetConnection*)conn->reverse;
netConn->readCallback(netConn->userData, buffer, size, net_ok);
}
示例11: esp8266_reconnectCallback
void ICACHE_FLASH_ATTR esp8266_reconnectCallback(void* arg, sint8 err)
{
char pageBuffer[20];
ets_sprintf(pageBuffer, "recon: %d\r\n", err);
uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
struct espconn* conn = (struct espconn*)arg;
NetConnection* netConn = (NetConnection*)conn->reverse;
esp8266_destroyConnection(netConn);
netConn->readCallback(netConn->userData, NULL, 0, net_error);
}
示例12: setPostEffectOn
void VTorque::setPostEffectOn( PostEffectType *pPostEffect, const bool &pStatus )
{
if ( !pPostEffect )
{
// Sanity!
return;
}
#ifdef VT_EDITOR
if ( pStatus )
{
// Enable Effect.
pPostEffect->enable();
}
else
{
// Disable Effect.
pPostEffect->disable();
}
#else
// Fetch Name.
StringTableEntry name = pPostEffect->getName();
if ( !name || name == StringTable->insert( "" ) )
{
Con::warnf( "VTorque::setPostEffectOn() - Invalid Object Name." );
return;
}
// Fetch Client Group.
SimGroup* clientGroup = Sim::getClientGroup();
for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ )
{
NetConnection *connection = static_cast<NetConnection*>( *itr );
if ( connection )
{
// Create Event.
VPostEffectNetEvent *event = new VPostEffectNetEvent();
// Setup Event.
event->mPostEffect = name;
event->mEnabled = pStatus;
// Post Event.
connection->postNetEvent( event );
}
}
#endif
}
示例13: onAdd
//--------------------------------------------------------------------------
// OnAdd
//--------------------------------------------------------------------------
bool Splash::onAdd()
{
// first check if we have a server connection, if we dont then this is on the server
// and we should exit, then check if the parent fails to add the object
NetConnection* conn = NetConnection::getConnectionToServer();
if(!conn || !Parent::onAdd())
return false;
if( !mDataBlock )
{
Con::errorf("Splash::onAdd - Fail - No datablock");
return false;
}
mDelayMS = mDataBlock->delayMS + sgRandom.randI( -mDataBlock->delayVariance, mDataBlock->delayVariance );
mEndingMS = mDataBlock->lifetimeMS + sgRandom.randI( -mDataBlock->lifetimeVariance, mDataBlock->lifetimeVariance );
mVelocity = mDataBlock->velocity;
mHeight = mDataBlock->height;
mTimeSinceLastRing = 1.0 / mDataBlock->ejectionFreq;
for( U32 i=0; i<SplashData::NUM_EMITTERS; i++ )
{
if( mDataBlock->emitterList[i] != NULL )
{
ParticleEmitter * pEmitter = new ParticleEmitter;
pEmitter->onNewDataBlock( mDataBlock->emitterList[i], false );
if( !pEmitter->registerObject() )
{
Con::warnf( ConsoleLogEntry::General, "Could not register emitter for particle of class: %s", mDataBlock->getName() );
delete pEmitter;
pEmitter = NULL;
}
mEmitterList[i] = pEmitter;
}
}
spawnExplosion();
mObjBox.minExtents = Point3F( -1, -1, -1 );
mObjBox.maxExtents = Point3F( 1, 1, 1 );
resetWorldBox();
gClientSceneGraph->addObjectToScene(this);
removeFromProcessList();
ClientProcessList::get()->addObject(this);
conn->addObject(this);
return true;
}
示例14: 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);
}
}
示例15: RemoveConnection
bool NetworkSession::RemoveConnection(const NetAddress&addr, const Byte& connIndex) {
NetConnectionMapIterator it = m_netConnectionMap.find(GetNetConnectionMapKey(addr, connIndex));
if (it != m_netConnectionMap.end()) {
NetConnection* connection = it->second;
if (connection) {
connection->CleanupTrackers();
delete connection;
connection = NULL;
}
it = m_netConnectionMap.erase(it);
return true;
}
return false;
}