> For the complete documentation index, see [llms.txt](https://docs.ragnasync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ragnasync.com/event-logs/players/login-logout.md).

# Login & Logout

Tracks player login and logout events for statistics

The `LoginScript` and `LogoutScript` handle player connection tracking, updating character online status and login statistics.

## Actions

* `login` - Player connects to the game
* `logout` - Player disconnects from the game

## When They're Used

These scripts are triggered automatically when:

* **Login**: A player successfully enters the game with a character
* **Logout**: A player disconnects from the game (normal or abnormal)

## Why Use Them

* **Track online status** to know who's currently playing
* **Login statistics** for player activity analysis
* **First/last seen** timestamps for player history
* **Online player counts** for dashboard displays
* **Activity patterns** to understand player behavior

## Server Configuration

Login and logout tracking is automatic when RagnaSync is connected. No additional configuration is required.

These scripts are **not counted toward usage limits** as they are triggered by player connections, not user actions.

## Data Tracked

### On Login

| Field            | Description             |
| ---------------- | ----------------------- |
| `is_online`      | Set to `true`           |
| `login_count`    | Incremented by 1        |
| `last_login_at`  | Current timestamp       |
| `first_login_at` | Set on first ever login |

### On Logout

| Field            | Description       |
| ---------------- | ----------------- |
| `is_online`      | Set to `false`    |
| `last_logout_at` | Current timestamp |

## Data Fields (Both Scripts)

| Field        | Type   | Description           |
| ------------ | ------ | --------------------- |
| `name`       | string | Character name        |
| `account_id` | int    | Player's account ID   |
| `char_id`    | int    | Player's character ID |

## Use Cases

### Online Player Dashboard

Query characters where `is_online = true` to show current players.

### Activity Reports

Analyze `login_count` and `last_login_at` to identify:

* Active players
* Returning players
* Inactive accounts

### Player History

Track first login dates to identify new players vs veterans.

## Discord Notifications

By default, login and logout events only track data — no Discord messages are sent. But you can optionally send notifications to Discord by adding a route on the **Message Routes** page.

Since these events fire on every player connection, routes are **not auto-created**. You need to add one manually if you want notifications.

### Setting It Up

1. Go to **Discord > Message Routes** in your dashboard
2. Find **Player Login** or **Player Logout**
3. Click **Add Route**
4. Pick your channel and format

### Custom Messages

When using the **Custom Message** format, you can use the `{{player_name}}` placeholder:

```
:green_circle: {{player_name}} has logged in!
```

```
:red_circle: {{player_name}} has logged out.
```

See [Message Routing](/ragnascript/message-routing.md) for more details on formats, conditions, and custom messages.

## Notes

* Login/logout tracking is automatic when RagnaSync is connected
* Discord notifications are opt-in — add a route to enable them
* Does not count toward RagnaSync usage limits
* Data can be used for player activity dashboards and reports
