934 lines
29 KiB
JavaScript
934 lines
29 KiB
JavaScript
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Welcome to your first Cloud Script revision!
|
|
//
|
|
// Cloud Script runs in the PlayFab cloud and has full access to the PlayFab Game Server API
|
|
// (https://api.playfab.com/Documentation/Server), and it runs in the context of a securely
|
|
// authenticated player, so you can use it to implement logic for your game that is safe from
|
|
// client-side exploits.
|
|
//
|
|
// Cloud Script functions can also make web requests to external HTTP
|
|
// endpoints, such as a database or private API for your title, which makes them a flexible
|
|
// way to integrate with your existing backend systems.
|
|
//
|
|
// There are several different options for calling Cloud Script functions:
|
|
//
|
|
// 1) Your game client calls them directly using the "ExecuteCloudScript" API,
|
|
// passing in the function name and arguments in the request and receiving the
|
|
// function return result in the response.
|
|
// (https://api.playfab.com/Documentation/Client/method/ExecuteCloudScript)
|
|
//
|
|
// 2) You create PlayStream event actions that call them when a particular
|
|
// event occurs, passing in the event and associated player profile data.
|
|
// (https://api.playfab.com/playstream/docs)
|
|
//
|
|
// 3) For titles using the Photon Add-on (https://playfab.com/marketplace/photon/),
|
|
// Photon room events trigger webhooks which call corresponding Cloud Script functions.
|
|
//
|
|
// The following examples demonstrate all three options.
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
handlers.aaTest = function(args)
|
|
{
|
|
//var now = new Date();
|
|
//log.info(now.getFullYear());
|
|
//log.info(now.getMonth());
|
|
//log.info(now.getDate());
|
|
|
|
//var curTime = new Date();
|
|
//log.info(curTime);
|
|
//var t1 = new Date(curTime.setHours(curTime.getHours() + 1));
|
|
//log.info(t1);
|
|
//var t2 = new Date(t1.setDate(t1.getDate() + 1));
|
|
//log.info(t2);
|
|
|
|
//server.UpdatePlayerStatistics({PlayFabId: currentPlayerId, Statistics : [
|
|
//{
|
|
// "StatisticName": "PetBattle",
|
|
// "Value": 1000
|
|
//}
|
|
//]});
|
|
|
|
/*
|
|
// https://learn.microsoft.com/en-us/rest/api/playfab/server/account-management/get-player-profile?view=playfab-rest#playerprofileviewconstraints
|
|
var playerprofile = server.GetPlayerCombinedInfo({ PlayFabId: currentPlayerId,
|
|
"InfoRequestParameters":
|
|
{
|
|
"GetPlayerProfile": true,
|
|
"ProfileConstraints":
|
|
{
|
|
"ShowTotalValueToDateInUsd": true,
|
|
"ShowDisplayName": true,
|
|
//"ShowStatistics": true, // 순위표 (레거시)
|
|
//"ShowLinkedAccounts": true, // 연결된 계정 (커스텀, 구글, 애플 등)
|
|
}
|
|
}
|
|
});
|
|
log.info(playerprofile);
|
|
if(!CheckNullOrEmpty(playerprofile.InfoResultPayload.PlayerProfile.TotalValueToDateInUSD))
|
|
{
|
|
log.info(playerprofile.InfoResultPayload.PlayerProfile.TotalValueToDateInUSD);
|
|
var price = playerprofile.InfoResultPayload.PlayerProfile.TotalValueToDateInUSD / 100;
|
|
log.info(parseInt(price * 50));
|
|
}
|
|
else
|
|
log.info('no cash buy');
|
|
*/
|
|
|
|
// 타이틀 Id 찾는 법
|
|
// currentPlayerId == master Id
|
|
// playerprofile.TitlePlayerAccounts[currentPlayerId].Id == title Id (★)
|
|
//var playerprofile = entity.GetTitlePlayersFromMasterPlayerAccountIds({ MasterPlayerAccountIds: [currentPlayerId]});
|
|
//var titleId = playerprofile.TitlePlayerAccounts[currentPlayerId].Id;
|
|
//log.info("titleId : " + titleId);
|
|
}
|
|
|
|
// 에러 정리 : 0 정상, 1 채팅 금지 유저, 2 서버 점검, 3 잘못된 우편을
|
|
// -1 중복 로그인, -2 금지 유저
|
|
function Get_Error(token)
|
|
{
|
|
var uidata = server.GetUserInternalData({ PlayFabId: currentPlayerId }).Data;
|
|
var titledata = Get_TitleData();
|
|
var jbSplit = titledata.PassIDs.split(',');
|
|
for ( var i in jbSplit )
|
|
{
|
|
if(jbSplit[i] == currentPlayerId)
|
|
return 0;
|
|
}
|
|
|
|
if(uidata.CurToken.Value != token)
|
|
return -1;
|
|
else if(!CheckNullOrEmpty(uidata.BanUser))
|
|
return -2;
|
|
else if(!CheckNullOrEmpty(uidata.BanChat))
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
handlers.Send_Mail = function(args)
|
|
{
|
|
Add_Mail(args);
|
|
}
|
|
|
|
function Add_Mail(args)
|
|
{
|
|
var makemail = {};
|
|
makemail.ItemID = args.ItemID;
|
|
makemail.Amount = args.Amount;
|
|
makemail.Msg = args.Msg;
|
|
|
|
var day = CheckNullOrEmpty(args.Day) ? 3 : args.Day;
|
|
var dt = Get_CurKoreaTime();
|
|
makemail.RemainTime = new Date(dt.setDate(dt.getDate() + day));
|
|
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId, Keys: ["Mail"] }).Data;
|
|
var mailjson = [];
|
|
if (!CheckNullOrEmpty(userdata.Mail))
|
|
mailjson = JSON.parse(userdata.Mail.Value);
|
|
mailjson.push(makemail);
|
|
|
|
// 시간 지난 메일 확인 후 삭제
|
|
for(var i in mailjson)
|
|
{
|
|
var mailtime = new Date(mailjson[i].RemainTime);
|
|
var nowtime = Get_CurKoreaTime();
|
|
if(mailtime - nowtime < 0)
|
|
delete mailjson[i];
|
|
}
|
|
mailjson = mailjson.filter(function(x) { return x !== null }); // null 모두 지우기
|
|
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Data: {"Mail": JSON.stringify(mailjson)} });
|
|
|
|
return {
|
|
result : mailjson
|
|
};
|
|
}
|
|
function Del_Mail(itemname)
|
|
{
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId, Keys: ["Mail"] }).Data;
|
|
var mailjson = JSON.parse(userdata.Mail.Value);
|
|
var mailindex = mailjson.findIndex(f=>f.Reward == itemname);
|
|
if(mailindex > -1)
|
|
{
|
|
mailjson.splice(mailindex, 1);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Data: {"Mail": JSON.stringify(mailjson)} });
|
|
return true;
|
|
}
|
|
else
|
|
log.info(itemname + ' 아이템을 우편함에서 찾지 못했습니다.');
|
|
return false;
|
|
}
|
|
handlers.Get_MailList = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId, Keys: ["Mail"] }).Data;
|
|
if (!CheckNullOrEmpty(userdata.Mail))
|
|
{
|
|
return {
|
|
error: error,
|
|
Mail: JSON.parse(userdata.Mail.Value)
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return {
|
|
error: error
|
|
}
|
|
}
|
|
}
|
|
handlers.Get_MailReward = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId, Keys: ["Mail"] }).Data;
|
|
if (!CheckNullOrEmpty(userdata.Mail))
|
|
{
|
|
var mailjson = JSON.parse(userdata.Mail.Value);
|
|
var existmail = false;
|
|
var getdate = new Date(args.RemainTime);
|
|
for (var i in mailjson)
|
|
{
|
|
var maildate = new Date(mailjson[i].RemainTime);
|
|
if (maildate.getTime() === getdate.getTime())
|
|
{
|
|
existmail = true;
|
|
delete mailjson[i];
|
|
break;
|
|
}
|
|
}
|
|
mailjson = mailjson.filter(function(x) { return x !== null }); // null 모두 지우기
|
|
|
|
if(existmail)
|
|
{
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"Mail": JSON.stringify(mailjson)} });
|
|
|
|
return {
|
|
error : error,
|
|
Mail: mailjson
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return {
|
|
error : 3
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return {
|
|
error : 3
|
|
}
|
|
}
|
|
}
|
|
handlers.Get_AllMail = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId, Keys: ["Mail"] }).Data;
|
|
if (!CheckNullOrEmpty(userdata.Mail))
|
|
{
|
|
var mailjson = JSON.parse(userdata.Mail.Value);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"Mail": "[]"} });
|
|
|
|
return {
|
|
error : error,
|
|
Mail: mailjson
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return {
|
|
error : 3
|
|
}
|
|
}
|
|
}
|
|
handlers.Get_UserInfo = function (args)
|
|
{
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: currentPlayerId }).Data;
|
|
|
|
return {
|
|
error: Get_Error(args.Token),
|
|
GetUserReadOnlyData: urod
|
|
};
|
|
}
|
|
handlers.Get_OtherUserInfo = function (args)
|
|
{
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: args.ID }).Data;
|
|
|
|
return {
|
|
error: Get_Error(args.Token),
|
|
GetUserReadOnlyData: urod
|
|
};
|
|
}
|
|
|
|
handlers.ServerSave_LoginToken = function(args)
|
|
{
|
|
//var urod = server.GetUserReadOnlyData({ PlayFabId: currentPlayerId }).Data;
|
|
server.UpdateUserInternalData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"CurToken": args.Token } });
|
|
}
|
|
|
|
handlers.ServerSave_AllData = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(args.AllData)} });
|
|
|
|
return {
|
|
error: error
|
|
}
|
|
}
|
|
|
|
handlers.Write_UnityInApp = function(args)
|
|
{
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(args.AllData)} });
|
|
Add_ShopMail(args.ProductID);
|
|
|
|
log.info("args.IsEditor " + args.IsEditor);
|
|
if (args.IsEditor)
|
|
{
|
|
log.info("아이템 저장 " + args.ProductID);
|
|
server.GrantItemsToUser( { PlayFabID: currentPlayerId, ItemIds : [args.ProductID] });
|
|
}
|
|
|
|
return {
|
|
error: Get_Error(args.Token)
|
|
}
|
|
}
|
|
handlers.Write_Onestore = function(args)
|
|
{
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(args.AllData)} });
|
|
Add_ShopMail(args.ProductID);
|
|
|
|
var customData = { };
|
|
customData["Receipt"] = args.Receipt;
|
|
|
|
server.GrantItemsToUsers({
|
|
"ItemGrants": [{
|
|
"PlayFabId" : currentPlayerId,
|
|
"ItemId" : args.ProductID,
|
|
"Data" : customData
|
|
}]
|
|
});
|
|
|
|
return {
|
|
error: Get_Error(args.Token)
|
|
}
|
|
}
|
|
|
|
function Add_ShopMail(productid)
|
|
{
|
|
var shoptable = Get_ShopTable();
|
|
var finddata = shoptable.find(f=>f.s_InappID == productid);
|
|
if(!CheckNullOrEmpty(finddata))
|
|
{
|
|
var maildata = {};
|
|
maildata.Day = 30;
|
|
maildata.ItemID = finddata.n_ShopItemID;
|
|
maildata.Amount = 1;
|
|
Add_Mail(maildata);
|
|
}
|
|
}
|
|
|
|
handlers.SendMail_Daily = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(args.AllData)} });
|
|
if(args.IsKing)
|
|
Add_ShopMail("com.filgoodbandits.john.dailyking");
|
|
if(args.IsGod)
|
|
Add_ShopMail("com.filgoodbandits.john.dailygod");
|
|
if(args.IsGemSubscribe)
|
|
{
|
|
var maildata = {};
|
|
maildata.Day = 30;
|
|
maildata.Reward = "GemSubscribeBox1";
|
|
maildata.RewardAmount = 1;
|
|
maildata.Msg = "그리폰이 배달한 주머니입니다.";
|
|
Add_Mail(maildata);
|
|
}
|
|
if(args.IsGemSubscribe2)
|
|
{
|
|
var maildata = {};
|
|
maildata.Day = 30;
|
|
maildata.Reward = "GemSubscribeBox2";
|
|
maildata.RewardAmount = 1;
|
|
maildata.Msg = "흰토끼가 배달한 주머니입니다.";
|
|
Add_Mail(maildata);
|
|
}
|
|
if(args.IsGemSubscribe3)
|
|
{
|
|
var maildata = {};
|
|
maildata.Day = 30;
|
|
maildata.Reward = "GemSubscribeBox3";
|
|
maildata.RewardAmount = 1;
|
|
maildata.Msg = "모조 거북이 배달한 주머니입니다.";
|
|
Add_Mail(maildata);
|
|
}
|
|
|
|
return {
|
|
error: error
|
|
}
|
|
}
|
|
handlers.GuideQuestComplete = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(args.AllData)} });
|
|
|
|
var maildata = {};
|
|
maildata.Reward = "Gem";
|
|
maildata.RewardAmount = 1000;
|
|
maildata.Msg = "가이드 퀘스트 완료를 축하합니다.";
|
|
Add_Mail(maildata);
|
|
|
|
return {
|
|
error: error
|
|
}
|
|
}
|
|
|
|
handlers.Save_Rank = function(args)
|
|
{
|
|
progression.UpdateLeaderboardEntries({PlayFabId: currentPlayerId, LeaderboardName: args.LeaderboardName,
|
|
Entries :
|
|
[
|
|
{
|
|
"EntityId": args.EntityID,
|
|
"Metadata": args.Metadata,
|
|
"Scores": args.Scores
|
|
}
|
|
]});
|
|
}
|
|
|
|
handlers.SaveToStageRank = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
server.UpdatePlayerStatistics({PlayFabId: currentPlayerId, Statistics : [
|
|
{
|
|
"StatisticName": "Stage",
|
|
"Value": args.MaxStage
|
|
}
|
|
]});
|
|
|
|
return {
|
|
error: error
|
|
}
|
|
}
|
|
handlers.SaveToDragonRank = function(args)
|
|
{
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
server.UpdatePlayerStatistics({PlayFabId: currentPlayerId, Statistics : [
|
|
{
|
|
"StatisticName": "Dragon",
|
|
"Value": args.Lv
|
|
}
|
|
]});
|
|
|
|
return {
|
|
error: error
|
|
}
|
|
}
|
|
|
|
handlers.Check_CanBuyInapp = function(args)
|
|
{ // 인앱 구매전 에러 확인용
|
|
return {
|
|
error: Get_Error(args.Token)
|
|
}
|
|
}
|
|
|
|
handlers.Del_TitlePlayer = function(args)
|
|
{
|
|
if(!CheckNullOrEmpty(args.Agree))
|
|
{
|
|
var playerprofile = entity.GetTitlePlayersFromMasterPlayerAccountIds({ MasterPlayerAccountIds: [currentPlayerId]});
|
|
var titleId = playerprofile.TitlePlayerAccounts[currentPlayerId].Id;
|
|
|
|
log.info("순위표를 지웁니다.");
|
|
progression.DeleteLeaderboardEntries({ Name: "Rank_Maze", EntityIds: [titleId]});
|
|
|
|
log.info("타이틀 계정을 지웁니다.");
|
|
server.DeletePlayer({PlayFabId: currentPlayerId});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handlers.Rank_Reward = function(args)
|
|
{
|
|
// 현재 버전 확인
|
|
var cur = progression.GetLeaderboardDefinition({ Name: args.LeaderboardName });
|
|
//log.info("현재 버전 : " + cur.Version);
|
|
|
|
var playerprofile = entity.GetTitlePlayersFromMasterPlayerAccountIds({ MasterPlayerAccountIds: [currentPlayerId]});
|
|
var titleId = playerprofile.TitlePlayerAccounts[currentPlayerId].Id;
|
|
//log.info("titleId : " + titleId);
|
|
|
|
// 이전 버전에서 내 순위 확인
|
|
var a = progression.GetLeaderboardAroundEntity({ LeaderboardName: args.LeaderboardName, MaxSurroundingEntries: 1,
|
|
Version: cur.Version - 1, Entity: { Id : titleId, Type: "title_player_account" } });
|
|
//log.info("a : " + JSON.stringify(a));
|
|
|
|
for (var i in a.Rankings)
|
|
{
|
|
//log.info("ranker id : " + a.Rankings[i].Entity.Id);
|
|
if (a.Rankings[i].Entity.Id == titleId)
|
|
{
|
|
//log.info("나의 랭킹 : " + a.Rankings[i].Rank);
|
|
|
|
// 현재 날짜 가져오기
|
|
const now = new Date();
|
|
const month = now.getMonth() + 1; // getMonth()는 0부터 시작하므로 +1
|
|
const day = now.getDate(); // getDate()는 1~31 반환
|
|
const rank = a.Rankings[i].Rank; // 리더보드에서 가져온 순위 값
|
|
|
|
var maildata = {};
|
|
maildata.Day = 7;
|
|
maildata.ItemID = 1;
|
|
maildata.Amount = 10; // TOOD 정인호 : 순위에 따라 지급
|
|
maildata.Msg = formatString(args.Msg, [month, day, rank]);
|
|
Add_Mail(maildata);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
handlers.Send_Cheat = function()
|
|
{
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"Cheat": "Use" } });
|
|
server.UpdatePlayerStatistics({PlayFabId: currentPlayerId, Statistics : [
|
|
{
|
|
"StatisticName": "Best Stage",
|
|
"Value": 1
|
|
},
|
|
{
|
|
"StatisticName": "WeeklyPvP",
|
|
"Value": 0
|
|
},
|
|
{
|
|
"StatisticName": "BossRaid",
|
|
"Value": 0
|
|
},
|
|
{
|
|
"StatisticName": "Reset Best Stage",
|
|
"Value": 0
|
|
}
|
|
]});
|
|
}
|
|
|
|
handlers.Use_Coupon = function(args)
|
|
{
|
|
log.info(args.Coupon);
|
|
|
|
var error = Get_Error(args.Token);
|
|
if(error < 0) return {error:error};
|
|
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId }).Data;
|
|
var couponinfo = [];
|
|
if(!CheckNullOrEmpty(userdata.CouponInfo)) couponinfo = JSON.parse(userdata.CouponInfo.Value);
|
|
|
|
var coupontable = Get_CouponTable();
|
|
var findcoupon = coupontable.find(f=>f.Coupon == args.Coupon);
|
|
if(findcoupon != null)
|
|
{ // 전체 쿠폰
|
|
var nowtime = Get_CurKoreaTime();
|
|
var starttime = new Date(findcoupon.StartTime);
|
|
var endtime = new Date(findcoupon.EndTime);
|
|
|
|
if(nowtime - starttime > 0 && endtime - nowtime > 0)
|
|
{
|
|
var find = couponinfo.find(f=>f == findcoupon.Index);
|
|
if(find == null)
|
|
{
|
|
// 참여 여부 저장
|
|
couponinfo.push(findcoupon.Index);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"CouponInfo": JSON.stringify(couponinfo)} });
|
|
|
|
// 보상 지급
|
|
var RtnValue = [];
|
|
var makereward = {};
|
|
|
|
var reward1 = findcoupon.Reward1.split(',');
|
|
makereward.Reward = reward1[0];
|
|
makereward.RewardAmount = reward1[1];
|
|
RtnValue.push(makereward);
|
|
|
|
var reward2 = [];
|
|
if(!CheckNullOrEmpty(findcoupon.Reward2))
|
|
{
|
|
makereward = {};
|
|
reward2 = findcoupon.Reward2.split(',');
|
|
makereward.Reward = reward2[0];
|
|
makereward.RewardAmount = reward2[1];
|
|
RtnValue.push(makereward);
|
|
}
|
|
|
|
return {
|
|
error: error,
|
|
Rewards: '{"Rewards":' + JSON.stringify(RtnValue) + '}'
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
error: 4
|
|
};
|
|
}
|
|
|
|
handlers.Send_Push = function(args)
|
|
{
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: currentPlayerId }).Data;
|
|
var common = JSON.parse(urod.UserInfo.Value).Common;
|
|
var isSendAgree = false;
|
|
var profile = server.GetPlayerProfile( {PlayFabId: currentPlayerId, ProfileConstraints: {ShowLocations: true}} );
|
|
if (profile.PlayerProfile.Locations[profile.PlayerProfile.Locations.length - 1].CountryCode == "KR")
|
|
{
|
|
var dt = new Date();
|
|
dt.setHours(dt.getHours() + 9);
|
|
if(dt.getHours() >= 8 && dt.getHours() <= 21)
|
|
isSendAgree = common.NotificationAgreeDaytime;
|
|
else
|
|
isSendAgree = common.NotificationAgreeNighttime;
|
|
}
|
|
|
|
if (isSendAgree)
|
|
{ // try to send push notification
|
|
try
|
|
{
|
|
server.SendPushNotification(
|
|
{
|
|
Recipient : currentPlayerId,
|
|
Package :
|
|
{
|
|
Message : args.Msg,
|
|
Title: args.Title
|
|
}
|
|
});
|
|
}
|
|
catch (ex)
|
|
{
|
|
log.info("Target player has not registered for Push Notifications");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handlers.CafeEvent_Lv5 = function(args)
|
|
{
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId }).Data;
|
|
var eventinfo = [];
|
|
if(!CheckNullOrEmpty(userdata.EventInfo)) eventinfo = JSON.parse(userdata.EventInfo.Value);
|
|
|
|
var find = eventinfo.find(f=>f.Event == "Lv10");
|
|
if(find == null)
|
|
{
|
|
// 참여 여부 저장
|
|
var eventwrite = {};
|
|
eventwrite.Event = "Lv10";
|
|
eventinfo.push(eventwrite);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"EventInfo": JSON.stringify(eventinfo)} });
|
|
|
|
var mail = {};
|
|
mail.Reward = "Gem";
|
|
mail.RewardAmount = 2000;
|
|
mail.Msg = "공식카페 마녀 레벨5 달성 이벤트 보상";
|
|
Add_Mail(mail);
|
|
|
|
log.info("Lv5 보상 지급");
|
|
}
|
|
else
|
|
log.info("Lv5 보상을 이미 지급한 유저입니다.");
|
|
}
|
|
handlers.CafeEvent_SNS = function(args)
|
|
{
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId }).Data;
|
|
var eventinfo = [];
|
|
if(!CheckNullOrEmpty(userdata.EventInfo)) eventinfo = JSON.parse(userdata.EventInfo.Value);
|
|
|
|
var find = eventinfo.find(f=>f.Event == "SNS");
|
|
if(find == null)
|
|
{
|
|
// 참여 여부 저장
|
|
var eventwrite = {};
|
|
eventwrite.Event = "SNS";
|
|
eventinfo.push(eventwrite);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"EventInfo": JSON.stringify(eventinfo)} });
|
|
|
|
var mail = {};
|
|
mail.Reward = "Gem";
|
|
mail.RewardAmount = 10000;
|
|
mail.Msg = "SNS 이벤트 보상입니다.";
|
|
Add_Mail(mail);
|
|
|
|
log.info("SNS 보상 지급");
|
|
}
|
|
else
|
|
log.info("SNS 보상을 이미 지급한 유저입니다.");
|
|
}
|
|
handlers.CafeEvent_Greeting = function(args)
|
|
{
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId }).Data;
|
|
var eventinfo = [];
|
|
if(!CheckNullOrEmpty(userdata.EventInfo)) eventinfo = JSON.parse(userdata.EventInfo.Value);
|
|
|
|
var find = eventinfo.find(f=>f.Event == "Greeting");
|
|
if(find == null)
|
|
{
|
|
// 참여 여부 저장
|
|
var eventwrite = {};
|
|
eventwrite.Event = "Greeting";
|
|
eventinfo.push(eventwrite);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"EventInfo": JSON.stringify(eventinfo)} });
|
|
|
|
var mail = {};
|
|
mail.Reward = "Gem";
|
|
mail.RewardAmount = 3000;
|
|
mail.Msg = "공식카페 이벤트 오픈 전 인사 보상입니다.";
|
|
Add_Mail(mail);
|
|
|
|
log.info("오픈 전 인사 보상 지급");
|
|
}
|
|
else
|
|
log.info("오픈 전 인사 보상을 이미 지급한 유저입니다.");
|
|
}
|
|
handlers.CafeEvent_MyFarm = function(args)
|
|
{
|
|
var userdata = server.GetUserData({ PlayFabId: currentPlayerId }).Data;
|
|
var eventinfo = [];
|
|
if(!CheckNullOrEmpty(userdata.EventInfo)) eventinfo = JSON.parse(userdata.EventInfo.Value);
|
|
|
|
var find = eventinfo.find(f=>f.Event == "MyFarm");
|
|
if(find == null)
|
|
{
|
|
// 참여 여부 저장
|
|
var eventwrite = {};
|
|
eventwrite.Event = "MyFarm";
|
|
eventinfo.push(eventwrite);
|
|
server.UpdateUserData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"EventInfo": JSON.stringify(eventinfo)} });
|
|
|
|
var mail = {};
|
|
mail.Reward = "Inven";
|
|
mail.ID = 50;
|
|
mail.RewardAmount = 50;
|
|
mail.Msg = "마이팜 인증 보상입니다.";
|
|
Add_Mail(mail);
|
|
|
|
log.info("마이팜 인증 보상 지급");
|
|
}
|
|
else
|
|
log.info("마이팜 인증 보상을 이미 지급한 유저입니다.");
|
|
}
|
|
|
|
handlers.SendMail_DailyInit = function(args)
|
|
{
|
|
var maildata = {};
|
|
maildata.Reward = "DailyInit";
|
|
maildata.RewardAmount = 0;
|
|
maildata.Msg = "일일 초기화 아이템\n바로 사용해주세요!!";
|
|
maildata.Day = 1;
|
|
Add_Mail(maildata);
|
|
}
|
|
|
|
handlers.CheckError = function(args)
|
|
{
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: currentPlayerId }).Data;
|
|
var uinfo = JSON.parse(urod.UserInfo.Value);
|
|
|
|
var existnull = false;
|
|
for(var i in uinfo.Common)
|
|
{
|
|
if(uinfo.Common[i] == null)
|
|
{
|
|
uinfo.Common[i] = 0;
|
|
existnull = true;
|
|
}
|
|
}
|
|
|
|
if(existnull)
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(uinfo)} });
|
|
|
|
/*
|
|
if(uinfo.Money[3] < 0)
|
|
{
|
|
var gem1 = JSON.parse(server.GetTitleInternalData("StoneMinus").Data.StoneMinus);
|
|
gem1.push(currentPlayerId);
|
|
server.SetTitleInternalData({ PlayFabId: currentPlayerId, Key: "StoneMinus", Value: JSON.stringify(gem1) });
|
|
}
|
|
|
|
if(uinfo.Money[0] < 0)
|
|
{
|
|
var gem1 = JSON.parse(server.GetTitleInternalData("GemMinus").Data.GemMinus);
|
|
gem1.push(currentPlayerId);
|
|
server.SetTitleInternalData({ PlayFabId: currentPlayerId, Key: "GemMinus", Value: JSON.stringify(gem1) });
|
|
}
|
|
*/
|
|
}
|
|
|
|
handlers.Update_BackUp = function(args)
|
|
{
|
|
BackUpUserInfo();
|
|
}
|
|
function BackUpUserInfo()
|
|
{
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: currentPlayerId }).Data;
|
|
var uinfo = JSON.parse(urod.UserInfo.Value);
|
|
var uprod = server.GetUserPublisherData({ PlayFabId: currentPlayerId }).Data;
|
|
var index = 1;
|
|
if(CheckNullOrEmpty(uprod.Key))
|
|
{
|
|
index = 1;
|
|
}
|
|
else
|
|
index = uprod.Key.Value;
|
|
|
|
if(index == 1)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo1 : JSON.stringify(uinfo)} });
|
|
else if(index == 2)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo2 : JSON.stringify(uinfo)} });
|
|
else if(index == 3)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo3 : JSON.stringify(uinfo)} });
|
|
else if(index == 4)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo4 : JSON.stringify(uinfo)} });
|
|
else if(index == 5)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo5 : JSON.stringify(uinfo)} });
|
|
else if(index == 6)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo6 : JSON.stringify(uinfo)} });
|
|
else if(index == 7)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo7 : JSON.stringify(uinfo)} });
|
|
else if(index == 8)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo8 : JSON.stringify(uinfo)} });
|
|
else if(index == 9)
|
|
server.UpdateUserPublisherReadOnlyData({ PlayFabId: currentPlayerId, Data: { UserInfo9 : JSON.stringify(uinfo)} });
|
|
|
|
++index;
|
|
if(index > 9) index = 1;
|
|
server.UpdateUserPublisherData({ PlayFabId: currentPlayerId, Data: { Key : index } });
|
|
}
|
|
|
|
handlers.Update_Mail = function(args)
|
|
{
|
|
// 점검 보상 우편
|
|
var makemail = {};
|
|
makemail.Reward = "Gem";
|
|
makemail.RewardAmount = 500;
|
|
var kortime = Get_CurKoreaTime();
|
|
makemail.Msg = (kortime.getMonth() + 1) + '월 ' + kortime.getDate() + '일 점검 보상입니다.';
|
|
makemail.Day = 1;
|
|
Add_Mail(makemail);
|
|
|
|
//if(!CheckNullOrEmpty(urod.EventInfo))
|
|
//{
|
|
// server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Data: {"EventInfo": null} });
|
|
//}
|
|
}
|
|
|
|
handlers.CheckOtherData = function(args)
|
|
{
|
|
var uidata = server.GetUserInternalData({ PlayFabId: args.ID }).Data;
|
|
if(!CheckNullOrEmpty(uidata.BanUser))
|
|
return {
|
|
error: -2
|
|
};
|
|
|
|
var error = 0;
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: args.ID }).Data.UserInfo.Value;
|
|
var json = JSON.parse(urod);
|
|
if(json.Common[49] == 0 || json.Common[49] != args.PW)
|
|
error = -1;
|
|
|
|
return {
|
|
error: error,
|
|
};
|
|
}
|
|
handlers.GetOtherData = function(args)
|
|
{
|
|
server.UpdateUserInternalData({ PlayFabId: args.ID, Permission: "Public", Data: {"BanUser": 1 } });
|
|
|
|
var urod = server.GetUserReadOnlyData({ PlayFabId: args.ID }).Data.UserInfo.Value;
|
|
var json = JSON.parse(urod);
|
|
json.Common[49] = 0;
|
|
server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Permission: "Public", Data: {"UserInfo": JSON.stringify(json)} });
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Get_Inventory()
|
|
{
|
|
return server.GetUserInventory({ PlayFabId: currentPlayerId });
|
|
}
|
|
function Get_Tables()
|
|
{
|
|
return server.GetTitleInternalData({ Keys: null }).Data;
|
|
}
|
|
function Get_TitleData()
|
|
{
|
|
return server.GetTitleData({ Keys: null }).Data;
|
|
}
|
|
function Get_PvPVersion()
|
|
{
|
|
var result = server.GetLeaderboard({
|
|
StatisticName: "WeeklyPvP",
|
|
StartPosition: 0,
|
|
MaxResultsCount: 0
|
|
});
|
|
|
|
return result.Version;
|
|
}
|
|
function Get_CouponTable()
|
|
{
|
|
var table = JSON.parse(server.GetTitleInternalData("CouponTable").Data.CouponTable);
|
|
return table.servertable_coupon;
|
|
}
|
|
function Get_ShopTable()
|
|
{
|
|
var titleData = server.GetTitleInternalData({ Keys: ["ShopTable"] });
|
|
return JSON.parse(titleData.Data.ShopTable);
|
|
}
|
|
function Get_PlayOCoupons()
|
|
{
|
|
var poc = JSON.parse(server.GetTitleInternalData("PlayO").Data.PlayO);
|
|
return poc.Coupons;
|
|
}
|
|
function Get_CurKoreaTime()
|
|
{
|
|
var curServerTime = new Date();
|
|
return new Date(curServerTime.setHours(curServerTime.getHours() + 9));
|
|
}
|
|
function CheckNullOrEmpty(value)
|
|
{
|
|
if (value == "" || value == null || value == undefined || (value != null && typeof value == "object" && !Object.keys(value).length))
|
|
return true;
|
|
return false;
|
|
}
|
|
function getRandomFloat(min, max) { return Math.random() * (max - min) + min; }
|
|
function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
|
|
function sleep(milliseconds)
|
|
{
|
|
const date = Date.now();
|
|
let currentDate = null;
|
|
do {
|
|
currentDate = Date.now();
|
|
} while (currentDate - date < milliseconds);
|
|
}
|
|
function formatString(template, values) { return template.replace(/{(\d+)}/g, (match, index) => values[index] || match); } |