void ConnectionGraph::OnConnectionGraphRequest(Packet *packet) { char password[256]; RakNet::BitStream inBitstream(packet->data, packet->length, false); inBitstream.IgnoreBits(8); stringCompressor->DecodeString(password,256,&inBitstream); if (pw && pw[0] && strcmp(pw, password)!=0) return; #ifdef _CONNECTION_GRAPH_DEBUG_PRINT RAKNET_DEBUG_PRINTF("ID_CONNECTION_GRAPH_REPLY "); #endif RakNet::BitStream outBitstream; outBitstream.Write((MessageID)ID_CONNECTION_GRAPH_REPLY); stringCompressor->EncodeString(pw,256,&outBitstream); SerializeWeightedGraph(&outBitstream, graph); SendUnified(&outBitstream, LOW_PRIORITY, RELIABLE_ORDERED, connectionGraphChannel, packet->systemAddress, false); #ifdef _CONNECTION_GRAPH_DEBUG_PRINT RAKNET_DEBUG_PRINTF("from %i to %i\n", peer->GetInternalID().port, packet->systemAddress.port); #endif // Add packet->systemAddress to the participant list if it is not already there AddParticipant(packet->systemAddress); }
void FullyConnectedMesh2::OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming) { (void) isIncoming; (void) rakNetGUID; (void) systemAddress; if (autoParticipateConnections) AddParticipant(rakNetGUID); }
void ReplicaManager::OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming) { (void) systemAddress; (void) rakNetGUID; (void) isIncoming; if (autoParticipateNewConnections) AddParticipant(systemAddress); }
void ConnectionGraph::OnConnectionGraphReply(Packet *packet) { unsigned char password[256]; RakNet::BitStream inBitstream(packet->data, packet->length, false); inBitstream.IgnoreBits(8); stringCompressor->DecodeString((char*)password,256,&inBitstream); if (pw && pw[0] && strcmp(pw, (const char*)password)!=0) return; // Serialize the weighted graph and send it to them RakNet::BitStream outBitstream; outBitstream.Write((MessageID)ID_CONNECTION_GRAPH_UPDATE); #ifdef _CONNECTION_GRAPH_DEBUG_PRINT RAKNET_DEBUG_PRINTF("ID_CONNECTION_GRAPH_UPDATE "); #endif // Send our current graph to the sender SerializeWeightedGraph(&outBitstream, graph); // Write the systems that have processed this graph so we don't resend to these systems outBitstream.Write((unsigned short) 1); outBitstream.Write(rakPeerInterface->GetExternalID(packet->systemAddress)); #ifdef _CONNECTION_GRAPH_DEBUG_PRINT RAKNET_DEBUG_PRINTF("from %i to %i\n", peer->GetInternalID().port, packet->systemAddress.port); #endif SendUnified(&outBitstream, LOW_PRIORITY, RELIABLE_ORDERED, connectionGraphChannel, packet->systemAddress, false); // Add packet->systemAddress to the participant list if it is not already there AddParticipant(packet->systemAddress); if (DeserializeWeightedGraph(&inBitstream, rakPeerInterface)==false) return; // Forward the updated graph to all current participants DataStructures::OrderedList<SystemAddress,SystemAddress> ignoreList; ignoreList.Insert(packet->systemAddress,packet->systemAddress, true, __FILE__, __LINE__); BroadcastGraphUpdate(ignoreList, rakPeerInterface); }
PluginReceiveResult ReplicaManager::OnReceive(RakPeerInterface *peer, Packet *packet) { unsigned char packetIdentifier; if ( ( unsigned char ) packet->data[ 0 ] == ID_TIMESTAMP ) { if ( packet->length > sizeof( unsigned char ) + sizeof( unsigned int ) ) packetIdentifier = ( unsigned char ) packet->data[ sizeof( unsigned char ) + sizeof( unsigned int ) ]; else return RR_STOP_PROCESSING_AND_DEALLOCATE; } else packetIdentifier = ( unsigned char ) packet->data[ 0 ]; switch (packetIdentifier) { case ID_NEW_INCOMING_CONNECTION: case ID_CONNECTION_REQUEST_ACCEPTED: if (autoParticipateNewConnections) AddParticipant(packet->playerId); return RR_CONTINUE_PROCESSING; case ID_DISCONNECTION_NOTIFICATION: case ID_CONNECTION_LOST: OnCloseConnection(peer, packet->playerId); return RR_CONTINUE_PROCESSING; case ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE: if (_receiveDownloadCompleteCB==0) { return RR_STOP_PROCESSING_AND_DEALLOCATE; } case ID_REPLICA_MANAGER_CONSTRUCTION: case ID_REPLICA_MANAGER_DESTRUCTION: case ID_REPLICA_MANAGER_SCOPE_CHANGE: case ID_REPLICA_MANAGER_SERIALIZE: { ParticipantStruct *participantStruct; bool hasNetworkId; ReceivedCommand receivedCommand; bool b=true; RakNet::BitStream inBitstream(packet->data, packet->length, false); // SetWriteOffset is used here to get around a design flaw, where I should have had the bitstream constructor take bits, rather than bytes // It sets the actual number of bits in the packet inBitstream.SetWriteOffset(packet->bitSize); receivedCommand.playerId=packet->playerId; receivedCommand.command=packetIdentifier; if ( ( unsigned char ) packet->data[ 0 ] == ID_TIMESTAMP ) { inBitstream.IgnoreBits(8); b=inBitstream.Read(receivedCommand.u1); } else receivedCommand.u1=0; inBitstream.IgnoreBits(8); // Ignore the packet id receivedCommand.networkID=UNASSIGNED_NETWORK_ID; if (packetIdentifier==ID_REPLICA_MANAGER_CONSTRUCTION) // ID_REPLICA_MANAGER_CONSTRUCTION has an optional networkID { b=inBitstream.Read(hasNetworkId); if (hasNetworkId) b=inBitstream.Read(receivedCommand.networkID); } else if (packetIdentifier!=ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE) { b=inBitstream.Read(receivedCommand.networkID); // Other packets always have an networkID } if (b==false) { // Invalid packet #ifdef _DEBUG assert(0); #endif return RR_STOP_PROCESSING_AND_DEALLOCATE; } receivedCommand.userData=&inBitstream; participantStruct=GetParticipantByPlayerID(receivedCommand.playerId); if (participantStruct) { // .Size()>0 is because commands are always processed in order. If a command is delayed, no further commands are processed. // ProcessReceivedCommand(...)==false means that the use signaled to delay a command if (participantStruct->pendingCommands.Size()>0 || ProcessReceivedCommand(participantStruct, &receivedCommand)==REPLICA_PROCESS_LATER) { // Copy the data and add this to a queue that will call ProcessReceivedCommand again in Update. // Allocate and copy structure ReceivedCommand *rc = new ReceivedCommand; memcpy(rc, &receivedCommand, sizeof(ReceivedCommand)); // Allocate and copy inBitstream remaining data rc->userData = new RakNet::BitStream; rc->userData->Write(&inBitstream, inBitstream.GetNumberOfBitsUsed()); participantStruct->pendingCommands.Push(rc); } } return RR_STOP_PROCESSING_AND_DEALLOCATE; } } return RR_CONTINUE_PROCESSING; }
void Canal::SendByCanal(const QString &message, AuthentificationSystem::AuthentificationSystemPtr System, QTcpSocket *Socket) { AddParticipant(System, Socket); SendMessageOnCanal(System, message); RemoveParticipant(System); }