All Projects → heroiclabs → nakama-java

heroiclabs / nakama-java

Licence: Apache-2.0 License
Android optimized Java client for Nakama server.

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to nakama-java

Nakama
Distributed server for social and realtime games and apps.
Stars: ✭ 5,293 (+20257.69%)
Mutual labels:  realtime, game-server, nakama
Realtime Server
A realtime dedicated game server ( FPS / MOBA ). 一个实时的专用游戏服务器.
Stars: ✭ 358 (+1276.92%)
Mutual labels:  realtime, game-server
Rnl
RNL - Realtime Network Library - The opensource reliable UDP network library
Stars: ✭ 59 (+126.92%)
Mutual labels:  realtime, game-server
laravel-realtime-chat-pusher
Contoh aplikasi realtime chat dengan pusher
Stars: ✭ 36 (+38.46%)
Mutual labels:  realtime, realtime-chat
nakama-docs
Documentation for Nakama social and realtime server.
Stars: ✭ 44 (+69.23%)
Mutual labels:  game-server, nakama
Nakama Js
JavaScript client for Nakama server written in TypeScript.
Stars: ✭ 101 (+288.46%)
Mutual labels:  realtime, game-server
unity-sampleproject
A sample game called Pirate Panic for Unity engine built with Nakama server.
Stars: ✭ 115 (+342.31%)
Mutual labels:  game-server, nakama
nakama-examples
A mono repo with project examples for the Nakama client libraries.
Stars: ✭ 22 (-15.38%)
Mutual labels:  realtime, nakama
grafana-api-java-client
A simple java client for interacting with Grafana using a fluent interface.
Stars: ✭ 40 (+53.85%)
Mutual labels:  java-client
obozrenie
Simple and easy to use game server browser.
Stars: ✭ 25 (-3.85%)
Mutual labels:  game-server
README.1ST
The starting point of Laclede’s LAN on GitHub.
Stars: ✭ 48 (+84.62%)
Mutual labels:  game-server
bong-bong
Open public chat service built for the web.
Stars: ✭ 17 (-34.62%)
Mutual labels:  realtime
onchat-web
A simple, beautiful, mobile-first instant messaging progressive web application.
Stars: ✭ 138 (+430.77%)
Mutual labels:  realtime
gameServer
A gameServer for car racing game which based on leaf game server
Stars: ✭ 23 (-11.54%)
Mutual labels:  game-server
ChatService
ChatService (SignalR).
Stars: ✭ 26 (+0%)
Mutual labels:  realtime
Computer-Vision-Project
The goal of this project was to develop a Face Recognition application using a Local Binary Pattern approach and, using the same approach, develop a real time Face Recognition application.
Stars: ✭ 20 (-23.08%)
Mutual labels:  realtime
Design-Prototype-Feedback-Application
Invision-like Design Prototype Feedback Application built using Laravel Vue and Pusher
Stars: ✭ 13 (-50%)
Mutual labels:  realtime
rmnp
Realtime Multiplayer Networking Protocol
Stars: ✭ 41 (+57.69%)
Mutual labels:  realtime
real time circle detection android
Real time circle detection and tracking by Hough Circle Transform with OpenCV on Android OS.
Stars: ✭ 39 (+50%)
Mutual labels:  realtime
signalr-client
SignalR client library built on top of @aspnet/signalr. This gives you more features and easier to use.
Stars: ✭ 48 (+84.62%)
Mutual labels:  realtime

Nakama Java

Android optimized Java client for Nakama server.

Nakama is an open-source server designed to power modern games and apps. Features include user accounts, chat, social, matchmaker, realtime multiplayer, and much more.

This client implements the full API and socket options with the server. It's written in C# with minimal dependencies to support Unity, Xamarin, Godot, XNA, and other engines and frameworks.

Full documentation is online - https://heroiclabs.com/docs

Getting Started

You'll need to setup the server and database before you can connect with the client. The simplest way is to use Docker but have a look at the server documentation for other options.

  1. Install and run the servers. Follow these instructions.

  2. The Java SDK can be imported with either Grade or Maven through Jitpack.

Gradle

repositories {
    maven {
        url 'https://jitpack.io'
    }
}

dependencies {
    implementation 'com.github.heroiclabs.nakama-java:nakama-java:<commit>'

 // or, depend on the fat Jar which bundles all of the Nakama Java dependencies into a single Jar.
 // implementation 'com.github.heroiclabs.nakama-java:nakama-java-all:<commit>'
}

Maven

  <repositories>
    <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
  </repositories>

  ...
  <dependencies>
    <dependency>
      <groupId>com.github.heroiclabs.nakama-java</groupId>
      <artifactId>nakama-java</artifactId>
      <version>_commit_</version>
      <type>jar</type>
    </dependency>
  </dependencies>

Or, if you would like to depend on a fat JAR with Maven:

  <dependencies>
    <dependency>
      <groupId>com.github.heroiclabs.nakama-java</groupId>
      <artifactId>nakama-java-all</artifactId>
      <version>_commit_</version>
      <type>jar</type>
    </dependency>
  </dependencies>

Alternatively, you can download the client from the releases page and import it into your project. You can also build from source.

You can view full integration examples in the examples folder.

  1. Use the connection credentials to build a client object.
import com.heroiclabs.nakama.Client;

public class NakamaSessionManager {
  private final Client client;

  public NakamaSessionManager() {
    client = new DefaultClient("defaultkey", "127.0.0.1", 7349, false);
  }
}

Usage

The client object has many methods to execute various features in the server or open realtime socket connections with the server.

Authenticate

There's a variety of ways to authenticate with the server. Authentication can create a user if they don't already exist with those credentials. It's also easy to authenticate with a social profile from Google Play Games, Facebook, Game Center, etc.

String email = "[email protected]";
String password = "batsignal";
Session session = client.authenticateEmail(email, password).get();
System.out.println(session);

Sessions

When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a Session object.

System.out.println(session.getAuthToken()); // raw JWT token
System.out.println(session.getUserId());
System.out.println(session.getUsername());
System.out.println("Session has expired: " + session.isExpired());
System.out.println("Session expires at: " + session.getExpireTime());

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

String authtoken = "restored from somewhere";
Session session = DefaultSession.restore(authtoken);
if (session.isExpired()) {
    System.out.println("Session has expired. Must reauthenticate!");
}

Requests

The client includes lots of builtin APIs for various features of the game server. These can be accessed with the async methods. It can also call custom logic as RPC functions on the server. These can also be executed with a socket object.

All requests are sent with a session object which authorizes the client.

Account account = client.getAccount(session);
System.out.println(account.getUser().getId());
System.out.println(account.getUser().getUsername());
System.out.println(account.getWallet());

Socket

The client can create one or more sockets with the server. Each socket can have it's own event listeners registered for responses received from the server.

String host = "localhost";
int port = 7350; // different port to the main API port
boolean ssl = false;
SocketClient socket = client.createSocket(host, port, ssl);
ClientListener listener = new AbstractClientListener() {
  @Override
  public void onDisconnect(final Throwable t) {
      System.out.println("Socket disconnected");
  }
};
socket.connect(session, listener).get();
System.out.println("Socket connected successfully.");

By default, all socket messages are processed in a single thread. Advanced users who want to pass a multithreaded ExecutorService to the client.createSocket method should be aware that incoming messages will not necessarily be processed in order by that socket.

For Android

Android uses a permissions system which determines which platform services the application will request to use and ask permission for from the user. The client uses the network to communicate with the server so you must add the "INTERNET" permission.

<uses-permission android:name="android.permission.INTERNET"/>

Contribute

To build the codebase you will need to install these dependencies:

  • Java Runtime Environment 1.8 through 1.11
  • Java Development Kit 1.8 through 1.11

Invoke the Gradle Wrapper with ./gradlew build and Gradle will install your dependencies over the network for you prior to building. It will then make a build and run the full test suite.

To test a specific test, run ./gradlew test --tests <ClassName.methodName>

You can also run ./gradlew tasks for a list of available build tasks.

To create a fat JAR with self-contained dependencies, run:

./gradlew shadow

All JAR artifacts are output to build/libs. The fat JAR will have an artifact id of 'nakama-java-all`.

If you'd like to test a Jitpack publish task locally prior to pushing, run:

./gradlew publishToMavenLocal

Protobuf Sourcing

If you need to re-download all .proto dependenies, run ./download-protos from the root of this repository.

Jitpack

Jitpack makes builds of each commit on its own servers. You can view the results of each build and the corresponding artifacts at the following url:

https://jitpack.io/com/github/heroiclabs/nakama-java/<commit>/build.log

Generate Docs

API docs are generated with javadoc and deployed to GitHub pages.

When changing the API comments, rerun javadoc and commit the changes in docs/*.

To run javadoc:

cd nakama-java/src/main/com/heroiclabs/nakama
javadoc *.java

License

This project is licensed under the Apache-2 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].