Пример #1
0
	protected UInt64 ComputeSettingsHash()
	{
		using( BitWriter writer = GetPooledWriter() )
		{
			// TODO: cozeroff
			//writer.WriteString(AlpacaConstant.ALPACA_PROTOCOL_VERSION);

			writer.Packed<Int32>( _commonSettings.customChannel.Length );
			foreach( CustomChannelSettings c in _commonSettings.customChannel )
			{
				// TODO: cozeroff
				//writer.WriteString( c.name );
				writer.Packed<Int32>( (Int32)c.type );
			}

			// we do not write the Entity's here because it is allowed for the client and server to have different prefabs.
			// eventually, we should do a more advanced check, since the prefabs do need to have matching Conducts.
			writer.Packed<Int32>( _commonSettings.messageBufferSize );
			writer.Packed<UInt32>( _commonSettings.maxEventCount );
			writer.Packed<Int32>( _commonSettings.lagCompensationHistory );
			writer.Packed<Int32>( (Int32)_commonSettings.stringHashSize );
			writer.Packed<Int32>( (Int32)_commonSettings.logLevel );
			writer.Packed<bool>( _commonSettings.enableTimeResync );
			writer.Packed<bool>( _commonSettings.enableEncryption );
			writer.Packed<bool>( _commonSettings.signKeyExchange );
			writer.AlignToByte();

			return writer.GetStableHash64();
		}
	}
Пример #2
0
 public void Write(BitWriter writer)
 {
     writer.Write(ref data.id);
     writer.Write(ref data.owner);
     writer.Write(ref data.prefabIndex);
     writer.Packed <Vector3>(position);
     writer.Packed <Quaternion>(rotation);
 }
Пример #3
0
        public void Write(BitWriter writer)
        {
            writer.Normal <byte>((byte)_type);
            writer.Packed <UInt32>(_frame);
            writer.Packed <UInt32>(_id);

            writer.Packed <UInt16>((UInt16)_events.Count);
            for (int i = 0; i < _events.Count; ++i)
            {
                _events[i].Write(writer);
            }
        }
	void OnMessageConnectionRequest( NodeIndex clientNode, BitReader reader )
	{
		// update ClientConnection state
		int clientIndex = clientNode.GetClientIndex();
		ClientConnection connection = _connection.GetAt( clientIndex - 1 );
		connection.SetConnected();

		// send the new client the data it needs, plus spawn instructions for all current entities
		using( BitWriter writer = GetPooledWriter() )
		{
			writer.Packed<Int32>( clientIndex  );
			writer.Packed<float>( _networkTime );
			writer.Packed<Int32>( NetworkTransport.GetNetworkTimestamp() );

			int entityCount = _entity.GetCount();
			writer.Packed<Int32>( entityCount );
			
			Entity e;
			for( int i = 0; i < entityCount; ++i )
			{
				e = _entity.GetAt(i);
				e.MakeSpawn().Write( writer );
			}

			string error;
			if( !SendInternal( clientNode, InternalMessage.ConnectionApproved, InternalChannel.Reliable, writer, true, out error ) )
			{
				Log.Error( $"OnMessageConnectionRequest failed to send connection approval data to new client {clientIndex}.\n{error}" );
			}
		}

		// Inform old clients of the new client
		using( BitWriter writer = GetPooledWriter() )
		{
			writer.Packed<Int32>( clientIndex );

			for( int i = 0; i < _connection.GetCount(); ++i )
			{
				if( i == (clientIndex - 1) ) { continue; } // skip the new client

				ClientConnection sibling = _connection.GetAt(i);
				string error;
				if( !SendInternal( sibling.GetId(), InternalMessage.SiblingConnected, InternalChannel.Reliable, writer, false, out error ) )
				{
					Log.Error( $"OnMessageConnectionRequest failed to send SiblingConnected message to all other clients.\n{error}" );
				}
			}
		}

		// callback
		//if( _onClientConnect != null ) { _onClientConnect.Invoke( clientNode ); }
	}
Пример #5
0
 public void Write(BitWriter writer)
 {
     writer.Packed <UInt32>(_byteCount);
     _channel.Write(writer);
     writer.Packed <UInt32>((UInt32)_message);
 }
Пример #6
0
	public void Write( BitWriter writer ) { writer.Packed<UInt32>( _indexPlusOne ); }