mooball
    Preparing search index...

    Interface ModifierCallbacks

    Beware that these callbacks do not exist in Renderer objects, but they do in all RoomConfig and Plugin objects.

    interface ModifierCallbacks {
        modifyClientPing?(ping: number, customData?: any): number;
        modifyPlayerData?(
            playerId: number,
            name: string,
            flag: string,
            avatar: string,
            conn: string,
            auth: string,
            customData?: any,
        ):
            | [modifiedName: string, modifiedFlag: string, modifiedAvatar: string]
            | Promise<
                [modifiedName: string, modifiedFlag: string, modifiedAvatar: string],
            >
            | null;
        modifyPlayerPing?(playerId: number, ping: number, customData?: any): number;
        onOperationReceived?(
            type: OperationType,
            msg: MooballEvent,
            globalFrameNo: number,
            clientFrameNo: number,
            customData?: any,
        ): boolean;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • If defined, runs only for the current player in a client room and modifies its ping value.

      Parameters

      • ping: number

        Current ping value of the current player.

      • OptionalcustomData: any

      Returns number

      The new ping value of the current player.

      this.modifyClientPing = (ping)=>(100000+ping**3); // set your ping to 100000 + its original value cubed;
      
    • Called 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.

      Parameters

      • playerId: number

        Id of the new player who is about to join the room.

      • name: string

        Name of the new player who is about to join the room.

      • flag: string

        Country code of the new player who is about to join the room.

      • avatar: string

        Avatar of the new player who is about to join the room.

      • conn: string

        Connection string of the new player who is about to join the room.

      • auth: string

        Auth string of the new player who is about to join the room.

      • OptionalcustomData: any

      Returns
          | [modifiedName: string, modifiedFlag: string, modifiedAvatar: string]
          | Promise<
              [modifiedName: string, modifiedFlag: string, modifiedAvatar: string],
          >
          | null

      • null: 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.
      ];
      };
    • If 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.

      Parameters

      • playerId: number

        Id of the current player.

      • ping: number

        Current ping value of the current player.

      • OptionalcustomData: any

      Returns number

      The new ping value of the current player.

      this.modifyPlayerPing = function(playerId, ping){
      return 100000 + ping*ping*ping; // set everybody(except host)'s ping to 100000 + its original value cubed.
      };
    • If 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.

      Parameters

      • type: OperationType

        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.

      • msg: MooballEvent

        The original message object. We can directly modify all contents of this object here as we wish.

      • globalFrameNo: number

        The global frame no that host's physics engine is at, at the time that the message is received.

      • clientFrameNo: number

        The frame no that this client's physics engine is at, at the time that the message is received.

      • OptionalcustomData: any

      Returns boolean

      • true: 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;
      };