{
  "rules": {
    "sites": {
      ".read": true,
      "$site": { ".write": "__ADMIN__" }
    },
    "presence": {
      "$site": {
        ".read": true,
        ".write": "__ADMIN__",
        "$sid": {
          ".write": "root.child('sites/'+$site).exists()",
          ".validate": "newData.hasChildren(['t']) && newData.child('t').isNumber() && newData.child('t').val() <= now + 60000 && (!newData.child('z').exists() || (newData.child('z').isString() && newData.child('z').val().length <= 40)) && (!newData.child('p').exists() || (newData.child('p').isString() && newData.child('p').val().length <= 90))"
        }
      }
    },
    "stats": {
      "$site": {
        ".read": true,
        ".write": "__ADMIN__",
        "total": { ".write": "root.child('sites/'+$site).exists()", ".validate": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || (data.exists() && newData.val() === data.val() + 1))" },
        "pv": { ".write": "root.child('sites/'+$site).exists()", ".validate": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || (data.exists() && newData.val() === data.val() + 1))" },
        "d": { "$day": { ".write": "root.child('sites/'+$site).exists() && $day.matches(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)", ".validate": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || (data.exists() && newData.val() === data.val() + 1))" } },
        "p": { "$day": { ".write": "root.child('sites/'+$site).exists() && $day.matches(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)", ".validate": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || (data.exists() && newData.val() === data.val() + 1))" } },
        "peak": {
          ".write": "root.child('sites/'+$site).exists()",
          ".validate": "newData.hasChildren(['n','t']) && newData.child('n').isNumber() && newData.child('t').val() === now && (!data.exists() || newData.child('n').val() > data.child('n').val()) && (!data.exists() || newData.child('n').val() <= data.child('n').val() + 25)"
        }
      }
    },
    "chat": {
      "$site": {
        ".read": true,
        ".write": "__ADMIN__",
        "m": {
          ".indexOn": ["ts", "u"],
          "$mid": {
            ".write": "__ADMIN__ || (auth != null && !data.exists() && newData.exists() && root.child('sites/'+$site).exists() && root.child('sites/'+$site+'/chat/on').val() !== false && !root.child('bans/'+$site+'/'+auth.uid).exists() && (!root.child('chat/'+$site+'/last/'+auth.uid).exists() || (now - root.child('chat/'+$site+'/last/'+auth.uid).val() > 1500 && (!root.child('sites/'+$site+'/chat/slow').exists() || now - root.child('chat/'+$site+'/last/'+auth.uid).val() >= root.child('sites/'+$site+'/chat/slow').val() * 1000))))",
            ".validate": "newData.hasChildren(['n','x','u','ts']) && newData.child('u').val() === auth.uid && newData.child('ts').val() === now && newData.child('n').isString() && newData.child('n').val().length >= 1 && newData.child('n').val().length <= 30 && newData.child('x').isString() && newData.child('x').val().length >= 1 && newData.child('x').val().length <= 500 && (!newData.child('mod').exists() || __ADMIN__)"
          }
        },
        "last": {
          "$uid": { ".write": "auth != null && auth.uid === $uid", ".validate": "newData.val() === now" }
        }
      }
    },
    "bans": {
      "$site": {
        ".read": "__ADMIN__",
        ".write": "__ADMIN__",
        "$uid": { ".read": "auth != null && auth.uid === $uid" }
      }
    }
  }
}
