Understand the heirarchy on the server

Please note that if you do not understand this at first glance, its absolutely fine. You can feed this into chatGPT and talk to it to better understand!!

And as always there is the NO CODE Visualiser available.

Game Class

The Game class represents a Rocket Networking game.

Properties

  • gameId: Unique identifier for the game. You set this in your GM Options.gml

  • serverId: Identifier of the server hosting the game. This is unique to your account. Do not share this or even read it, because its not that useful.

  • rooms: A dictionary of Room instances associated with the game. This is very important! This dictionary the keys are roomIds or Room Names that you made, and values are the Room Objects

Methods

  • SendEventToClientFromServer(ReceiverclientId, eventName, messageStruct) 
    //The most important function. You use this to send a message to a client directly from the server
  • NumberOfClientsInGame(): Returns the total number of clients across all rooms in the game.

  • getClientsInArray(): Returns an array of all clients in the game.

  • stateUpdate(): Executes server-side logic for state updates. This takes your code from the "step" script and executes it, then it does the normal automatic RNet functions.

Less useful methods which may not be relevant to you...

  • addRoom(room): Adds a Room instance to the game. Happens automatically, don't worry about it.

  • RoomsCleanup(): Cleans up rooms with no active clients or persistent objects. Happens automatically, don't worry.

Room Class

The Room class represents a room within a Rocket Networking game.

Properties

  • roomId: Unique identifier for the room. Set by a client. Numerical rooms represent private single Client rooms. Other rooms can have any clients in any combination.

  • serverId: Identifier of the server to which the room belongs. Again, please don't touch this.

  • clients: A dictionary of Client instances within the room. This is very important. The keys here are client id's and the values are the Client Instances (a JS Object) themselves

  • persistentObjects: A dictionary of PersistentObject instances within the room. This is very important. The keys here are persistent object id's and the values are the Persistent Object Instances (a JS Object)

Methods

  • getClientsInArray(): Returns an array of all clients in the room.

  • revisePseudoHost(): Updates the pseudo host based on the earliest joined client. This happens automatically too, but you can call it.

  • getPseudoHostKey(): Returns the key of the current pseudo host. You can call it.

Less useful methods, don't touch.

  • addClient(client): Adds a Client instance to the room. Happens automatically, dont touch.

  • clientsCleanup(): Removes disconnected clients from the room and updates the pseudo host. Happens automatically, dont touch.

Client Class

The Client class represents a client connection within a Rocket Networking room.

Properties

  • socket: WebSocket connection object. Please don't tamper with this. You can view it and see it's structure(which is beautiful btw) but please don't edit it, it will cause dangerous changes to your game.

  • roomId: Identifier of the room to which the client belongs.

  • clientId: Unique identifier for the client.

  • sharedProperties: JSON string representing client-specific shared properties. THIS IS NOT A DICTIONARY!! It is the JSON string representing this dictionary, so use the functions defined below to work with this!

  • sharedPropertiesFromServer: JSON string representing shared properties received from the server. This is what the server edits and sends to the clients in Server side scripting. THIS IS NOT A DICTIONARY!! It is the JSON string representing this dictionary, so use the functions defined below to work with this!

  • isPseudoHost: Indicates whether the client is the pseudo host.

  • lastPingAt: Timestamp of the client's last ping. Epoch format.

  • entities: A dictionary of Entity instances owned by the client. Every key is the entity id and the value is the Entity instance itself.

Methods

The blue code is an example flow for authroitative server logic

  • getSP(): Returns parsed shared properties. Now you can edit this freely!! Like var SP = client.getSP() console.log(SP.W_key_pressed)

  • setSP(sharedPropertiesDict): Sets client-specific shared properties. This takes the new shared properties dictionary and applies it. Not useful in Server side scripting or even in general.

  • getSPfromServer(): Returns parsed shared properties received from the server. This returns the other set of shared properties which are controlled by the server. For example in an authoritative game this could store the x,y coordinates of the player. var SPS = client.getSPfromServer() console.log(SPS.x) //the current x if(SP.W_key_pressed){ SPS.x += 10 }

  • setSPfromServer(sharedPropertiesFromServerDict): Sets shared properties received from the server. client.setSPfromServer(SPS) //SPS which you just edited the x in

Entity Class

The Entity class represents an entity owned by a client within a Rocket Networking game.

Properties

  • EPstring: JSON string representing entity-specific properties. THIS IS NOT A DICTIONARY!! It is the JSON string representing this dictionary, so use the functions defined below to work with this!

  • EPSstring: JSON string representing entity-specific properties received from the server. THIS IS NOT A DICTIONARY!! It is the JSON string representing this dictionary, so use the functions defined below to work with this!

Methods

The usage is very similar to the Client's coresponding code.

  • getEP(): Returns parsed entity-specific properties.

  • setEP(entitySharedPropertiesDict): Sets entity-specific shared properties.

  • getEPfromServer(): Returns parsed entity-specific properties received from the server.

  • setEPfromServer(entitySharedPropertiesFromServerDict): Sets entity-specific shared properties received from the server.

Persistent Object Class

The PersistentObject class represents a persistent object within a Rocket Networking room.

Properties

  • persistentObjectId: Unique identifier for the persistent object.

  • sharedProperties: JSON string representing persistent object properties. THIS IS NOT A DICTIONARY!! It is the JSON string representing this dictionary, so use the functions defined below to work with this!

  • roomRef: Reference to the Room instance containing the persistent object. This is the Room Object Instance itself, not the roomId

Methods

  • getProperties(): Returns parsed persistent object properties.

  • editProperties(newPropertyDict): Edits persistent object properties and notifies clients.

  • destroy(): Removes the persistent object and notifies clients of its deletion.

Last updated