Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
101 changes: 101 additions & 0 deletions Nakama+Hiro/definitions/dev1/base-teams.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"initial_max_team_size": 30,
"max_team_size": 50,
"allow_multiple_teams": false,
"wallet": {
"currencies": {
"TeamCoins": 0
}
},
"stats": {
"stats_public": {
"wins": { "value": 0 },
"level": { "value": 1 },
"totalScore": { "value": 0 }
},
"stats_private": {
"internal_rating": { "value": 1000 }
}
},
"gifts": {
"gifts": {
"daily_gift": {
"name": "Daily Team Gift",
"description": "Contribute together for rewards!",
"category": "daily",
"max_count": 100,
"max_contributor_count": 5,
"reset_schedule": "0 0 * * *",
"duration_sec": 86400,
"contribution_cost": {
"currencies": {
"TeamCoins": { "min": 10 }
}
},
"contribution_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 5 }
}
}
},
"rewards": [
{
"min_count": 25,
"contributor_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 50 }
}
}
},
"noncontributor_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 25 }
}
}
}
},
{
"min_count": 50,
"contributor_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 100 }
}
}
},
"noncontributor_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 50 }
}
}
}
},
{
"min_count": 100,
"contributor_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 200 }
}
}
},
"noncontributor_reward": {
"guaranteed": {
"currencies": {
"TeamCoins": { "min": 100 }
}
}
}
}
]
}
}
},
"reward_mailbox": {
"max_size": 100
}
}
6 changes: 3 additions & 3 deletions Nakama+Hiro/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ console:
max_message_size_bytes: 409600
leaderboard:
blacklist_rank_cache:
- "*"
- "*"
logger:
level: "DEBUG"
runtime:
env:
- "ENV=dev1"
- "HIRO_LICENSE="
- "ENV=dev1"
- "HIRO_LICENSE="
session:
token_expiry_sec: 86400 # 24 hours
refresh_token_expiry_sec: 604800 # 7 days
Expand Down
3 changes: 2 additions & 1 deletion Nakama+Hiro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runti
hiro.WithLeaderboardsSystem(fmt.Sprintf("definitions/%s/base-leaderboards.json", env), true),
hiro.WithChallengesSystem(fmt.Sprintf("definitions/%s/base-challenges.json", env), true),
hiro.WithEconomySystem(fmt.Sprintf("definitions/%s/base-economy.json", env), true),
hiro.WithEventLeaderboardsSystem(fmt.Sprintf("definitions/%s/base-event-leaderboards.json", env), true))
hiro.WithEventLeaderboardsSystem(fmt.Sprintf("definitions/%s/base-event-leaderboards.json", env), true),
hiro.WithTeamsSystem(fmt.Sprintf("definitions/%s/base-teams.json", env), true))
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ public static NakamaSystem.AuthorizerFunc NakamaAuthorizerFunc(int index = 0)

return async client =>
{
// Due to the Account Switcher tool, we might need to log out before re-authenticating.
var nakamaSystem = Instance.GetSystem<NakamaSystem>();
if (nakamaSystem.Session != null)
{
await client.SessionLogoutAsync(nakamaSystem.Session);
}

// Attempt to load a previous session if it is still valid.
var authToken = PlayerPrefs.GetString($"{playerPrefsAuthToken}_{index}");
var refreshToken = PlayerPrefs.GetString($"{playerPrefsRefreshToken}_{index}");
Expand All @@ -86,17 +79,11 @@ public static NakamaSystem.AuthorizerFunc NakamaAuthorizerFunc(int index = 0)

// Add an hour, so we check whether the token is within an hour of expiration to refresh it.
var expiredDate = DateTime.UtcNow.AddHours(1);
if (session != null && !session.HasRefreshExpired(expiredDate))
{
return session;
}
if (session != null && !session.HasRefreshExpired(expiredDate)) return session;

// Attempt to read the device ID to use for Authentication.
var deviceId = PlayerPrefs.GetString(playerPrefsDeviceId, SystemInfo.deviceUniqueIdentifier);
if (deviceId == SystemInfo.unsupportedIdentifier)
{
deviceId = Guid.NewGuid().ToString();
}
if (deviceId == SystemInfo.unsupportedIdentifier) deviceId = Guid.NewGuid().ToString();

session = await client.AuthenticateDeviceAsync($"{deviceId}_{index}");

Expand All @@ -105,10 +92,7 @@ public static NakamaSystem.AuthorizerFunc NakamaAuthorizerFunc(int index = 0)
PlayerPrefs.SetString($"{playerPrefsAuthToken}_{index}", session.AuthToken);
PlayerPrefs.SetString($"{playerPrefsRefreshToken}_{index}", session.RefreshToken);

if (session.Created)
{
Debug.LogFormat("New user account '{0}' created.", session.UserId);
}
if (session.Created) Debug.LogFormat("New user account '{0}' created.", session.UserId);

return session;
};
Expand All @@ -125,4 +109,4 @@ protected override void SystemsInitializeFailed(Exception e)
ReceivedStartError?.Invoke(e);
}
}
}
}
56 changes: 56 additions & 0 deletions UnityHiroTeams/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# Created by https://www.gitignore.io/api/unity
# Edit at https://www.gitignore.io/?templates=unity

# Jetbrain Rider Cache
.idea/
Assets/Plugins/Editor/JetBrains*

# Visual Studio Code
.vscode/


### Unity ###
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
Assets/AssetStoreTools*
# Unity local user project setting
UserSettings/

# Visual Studio cache directory
.vs/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# End of https://www.gitignore.io/api/unity
8 changes: 8 additions & 0 deletions UnityHiroTeams/Assets/UnityHiroTeams.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions UnityHiroTeams/Assets/UnityHiroTeams/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading