class MAGES::Networking::MAGESNetworking

Overview

The MAGES networking module. More…

class MAGESNetworking: public MAGES::NetworkingModule
{
public:
    // properties

    GameObject NetworkHandLeft;
    GameObject NetworkHandRight;
    GameObject NetworkAvatar;
    GameObject MessageHandlerPrefab;
    SerializableDictionary PathReferences;
    SerializableDictionary PathToGameObject;
    SerializableDictionary PathToPrefabID;

    // methods

    virtual override bool EstablishConnectionToMainServer(string args);
    virtual override void DisconnectFromMainServer();
    virtual override bool CreateRoom(string roomName);
    virtual override bool JoinRoom(string roomName = null);
    virtual override bool ExitCurrentRoom();
    virtual override List GetAvailableRooms();
    virtual override string GetCurrentConnectedRoom();
    virtual override void OnDisconnected(string cause);
    virtual override void OnConnected(string info);
    virtual override bool OwnershipRequest(MAGESObject obj);

    virtual override bool LinkNetworkObject(
        GameObject remotePrefab,
        GameObject localPrefab
    );

    virtual override GameObject NetworkSpawn(
        GameObject prefab,
        bool isUnique = true
    );

    virtual override void RemoteDestroyComponent(
        GameObject gameObject,
        string componentType
    );

    virtual override void RequestChangeState(byte changeState, string actionID);
    virtual override int GetConnectedUsersToRoom(string roomName);
    virtual override int GetConnectedUsersToCurrentRoom();
    virtual override void AddSyncTransform(GameObject objectToBeSynchronized);
    virtual override bool HasAuthority(GameObject networkObject);

    virtual override void RegisterActivatedObject(
        GameObject grabbableObject,
        bool isActivated
    );

    virtual override bool IsRemoteActivated(GameObject grabbableObject);
    virtual override void Startup();

    virtual override int GetPrefabIDFromNetwork(
        GameObject prefab,
        out bool isUnique
    );

    virtual override void Shutdown();
};

Inherited Members

public:
    // properties

    bool AutomaticSceneSetup;
    Type NetworkIdType;
    IMAGESNetworkIntegration Integration;
    bool IsInitialized;
    bool IsHost;

    // methods

    virtual abstract void Startup() = 0;
    virtual abstract void Shutdown() = 0;
    virtual abstract bool EstablishConnectionToMainServer(string args) = 0;
    virtual abstract void DisconnectFromMainServer() = 0;
    virtual abstract bool CreateRoom(string roomName) = 0;
    virtual abstract bool JoinRoom(string roomName = null) = 0;
    virtual abstract bool ExitCurrentRoom() = 0;
    virtual abstract List GetAvailableRooms() = 0;
    virtual abstract string GetCurrentConnectedRoom() = 0;
    virtual abstract void OnDisconnected(string cause) = 0;
    virtual abstract void OnConnected(string info) = 0;
    virtual abstract bool OwnershipRequest(MAGESObject obj) = 0;

    virtual abstract int GetPrefabIDFromNetwork(
        GameObject prefab,
        out bool isUnique
    ) = 0;

    virtual abstract bool LinkNetworkObject(
        GameObject networkPrefab,
        GameObject localPrefab
    ) = 0;

    virtual abstract GameObject NetworkSpawn(
        GameObject prefab,
        bool spawnedByHost = true
    ) = 0;

    virtual abstract void RemoteDestroyComponent(
        GameObject gameObject,
        string componentType
    ) = 0;

    virtual abstract void RequestChangeState(byte changeState, string actionID) = 0;
    virtual abstract int GetConnectedUsersToRoom(string roomName) = 0;
    virtual abstract int GetConnectedUsersToCurrentRoom() = 0;
    virtual abstract void AddSyncTransform(GameObject objectToBeSynchronized) = 0;

    virtual abstract void RegisterActivatedObject(
        GameObject grabbableObject,
        bool isActivated
    ) = 0;

    virtual abstract bool IsRemoteActivated(GameObject grabbableObject) = 0;
    virtual abstract bool HasAuthority(GameObject networkObject) = 0;

Detailed Documentation

The MAGES networking module.

Properties

GameObject NetworkHandLeft

Gets the left hand that is visible to other users.

GameObject NetworkHandRight

Gets the right hand that is visible to other users.

GameObject NetworkAvatar

Gets the avatar that is visible to other users.

GameObject MessageHandlerPrefab

Gets the network prefab responsible for synchronizing the game state and exchanging messages between users.

SerializableDictionary PathReferences

Gets the map of gameobject references to prefab paths.

SerializableDictionary PathToGameObject

Gets the map of gameobject references to prefab paths.

SerializableDictionary PathToPrefabID

Gets the map of prefab paths to local prefab IDs.

Methods

virtual override bool EstablishConnectionToMainServer(string args)

Establish connection to the main server.

Parameters:

args

Connect arguments. Regions eu, us etc.

Returns:

Return true if connection succeed.

virtual override void DisconnectFromMainServer()

Disconnect from main server. Does nothing if client is not already connected.

virtual override bool CreateRoom(string roomName)

Creates a room with the provided name.

Parameters:

roomName

Room name.

Returns:

True if room was created successfully.

virtual override bool JoinRoom(string roomName = null)

Attempts to join a room with the provided name.

Parameters:

roomName

The room name to join.

Returns:

True if room was created successfully.

virtual override bool ExitCurrentRoom()

Exits the current room.

Returns:

True if exited successfully.

virtual override List GetAvailableRooms()

Find and return all available rooms.

Returns:

Return a list with all available rooms.

virtual override string GetCurrentConnectedRoom()

Return current connected room.

Returns:

Returns name of current room. Null if user is not connected to a room.

virtual override void OnDisconnected(string cause)

Called on disconnected.

Parameters:

cause

Disconnect cause.

virtual override void OnConnected(string info)

Called on connected to a room.

Parameters:

info

Connection info.

virtual override bool OwnershipRequest(MAGESObject obj)

Request ownership for a MAGESObject.

Parameters:

obj

The obj to take ownership.

Returns:

Returns true if request succeed.

virtual override bool LinkNetworkObject(
    GameObject remotePrefab,
    GameObject localPrefab
)

Links network object with the remote object.

Parameters:

networkPrefab

The remote object will be linked with the local prefab. At the end it is destroyed.

localPrefab

The local object that will be marked as remote.

Returns:

True if linking was successful. False otherwise.

virtual override GameObject NetworkSpawn(
    GameObject prefab,
    bool isUnique = true
)

Spawns a gameobject over the network. Only required to be called from one user, preferably the host.

Parameters:

prefab

Network object to be spawned.

spawnedByHost

If the object will be spawned by the host to all users. True by default.

Returns:

The spawned object.

virtual override void RemoteDestroyComponent(
    GameObject gameObject,
    string componentType
)

Destroys component in all other users.

Parameters:

gameObject

The gameobject that has that component.

componentType

The type of component.

virtual override void RequestChangeState(byte changeState, string actionID)

Request a change in scenegraph’s state.

Parameters:

changeState

The change keycode that will be requested.

actionID

The ID of the action that will change.

virtual override int GetConnectedUsersToRoom(string roomName)

Gets connected users to a specific room.

Parameters:

roomName

The name ID of the room.

Returns:

The number of the connected users. Returns -1 if the room does not exist.

virtual override int GetConnectedUsersToCurrentRoom()

Gets connected users to the current room.

Returns:

The number of the connected users in the current room. Returns -1 if not connected to a room.

virtual override void AddSyncTransform(GameObject objectToBeSynchronized)

Adds default sync transform to a gameobject.

Parameters:

objectToBeSynchronized

The change keycode that will be requested.

virtual override bool HasAuthority(GameObject networkObject)

Checks if local user has authority over a network object.

Parameters:

networkObject

The network object that will be checked.

Returns:

True if user has authority else false. If the user is not connected in a session.

virtual override void RegisterActivatedObject(
    GameObject grabbableObject,
    bool isActivated
)

Register an object that was remotely activated.

Parameters:

grabbableObject

Object that is remotely activated.

isActivated

If true the object is added, if false the object is removed.

virtual override bool IsRemoteActivated(GameObject grabbableObject)

Returns true if object is remotely activated.

Parameters:

grabbableObject

Object to check.

Returns:

Returns true if object is activated from another user.

virtual override void Startup()

Called when the module is started (usually on application start).

virtual override int GetPrefabIDFromNetwork(
    GameObject prefab,
    out bool isUnique
)

Gets the prefab id from an object that was spawned from the network.

Parameters:

prefab

The object to be checked.

isUnique

Whether this object should be unique.

Returns:

A positive integer in case the object is from network. Else, returns -1.

virtual override void Shutdown()

Called when the module is destroyed or replaced.