OptionalmodifyIf defined, runs only for the current player in a client room and modifies its ping value.
Current ping value of the current player.
OptionalcustomData: anyThe new ping value of the current player.
OptionalmodifyCalled just before the player has joined the room. Using this callback, you may block all players or modify all players' name, flag and avatar properties just before they join the room.
Id of the new player who is about to join the room.
Name of the new player who is about to join the room.
Country code of the new player who is about to join the room.
Avatar of the new player who is about to join the room.
Connection string of the new player who is about to join the room.
Auth string of the new player who is about to join the room.
OptionalcustomData: anynull: Blocks the player from joining the room.
[modifiedName: string, modifiedFlag: string, modifiedAvatar: string]: Modifies the name, flag and avatar values.Promise<[modifiedName: string, modifiedFlag: string, modifiedAvatar: string]>: Modifies the name, flag and avatar values after the promise might be resolved.(sync)
this.modifyPlayerData = function(playerId, name, flag, avatar, conn, auth){
if (name=="abc")
return null; // block anyone trying to join the room with name "abc", before he can join the room.
return [
"[" + playerId + "] " + name, // prefix everyone's name with [playerId]
"tr", // set everyone's flag to tr
avatar // do not change avatars
];
};
(async)
this.modifyPlayerData = async function(playerId, name, flag, avatar, conn, auth){
// connect to whatever database you want
var dbPlayerSpecs = await db.getPlayerSpecs(conn, auth);
if (!dbPlayerSpecs)
return null; // blocked.
return [
"[" + playerId + "] {" + dbPlayerSpecs.name + "}" + name, // prefix everyone's name with [playerId] and then player's name in the database.
dbPlayerSpecs.flag, // always use player's flag in the database.
dbPlayerSpecs.avatar // always use player's avatar in the database.
];
};
OptionalmodifyIf defined, runs for all players except host in a host room. Modifies the ping value of the player whose id is playerId.
Host player's ping will not change using this callback. In order to change host player's ping, you need to modify room.hostPing value directly.
Id of the current player.
Current ping value of the current player.
OptionalcustomData: anyThe new ping value of the current player.
OptionalonIf defined, runs for each message received from all clients in a host room, before they are processed and sent to all clients. This is the most important callback inside a host room; all permission logic should reside here. You are also allowed to freely modify the contents of all messages here.
Type of the received message. We have to look it up in the global OperationType object to understand what type of message it actually is.
The original message object. We can directly modify all contents of this object here as we wish.
The global frame no that host's physics engine is at, at the time that the message is received.
The frame no that this client's physics engine is at, at the time that the message is received.
OptionalcustomData: anytrue: accept event.
false: block message from being processed.throw exception: break the connection of the sender of this message.this.onOperationReceived = function(type, msg, globalFrameNo, clientFrameNo, customData){
switch (type){
case OperationType.KickBanPlayer: { // if someone is leaving or being kicked/banned by someone else
var reason = msg.reason; // get the reason. this is null if the player is leaving by himself/herself.
if (reason!=null && playerId!=0) // if any player sends a kick/ban event message other than room host
return false; // block the event message
break;
}
}
return true;
};
Beware that these callbacks do not exist in Renderer objects, but they do in all RoomConfig and Plugin objects.