Room class. Should be extended by the actual room implementation.

Note: The room class that extends this one can make a convenience link to the proper game (or slave) server class in its constructor like this:

var server: ServerTest;

public function new(s, t, vid)
  {
    super(s, t, vid);
    server = cast _server;
  }

Constructor

new (s:Server, t:_RoomType, vid:Int)

Fields

read only _clients:Array<ClientInfo>

Clients attached to the room.

_server:Server

Game server instance link.

id:Int

Unique room ID.

isDead:Bool

Marks this room as dead when set to true. This should be set to true when the room is no longer needed.

Room.tick() stops working and no updates and notifications will be sent to room clients anymore. Keep in mind that Room.leavePost() callback will not be executed for any clients.

typeID:String

Room type string ID.

Methods

inline broadcast (type:String, msg:Dynamic):Void

Broadcasts the message to all clients in this room.

Parameters:

type

Message type.

msg

Message parameters.

dynamic createPost ():Void

This hook is called after the room is created.

dynamic event (msg:Dynamic):Void

This hook should handle remote room notifications sent with snipe.package.room.SlaveModule.notify().

It can also be used to communicate with the room instance locally.

Parameters:

msg

Notification message.

join (c:ClientInfo):Void

Adds this client to room clients and calls joinPost() callback. Does not check whether this client is already in another room.

Sets "packages/room.id" and "packages/room.type" client variables.

Parameters:

c

Client to join the room.

leave (c:ClientInfo):Void

Removes this client from a list of clients and calls leavePost() callback.

Unsets the "packages/room.id" and "packages/room.type" client variables.

If one of the clients in the room disconnects, this method will be called automatically.

If the room is dead, leavePost() callback will not be called.

Parameters:

c

Client to remove from the room.

replicate (?doFull:Bool):Void

Replicates updated or full public room state to clients. Public state consists of fields defined in the _RoomType.replicated array.

The message will have a "packages/room.state" type with message fields containing room state fields.

Parameters:

doFull

If set to true, will do full state replication. Optional. If not enabled, will only replicate room fields that were updated. Always clears the list of updated fields.

dynamic tick (timePassed:Float):Void

Room time passage. Called periodically in the main server thread (the exact amount is specified in the room type).

Since the server cannot guarantee that this precise amount of time will pass since the last call, it will pass the time that passed since the last tick finished into the method call.

Parameters:

timePassed

How much time has actually passed since the last tick finished in seconds.

updated (key:String):Void

Marks room field as changed. This will put the field in a list of changed fields until the replicate() method is called. Should be called after each state change that will need to be propagated to the clients.

In case when the room is persistent, this will also update the block field which will be saved later.

Parameters:

key

Room instance field name.