---
# System prepended metadata

title: 'MASTER CONFIGURATION, NETWORK AND STEAM'
tags: [Documentation, ReptileMultiplayer]

---

---
title: 'MASTER CONFIGURATION, NETWORK AND STEAM'
disqus: lucas cavataio
---

<style>
.markdown-body img[src$=".png"] {background-color:transparent;}

.alert-info.lecture,
.alert-success.lecture,
.alert-warning.lecture,
.alert-danger.lecture {
  box-shadow:0 0 0 .5em rgba(64, 96, 85, 0.4); margin-top:20px;margin-bottom:20px;
  position:relative;
  ddisplay:none;
}

.alert-info.lecture:before,
.alert-success.lecture:before,
.alert-warning.lecture:before,
.alert-danger.lecture:before {
  content:"👨‍🏫\A"; white-space:pre-line;
  display:block;margin-bottom:.5em;
  /*position:absolute; right:0; top:0;
  margin:3px;margin-right:7px;*/
}
</style>

MASTER CONFIGURATION, NETWORK AND STEAM
===

:::success
# DOCUMENTATION INDEX

### Reptile Multiplayer Documentation

- PROJECT SETUP: [**GO TO PROJECT SETUP**](https://hackmd.io/@ReptileMultiplayerDocumentation/rkyWOa10n)
- MASTER, NETWORK AND STEAM: **YOU ARE HERE**
- MENU DOCUMENTATION: [**GO TO MENU DOCUMENTATION**](https://hackmd.io/@ReptileMultiplayerDocumentation/SJncKmApn)
- GAMEPLAY DOCUMENTATION: [**GO TO GAMEPLAY DOCUMENTATION**](https://hackmd.io/@ReptileMultiplayerDocumentation/rJxH4yz0h)
:::
---

# CONTENT

[TOC]

## OVERVIEW

This documentation serves as your comprehensive guide to Reptile Multiplayer Solution. It covers a wide range of topics, including configuration, network management, and Steam integration. Whether you are new to game development or an experienced developer, this documentation will provide valuable insights into building multiplayer games with Reptile.

This documentation is organized into sections to help you navigate and find the information you need efficiently. Here's an overview of the main sections you'll find in this documentation:

- **Master:** Learn about the Reptile Master script, which is responsible for storing game configuration and prefab information.

- **Reptile Network Handler:** Explore the Reptile Network Handler, which manages the game's network connectivity, both online and offline.

- **Steam Manager:** Discover how the Steam Manager integrates Steamworks into your game, handling messages and notifications.

- **Reptile Indexes:** Get an overview of various indexes and enumerations used in the Reptile Multiplayer Solution for easy reference.

- **Loading Messages:** Find loading messages used during different stages of the game to provide feedback to players.

- **Room Properties Keys and Values:** Understand the keys and values used for custom room properties in Photon networking.

- **Player Properties Keys:** Learn about keys used for player properties in Photon networking.

- **Region Tokens:** Explore region tokens for different Photon server regions, facilitating server region selection.

Throughout this documentation, you'll find code snippets, explanations, and visuals to help you grasp the concepts and implementation details effectively. We encourage you to explore each section to gain a comprehensive understanding of Reptile Multiplayer Solution and use it to build exciting multiplayer games.

Let's begin by delving into the "Master" section, where you'll learn about key components related to game configuration and asset management.

::: info
This documentation is designed to help you understand the components and functionality of the Reptile Multiplayer Solution fully. If you have any questions or need further assistance, please email at: [lucascavataio@gmail.com](mailto:lucascavataio@gmail.com).
:::

# MASTER

In this solution, we use a Master script to store both value and Prefab information.

## Reptile Master

```csharp=

        //Name of the ReptileGameSettings file.
        private const string GameSettingsFileName = "ReptileGameSettings";
        
        private static GameSettings _gameSettings;
        
        // A property to access the game settings. Loads the settings if not already loaded.
        public static GameSettings gameSettings
        {
            get
            {
                if (_gameSettings == null)
                {
                    LoadGameSettings();
                }

                return _gameSettings;
            }
            private set { _gameSettings = value; }
        }

```

This class loads the 'GameSettings' ScriptableObject, and from here, we would access that element.

EXAMPLE:

```csharp= 
// Set the maximum player count for the room.
options.MaxPlayers = ReptileMaster.gameSettings.maxPlayersInPublicMatchmaking; 
```

---

## GameSettings

### Create and locate new GameSettings

This class is a Scriptable Object that provides the various properties of our game, including configurations and objects we want to instantiate.

You can create a **brand new GameSettings ScriptableObject** by going into "Create/Reptile/GameSettings". This add to your project a new GameSettings ScriptableObject.

![](https://hackmd.io/_uploads/By2hBD1R3.png)

:::warning
Remember that this **GameSettings Scriptable Object** must be located in a folder named **'Resources'**, as the **ReptileMaster** won't be able to locate and load it otherwise.

![](https://hackmd.io/_uploads/rkNuQX9an.png)

In the case you create a **new GameSettings Scriptable Objet** remember you have to replace the field **ReptileMaster.GameSettingsFileName** by the name of the new **GameSettings Scriptable Object**

![](https://hackmd.io/_uploads/S1oQL796n.png)

:::

### GameSettings Properties

---

#### SteamAPPID
- **Type**: `int`
- **Tooltip**: The Steam App ID for the game.
- This property stores the Steam App ID associated with the steam game.

---

### Public Matchmaking

#### maxPlayersInPublicMatchmaking
- **Type**: `int`
- **Tooltip**: Maximum number of players in public matchmaking.
- This property determines the maximum number of players allowed in public matchmaking.

#### needAllPlayersToStartTheMatch
- **Type**: `bool`
- **Tooltip**: Set this to TRUE if your game needs all players to start the match.
- If enabled, this property indicates that all players must be present to start a match.

#### necessaryPlayersToStartTheMatch
- **Type**: `int`
- **Tooltip**: The number of players required to start the match. Set this to 0 if you want the players required to start to always be half the maximum players in public matches.
- This property specifies the minimum number of players required to start a match in public matchmaking. If set to 0, it will default to half of the maximum players.

#### timeToStartInMarchmaking
- **Type**: `float`
- **Tooltip**: Time to start a match in matchmaking.
- This property defines the amount of time the matchmaking process allows before starting a match.

---

### Custom Game

#### maxPlayersInCustomGame
- **Type**: `int`
- **Tooltip**: Maximum number of players in a custom game.
- This property sets the maximum number of players allowed in a custom game.

#### timeToStartInCustomgame
- **Type**: `float`
- **Tooltip**: Time to start a custom game.
- This property specifies the time allocated for starting a custom game.

---

### Local Splitscreen Players

#### maxLocalPlayersInOnlineMode
- **Type**: `int`
- **Tooltip**: Maximum local players in online mode.
- This property determines the maximum number of local players allowed in online mode.

#### maxLocalPlayersInLocalMode
- **Type**: `int`
- **Tooltip**: Maximum local players in local mode.
- This property sets the maximum number of local players allowed in local mode.

---

### GameModes

#### gameModesNames
- **Type**: `string[]`
- **Tooltip**: The position of the array must match the game modes indexes in the "ReptileIndexes.GameModeIndexes".
- This property is an array of strings representing the names of various game modes. The positions of the names should correspond to the game mode indexes defined elsewhere.

---

### Components

#### user
- **Type**: `UserView` - Scriptabe Object
- **Tooltip**: Reference to the UserView component.
- This property holds a reference to the `UserView` component, likely used to manage user information.

#### gamePrefabs
- **Type**: `GamePrefabs` - Scriptabe Object
- **Tooltip**: Reference to the GamePrefabs component.
- This property stores a reference to the `GamePrefabs` component, which likely manages game-related prefabs.

#### gameSounds
- **Type**: `GameSoundsStorage` - Scriptabe Object
- **Tooltip**: Reference to the GameSoundsStorage component.
- This property holds a reference to the `GameSoundsStorage` component, used to store game audio clips.

#### gameUI
- **Type**: `GameUIStorage` - Scriptabe Object
- **Tooltip**: Reference to the GameUIStorage component.
- This property references the `GameUIStorage` component, likely utilized to store game UI elements.

---

## GameSettings Components

### GameSettings Flow

```graphviz
digraph hierarchy {

                nodesep=1.0 // increases the separation between nodes

                node [color=Blue,fontname=Courier,shape=box] 
                edge [color=Red, style=dashed]

                ReptileMaster->{GameSettings}
                GameSettings->{UserView GamePrefabs GameSounds GameUI}
}
```

### UserView

![](https://hackmd.io/_uploads/HkYgX496h.png)

The `UserView` class is a `ScriptableObject` that represents a user's view or profile in the game. It contains information about the user's nickname, user ID, and level.

:::warning

In this example template, the level is set randomly, you may want to change it in the future...

![](https://hackmd.io/_uploads/SkfIN496n.png)
:::

---

#### nickname
- **Type**: `string`
- This property stores the nickname of the user.
- It represents the display name or username of the user within the game.

#### userID
- **Type**: `string`
- This property stores the unique user ID.
- It represents a unique identifier associated with the user.

#### lvl
- **Type**: `int`
- This property stores the user's level.
- It represents the level or progress of the user within the game.

---

#### Methods

#### Setup(string _nickname, string _userID)
- This method is used to set up the user's information, including a random level.
- **Parameters**:
  - `_nickname`: The nickname or display name of the user.
  - `_userID`: The unique identifier of the user.
- This method assigns the provided `nickname` and `userID` values to their respective properties. Additionally, it assigns a random value between 0 and 100 to the `lvl` property, effectively initializing the user's profile with a random level.

---

### GamePrefabs

![](https://hackmd.io/_uploads/Skewv49p3.png)


The `GamePrefabs` class is a `ScriptableObject` that holds references to various prefabricated game objects used throughout the game. These prefabs are commonly used in different UI elements and gameplay scenarios.

---

#### PlayerPrefabs
- **Type**: `GameObject[]`
- This property is an array of GameObjects representing player prefabs.
- It contains references to prefabricated objects representing different player characters that can be used in the game.

---
#### **UI Prefabs**

#### PlayerListCellPrefab
- **Type**: `GameObject`
- **Tooltip**: A representation of the players in the Lobby.
- This prefab is used to display information about players in the game's lobby UI.

#### FriendListCellPrefab
- **Type**: `GameObject`
- **Tooltip**: A representation of the friends in the FriendsMenu/FriendList.
- This prefab is used to display information about friends in the game's friend list UI.

#### SplitScreenCellInfoPrefab
- **Type**: `GameObject`
- **Tooltip**: The information about adding a local player in split screen that appears below your PlayerListCell.
- This prefab provides additional information related to adding a local player in split-screen mode.

#### SearchingPlayerCell
- **Type**: `GameObject`
- **Tooltip**: Represent the empty player slot in the matchmaking menu.
- This prefab is used to display an empty player slot while searching for players in the matchmaking menu.

#### InvitationNotificationPrefab
- **Type**: `GameObject`
- **Tooltip**: The notification that appears when a player invites you to the game.
- This prefab is used to display a notification when a player receives an invitation to join a game.

#### InvitationSentNotificiationPrefab
- **Type**: `GameObject`
- **Tooltip**: The notification that appears when you invite a player to your game.
- This prefab is used to display a visual representation of the invitation you just sent.

---

### GameSoundsStorage

![](https://hackmd.io/_uploads/ByikN226h.png)

The `GameSoundsStorage` class is a `ScriptableObject` that stores references to audio-related assets and settings used within the game. These assets include audio mixers, audio mixer groups, and individual sound clips.

#### masterMixer
- **Type**: `AudioMixer`
- This property holds a reference to the master audio mixer.
- It represents the main audio mixer that controls the overall audio output in the game.

#### menuEffectsMixer
- **Type**: `AudioMixerGroup`
- This property holds a reference to an audio mixer group for menu sound effects.
- It represents an audio mixer group specifically used for controlling sound effects in the game's menus.

#### hoverMenuButtonSound
- **Type**: `AudioClip`
- This property holds a reference to an audio clip for the hover sound effect on menu buttons.
- It represents the sound that is played when a player hovers over a menu button.

#### countDownSound
- **Type**: `AudioClip`
- This property holds a reference to an audio clip for the countdown sound effect.
- It represents the sound that is played during countdown sequences in the game.

### GameUIStorage

![](https://hackmd.io/_uploads/BJt8I33a2.png)

The `GameUIStorage` class is a `ScriptableObject` that holds references to UI-related assets used within the game. In this case, it includes an array of textures representing pictures of maps used in the game.

:::info
**EXAMPLE:**

Build Settings
![](https://hackmd.io/_uploads/HJAEPnh6n.png)

GameUIStorage - Maps Pictures
![](https://hackmd.io/_uploads/BJsf_23T2.png)

:::


#### MapsPictures
- **Type**: `Texture2D[]`
- **Tooltip**: The position of the array must match the scenes index in the build settings.
- This property is an array of `Texture2D` objects representing pictures of maps in the game, these images are displayed in MapView.

:::info
**MAP VIEW:**

![](https://hackmd.io/_uploads/mapview.png)

:::

- The positions of the textures in the array correspond to the scenes' index in the build settings.

# REPTILE NETWORK HANDLER

## ReptileNetwork

The `ReptileNetwork` class is responsible for managing the connection to the Photon server and controlling offline and online modes for the game.

### Public Properties

#### isInOfflineMode
- **Type**: `bool`
- **Tooltip**: Indicates whether the game is currently in offline mode.
- This property is used to determine whether the game is set to offline mode.

---

### Methods

#### Awake()
- **Description**: Initializes the `ReptileNetwork` instance as a singleton and makes it persistent across scenes.

#### Start()
- **Description**: Sets up Photon if it hasn't already been set up.

#### PhotonSetup()
- **Description**: Configures Photon settings and prepares for connection to the Photon server. It also handles cursor settings.

#### SetupUser()
- **Description**: Sets up the user's information for Photon, including their nickname and Steam authentication values.

#### PlayOnline()
- **Description**: Sets the game to online mode and connects to the Photon server.

#### PlayOffline()
- **Description**: Sets the game to offline mode, enabling local play without a server connection.

#### CreateOfflineRoom()
- **Description**: Creates an offline room for local play when in offline mode.

#### ConnectToServer()
- **Description**: Connects to the Photon server and enables automatic scene synchronization.

#### DisconnectFromServer()
- **Description**: Disconnects from the Photon server if already connected.

#### ChangeRegion(string _token, bool restartConnection = false)
- **Description**: Changes the Photon server region.
- **Parameters**:
  - `_token`: The new server region token.
  - `restartConnection`: (Optional) Whether to restart the connection after changing the region.

---

**Note**: Detailed comments within the code provide additional information about each method and property.

This class is part of the `Reptile.Networks` namespace and plays a crucial role in managing the game's network functionality.

## ReptileEventsHandler

The `ReptileEventsHandler` class is responsible for handling Photon network events and performing corresponding actions within the game.

When `PhotonNetwork.RaiseEvent()` is triggered, it calls the `OnEvent()` method.

### Public Properties

#### Instance
- **Type**: `ReptileEventsHandler`
- **Description**: Singleton instance of the `ReptileEventsHandler` class.
- This property allows access to the singleton instance of the `ReptileEventsHandler` class.

### Methods

#### Awake()
- **Description**: Initializes the `ReptileEventsHandler` instance as a singleton and makes it persistent across scenes.

#### OnEnable()
- **Description**: Subscribes to Photon network events when the component is enabled.

#### OnDisable()
- **Description**: Unsubscribes from Photon network events when the component is disabled.

#### OnEvent(EventData photonEvent)
- **Description**: Handles incoming Photon network events and performs corresponding actions.
- **Parameters**:
  - `photonEvent`: The Photon event data containing event code and custom data.

### Events Handling

#### SpawnEvents
- **Description**: Handles Photon events related to spawning game objects and player list items.

#### LobbyEvents
- **Description**: Handles Photon events related to lobby management and UI interactions.

**Note**: Detailed comments within the code provide additional information about each method, property, and event handling section.

This class is part of the `Reptile.Networks` namespace and plays a crucial role in responding to network events in the game.


## SteamManager

The `SteamManager` class manages Steamworks integration, handles incoming Steam messages, and provides utility functions for Steam-related operations.

### Public Properties

#### Instance
- **Type**: `SteamManager`
- **Description**: Singleton instance of the `SteamManager` class.
- This property allows access to the singleton instance of the `SteamManager` class.

### Methods

#### Awake()
- **Description**: Initializes the `SteamManager` instance as a singleton and initializes the Steam client if valid.

#### Update()
- **Description**: Updates the Steam manager to handle incoming Steam messages.

#### HandleMessageFrom(SteamId _steamId, byte[] _data)
- **Description**: Handles incoming messages from Steam and creates notifications for incoming friend invites.
- **Parameters**:
  - `_steamId`: The Steam ID of the sender.
  - `_data`: The data received from Steam.

#### OnApplicationQuit()
- **Description**: Shuts down the Steam client when the application quits.

#### GetTextureFromImage(Steamworks.Data.Image image)
- **Description**: Converts a Steam image into a Unity Texture2D.
- **Parameters**:
  - `image`: The Steam image to convert.
- **Returns**: A Texture2D representation of the Steam image.

### SteamCallbacks

- **Description**: This region can be used to add any Steam callback methods as needed.

**Note**: Detailed comments within the code provide additional information about each method and property.

This class is part of the `Reptile.Managers` namespace and plays a crucial role in handling Steam integration and notifications in the game.

---

# REPTILE INDEXES

## ReptileIndexes Class

The `ReptileIndexes` class defines various enumerations and indexes used in the game.

### Enumerations

#### LevelsIndexes
- **Description**: Represents indexes for different game levels.
- It includes indexes for the lobby and levels.

#### MenuIndexes
- **Description**: Represents indexes for different menus in the game.
- It includes indexes for loading, multiplayer, lobby, custom game, matchmaking, and local game menus.

#### SettingMenusIndexes
- **Description**: Represents indexes for different settings menus in the game.
- It includes indexes for the main settings menu, controls, graphics, sounds, and network settings.

#### GameModeIndexes
- **Description**: Represents indexes for different game modes in the game.
- It currently includes an index for the "Free For All" game mode.

## LoadingMessages Class

The `LoadingMessages` class defines messages used during the loading process in the game.

### Properties

- Various static string properties define loading messages for different stages of the game.

## ReptileRoomPropertiesKeys Class

The `ReptileRoomPropertiesKeys` class defines keys used for custom room properties in Photon.

### Properties

- `STATUS_KEY`: Represents the status key used for room status.
- `ROOM_TYPE_KEY`: Represents the room type key used for room type.
- `MAP_KEY`: Represents the map key used for room maps.
- `GAMEMODE_KEY`: Represents the game mode key used for room game modes.

## ReptileRoomPropertiesValues Class

The `ReptileRoomPropertiesValues` class defines values used for custom room properties in Photon.

### Properties

- Various static string properties define values for room status, room type, and room game modes.

## ReptilePlayerPropertiesKeys Class Documentation

The `ReptilePlayerPropertiesKeys` class defines keys used for player properties in Photon.

### Properties

- `SPLITSCREEN_PLAYERS_COUNT`: Represents the key used to store the count of split-screen players.

## RegionTokens Class

The `RegionTokens` class defines region tokens for different Photon server regions.

### Properties

- Various constant string properties represent different region tokens.
- The `Tokens` dictionary maps region names to their corresponding tokens.

**Note**: Detailed comments within the code provide additional information about each class, enumeration, and property.

