Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. bradrisse
bradrisse

bradrisse

@bradrisse

Chat Follow Unfollow
0
Reputation
1
Posts
600
Profile views
0
Followers
0
Following
Joined 18 Jan 2020, 23:08 Last Online 7 Feb 2020, 04:07

  • Profile
  • More
    • Continue chat with bradrisse
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
bradrisse Follow

Posts made by bradrisse

Filter Schema in Javascript

I was having issues getting the filter to work correctly in Javascript. The javascript tab was missing on the documentation. I was able to get it working by using the following code:

schema.defineTypes(Player, {
  owner: "string",
  secret: "string"
})

schema.filter(function(client) {
  return this.owner === client.sessionId && this.secret
})(Player, "secret")

However some modifications were needed for this to get passed correctly. Specifically in annotations.js I had to change filter function to:

function filter(cb) {
    return function (target, field) {
        /*
         * static filters
         */
        if (!target._filters) {
            target._filters = {};
        }
        target._filters[field] = cb;
    };
}
exports.filter = filter;

This issue was it was adding to the schemas constructor _filters variable but in the schema serializer it was looking for newState['_filters'])

this.hasFiltersByClient = this.hasFilter(newState['_schema'], newState['_filters']);

After those changes were made the data is successfully protected from other clients and shows undefined instead of the string "secret"

Is this change going to break something else? Was adding to the _filters in the schema constructor being pulled from another section?

posted in Questions & Help • 18 Jan 2020, 23:14

© 2023 Endel Dreyer