# Common Functions

Here are some Common fuctions that NetworkManager provides that you may find usful.

<details>

<summary>IsRunningLogic()</summary>

This checks if your current device is the **host** — the one responsible for running all the **authoritative game logic**.

* In both normal and relay modes, it returns `true` only for the actual gameplay host (not the relay server).
* This is what you should use when deciding who runs logic like health updates, object spawning, etc.

> Think of this as: *"Am I in charge of running the game world?"*

```csharp
NetworkManager.Instance().IsRunningLogic()
```

</details>

<details>

<summary>IsServerConnection()</summary>

This checks if your current connection is the **server** (the one routing messages).

* In a **relay setup**, this will return `true` for the relay server — even though it's not running game logic.
* In Embedded and Authoritative server, this also returns `true` for the headless instance.

> Think of this as: *"Am I the connection point for others?"*

```csharp
NetworkManager.Instance().IsServerConnection();
```

</details>

<details>

<summary>GetConnectionID()</summary>

Each Clients that join the session has a unique Connection ID used to distinguish between clients you can get that using.

```csharp
NetworkManager.Instance().GetConnection().GetSocket().GetConnectionID();
```

You can do the same if you have the IClient of the client

```csharp
//where client is an IClient 
(client as NetworkClient).GetConnectionId();
```

</details>

<details>

<summary>DisableAutoLoadSceneElements()</summary>

ObjectNet AutoMatically detects elements that are existing on the scene and send them to the  newlly joinned client. However you can disable this process and do it manually using

```csharp
//Disable the AutoLoad Scene elements system
NetworkManager.Instance().DisableAutoLoadSceneElements();
//Enable the AutoLoad scene elements system
NetworkManager.Instance().EnableAutoLoadSceneElements();
//request the scene elements from the server
NetworkManager.Instance().RequestRemoteSceneElements();  
```

</details>

<details>

<summary>GetLocalPlayerObject()</summary>

You can get the Local Player gameObject using

```csharp
NetworkManager.Instance().GetLocalPlayerObject();
```

</details>

<details>

<summary>Get any Network Object </summary>

you can get the refrence of any Network Object in the scene using its NetworkID

```csharp
//Get the GameObject of any Network object using the Network id 
GameObject instance = 
NetworkManager.Container.GetElement(NetworkId).GetGameObject();
```

</details>

<details>

<summary>GetActiveTransport()</summary>

You can get the currently used NetworkTransport name using

```csharp
NetworkManager.Instance().GetActiveTransport().GetName();
```

</details>

<details>

<summary>Kick players</summary>

you can kick any player if you have their IClient just like the example below

```csharp
client.GetTransport().Disconnect()
```

Here is an example that will kick all players except for the host

```csharp
IClient[] clients = NetworkManager.Instance().GetConnectedClients<IClient>();
foreach (IClient client in clients) {                
    client.GetTransport().Disconnect();
 }
```

</details>

For a complete list, refer to the  [API Documentation](https://onlineobject.net/objectnet/docs/api/html/N-com.onlineobject.objectnet.htm).
