This commit is contained in:
mileswa1q2 authored and GitHub committed 2023-11-23 20:37:33 +00:00
1 parent 1cf1d1988e
commit 40fdf2a04e
714 files changed
+3 -3

No files matched your search

@@ -0,0 +1,2 @@
var gdjs;(function(d){const a=new d.Logger("Player Authentication"),c=d.playerAuthenticationComponents;let S;(function(i){let f=null,T=null,p=null,M=!1,w=!1,G=null,b=null,E=null,C=null,D=null,h=null,l=null,x=null,W=null,u=null,_=null,g=null;d.registerRuntimeScenePostEventsCallback(()=>{M=!1}),d.registerFirstRuntimeSceneLoadedCallback(e=>{B(e)==="web"&&(L(),u=t=>{U(e,t,{checkOrigin:!0})},window.addEventListener("message",u,!0),a.info("Notifying parent window that player authentication is ready."),window.parent.postMessage({id:"playerAuthReady"},"*"),x=setTimeout(()=>{a.info("Removing initial authentication listener."),L()},3e3))});const O=e=>`${e}_authenticatedUser`,j=({runtimeGame:e,gameId:t,connectionId:n})=>`https://gd.games/auth?gameId=${t}${n?`&connectionId=${n}`:""}${e.isUsingGDevelopDevelopmentEnvironment()?"&dev=true":""}`,B=e=>e.getGame().getRenderer().getElectron()?"electron":typeof cordova!="undefined"?"cordova":"web",q=e=>{const t=e.getGame().getAdditionalOptions();return t&&t.isPreview&&t.allowAuthenticationUsingIframeForPreview};i.isAuthenticated=()=>(w||R(),p!==null),i.hasLoggedIn=()=>M,i.getUsername=()=>(w||R(),f||""),i.getUserToken=()=>(w||R(),p||null),i.getUserId=()=>(w||R(),T||null);const P=(e,t,n=0)=>{const r=`${e.isUsingGDevelopDevelopmentEnvironment()?"https://api-dev.gdevelop.io":"https://api.gdevelop.io"}/game/public-game/${t}`;return fetch(r,{method:"HEAD"}).then(s=>s.status!==200?(a.warn(`Error while fetching the game: ${s.status} ${s.statusText}`),s.status===404||n>2?!1:P(e,t,n+1)):!0,s=>(a.error("Error while fetching game:",s),!1))};i.logout=e=>{f=null,p=null,T=null;const t=d.projectData.properties.projectUuid;if(!t){a.error("Missing game id in project properties.");return}window.localStorage.removeItem(O(t)),k(e),i.removeAuthenticationBanner(e);const n=e.getGame().getRenderer().getDomElementContainer();if(!n){m(e,"The div element covering the game couldn't be found, the authentication banner cannot be displayed.");return}c.displayLoggedOutNotification(n)};const R=()=>{const e=d.projectData.properties.projectUuid;if(!e){a.error("Missing game id in project properties.");return}try{const t=window.localStorage.getItem(O(e));if(!t){w=!0;return}const n=JSON.parse(t);f=n.username,T=n.userId,p=n.userToken,w=!0}catch(t){a.warn("Unable to read authentication details from localStorage. Player authentication will not be available.",t)}},k=e=>{i.removeAuthenticationContainer(e),J(),g&&(g.close(),g=null),G&&(G.close(),G=null),b&&(b.close(),b=null)},F=({username:e,userId:t,userToken:n})=>{e||a.warn("The authenticated player does not have a username"),f=e,T=t,p=n,M=!0;const o=d.projectData.properties.projectUuid;if(!o){a.error("Missing game id in project properties.");return}try{window.localStorage.setItem(O(o),JSON.stringify({username:f,userId:T,userToken:p}))}catch(r){a.warn("Unable to save the authentication details to localStorage. Player authentication will not be available.",r)}},H=function(e,t,n,o){F({userId:t,username:n,userToken:o}),k(e),i.removeAuthenticationBanner(e);const r=e.getGame().getRenderer().getDomElementContainer();if(!r){m(e,"The div element covering the game couldn't be found, the authentication banner cannot be displayed.");return}c.displayLoggedInNotification(r,f||"Anonymous"),$(e)},U=function(e,t,{checkOrigin:n}){if(!(n&&!["https://liluo.io","https://gd.games"].includes(t.origin))){if(!t.data.id)throw new Error("Malformed message");switch(t.data.id){case"authenticationResult":{if(!(t.data.body&&t.data.body.token))throw new Error("Malformed message.");H(e,t.data.body.userId,t.data.body.username,t.data.body.token);break}case"alreadyAuthenticated":{if(!(t.data.body&&t.data.body.token))throw new Error("Malformed message.");F({userId:t.data.body.userId,username:t.data.body.username,userToken:t.data.body.token}),L(),V(e);break}}}},m=function(e,t){a.error(t),k(e);const n=e.getGame().getRenderer().getDomElementContainer();if(!n){m(e,"The div element covering the game couldn't be found, the authentication banner cannot be displayed.");return}c.displayErrorNotification(n),$(e)},z=e=>{J();const t=12*60*1e3;W=setTimeout(()=>{a.info("Authentication window did not send message in time. Closing it."),k(e),$(e)},t)},J=()=>{x&&clearTimeout(x),W&&clearTimeout(W)},K=function(e){const t=()=>{i.removeAuthenticationBanner(e)},n=()=>{i.openAuthenticationWindow(e)};return p?c.computeAuthenticatedBanner(n,t,f):c.computeNotAuthenticatedBanner(n,t)};i.displayAuthenticationBanner=function(e){if(l){l.style.opacity="1";return}w||R();const t=e.getGame().getRenderer().getDomElementContainer();if(!t){m(e,"The div element covering the game couldn't be found, the authentication banner cannot be displayed.");return}l=K(e),t.appendChild(l)};const V=function(e){if(!l)return;const t=e.getGame().getRenderer().getDomElementContainer();if(!t){m(e,"The div element covering the game couldn't be found, the authentication banner cannot be displayed.");return}const n=l;l=K(e),t.replaceChild(l,n)},X=(e,t)=>{const n=Line truncated
//# sourceMappingURL=playerauthenticationtools.js.map