Supercharge Your Game’s Social Features with Nakama

Rate this content
Bookmark

Explore the impact of social features on game success and learn how to integrate them swiftly with Nakama OSS game server. This session will guide you through code examples, revealing how to enhance your game’s social capabilities. Discover a faster, simpler way to supercharge your game development journey and unleash your game’s social potential with Nakama!

Tom Glenn
Tom Glenn
17 min
28 Sep, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Social features in games increase player engagement, drive in-app purchases, and allow for community building. Nakama is a tool that enables the addition of multiple social features to games, such as authentication, friend management, and leaderboards. The implementation process involves installing the nakama.js package, creating a client object, and using custom authentication. Users can log out, manage friends, view user information, and interact with leaderboards. Additionally, Nakama allows for the implementation of player participation rewards through custom code.

Available in Español

1. Introduction to Social Features in Games

Short description:

Hi, I'm Tom Glenn, a software engineer with 15 years of experience. Heroic Labs is a team of 40 people, creators of the open-source game back-end Nakama. Social experiences in games, like adding friends and participating in leaderboards, are important because they increase player engagement and allow for community building. These features can also drive in-app purchases and monetization opportunities.

♪♪ Hi, I'm Tom, and welcome to this talk on how to supercharge your games' social features with Nakama. Before we begin, let me give you a brief background on who I am. I'm Tom Glenn, I'm a software engineer with roughly 15 years of experience across a wide variety of sectors, including web development, banking, 3D simulations, and more. I'm also an engineer and part of the developer relations team here at Heroic Labs, as well as a content creator and educator over on YouTube, and you can find me at CodeWithTom.

So who are Heroic Labs? Well, we're a team of roughly 40 people and creators of the open-source game back-end, Nakama. We power some of the largest multiplayer games across mobile and desktop, and our clients include the likes of Paradox Interactive, Lightheart Entertainment, Lion Studios, and more. Our other products include our live ops platform, Satori, as well as our game framework, Hero, and Heroic Cloud for our managed server hosting.

So what are social experiences? I have no doubt you will all have experienced these before, but social experiences in games can include things like being able to add friends, participate in leaderboards, chat to other players, join groups or guilds, complete achievements, and show them off on your public profile, take part in live events, and so on. There are so many different kinds of social experiences that you can encounter in games today. But why are these important? Well, multiplayer and cooperative experience have been shown to increase the amount of time that players spend in your game, and social competitions such as leaderboards keep your players coming back for more. They can also allow your players to form communities with shared interests and experiences, and this can lead to an increased player base as players are incentivized to invite friends, share achievements, and collaborate to complete goals. Social features, such as gifting or live events, can also drive in-app purchases and open the door for other monetization opportunities.

2. Adding Social Features with Nakama

Short description:

I will demonstrate how to add multiple social features to your game using Nakama. We'll cover authentication, adding and listing friends, viewing leaderboards, submitting scores, and rewarding player participation. To implement these functions, we'll install the nakama.js package, create a client object, and use the custom authentication method. The authenticate function returns a session object, allowing us to access different user account information. After implementing the restore session flow, users will be automatically logged in when they return to the application. Finally, we'll implement a log-out function to complete the authentication flow.

So rather than talk to you about the theory of adding social features to your game, what I want to do is give you a practical demonstration of how you can add multiple social features to your game using Nakama. We're going to quickly run through how to add authentication, adding and listing friends, viewing a global and a friend-specific leaderboard, submitting scores to that leaderboard, and then rewarding that player participation by giving the player some coins for participating in that leaderboard.

So let's jump over to the code. Okay, so you can see we've got our demo application running here. It's a simple React application with a login screen that if I try to log in right now, nothing's going to happen because we haven't implemented any of these functions here which the React application is expecting to call to perform various things such as authenticating, getting the account details, adding a list in friends, and so on. So what I'd like to do is quickly run through how easy it is to implement these functions using Nakama.

So before I start, what I have done here is I've ran npm install and I have installed the nakama.js package which you can find at heroic.labs.nakama-js. Once you've done that, we can then import the client and session object from the nakama.js package. We're then going to create a client object. Now, this client object expects to take a server key, the default one is default-key, the host address of the Nakama instance, in which case I'm currently running this using Docker on my local machine, and the port number for where the Nakama instance is running. We're then gonna implement the authenticate function. Now, Nakama supports various different mechanisms for authentication, these include device authentication, email and password, Apple, Google, Facebook, and custom authentication to name a few. We're gonna use custom authentication here just because it allows us to pass in a custom identifier as well as a username, and this true flag here also allows us to specify if the user account doesn't already exist, then we will go ahead and create it. Now, this authenticate custom function as well as all of the other authenticate functions will return a session object, which you can see we have up here. This session object allows us then to call into various other functions within Nakama to get different pieces of information for that user account. If we save this file now and come over to our login screen and try and log in again, you can see that we are now logged in. It says, hi, CodewithTom. We can't access anything such as friends or leaderboard right now as we haven't implemented those functions, but let's go ahead and do that now. I'll just quickly log out.

And before we go any further in to get an account or anything else, what I'd like to do is implement a restore session flow so that the next time the user comes back to the application, they don't have to re-log into their account. To do that, we're going to set, we're going to get rather two items from local storage. These are going to be session token and refresh token. Now, we're also going to have to set these items. So what we'll do is just after we authenticate, we will go to local storage and set the session token as our session.token value and the refresh token as the session.refresh token. We'll also implement a function here called restore session. And what we're going to do here is we're going to get the two values for session token and refresh token just to make sure we have the most up-to-date version. And if they have a value, then we're going to use the session.restore. Now this is a function that lives on the session class itself passing the session token and the refresh token and assign that value back to our session variable. We will save that and let's log in here code with Tom and you can see now if I refresh the page I'm automatically logged back in, which is great. Now, the last thing we need to do is implement a log-out function and that is our authentication flow complete.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Optimizing HTML5 Games: 10 Years of Learnings
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Optimizing HTML5 Games: 10 Years of Learnings
Top Content
The open source PlayCanvas game engine is built specifically for the browser, incorporating 10 years of learnings about optimization. In this talk, you will discover the secret sauce that enables PlayCanvas to generate games with lightning fast load times and rock solid frame rates.
Building Fun Experiments with WebXR & Babylon.js
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Building Fun Experiments with WebXR & Babylon.js
Top Content
During this session, we’ll see a couple of demos of what you can do using WebXR, with Babylon.js. From VR audio experiments, to casual gaming in VR on an arcade machine up to more serious usage to create new ways of collaboration using either AR or VR, you should have a pretty good understanding of what you can do today.
Check the article as well to see the full content including code samples: article. 
Making Awesome Games with LittleJS
JS GameDev Summit 2022JS GameDev Summit 2022
34 min
Making Awesome Games with LittleJS
LittleJS is a super lightweight game engine that is easy to use and powerfully fast. The developer will talk about why he made it, what it does, and how you can use it to create your own games. The talk will include a demonstration of how to build a small game from scratch with LittleJS.
How Not to Build a Video Game
React Summit 2023React Summit 2023
32 min
How Not to Build a Video Game
In this talk we'll delve into the art of creating something meaningful and fulfilling. Through the lens of my own journey of rediscovering my passion for coding and building a video game from the ground up with JavaScript and React, we will explore the trade-offs between easy solutions and fast performance. You will gain valuable insights into rapid prototyping, test infrastructure, and a range of CSS tricks that can be applied to both game development and your day-to-day work.
Boost the Performance of Your WebGL Unity Games!
JS GameDev Summit 2023JS GameDev Summit 2023
7 min
Boost the Performance of Your WebGL Unity Games!
Unity, when deployed on the web, faces three critical challenges: build size, memory usage, and overall performance. This lecture delves deep into advanced optimization techniques to help you address each of these issues. Attendees will gain insights into:
- Effective strategies for optimizing textures, audio, and models.- A detailed analysis of our ASTC experimentation with Unity, shedding light on the unexpected results despite Unity's claims.- A comprehensive guide to Unity's memory profiling tool and its implications.- An exploration of lesser-known Unity settings that remain underutilized by many developers.
Additionally, we'll introduce our proprietary tool designed specifically for Unity optimization. We will also showcase CrazyGames' developer dashboard, our platform that enables developers to monitor and enhance the performance of their web-based games seamlessly. 
Join us to equip yourself with the latest strategies and tools to elevate your Unity web gaming projects.

Workshops on related topic

Make a Game With PlayCanvas in 2 Hours
JSNation 2023JSNation 2023
116 min
Make a Game With PlayCanvas in 2 Hours
Featured WorkshopFree
Steven Yau
Steven Yau
In this workshop, we’ll build a game using the PlayCanvas WebGL engine from start to finish. From development to publishing, we’ll cover the most crucial features such as scripting, UI creation and much more.
Table of the content:- Introduction- Intro to PlayCanvas- What we will be building- Adding a character model and animation- Making the character move with scripts- 'Fake' running- Adding obstacles- Detecting collisions- Adding a score counter- Game over and restarting- Wrap up!- Questions
Workshop levelFamiliarity with game engines and game development aspects is recommended, but not required.
PlayCanvas End-to-End : the quick version
JS GameDev Summit 2022JS GameDev Summit 2022
121 min
PlayCanvas End-to-End : the quick version
Top Content
WorkshopFree
João Ruschel
João Ruschel
In this workshop, we’ll build a complete game using the PlayCanvas engine while learning the best practices for project management. From development to publishing, we’ll cover the most crucial features such as asset management, scripting, audio, debugging, and much more.
Introduction to WebXR with Babylon.js
JS GameDev Summit 2022JS GameDev Summit 2022
86 min
Introduction to WebXR with Babylon.js
Workshop
Gustavo Cordido
Gustavo Cordido
In this workshop, we'll introduce you to the core concepts of building Mixed Reality experiences with WebXR and Balon.js.
You'll learn the following:- How to add 3D mesh objects and buttons to a scene- How to use procedural textures- How to add actions to objects- How to take advantage of the default Cross Reality (XR) experience- How to add physics to a scene
For the first project in this workshop, you'll create an interactive Mixed Reality experience that'll display basketball player stats to fans and coaches. For the second project in this workshop, you'll create a voice activated WebXR app using Balon.js and Azure Speech-to-Text. You'll then deploy the web app using Static Website Hosting provided Azure Blob Storage.