It looks like you're new here. If you want to get involved, click one of these buttons!
local bs = {[0]='A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',} local function base64(s) local byte,rep=string.byte,string.rep local pad=2-((#s-1)%3) s=(s..rep('\0',pad)):gsub("...",function(cs) local a,b,c=byte(cs,1,3) return bs[a>>2]..bs[(a&3)<<4|b>>4]..bs[(b&15)<<2|c>>6]..bs[c&63] end) return s:sub(1,#s-pad)..rep('=',pad) end function xtralifeSave() if xtralife then local file=io.open("|D|xtralife.txt","w+") local saveString=json.encode(xtralife) if file then file:write(saveString) file:close() end end end function xtralifeSave() if xtralife then local file=io.open("|D|xtralife.txt","w+") local saveString=json.encode(xtralife) if file then file:write(saveString) file:close() end end end function xtralifeProfileEx(reply) if xtralife then if reply["displayName"] then xtralife.displayName=reply["displayName"] end if reply["lang"] then xtralife.language=reply["lang"] end if reply["firstName"] then xtralife.forename=reply["firstName"] end if reply["lastName"] then xtralife.surname=reply["lastName"] end if reply["addr1"] then xtralife.addr1=reply["addr1"] end if reply["addr2"] then xtralife.addr2=reply["addr2"] end if reply["addr3"] then xtralife.addr3=reply["addr3"] end if reply["avatar"] then xtralife.avatar=reply["avatar"] end end end function xtralifeHeader() local header={ ["User-Agent"]="Gideros",["x-apikey"]=xtralife.apiKey,["x-apisecret"]=xtralife.apiSecret,["content-type"]="application/json"} if xtralife.id and xtralife.secret then header["Authorization"]="Basic "..base64(xtralife.id..":"..xtralife.secret) end return header end function xtralifeCall(call) return "<a href="https://"..xtralife.name.."-api0"..xtralife.server..".clanofthecloud.mobi/"..call" rel="nofollow">https://"..xtralife.name.."-api0"..xtralife.server..".clanofthecloud.mobi/"..call</a> end function xtralifeInit(key,secret,test,server) if json then if not pcall(function() local file=io.open("|D|xtralife.txt","r") if file then local originaldata=file:read() file:close() if originaldata then xtralife=json.decode(originaldata) end end end) then xtralife={} end if not xtralife then xtralife={} end local name="prod" xtralife.test=test or false if test then name="sandbox" end xtralife.name=name xtralife.server=server or 1 xtralife.apiKey=key or "" xtralife.apiSecret=secret or "" xtralife.login=false end end function xtralifeResume() if xtralife and not xtralife.login then if xtralife.id and xtralife.secret and xtralife.id~="" then xtralifeLogin() end end end function xtralifeLogin(network,id,secret) if xtralife and not xtralife.login then print("xtralife Login",network,id,secret) local call="v1/login" xtralife.login=false local body={} if xtralife.id and xtralife.secret then body={network="anonymous",id=xtralife.id,secret=xtralife.secret,options={preventRegistration=true}} xtralife.linkNetwork=network xtralife.linkId=id xtralife.linkSecret=secret elseif id and secret and (network=="facebook" or network=="googleplus" or network=="gamecenter" or network=="email") then body={network=network,id=id,secret=secret} xtralife.linkNetwork=nil else call="v1/login/anonymous" xtralife.linkNetwork=nil end local request=UrlLoader.new() if request then request:addEventListener(Event.COMPLETE,function(e) --print(e.httpStatusCode,e.data) if (e.httpStatusCode==200 or e.httpStatusCode==201) and e.data then local reply=json.decode(e.data) if reply then xtralife.login=true if reply["gamer_id"] then xtralife.id=reply["gamer_id"] end if reply["gamer_secret"] then xtralife.secret=reply["gamer_secret"] end if reply["profile"] then xtralifeProfileEx(reply["profile"]) end xtralifeSave() if xtralife.linkNetwork then xtralifeLink(xtralife.linkNetwork,xtralife.linkId,xtralife.linkSecret) end -- Here you can put some code if the login has been successful, eg: --xtralifeScores(64) end elseif e.httpStatusCode==401 and e.data then local reply=json.decode(e.data) if reply then if reply["name"]=="LoginError" and reply["message"]=="Invalid user credentials" then xtralife.id=nil xtralife.secret=nil xtralifeSave() end end end end) request:addEventListener(Event.ERROR,function(e) print("xtralife login failed",e.error) end) request:load(xtralifeCall(call),UrlLoader.POST,xtralifeHeader(),json.encode(body)) end end end function xtralifeLogout() if xtralife and xtralife.login then local call="v1/gamer/logout" local request=UrlLoader.new() if request then request:addEventListener(Event.COMPLETE,function(e) --print(e.httpStatusCode,e.data) if e.httpStatusCode==200 then xtralife.login=false end end) request:addEventListener(Event.ERROR,function(e) print("xtralife logout failed",e.error) end) request:load(xtralifeCall(call),UrlLoader.POST,xtralifeHeader()) end end end function xtralifeLink(network,id,secret) if xtralife and xtralife.login then local call="v1/gamer/link" local body={network=network,id=id,secret=secret} local request=UrlLoader.new() if request then request:addEventListener(Event.COMPLETE,function(e) --print(e.httpStatusCode,e.data) end) request:addEventListener(Event.ERROR,function(e) print("xtralife link failed",e.error) end) request:load(xtralifeCall(call),UrlLoader.POST,xtralifeHeader(),json.encode(body)) end end end function xtralifeUnlink(network) if xtralife and xtralife.login then local call="v1/gamer/unlink" local body={network=network} local request=UrlLoader.new() if request then request:addEventListener(Event.COMPLETE,function(e) --print(e.httpStatusCode,e.data) end) request:addEventListener(Event.ERROR,function(e) print("xtralife unlink failed",e.error) end) request:load(xtralifeCall(call),UrlLoader.POST,xtralifeHeader(),json.encode(body)) end end end -- body is a table with "displayName", "lang", "firstName", "lastName", "addr1", "addr2", "addr3", "avatar" - avatar is a url to and image, lang is a iso-639-1 country code function xtralifeSetProfile(body) if xtralife and xtralife.login then local call="v1/gamer/profile" local request=UrlLoader.new() if request then request:addEventListener(Event.COMPLETE,function(e) --print(e.httpStatusCode,e.data) if e.httpStatusCode==200 then end end) request:addEventListener(Event.ERROR,function(e) print("xtralife setprofile failed",e.error) end) request:load(xtralifeCall(call),UrlLoader.POST,xtralifeHeader(),json.encode(body)) end end end |
Comments
It needs a plugin to be present: json. You can easily addit to your project using the new plugin system in the Gideros main project tree. If you are using anything other than the pre-built QT player then you may need to make a new player - eg for Android, iOS, etc...
Now in your main code, you enable 'json' first.
At some point you should call 'xtralifeResume()', this will login if the user has used xtralife in your game before, if not then it won't do anything. I usually call this on my main game front end loop - the start screen for example in the game.
Before you update any high scores or achievements - eg - as the gameover starts or level ends, then you should also call 'xtralifeLogin()' - this will create a new xtralife user if you haven't logged in before.
These two routine calls ensure that all goes smoothly on systems that don't already have a gaming lib - like html5, windows, etc...
If you are using the Gideros gaming plugin then you can use the gaming lib's 'getPlayerInfo()' to find the users id and alias name.
continued...
https://deluxepixel.com
Here is the code for the way I init the gaming lib:
Here is my typical player_information_complete event code:
Now you are done!
All you need to do now is submit scores, grab the leaderboard, etc:
Notice that people will be logged in as 'Guest'.
Add this to the beginning of xtralife.lua :
If you make these routines better then please add your new code to this thread so everyone benefits.
https://deluxepixel.com
Likes: HubertRonald
see function xtralifeHeader()
https://deluxepixel.com
https://deluxepixel.com
https://deluxepixel.com
Likes: SinisterSoft
Likes: SinisterSoft
[-] Liasoft
For windows however you have to include a couple of extra files:
https://www.dropbox.com/s/y8ixf3d03ygf29t/extra_ssl.rar?dl=0
Likes: HubertRonald
https://deluxepixel.com
Likes: HubertRonald
https://deluxepixel.com
Anthony has pretty much said everything (many thanks to him), but just wanted to add that we offer a hosted solution (which means you just need Anthony's SDK and you're good to go), or you can use our Open Source solution. In this case, you install everything on your own servers and you manage it the way you like it!
Other than that, we provide mostly all the features you'd expect from a backend, including player management (with support for social networks or private user base), leaderboards, achievements, turn by turn multiplayer, virtual currencies, cloud synchronization, sending of data between users, referral system, server side code, and much more.
Also, we do provide many "low level" features with which you can implement pretty much all your needs. Do you need a very custom clan feature? Check. Challenges based on virtual currencies betting? Check
Do not hesitate to contact us (or me) if you need more info. We like to talk about your needs on Slack!
Likes: SinisterSoft, antix
https://www.dropbox.com/s/4vrput6ytgvsqas/xtralife.lua?dl=0
It down downloads the avatar of the person if xtralife have it, it shows how to manipulate the image before saving.
It's all a bit of a hack so use it as the basis for your own mods. I'm updating soon because of work done by @MikeOfTheClan for extra googleplay and gamecircle support. So expect changes!
https://deluxepixel.com
https://deluxepixel.com
https://deluxepixel.com
This will login to xtralife if previously logged in.
At the end of the game I check if xtralife is logged in, if not then I try the xtralifeLogin() so it makes up a username/password. That way, in the future, if no facebook, google place, gamecircle or gamecentre then it will still record and compare leaderboards, etc...
Likes: antix
https://deluxepixel.com