function initConfig(ctx,config) { var obj = store.get(ctx, "Config",config._id); if(obj) config.value=obj.value; var obj = store.upsert(ctx, "Config", config); return obj; } // Fixures function setFixures() { var ctx = context.new(); // Migration var obj = store.get(ctx, "Config", "version"); console.log("Migration"); if(obj) { console.log(obj); } // Config console.log("Fixures Config"); var obj = initConfig(ctx, {"_id": "version", "default": "0.0.0","visible":false}); } // La fonction "onInit()" (si déclarée) est automatiquement // exécutée au démarrage du serveur de votre application. function onInit() { setFixures(); rpc.register("getAuthrole"); rpc.register("getAuthid"); rpc.register("getAuthpseudo"); rpc.register("getAuthisuser"), rpc.register("getConfigs"); rpc.register("getConfig"); rpc.register("upsertConfig"); rpc.register("getCard"); rpc.register("upsertCard"); rpc.register("initCard"); rpc.register("getTile"); rpc.register("upsertTile"); rpc.register("initTile"); rpc.register("getTiletype"); rpc.register("upsertTiletype"); rpc.register("initTiletype"); rpc.register("getTilelevel"); rpc.register("upsertTilelevel"); rpc.register("initTilelevel"); rpc.register("getPartys"); rpc.register("getPartyswait"); rpc.register("getParty"); rpc.register("upsertParty"); rpc.register("deleteParty"); rpc.register("getPartyplayers"); rpc.register("getPlayer"); rpc.register("initPlayer"); rpc.register("upsertPlayer"); rpc.register("getPlayerParty"); rpc.register("upsertlayerParty"); rpc.register("getPlayerPartyTile"); rpc.register("upsertlayerPartyTile"); } // Repository Auth async function getAuthrole(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_ROLE); return obj; } async function getAuthid(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_SUBJECT); if(!obj) { obj = await context.get(ctx, context.SESSION_ID); } return obj; } async function getAuthpseudo(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_PREFERRED_USERNAME); if(!obj) { obj = await context.get(ctx, context.SESSION_ID); } return obj; } async function getAuthisuser(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_ISSUER); if(!obj) { obj = false; } return obj; } // Repository Config async function getConfigs(ctx) { var obj = await store.query(ctx, "Config",{"eq":{ "visible": true }},); return obj; } async function getConfig(ctx,id) { var obj = await store.get(ctx, "Config",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertConfig(ctx,config) { var obj = await store.upsert(ctx, "Config", config); return obj; } // Repository Card async function getCard(ctx,id) { var obj = await store.get(ctx, "Card",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertCard(ctx,card) { var obj = await store.upsert(ctx, "Card", config); return obj; } function initCard(ctx,card) { var obj = store.get(ctx, "Card",card._id); if(obj) card.value=obj.value; var obj = store.upsert(ctx, "Card", card); return obj; } // Repository Tile async function getTile(ctx,id) { var obj = await store.get(ctx, "Tile",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertTile(ctx,card) { var obj = await store.upsert(ctx, "Tile", config); return obj; } function initTile(ctx,tile) { var obj = store.get(ctx, "Tile",tile._id); if(obj) tile.value=obj.value; var obj = store.upsert(ctx, "Tile", tile); } // Repository TileType async function getTiletype(ctx,id) { var obj = await store.get(ctx, "Tiletype",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertTiletype(ctx,card) { var obj = await store.upsert(ctx, "Tiletype", config); return obj; } function initTiletype(ctx,tiletype) { var obj = store.get(ctx, "Tiletype",tiletype._id); if(obj) tiletype.value=obj.value; var obj = store.upsert(ctx, "Tiletype", tiletype); } // Repository Tilelevel async function getTilelevel(ctx,id) { var obj = await store.get(ctx, "Tilelevel",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertTilelevel(ctx,card) { var obj = await store.upsert(ctx, "Tilelevel", config); return obj; } function initTilelevel(ctx,tilelevel) { var obj = store.get(ctx, "Tilelevel",tilelevel._id); if(obj) tilelevel.value=obj.value; var obj = store.upsert(ctx, "Tilelevel", tilelevel); } // Repository Party async function getPartys(ctx) { var obj = await store.query(ctx, "Party"); return obj; } async function getPartyswait(ctx) { var obj = await store.query(ctx, "Party",{"eq":{ "status": "playerwait" }},); return obj; } async function getParty(ctx,id) { var obj = await store.get(ctx, "Party",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertParty(ctx,party) { var obj = await store.upsert(ctx, "Party", party); return obj; } async function deleteParty(ctx,id) { // Supprimer le media des Partyplayer var obj = await store.query(ctx, "Player", { "eq":{ "partyid": id }, }); obj.forEach(async(player) => { player.partyid=null; var obj = await store.upsert(ctx, "Player", player); }); // Supprimer le media var obj = await store.delete(ctx, "Party", id); return obj; } async function getPartyplayers(ctx,id) { var obj = await store.query(ctx, "Player",{"eq":{ "partyid": id }},); return obj; } // Repository Player async function getPlayer(ctx,id) { var obj = await store.get(ctx, "Player",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function initPlayer(ctx,player) { if(!player.isuser) player.name=player.name.replace("Anon ",""); var obj = await store.get(ctx, "Player",player._id); if(!obj) obj = await store.upsert(ctx, "Player", player); return obj; } async function upsertPlayer(ctx,player) { var obj = await store.upsert(ctx, "Player", player); return obj; } // Repository PlayerParty async function getPlayerParty(ctx,playerid,partyid) { var obj = await store.query(ctx, "PlayerParty", { "and": [ "eq":{ "playerid": playerid }, "eq":{ "partyid": partyid } ] } ); return obj; } async function upsertPlayerParty(ctx,playerparty) { var obj = await store.upsert(ctx, "PlayerParty", playerparty); return obj; } // Repository PlayerPartyCase async function getPlayerPartyTile(ctx,playerid,partyid,Tileid) { var obj = await store.query(ctx, "PlayerPartyTile", { "and": [ "eq":{ "playerid": playerid }, "eq":{ "partyid": partyid }, "eq":{ "tileid": tileid }, ] } ); return obj; } async function upsertPlayerPartyCase(ctx,playerpartycase) { var obj = await store.upsert(ctx, "PlayerPartyCase", playerpartycase); return obj; } // La fonction "onClientMessage(ctx, message)" est automatiquement // exécutée quand le serveur de votre application reçoit un // message en provenance du client. async function onClientMessage(ctx, message) { await net.broadcast(message); }