# Redirection

Netcode for GameObjects is built on the principle of server authorization, which has its advantages and disadvantages. When using RPCs, I can be confident that I received the RPC from a client if I am the server, or from the server if I am the client.

Messages also support this assurance by default. However, there are scenarios where you may need to bypass this, such as when creating a chat system that allows private messages between clients. This is easily achievable with Messages by adding a `true` parameter to the `[Message]` attribute.

## How does it work?

It works by redirecting the message to the server if it can't be sent directly (*for example, from client 1 to client 2*). The server then checks if this action is permitted. If it is, the server forwards the message to client 2, allowing client 2 to recognize that it was sent by client 1.

{% hint style="info" %} <mark style="color:red;">**IMPORTANT:**</mark> <mark style="color:red;"></mark><mark style="color:red;">This introduces some vulnerabilities! We can't assume that a message comes from the server when redirection is enabled, as it allows any client to send messages to any other client.</mark>
{% endhint %}

## Example

Let's use our good old ‘hello’ message again for this example as well!

```csharp
private void Start()
{
    // This is called on every client when they join!
    NetworkManager.Singleton.OnClientStarted += () =>
    {
        // Normally sending a message to everyone is only a thing for the server to do!
        // Let's say hello to everyone when we join!
        Messenger.ToAll(HelloMessage);
    };
}

[Message(allowRedirect:true)]
private void HelloMessage(ulong senderId)
{
    Debug.Log($"{senderId} says hello!");
}
```

If you want more examples please go to the [samples page](https://jrcooler.gitbook.io/easy-multiplayer/messenger/pages/rkbqiWiylu9nBB2GneVi#messengersamplegettingstarted.cs).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jrcooler.gitbook.io/easy-multiplayer/messenger/redirection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
