> For the complete documentation index, see [llms.txt](https://qpapel.papelship.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://qpapel.papelship.com/documentation/tr-documentation/fonksiyonlar/heartbeat-1.md).

# Heartbeat

Establishes a secure connection to the authentication server and initializes the session.

{% hint style="warning" %}
This function must be called successfully before any other license validation operations.
{% endhint %}

## Signature

```cpp
int Connect(QPCTX c);
```

## Parameters

| Parameter | Type    | Description            | Required |
| --------- | ------- | ---------------------- | -------- |
| `c`       | `QPCTX` | Client context pointer | Yes      |

## Returns

**Type:** `int`

| Value | Description                         |
| ----- | ----------------------------------- |
| `1`   | Connection established successfully |
| `0`   | Connection failed                   |

## Description

`Connect` performs the following security and network initialization steps:

1. **TCP Connection**: Connects to the authentication server using secure sockets.
2. **ECDH Handshake**: Ephemeral Diffie-Hellman key exchange for secure time-synced packet generation.
3. **Hardware Registry**: Registers local HWID characteristics with the active session.
4. **Security Rules**: Retrieves the configuration settings set on the web dashboard.

## Basic Example

```cpp
#include <iostream>
#include "qPapelLib.h"

int main() {
    if (!qpapel::Init()) return 1;
    
    QPCTX ctx = qpapel::CreateContext();
    qpapel::SetConfig(ctx, "pk_your_api_key", "", 0, "1.0.0");
    
    std::cout << "Connecting to authentication server..." << std::endl;
    
    if (qpapel::Connect(ctx)) {
        std::cout << "Secure connection established!" << std::endl;
    } else {
        char* err = qpapel::GetLastStatus(ctx);
        std::cerr << "Connection failed: " << (err ? err : "Unknown Error") << std::endl;
        if (err) qpapel::FreeString(err);
        
        qpapel::DestroyContext(ctx);
        return 1;
    }
    
    qpapel::DestroyContext(ctx);
    return 0;
}
```

## Security Scanning & Watchdogs

Once connected, you can run background threads to scan for threats (debuggers, dumps, and file modification):

```cpp
void SecurityWatchdog(QPCTX ctx) {
    while (true) {
        // Run debugger checks
        if (qpapel::CheckDebugger(ctx) != 0) {
            qpapel::ReportEvent(ctx, "dbgdthigh", "ban", "{\"screenshot\":true}");
            std::this_thread::sleep_for(std::chrono::seconds(2));
            std::exit(-1);
        }
        
        qpapel::OptimizeClock(ctx);
        std::this_thread::sleep_for(std::chrono::seconds(5));
    }
}
```

{% hint style="warning" %}
**VMProtect / OLLVM / Packer Compatibility**

If you plan to protect your final loader binary with commercial packers like VMProtect or Themida:

* Do **not** call `qpapel::CheckIntegrity(ctx)` in your watchdog. Packers virtualize, mutate, and encrypt your `.text` segment, altering the binary code. This will cause `CheckIntegrity` to fail and falsely trigger anti-tamper bans.
* Commercial packer anti-debugging features may conflict with `qpapel::CheckDebugger(ctx)`. Remove `CheckDebugger` from your loop if you configure VMProtect's anti-debug options.
  {% endhint %}

## Web Dashboard Configuration

All actions for debugger and integrity scans are configured on your dashboard at [papelship.com](https://papelship.com/):

1. **Integrity Tab**: Upload your compiled release binary to calculate its hash.
2. **Blacklist Tab**: Add forbidden process names (e.g., `x64dbg.exe`, `cheatengine.exe`).
3. **Action Config**: Set what the SDK should do on detection (Close App / BSOD).
