mirror of
https://github.com/heroiclabs/nakama-java.git
synced 2026-11-24 08:55:49 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cd7bd7e71 | ||
|
|
d9c2ffe343 | ||
|
|
5f044e2cf7 | ||
|
|
55119792d9 | ||
|
|
38362c56ef | ||
|
|
4f43a4acb9 | ||
|
|
6fc77a2b23 | ||
|
|
5922d7e655 | ||
|
|
5f54b0a385 | ||
|
|
e9838c710b | ||
|
|
225edc9db8 | ||
|
|
f36998356c | ||
|
|
dcd0a7ee4e | ||
|
|
99a822c13a | ||
|
|
eeec680c65 | ||
|
|
40f0e7166b | ||
|
|
66df48c258 | ||
|
|
7225ef4674 | ||
|
|
e3a3c49af4 |
No files matched your search
@@ -4,6 +4,31 @@ All notable changes to this project are documented below.
|
||||
|
||||
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).
|
||||
|
||||
## [0.3.0] - 2017-10-17
|
||||
### Added
|
||||
- Advanced Matchmaking with custom filters and user properties.
|
||||
|
||||
### Fixed
|
||||
- Improved errors to contain the underlying error reason.
|
||||
|
||||
## [0.2.0] - 2017-09-24
|
||||
### Added
|
||||
- Leaderboard messages.
|
||||
- Matchmaking messages.
|
||||
- Match messsages.
|
||||
- Match presence updates.
|
||||
- Topic messages.
|
||||
- Topic presence updates.
|
||||
|
||||
## [0.1.2] - 2017-09-02
|
||||
### Fixed
|
||||
- Pin transitive SLF4J dependency on 1.7.* stable release.
|
||||
- Use "okio.ByteString" rather than "java.util.Base64" for base64 support.
|
||||
|
||||
## [0.1.1] - 2017-08-14
|
||||
### Fixed
|
||||
- Correctly expose builder functions to external packages.
|
||||
|
||||
## [0.1.0] - 2017-08-13
|
||||
### Added
|
||||
- Initial public release.
|
||||
@@ -16,8 +16,17 @@ The client can be downloaded from [GitHub releases](https://github.com/heroiclab
|
||||
If you use a build tool like Gradle you can skip the download and fetch it from the central repository.
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://dl.bintray.com/heroiclabs/default/'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(group: 'com.heroiclabs.nakama', name: 'client', version: '+')
|
||||
compile('org.slf4j:slf4j-api:1.7.25') {
|
||||
force = true // don't upgrade to "1.8.0-alpha2"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+7
-2
@@ -25,7 +25,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.heroiclabs.nakama'
|
||||
version = '0.1.0'
|
||||
version = '0.3.0'
|
||||
def description = 'Android optimized Java client for Nakama server.'
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
@@ -87,7 +87,9 @@ dependencies {
|
||||
compile 'com.google.protobuf:protobuf-lite:3.0.1'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.8.1'
|
||||
compile 'com.stumbleupon:async:1.4.1'
|
||||
compile 'org.slf4j:slf4j-api:1.7.25'
|
||||
compile ('org.slf4j:slf4j-api:1.7.25') {
|
||||
force = true // don't upgrade to "1.8.0-alpha2"
|
||||
}
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
@@ -104,6 +106,9 @@ gitPublish {
|
||||
}
|
||||
preserve {
|
||||
include '0.1.0/**'
|
||||
include '0.1.1/**'
|
||||
include '0.1.2/**'
|
||||
include '0.2.0/**'
|
||||
}
|
||||
commitMessage = "Published javadoc '$project.version' via Gradle ${GradleVersion.current().version}."
|
||||
}
|
||||
|
||||
+1
-1
Submodule server updated: 15dc7ba786...e0a93a8615.
@@ -25,21 +25,21 @@ public interface AuthenticateMessage extends CollatedMessage<Session> {
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static AuthenticateMessage custom(final @NonNull String id) {
|
||||
public static AuthenticateMessage custom(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
com.heroiclabs.nakama.Api.AuthenticateRequest.newBuilder()
|
||||
.setCustom(id);
|
||||
return new DefaultAuthenticateMessage(payload);
|
||||
}
|
||||
|
||||
static AuthenticateMessage device(final @NonNull String id) {
|
||||
public static AuthenticateMessage device(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
com.heroiclabs.nakama.Api.AuthenticateRequest.newBuilder()
|
||||
.setDevice(id);
|
||||
return new DefaultAuthenticateMessage(payload);
|
||||
}
|
||||
|
||||
static AuthenticateMessage email(final @NonNull String email, final @NonNull String password) {
|
||||
public static AuthenticateMessage email(final @NonNull String email, final @NonNull String password) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
com.heroiclabs.nakama.Api.AuthenticateRequest.newBuilder()
|
||||
.setEmail(com.heroiclabs.nakama.Api.AuthenticateRequest.Email.newBuilder()
|
||||
@@ -49,14 +49,14 @@ public interface AuthenticateMessage extends CollatedMessage<Session> {
|
||||
return new DefaultAuthenticateMessage(payload);
|
||||
}
|
||||
|
||||
static AuthenticateMessage facebook(final @NonNull String oauthToken) {
|
||||
public static AuthenticateMessage facebook(final @NonNull String oauthToken) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
com.heroiclabs.nakama.Api.AuthenticateRequest.newBuilder()
|
||||
.setFacebook(oauthToken);
|
||||
return new DefaultAuthenticateMessage(payload);
|
||||
}
|
||||
|
||||
static AuthenticateMessage gameCenter(final @NonNull String playerId, final @NonNull String bundleId,
|
||||
public static AuthenticateMessage gameCenter(final @NonNull String playerId, final @NonNull String bundleId,
|
||||
final long timestamp, final @NonNull String salt,
|
||||
final @NonNull String signature, final @NonNull String publicKeyUrl) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
@@ -72,14 +72,14 @@ public interface AuthenticateMessage extends CollatedMessage<Session> {
|
||||
return new DefaultAuthenticateMessage(payload);
|
||||
}
|
||||
|
||||
static AuthenticateMessage google(final @NonNull String oauthToken) {
|
||||
public static AuthenticateMessage google(final @NonNull String oauthToken) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
com.heroiclabs.nakama.Api.AuthenticateRequest.newBuilder()
|
||||
.setGoogle(oauthToken);
|
||||
return new DefaultAuthenticateMessage(payload);
|
||||
}
|
||||
|
||||
static AuthenticateMessage steam(final @NonNull String sessionToken) {
|
||||
public static AuthenticateMessage steam(final @NonNull String sessionToken) {
|
||||
final com.heroiclabs.nakama.Api.AuthenticateRequest.Builder payload =
|
||||
com.heroiclabs.nakama.Api.AuthenticateRequest.newBuilder()
|
||||
.setSteam(sessionToken);
|
||||
|
||||
@@ -68,5 +68,5 @@ public interface Client {
|
||||
* @param message The message to send.
|
||||
* @return Placeholder return type to allow chaining operations.
|
||||
*/
|
||||
Deferred<Boolean> send(Message message);
|
||||
Deferred<Boolean> send(UncollatedMessage message);
|
||||
}
|
||||
@@ -24,4 +24,39 @@ public interface ClientListener {
|
||||
* Called when the client socket disconnects.
|
||||
*/
|
||||
void onDisconnect();
|
||||
|
||||
/**
|
||||
* Called when a new topic message has been received.
|
||||
*
|
||||
* @param message The {@code TopicMessage} received.
|
||||
*/
|
||||
void onTopicMessage(TopicMessage message);
|
||||
|
||||
/**
|
||||
* Called when a new topic presence update has been received.
|
||||
*
|
||||
* @param presence The {@code TopicPresence} received.
|
||||
*/
|
||||
void onTopicPresence(TopicPresence presence);
|
||||
|
||||
/**
|
||||
* Called when a matchmaking has found a match.
|
||||
*
|
||||
* @param matched The {@code MatchmakeMatched} received.
|
||||
*/
|
||||
void onMatchmakeMatched(MatchmakeMatched matched);
|
||||
|
||||
/**
|
||||
* Called when a new match data is received.
|
||||
*
|
||||
* @param matchData The {@code MatchData} received.
|
||||
*/
|
||||
void onMatchData(MatchData matchData);
|
||||
|
||||
/**
|
||||
* Called when a new match presence update is received.
|
||||
*
|
||||
* @param matchPresence The {@code MatchPresence} received.
|
||||
*/
|
||||
void onMatchPresence(MatchPresence matchPresence);
|
||||
}
|
||||
@@ -62,9 +62,9 @@ public class DefaultClient implements Client {
|
||||
|
||||
private long serverTime;
|
||||
|
||||
private DefaultClient(final String serverKey, final String host, final int port, final String lang,
|
||||
final boolean ssl, final int connectTimeout, final int timeout, final boolean trace,
|
||||
final ClientListener listener) {
|
||||
private DefaultClient(final @NonNull String serverKey, final @NonNull String host, final int port,
|
||||
final @NonNull String lang, final boolean ssl, final int connectTimeout, final int timeout,
|
||||
final boolean trace, final @NonNull ClientListener listener) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.serverKey = serverKey;
|
||||
@@ -126,7 +126,7 @@ public class DefaultClient implements Client {
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
deferred.callback(new DefaultError("Error sending message to server", Error.ErrorCode.UNKNOWN));
|
||||
deferred.callback(new DefaultError("Error sending message to server", e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +140,7 @@ public class DefaultClient implements Client {
|
||||
try {
|
||||
authResponse = com.heroiclabs.nakama.Api.AuthenticateResponse.parseFrom(body.byteStream());
|
||||
} catch (IOException e) {
|
||||
deferred.callback(new DefaultError("Error reading response from server", Error.ErrorCode.UNKNOWN));
|
||||
deferred.callback(new DefaultError("Error reading response from server", e));
|
||||
return;
|
||||
} finally {
|
||||
response.close();
|
||||
@@ -152,13 +152,13 @@ public class DefaultClient implements Client {
|
||||
|
||||
switch (authResponse.getIdCase()) {
|
||||
case ERROR:
|
||||
deferred.callback(new DefaultError(authResponse.getError().getMessage(), authResponse.getError().getCode()));
|
||||
deferred.callback(new DefaultError(authResponse.getError().getMessage(), authResponse.getError().getCode(), authResponse.getCollationId()));
|
||||
break;
|
||||
case SESSION:
|
||||
deferred.callback(DefaultSession.restore(authResponse.getSession().getToken()));
|
||||
break;
|
||||
default:
|
||||
deferred.callback(new DefaultError("Unknown response format from server", Error.ErrorCode.UNKNOWN));
|
||||
deferred.callback(new DefaultError("Unknown response format from server for message", Error.ErrorCode.UNKNOWN, authResponse.getCollationId()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
|
||||
final String collationId = envelope.getCollationId();
|
||||
if (collationId == null) {
|
||||
if (collationId == null || "".equals(collationId)) {
|
||||
switch (envelope.getPayloadCase()) {
|
||||
case PAYLOAD_NOT_SET:
|
||||
log.error("No payload in incoming uncollated message from server: " + envelope.toString());
|
||||
@@ -237,6 +237,21 @@ public class DefaultClient implements Client {
|
||||
serverTime = newServerTime;
|
||||
}
|
||||
break;
|
||||
case TOPIC_MESSAGE:
|
||||
listener.onTopicMessage(DefaultTopicMessage.fromProto(envelope.getTopicMessage()));
|
||||
break;
|
||||
case TOPIC_PRESENCE:
|
||||
listener.onTopicPresence(DefaultTopicPresence.fromProto(envelope.getTopicPresence()));
|
||||
break;
|
||||
case MATCH_DATA:
|
||||
listener.onMatchData(DefaultMatchData.fromProto(envelope.getMatchData()));
|
||||
break;
|
||||
case MATCH_PRESENCE:
|
||||
listener.onMatchPresence(DefaultMatchPresence.fromProto(envelope.getMatchPresence()));
|
||||
break;
|
||||
case MATCHMAKE_MATCHED:
|
||||
listener.onMatchmakeMatched(DefaultMatchmakeMatched.fromProto(envelope.getMatchmakeMatched()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -254,7 +269,7 @@ public class DefaultClient implements Client {
|
||||
def.callback(Boolean.TRUE);
|
||||
break;
|
||||
case ERROR:
|
||||
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode()));
|
||||
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode(), collationId));
|
||||
break;
|
||||
case SELF:
|
||||
def.callback(DefaultSelf.fromProto(envelope.getSelf().getSelf()));
|
||||
@@ -287,8 +302,52 @@ public class DefaultClient implements Client {
|
||||
case RPC:
|
||||
def.callback(DefaultRpcResult.fromProto(envelope.getRpc()));
|
||||
break;
|
||||
case TOPICS:
|
||||
final List<Topic> topics = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.TTopics.Topic topic : envelope.getTopics().getTopicsList()) {
|
||||
topics.add(DefaultTopic.fromProto(topic));
|
||||
}
|
||||
def.callback(new DefaultResultSet<Topic>(null, topics));
|
||||
break;
|
||||
case TOPIC_MESSAGE_ACK:
|
||||
def.callback(DefaultTopicMessageAck.fromProto(envelope.getTopicMessageAck()));
|
||||
break;
|
||||
case TOPIC_MESSAGES:
|
||||
final List<TopicMessage> messages = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.TopicMessage m : envelope.getTopicMessages().getMessagesList()) {
|
||||
messages.add(DefaultTopicMessage.fromProto(m));
|
||||
}
|
||||
def.callback(new DefaultResultSet<TopicMessage>(new DefaultCursor(envelope.getTopicMessages().getCursor().toByteArray()), messages));
|
||||
break;
|
||||
case MATCH:
|
||||
def.callback(DefaultMatch.fromProto(envelope.getMatch()));
|
||||
break;
|
||||
case MATCHES:
|
||||
final List<Match> matches = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.Match m : envelope.getMatches().getMatchesList()) {
|
||||
matches.add(DefaultMatch.fromProto(m));
|
||||
}
|
||||
def.callback(new DefaultResultSet<Match>(null, matches));
|
||||
break;
|
||||
case MATCHMAKE_TICKET:
|
||||
def.callback(DefaultMatchmakeTicket.fromProto(envelope.getMatchmakeTicket()));
|
||||
break;
|
||||
case LEADERBOARDS:
|
||||
final List<Leaderboard> leaderboards = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.Leaderboard l : envelope.getLeaderboards().getLeaderboardsList()) {
|
||||
leaderboards.add(DefaultLeaderboard.fromProto(l));
|
||||
}
|
||||
def.callback(new DefaultResultSet<Leaderboard>(new DefaultCursor(envelope.getLeaderboards().getCursor().toByteArray()), leaderboards));
|
||||
break;
|
||||
case LEADERBOARD_RECORDS:
|
||||
final List<LeaderboardRecord> leaderboardRecords = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.LeaderboardRecord r : envelope.getLeaderboardRecords().getRecordsList()) {
|
||||
leaderboardRecords.add(DefaultLeaderboardRecord.fromProto(r));
|
||||
}
|
||||
def.callback(new DefaultResultSet<LeaderboardRecord>(new DefaultCursor(envelope.getLeaderboardRecords().getCursor().toByteArray()), leaderboardRecords));
|
||||
break;
|
||||
default:
|
||||
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode()));
|
||||
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode(), collationId));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -308,9 +367,7 @@ public class DefaultClient implements Client {
|
||||
// TODO callback any leftover deferred items with a disconnect error message?
|
||||
collationIds.clear();
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onDisconnect();
|
||||
}
|
||||
listener.onDisconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -322,9 +379,7 @@ public class DefaultClient implements Client {
|
||||
// TODO callback any leftover deferred items with a disconnect error message?
|
||||
collationIds.clear();
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onDisconnect();
|
||||
}
|
||||
listener.onDisconnect();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -365,7 +420,7 @@ public class DefaultClient implements Client {
|
||||
|
||||
final boolean isEnqueued = socket.send(ByteString.of(payload));
|
||||
if (!isEnqueued) {
|
||||
deferred.callback(new DefaultError("Failed to send message, make sure the client is connected", Error.ErrorCode.UNKNOWN));
|
||||
deferred.callback(new DefaultError("Failed to send message, make sure the client is connected", Error.ErrorCode.UNKNOWN, collationId));
|
||||
return deferred;
|
||||
}
|
||||
|
||||
@@ -374,7 +429,7 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Deferred<Boolean> send(final @NonNull Message message) {
|
||||
public Deferred<Boolean> send(final @NonNull UncollatedMessage message) {
|
||||
final Deferred<Boolean> deferred = new Deferred<>();
|
||||
|
||||
if (socket == null) {
|
||||
@@ -412,7 +467,7 @@ public class DefaultClient implements Client {
|
||||
private int connectTimeout = 3000;
|
||||
private int timeout = 5000;
|
||||
private boolean trace = false;
|
||||
private ClientListener listener;
|
||||
private ClientListener listener = new NoopClientListener();
|
||||
|
||||
public Client build() {
|
||||
return new DefaultClient(serverKey, host, port, lang, ssl, connectTimeout, timeout, trace, listener);
|
||||
@@ -453,7 +508,7 @@ public class DefaultClient implements Client {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder listener(final ClientListener listener) {
|
||||
public Builder listener(final @NonNull ClientListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Base64;
|
||||
import okio.ByteString;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@@ -31,7 +30,7 @@ public class DefaultCursor implements Cursor {
|
||||
private final byte[] value;
|
||||
|
||||
public String serialize() {
|
||||
return Base64.getEncoder().encodeToString(value);
|
||||
return ByteString.of(value).base64();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +38,7 @@ public class DefaultCursor implements Cursor {
|
||||
* @return A new cursor which was stored.
|
||||
*/
|
||||
public static Cursor restore(final String serializedCursor) {
|
||||
final byte[] cursor = Base64.getDecoder().decode(serializedCursor);
|
||||
final byte[] cursor = ByteString.decodeBase64(serializedCursor).toByteArray();
|
||||
return new DefaultCursor(cursor);
|
||||
}
|
||||
}
|
||||
@@ -24,15 +24,30 @@ import lombok.*;
|
||||
class DefaultError extends Error {
|
||||
|
||||
private final ErrorCode code;
|
||||
private final String collationId;
|
||||
|
||||
DefaultError(final @NonNull String message, final @NonNull ErrorCode code) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.collationId = null;
|
||||
}
|
||||
|
||||
DefaultError(final @NonNull String message, final int code) {
|
||||
DefaultError(final @NonNull String message, final @NonNull ErrorCode code, final String collationId) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.collationId = collationId;
|
||||
}
|
||||
|
||||
DefaultError(final @NonNull String message, final @NonNull Throwable cause) {
|
||||
super(message, cause);
|
||||
this.code = ErrorCode.UNKNOWN;
|
||||
this.collationId = null;
|
||||
}
|
||||
|
||||
DefaultError(final @NonNull String message, final int code, final String collationId) {
|
||||
super(message);
|
||||
this.code = ErrorCode.fromInt(code);
|
||||
this.collationId = collationId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultLeaderboard implements Leaderboard {
|
||||
private final byte[] id;
|
||||
private final boolean authoritative;
|
||||
private final long sort;
|
||||
private final long count;
|
||||
private final String resetSchedule;
|
||||
private final byte[] metadata;
|
||||
private final byte[] nextId;
|
||||
private final byte[] prevId;
|
||||
|
||||
public <T> T getMetadata(final Class<T> clazz) {
|
||||
return DefaultClient.GSON.fromJson(new String(metadata), clazz);
|
||||
}
|
||||
|
||||
static Leaderboard fromProto(final @NonNull com.heroiclabs.nakama.Api.Leaderboard leaderboard) {
|
||||
return new DefaultLeaderboard(
|
||||
leaderboard.getId().toByteArray(),
|
||||
leaderboard.getAuthoritative(),
|
||||
leaderboard.getSort(),
|
||||
leaderboard.getCount(),
|
||||
leaderboard.getResetSchedule(),
|
||||
leaderboard.getMetadata().toByteArray(),
|
||||
leaderboard.getNextId().toByteArray(),
|
||||
leaderboard.getPrevId().toByteArray()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultLeaderboardRecord implements LeaderboardRecord {
|
||||
private final byte[] leaderboardId;
|
||||
private final byte[] ownerId;
|
||||
private final String handle;
|
||||
private final String lang;
|
||||
private final String location;
|
||||
private final String timezone;
|
||||
private final long rank;
|
||||
private final long score;
|
||||
private final long numScore;
|
||||
private final byte[] metadata;
|
||||
private final long rankedAt;
|
||||
private final long updatedAt;
|
||||
private final long expiresAt;
|
||||
|
||||
static LeaderboardRecord fromProto(final @NonNull com.heroiclabs.nakama.Api.LeaderboardRecord record) {
|
||||
return new DefaultLeaderboardRecord(
|
||||
record.getLeaderboardId().toByteArray(),
|
||||
record.getOwnerId().toByteArray(),
|
||||
record.getHandle(),
|
||||
record.getLang(),
|
||||
record.getLocation(),
|
||||
record.getTimezone(),
|
||||
record.getRank(),
|
||||
record.getScore(),
|
||||
record.getNumScore(),
|
||||
record.getMetadata().toByteArray(),
|
||||
record.getRankedAt(),
|
||||
record.getUpdatedAt(),
|
||||
record.getExpiresAt()
|
||||
);
|
||||
}
|
||||
|
||||
public <T> T getMetadata(final Class<T> clazz) {
|
||||
return DefaultClient.GSON.fromJson(new String(metadata), clazz);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultLeaderboardRecordWriteMessage implements LeaderboardRecordWriteMessage {
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultLeaderboardRecordsFetchMessage implements LeaderboardRecordsFetchMessage {
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultLeaderboardRecordsListMessage implements LeaderboardRecordsListMessage {
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultLeaderboardsListMessage implements LeaderboardsListMessage {
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatch implements Match {
|
||||
private final byte[] id;
|
||||
private final List<UserPresence> presence;
|
||||
private final UserPresence self;
|
||||
|
||||
static Match fromProto(final @NonNull com.heroiclabs.nakama.Api.TMatch match) {
|
||||
return DefaultMatch.fromProto(match.getMatch());
|
||||
}
|
||||
|
||||
static Match fromProto(final @NonNull com.heroiclabs.nakama.Api.Match match) {
|
||||
List<UserPresence> userPresences = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : match.getPresencesList()) {
|
||||
userPresences.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
return new DefaultMatch(match.getMatchId().toByteArray(), userPresences, DefaultUserPresence.fromProto(match.getSelf()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchCreateMessage implements MatchCreateMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchData implements MatchData {
|
||||
private final byte[] id;
|
||||
private final byte[] data;
|
||||
private final long opCode;
|
||||
private final UserPresence presence;
|
||||
|
||||
static MatchData fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchData matchData) {
|
||||
return new DefaultMatchData(matchData.getMatchId().toByteArray(), matchData.getData().toByteArray(), matchData.getOpCode(), DefaultUserPresence.fromProto(matchData.getPresence()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchDataSendMessage implements MatchDataSendMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes() {
|
||||
return payload.clone().build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public class DefaultMatchPresence implements MatchPresence {
|
||||
|
||||
private final byte[] id;
|
||||
private final List<UserPresence> join;
|
||||
private final List<UserPresence> leave;
|
||||
|
||||
static MatchPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchPresence matchPresence) {
|
||||
List<UserPresence> joins = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : matchPresence.getJoinsList()) {
|
||||
joins.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
List<UserPresence> leaves = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : matchPresence.getLeavesList()) {
|
||||
leaves.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
return new DefaultMatchPresence(matchPresence.getMatchId().toByteArray(), joins, leaves);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchToken implements MatchToken {
|
||||
private final byte[] token;
|
||||
|
||||
static MatchToken fromProto(final @NonNull byte[] token) {
|
||||
return new DefaultMatchToken(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchesJoinMessage implements MatchesJoinMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchesLeaveMessage implements MatchesLeaveMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeAddMessage implements MatchmakeAddMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeCheckFilter implements MatchmakeCheckFilter {
|
||||
private final boolean value;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeMatched implements MatchmakeMatched {
|
||||
private final MatchmakeTicket ticket;
|
||||
private final List<UserPresence> presence;
|
||||
private final MatchToken token;
|
||||
private final UserPresence self;
|
||||
private final List<MatchmakeUserProperty> properties;
|
||||
|
||||
static MatchmakeMatched fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchmakeMatched matched) {
|
||||
List<UserPresence> userPresences = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : matched.getPresencesList()) {
|
||||
userPresences.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
List<MatchmakeUserProperty> userProperties = new ArrayList<MatchmakeUserProperty>();
|
||||
for (com.heroiclabs.nakama.Api.MatchmakeMatched.UserProperty u : matched.getPropertiesList()) {
|
||||
userProperties.add(DefaultMatchmakeUserProperty.fromProto(u));
|
||||
}
|
||||
|
||||
return new DefaultMatchmakeMatched(
|
||||
DefaultMatchmakeTicket.fromProto(matched.getTicket().toByteArray()),
|
||||
userPresences,
|
||||
DefaultMatchToken.fromProto(matched.getToken().toByteArray()),
|
||||
DefaultUserPresence.fromProto(matched.getSelf()),
|
||||
userProperties
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeRangeFilter implements MatchmakeRangeFilter {
|
||||
private final long lowerbound;
|
||||
private final long upperbound;
|
||||
|
||||
static MatchmakeRangeFilter fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchmakeFilter.RangeFilter filter) {
|
||||
return new DefaultMatchmakeRangeFilter(filter.getLowerBound(), filter.getUpperBound());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeRemoveMessage implements MatchmakeRemoveMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeTermFilter implements MatchmakeTermFilter {
|
||||
private final List<String> terms;
|
||||
private final boolean matchingAllTerms;
|
||||
|
||||
static MatchmakeTermFilter fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchmakeFilter.TermFilter filter) {
|
||||
return new DefaultMatchmakeTermFilter(filter.getTermsList(), filter.getMatchAllTerms());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeTicket implements MatchmakeTicket {
|
||||
private final byte[] ticket;
|
||||
|
||||
static MatchmakeTicket fromProto(final @NonNull com.heroiclabs.nakama.Api.TMatchmakeTicket matchmakeTicket) {
|
||||
return new DefaultMatchmakeTicket(matchmakeTicket.getTicket().toByteArray());
|
||||
}
|
||||
|
||||
static MatchmakeTicket fromProto(final @NonNull byte[] matchmakeTicket) {
|
||||
return new DefaultMatchmakeTicket(matchmakeTicket);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultMatchmakeUserProperty implements MatchmakeUserProperty {
|
||||
private final byte[] userId;
|
||||
private final Map<String, Object> properties;
|
||||
private final Map<String, MatchmakeFilter> filters;
|
||||
|
||||
static DefaultMatchmakeUserProperty fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchmakeMatched.UserProperty p) {
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
for (com.heroiclabs.nakama.Api.PropertyPair pp : p.getPropertiesList()) {
|
||||
switch (pp.getValueCase()) {
|
||||
case INTVALUE:
|
||||
props.put(pp.getKey(), pp.getIntValue());
|
||||
break;
|
||||
case BOOLVALUE:
|
||||
props.put(pp.getKey(), pp.getBoolValue());
|
||||
break;
|
||||
case STRINGSET:
|
||||
props.put(pp.getKey(), pp.getStringSet().getValuesList());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, MatchmakeFilter> filters = new HashMap<>();
|
||||
for (com.heroiclabs.nakama.Api.MatchmakeFilter f : p.getFiltersList()) {
|
||||
switch (f.getValueCase()) {
|
||||
case TERM:
|
||||
filters.put(f.getName(), DefaultMatchmakeTermFilter.fromProto(f.getTerm()));
|
||||
break;
|
||||
case RANGE:
|
||||
filters.put(f.getName(), DefaultMatchmakeRangeFilter.fromProto(f.getRange()));
|
||||
break;
|
||||
case CHECK:
|
||||
filters.put(f.getName(), new DefaultMatchmakeCheckFilter(f.getCheck()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new DefaultMatchmakeUserProperty(p.getUserId().toByteArray(), props, filters);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,9 @@ import lombok.ToString;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Base64;
|
||||
import okio.*;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -45,7 +47,7 @@ public class DefaultSession implements Session {
|
||||
if (decoded.length != 3) {
|
||||
throw new IllegalArgumentException("Not a valid token.");
|
||||
}
|
||||
final String decodedJson = new String(Base64.getDecoder().decode(decoded[1]));
|
||||
final String decodedJson = ByteString.decodeBase64(decoded[1]).string(Charset.defaultCharset());
|
||||
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
||||
Map<String, Object> jsonMap = DefaultClient.GSON.fromJson(decodedJson, type);
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopic implements Topic {
|
||||
private final TopicId topicId;
|
||||
private final List<UserPresence> presences;
|
||||
private final UserPresence self;
|
||||
|
||||
static Topic fromProto(final @NonNull com.heroiclabs.nakama.Api.TTopics.Topic topic) {
|
||||
List<UserPresence> userPresences = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : topic.getPresencesList()) {
|
||||
userPresences.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
return new DefaultTopic(DefaultTopicId.fromProto(topic.getTopic()), userPresences, DefaultUserPresence.fromProto(topic.getSelf()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopicId implements TopicId {
|
||||
private final byte[] Id;
|
||||
private final TopicType topicType;
|
||||
|
||||
static TopicId fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicId topicId) {
|
||||
switch (topicId.getIdCase()) {
|
||||
case DM:
|
||||
return new DefaultTopicId(topicId.getDm().toByteArray(), TopicType.DirectMessage);
|
||||
case ROOM:
|
||||
return new DefaultTopicId(topicId.getRoom().toByteArray(), TopicType.Room);
|
||||
case GROUP_ID:
|
||||
return new DefaultTopicId(topicId.getGroupId().toByteArray(), TopicType.Group);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopicJoinMessage implements TopicJoinMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopicLeaveMessage implements TopicLeaveMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public class DefaultTopicMessage implements TopicMessage {
|
||||
private final TopicId topic;
|
||||
private final byte[] userId;
|
||||
private final byte[] messageId;
|
||||
private final long createdAt;
|
||||
private final long expiresAt;
|
||||
private final String handle;
|
||||
private final TopicMessageType type;
|
||||
private final byte[] data;
|
||||
|
||||
static TopicMessage fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicMessage message) {
|
||||
return new DefaultTopicMessage(
|
||||
DefaultTopicId.fromProto(message.getTopic()),
|
||||
message.getUserId().toByteArray(),
|
||||
message.getMessageId().toByteArray(),
|
||||
message.getCreatedAt(),
|
||||
message.getExpiresAt(),
|
||||
message.getHandle(),
|
||||
TopicMessageType.fromProto((int)message.getType()),
|
||||
message.getData().toByteArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopicMessageAck implements TopicMessageAck {
|
||||
private final byte[] messageId;
|
||||
private final String handle;
|
||||
private final long createdAt;
|
||||
private final long expiresAt;
|
||||
|
||||
static TopicMessageAck fromProto(final @NonNull com.heroiclabs.nakama.Api.TTopicMessageAck ack) {
|
||||
return new DefaultTopicMessageAck(ack.getMessageId().toByteArray(), ack.getHandle(), ack.getCreatedAt(), ack.getExpiresAt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopicMessageSendMessage implements TopicMessageSendMessage {
|
||||
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultTopicMessagesListMessage implements TopicMessagesListMessage {
|
||||
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
|
||||
|
||||
public byte[] asBytes(final @NonNull String collationId) {
|
||||
return payload.clone().setCollationId(collationId).build().toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public class DefaultTopicPresence implements TopicPresence {
|
||||
|
||||
private final TopicId topic;
|
||||
private final List<UserPresence> join;
|
||||
private final List<UserPresence> leave;
|
||||
|
||||
static TopicPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicPresence topicPresence) {
|
||||
List<UserPresence> joins = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : topicPresence.getJoinsList()) {
|
||||
joins.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
List<UserPresence> leaves = new ArrayList<UserPresence>();
|
||||
for (com.heroiclabs.nakama.Api.UserPresence u : topicPresence.getLeavesList()) {
|
||||
leaves.add(DefaultUserPresence.fromProto(u));
|
||||
}
|
||||
|
||||
return new DefaultTopicPresence(DefaultTopicId.fromProto(topicPresence.getTopic()), joins, leaves);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(includeFieldNames = true)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class DefaultUserPresence implements UserPresence {
|
||||
private final byte[] userId;
|
||||
private final byte[] sessionId;
|
||||
private final String handle;
|
||||
|
||||
static UserPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.UserPresence presence) {
|
||||
return new DefaultUserPresence(presence.getUserId().toByteArray(), presence.getSessionId().toByteArray(), presence.getHandle());
|
||||
}
|
||||
}
|
||||
@@ -36,11 +36,18 @@ public abstract class Error extends Exception {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message The error message to construct with.
|
||||
*/
|
||||
public Error(final @NonNull String message, final @NonNull Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* The error code for the problem.
|
||||
*/
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
enum ErrorCode {
|
||||
public enum ErrorCode {
|
||||
UNKNOWN(0),
|
||||
RUNTIME_EXCEPTION(1),
|
||||
UNRECOGNISED_PAYLOAD(2),
|
||||
@@ -62,17 +69,45 @@ public abstract class Error extends Exception {
|
||||
|
||||
private final int code;
|
||||
|
||||
// Static helpers to transform wire protocol int codes into their enum equivalents.
|
||||
private static final Map<Integer, ErrorCode> codeMappings;
|
||||
static {
|
||||
Map<Integer, ErrorCode> codes = new HashMap<>();
|
||||
for (ErrorCode code : ErrorCode.values()) {
|
||||
codes.put(code.code, code);
|
||||
}
|
||||
codeMappings = Collections.unmodifiableMap(codes);
|
||||
}
|
||||
static ErrorCode fromInt(final int code) {
|
||||
return codeMappings.getOrDefault(code + 1, ErrorCode.UNKNOWN);
|
||||
switch (code) {
|
||||
case 0:
|
||||
return RUNTIME_EXCEPTION;
|
||||
case 1:
|
||||
return UNRECOGNISED_PAYLOAD;
|
||||
case 2:
|
||||
return MISSING_PAYLOAD;
|
||||
case 3:
|
||||
return BAD_INPUT;
|
||||
case 4:
|
||||
return AUTH_ERROR;
|
||||
case 5:
|
||||
return USER_NOT_FOUND;
|
||||
case 6:
|
||||
return USER_REGISTER_INUSE;
|
||||
case 7:
|
||||
return USER_LINK_INUSE;
|
||||
case 8:
|
||||
return USER_LINK_PROVIDER_UNAVAILABLE;
|
||||
case 9:
|
||||
return USER_UNLINK_DISALLOWED;
|
||||
case 10:
|
||||
return USER_HANDLE_INUSE;
|
||||
case 11:
|
||||
return GROUP_NAME_INUSE;
|
||||
case 12:
|
||||
return GROUP_LAST_ADMIN;
|
||||
case 13:
|
||||
return STORAGE_REJECTED;
|
||||
case 14:
|
||||
return MATCH_NOT_FOUND;
|
||||
case 15:
|
||||
return RUNTIME_FUNCTION_NOT_FOUND;
|
||||
case 16:
|
||||
return RUNTIME_FUNCTION_EXCEPTION;
|
||||
default:
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,4 +115,9 @@ public abstract class Error extends Exception {
|
||||
* @return The code for the error.
|
||||
*/
|
||||
public abstract ErrorCode getCode();
|
||||
|
||||
/**
|
||||
* @return The collation ID associated with this error. Could be null.
|
||||
*/
|
||||
public abstract String getCollationId();
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
/**
|
||||
* The object which represents a leaderboard object.
|
||||
*/
|
||||
public interface Leaderboard {
|
||||
/**
|
||||
* @return Leaderboard ID.
|
||||
*/
|
||||
byte[] getId();
|
||||
|
||||
/**
|
||||
* @return Whether leaderboard is server authoritative or not.
|
||||
*/
|
||||
boolean isAuthoritative();
|
||||
|
||||
/**
|
||||
* @return Sort order for the record.
|
||||
*/
|
||||
long getSort();
|
||||
|
||||
/**
|
||||
* @return Record count.
|
||||
*/
|
||||
long getCount();
|
||||
|
||||
/**
|
||||
* @return Reset schedule.
|
||||
*/
|
||||
String getResetSchedule();
|
||||
|
||||
/**
|
||||
* @return Metadata associated with the leaderboard.
|
||||
*/
|
||||
byte[] getMetadata();
|
||||
|
||||
/**
|
||||
* @param clazz A hint for the type of the class.
|
||||
* @param <T> A type parameter for the metadata to decode.
|
||||
* @return Metadata associated with the leaderboard.
|
||||
*/
|
||||
<T> T getMetadata(final Class<T> clazz);
|
||||
|
||||
byte[] getNextId();
|
||||
|
||||
byte[] getPrevId();
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The object which represents a leaderboard record.
|
||||
*/
|
||||
public interface LeaderboardRecord {
|
||||
|
||||
/**
|
||||
* @return Leaderboard ID.
|
||||
*/
|
||||
byte[] getLeaderboardId();
|
||||
|
||||
/**
|
||||
* @return User ID that owns this record.
|
||||
*/
|
||||
byte[] getOwnerId();
|
||||
|
||||
/**
|
||||
* @return User handle.
|
||||
*/
|
||||
String getHandle();
|
||||
|
||||
/**
|
||||
* @return Language associated with the record.
|
||||
*/
|
||||
String getLang();
|
||||
|
||||
/**
|
||||
* @return Location associated with the record.
|
||||
*/
|
||||
String getLocation();
|
||||
|
||||
/**
|
||||
* @return Timezone associated with the record.
|
||||
*/
|
||||
String getTimezone();
|
||||
|
||||
long getRank();
|
||||
|
||||
long getScore();
|
||||
|
||||
long getNumScore();
|
||||
|
||||
/**
|
||||
* @return Metadata associated with the leaderboard record.
|
||||
*/
|
||||
byte[] getMetadata();
|
||||
|
||||
/**
|
||||
* @param clazz A hint for the type of the class.
|
||||
* @param <T> A type parameter for the metadata to decode.
|
||||
* @return Metadata associated with the leaderboard.
|
||||
*/
|
||||
<T> T getMetadata(final Class<T> clazz);
|
||||
|
||||
long getRankedAt();
|
||||
|
||||
/**
|
||||
* @return When the record was last updated
|
||||
*/
|
||||
long getUpdatedAt();
|
||||
|
||||
/**
|
||||
* @return When the record expires.
|
||||
*/
|
||||
long getExpiresAt();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface LeaderboardRecordWriteMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class LeaderboardRecordWrite {
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder write;
|
||||
|
||||
public static LeaderboardRecordWriteMessage.LeaderboardRecordWrite newBuilder(final @NonNull byte[] leaderboardId) {
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder b = com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.newBuilder();
|
||||
b.setLeaderboardId(ByteString.copyFrom(leaderboardId));
|
||||
return new LeaderboardRecordWriteMessage.LeaderboardRecordWrite(b);
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite location(final @NonNull String location) {
|
||||
write.setLocation(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite timezone(final @NonNull String timezone) {
|
||||
write.setTimezone(timezone);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite metadata(final @NonNull byte[] metadata) {
|
||||
write.setMetadata(ByteString.copyFrom(metadata));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite increment(final long value) {
|
||||
write.setIncr(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite decrement(final long value) {
|
||||
write.setDecr(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite set(final long value) {
|
||||
write.setSet(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite best(final long value) {
|
||||
write.setBest(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
private com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder build() {
|
||||
return write;
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static LeaderboardRecordWriteMessage.Builder newBuilder() {
|
||||
return new LeaderboardRecordWriteMessage.Builder(com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.Builder writes;
|
||||
|
||||
public LeaderboardRecordWriteMessage.Builder add(final @NonNull LeaderboardRecordWrite write) {
|
||||
writes.addRecords(write.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordWriteMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLeaderboardRecordsWrite(writes);
|
||||
return new DefaultLeaderboardRecordWriteMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface LeaderboardRecordsFetchMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static LeaderboardRecordsFetchMessage.Builder newBuilder() {
|
||||
return new LeaderboardRecordsFetchMessage.Builder(com.heroiclabs.nakama.Api.TLeaderboardRecordsFetch.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsFetch.Builder fetch;
|
||||
|
||||
public LeaderboardRecordsFetchMessage.Builder fetch(final @NonNull byte[] leaderboardId) {
|
||||
fetch.addLeaderboardIds(ByteString.copyFrom(leaderboardId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsFetchMessage.Builder limit(final long limit) {
|
||||
fetch.setLimit(limit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsFetchMessage.Builder cursor(final @NonNull byte[] cursor) {
|
||||
fetch.setCursor(ByteString.copyFrom(cursor));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsFetchMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLeaderboardRecordsFetch(fetch);
|
||||
return new DefaultLeaderboardRecordsFetchMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LeaderboardRecordsListMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static LeaderboardRecordsListMessage.Builder newBuilder(final @NonNull byte[] leaderboardId) {
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Builder b = com.heroiclabs.nakama.Api.TLeaderboardRecordsList.newBuilder();
|
||||
b.setLeaderboardId(ByteString.copyFrom(leaderboardId));
|
||||
return new DefaultLeaderboardRecordsListMessage.Builder(b);
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Builder listing;
|
||||
|
||||
public LeaderboardRecordsListMessage.Builder filterByPagingToOwnerId(final @NonNull byte[] ownerId) {
|
||||
listing.setOwnerId(ByteString.copyFrom(ownerId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsListMessage.Builder filterByPagingToOwnerIds(final @NonNull List<byte[]> ownerIds) {
|
||||
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Owners.Builder o = com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Owners.newBuilder();
|
||||
for (byte[] b : ownerIds) {
|
||||
o.addOwnerIds(ByteString.copyFrom(b));
|
||||
}
|
||||
listing.setOwnerIds(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsListMessage.Builder filterByLang(final @NonNull String lang) {
|
||||
listing.setLang(lang);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsListMessage.Builder filterByTimezone(final @NonNull String tz) {
|
||||
listing.setTimezone(tz);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsListMessage.Builder limit(final long limit) {
|
||||
listing.setLimit(limit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsListMessage.Builder cursor(final @NonNull byte[] cursor) {
|
||||
listing.setCursor(ByteString.copyFrom(cursor));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardRecordsListMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLeaderboardRecordsList(listing);
|
||||
return new DefaultLeaderboardRecordsListMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface LeaderboardsListMessage extends CollatedMessage<ResultSet<Leaderboard>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static LeaderboardsListMessage.Builder newBuilder() {
|
||||
return new LeaderboardsListMessage.Builder(com.heroiclabs.nakama.Api.TLeaderboardsList.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TLeaderboardsList.Builder listing;
|
||||
|
||||
public LeaderboardsListMessage.Builder limit(final long limit) {
|
||||
listing.setLimit(limit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardsListMessage.Builder addFilter(final @NonNull byte[] leaderboardId) {
|
||||
listing.addFilterLeaderboardId(ByteString.copyFrom(leaderboardId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardsListMessage.Builder cursor(final @NonNull byte[] cursor) {
|
||||
listing.setCursor(ByteString.copyFrom(cursor));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeaderboardsListMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLeaderboardsList(listing);
|
||||
return new DefaultLeaderboardsListMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,12 @@ package com.heroiclabs.nakama;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
public interface LogoutMessage extends Message {
|
||||
public interface LogoutMessage extends UncollatedMessage {
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static LogoutMessage build() {
|
||||
public static LogoutMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLogout(com.heroiclabs.nakama.Api.Logout.newBuilder());
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The object which represents a match.
|
||||
*/
|
||||
public interface Match {
|
||||
/**
|
||||
* @return Match ID.
|
||||
*/
|
||||
byte[] getId();
|
||||
|
||||
/**
|
||||
* @return List of presences in this match.
|
||||
*/
|
||||
List<UserPresence> getPresence();
|
||||
|
||||
/**
|
||||
* @return Match presence for the current user.
|
||||
*/
|
||||
UserPresence getSelf();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface MatchCreateMessage extends CollatedMessage<Match> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static MatchCreateMessage build() {
|
||||
com.heroiclabs.nakama.Api.TMatchCreate.Builder builder = com.heroiclabs.nakama.Api.TMatchCreate.newBuilder();
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchCreate(builder);
|
||||
return new DefaultMatchCreateMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The object which represents match data.
|
||||
*/
|
||||
public interface MatchData {
|
||||
/**
|
||||
* @return Match ID.
|
||||
*/
|
||||
byte[] getId();
|
||||
|
||||
/**
|
||||
* @return Match Data.
|
||||
*/
|
||||
byte[] getData();
|
||||
|
||||
/**
|
||||
* @return Data opcode.
|
||||
*/
|
||||
long getOpCode();
|
||||
|
||||
/**
|
||||
* @return Presence for the current match data.
|
||||
*/
|
||||
UserPresence getPresence();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface MatchDataSendMessage extends UncollatedMessage {
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static MatchDataSendMessage.Builder newBuilder(final @NonNull byte[] matchId) {
|
||||
return new DefaultMatchDataSendMessage.Builder(com.heroiclabs.nakama.Api.MatchDataSend.newBuilder()
|
||||
.setMatchId(ByteString.copyFrom(matchId)));
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.MatchDataSend.Builder matchData;
|
||||
|
||||
public MatchDataSendMessage.Builder opCode(final long opcode) {
|
||||
matchData.setOpCode(opcode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchDataSendMessage.Builder data(final @NonNull byte[] data) {
|
||||
matchData.setData(ByteString.copyFrom(data));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchDataSendMessage.Builder presences(final @NonNull UserPresence[] presences) {
|
||||
for (UserPresence p : presences) {
|
||||
com.heroiclabs.nakama.Api.UserPresence.Builder up = com.heroiclabs.nakama.Api.UserPresence.newBuilder();
|
||||
up.setHandle(p.getHandle());
|
||||
up.setSessionId(ByteString.copyFrom(p.getSessionId()));
|
||||
up.setUserId(ByteString.copyFrom(p.getUserId()));
|
||||
matchData.addPresences(up);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchDataSendMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchDataSend(matchData);
|
||||
return new DefaultMatchDataSendMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MatchPresence {
|
||||
/**
|
||||
* @return The ID associated with this presence update
|
||||
*/
|
||||
byte[] getId();
|
||||
|
||||
/**
|
||||
* @return Users that have joined
|
||||
*/
|
||||
List<UserPresence> getJoin();
|
||||
|
||||
/**
|
||||
* @return Users that have left
|
||||
*/
|
||||
List<UserPresence> getLeave();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
/**
|
||||
* The object which represents a match token.
|
||||
*/
|
||||
public interface MatchToken {
|
||||
/**
|
||||
* @return Match Token.
|
||||
*/
|
||||
byte[] getToken();
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface MatchesJoinMessage extends CollatedMessage<ResultSet<Match>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static MatchesJoinMessage.Builder newBuilder() {
|
||||
return new DefaultMatchesJoinMessage.Builder(com.heroiclabs.nakama.Api.TMatchesJoin.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TMatchesJoin.Builder joins;
|
||||
|
||||
public MatchesJoinMessage.Builder matchId(final @NonNull byte[] matchId) {
|
||||
com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.newBuilder();
|
||||
topicJoinBuilder.setMatchId(ByteString.copyFrom(matchId));
|
||||
joins.addMatches(topicJoinBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchesJoinMessage.Builder token(final @NonNull MatchToken token) {
|
||||
com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.newBuilder();
|
||||
topicJoinBuilder.setToken(ByteString.copyFrom(token.getToken()));
|
||||
joins.addMatches(topicJoinBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchesJoinMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchesJoin(joins);
|
||||
return new DefaultMatchesJoinMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface MatchesLeaveMessage extends CollatedMessage<Boolean> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static MatchesLeaveMessage.Builder newBuilder() {
|
||||
return new DefaultMatchesLeaveMessage.Builder(com.heroiclabs.nakama.Api.TMatchesLeave.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TMatchesLeave.Builder leaves;
|
||||
|
||||
public MatchesLeaveMessage.Builder matchId(final @NonNull byte[] matchId) {
|
||||
leaves.addMatchIds(ByteString.copyFrom(matchId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchesLeaveMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchesLeave(leaves);
|
||||
return new DefaultMatchesLeaveMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface MatchmakeAddMessage extends CollatedMessage<MatchmakeTicket> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static MatchmakeAddMessage.Builder newBuilder(long requiredCount) {
|
||||
com.heroiclabs.nakama.Api.TMatchmakeAdd.Builder add = com.heroiclabs.nakama.Api.TMatchmakeAdd.newBuilder()
|
||||
.setRequiredCount(requiredCount);
|
||||
return new MatchmakeAddMessage.Builder(add);
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TMatchmakeAdd.Builder add;
|
||||
|
||||
public MatchmakeAddMessage.Builder addTermFilter(String name, Set<String> terms, boolean matchAllTerms)
|
||||
{
|
||||
com.heroiclabs.nakama.Api.MatchmakeFilter.TermFilter.Builder f = com.heroiclabs.nakama.Api.MatchmakeFilter.TermFilter.newBuilder()
|
||||
.addAllTerms(terms)
|
||||
.setMatchAllTerms(matchAllTerms);
|
||||
|
||||
add.addFilters(com.heroiclabs.nakama.Api.MatchmakeFilter.newBuilder().setName(name).setTerm(f));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchmakeAddMessage.Builder addRangeFilter(String name, long lowerbound, long upperbound)
|
||||
{
|
||||
com.heroiclabs.nakama.Api.MatchmakeFilter.RangeFilter.Builder f = com.heroiclabs.nakama.Api.MatchmakeFilter.RangeFilter.newBuilder()
|
||||
.setLowerBound(lowerbound)
|
||||
.setUpperBound(upperbound);
|
||||
|
||||
add.addFilters(com.heroiclabs.nakama.Api.MatchmakeFilter.newBuilder().setName(name).setRange(f));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchmakeAddMessage.Builder addCheckFilter(String name, boolean value)
|
||||
{
|
||||
add.addFilters(com.heroiclabs.nakama.Api.MatchmakeFilter.newBuilder().setName(name).setCheck(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchmakeAddMessage.Builder addProperty(String key, boolean value)
|
||||
{
|
||||
com.heroiclabs.nakama.Api.PropertyPair.Builder p = com.heroiclabs.nakama.Api.PropertyPair.newBuilder()
|
||||
.setKey(key)
|
||||
.setBoolValue(value);
|
||||
|
||||
add.addProperties(p);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchmakeAddMessage.Builder addProperty(String key, long value)
|
||||
{
|
||||
com.heroiclabs.nakama.Api.PropertyPair.Builder p = com.heroiclabs.nakama.Api.PropertyPair.newBuilder()
|
||||
.setKey(key)
|
||||
.setIntValue(value);
|
||||
|
||||
add.addProperties(p);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchmakeAddMessage.Builder addProperty(String key, Set<String> values)
|
||||
{
|
||||
com.heroiclabs.nakama.Api.PropertyPair.Builder p = com.heroiclabs.nakama.Api.PropertyPair.newBuilder()
|
||||
.setKey(key)
|
||||
.setStringSet(com.heroiclabs.nakama.Api.PropertyPair.StringSet.newBuilder().addAllValues(values));
|
||||
|
||||
add.addProperties(p);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatchmakeAddMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchmakeAdd(add);
|
||||
return new DefaultMatchmakeAddMessage(payload);
|
||||
}
|
||||
|
||||
public static MatchmakeAddMessage build(long requiredCount) {
|
||||
com.heroiclabs.nakama.Api.TMatchmakeAdd.Builder add = com.heroiclabs.nakama.Api.TMatchmakeAdd.newBuilder()
|
||||
.setRequiredCount(requiredCount);
|
||||
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchmakeAdd(add);
|
||||
return new DefaultMatchmakeAddMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface MatchmakeCheckFilter extends MatchmakeFilter {
|
||||
/**
|
||||
* @return Filter value
|
||||
*/
|
||||
boolean isValue();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface MatchmakeFilter { }
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The object which represents a matchmake matched.
|
||||
*/
|
||||
public interface MatchmakeMatched {
|
||||
/**
|
||||
* @return Matchmaking Ticket.
|
||||
*/
|
||||
MatchmakeTicket getTicket();
|
||||
|
||||
/**
|
||||
* @return List of presences in this match.
|
||||
*/
|
||||
List<UserPresence> getPresence();
|
||||
|
||||
/**
|
||||
* @return Match token.
|
||||
*/
|
||||
MatchToken getToken();
|
||||
|
||||
/**
|
||||
* @return Match presence for the current user.
|
||||
*/
|
||||
UserPresence getSelf();
|
||||
|
||||
/**
|
||||
* @return Match properties for matched users.
|
||||
*/
|
||||
List<MatchmakeUserProperty> getProperties();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface MatchmakeRangeFilter extends MatchmakeFilter {
|
||||
/**
|
||||
* @return Range lower bound
|
||||
*/
|
||||
long getLowerbound();
|
||||
|
||||
/**
|
||||
* @return Range upper bound
|
||||
*/
|
||||
long getUpperbound();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface MatchmakeRemoveMessage extends CollatedMessage<Boolean> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static MatchmakeRemoveMessage build(@NonNull MatchmakeTicket ticket) {
|
||||
com.heroiclabs.nakama.Api.TMatchmakeRemove.Builder remove = com.heroiclabs.nakama.Api.TMatchmakeRemove.newBuilder();
|
||||
remove.setTicket(ByteString.copyFrom(ticket.getTicket()));
|
||||
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setMatchmakeRemove(remove);
|
||||
return new DefaultMatchmakeRemoveMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MatchmakeTermFilter extends MatchmakeFilter {
|
||||
/**
|
||||
* @return Matching terms
|
||||
*/
|
||||
List<String> getTerms();
|
||||
|
||||
/**
|
||||
* @return Whether to match all terms, or match any of the terms
|
||||
*/
|
||||
boolean isMatchingAllTerms();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
/**
|
||||
* The object which represents a matchmake.
|
||||
*/
|
||||
public interface MatchmakeTicket {
|
||||
/**
|
||||
* @return Matchmake Ticket
|
||||
*/
|
||||
byte[] getTicket();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Properties associated with each matched user
|
||||
*/
|
||||
public interface MatchmakeUserProperty {
|
||||
/**
|
||||
* @return Matchmake user ID
|
||||
*/
|
||||
byte[] getUserId();
|
||||
|
||||
/**
|
||||
* @return Matchmake user properties
|
||||
*/
|
||||
Map<String, Object> getProperties();
|
||||
|
||||
/**
|
||||
* @return Matchmake user filters
|
||||
*/
|
||||
Map<String, MatchmakeFilter> getFilters();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
/**
|
||||
* Default implementation of client listener, all operations are no-op.
|
||||
*/
|
||||
public class NoopClientListener implements ClientListener {
|
||||
@Override public void onDisconnect() {}
|
||||
@Override public void onTopicMessage(TopicMessage message) {}
|
||||
@Override public void onTopicPresence(TopicPresence presence) {}
|
||||
@Override public void onMatchmakeMatched(MatchmakeMatched matched) {}
|
||||
@Override public void onMatchData(MatchData matchData) {}
|
||||
@Override public void onMatchPresence(MatchPresence matchPresence) {}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public interface RpcMessage extends CollatedMessage<RpcResult> {
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder(final @NonNull String id) {
|
||||
public static Builder newBuilder(final @NonNull String id) {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TRpc.newBuilder().setId(id));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface SelfFetchMessage extends CollatedMessage<Self> {
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static SelfFetchMessage build() {
|
||||
public static SelfFetchMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setSelfFetch(com.heroiclabs.nakama.Api.TSelfFetch.newBuilder());
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static SelfLinkMessage custom(final @NonNull String id) {
|
||||
public static SelfLinkMessage custom(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLink(com.heroiclabs.nakama.Api.TLink.newBuilder()
|
||||
@@ -33,7 +33,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfLinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfLinkMessage device(final @NonNull String id) {
|
||||
public static SelfLinkMessage device(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLink(com.heroiclabs.nakama.Api.TLink.newBuilder()
|
||||
@@ -41,7 +41,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfLinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfLinkMessage email(final @NonNull String email, final @NonNull String password) {
|
||||
public static SelfLinkMessage email(final @NonNull String email, final @NonNull String password) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLink(com.heroiclabs.nakama.Api.TLink.newBuilder()
|
||||
@@ -52,7 +52,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfLinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfLinkMessage facebook(final @NonNull String oauthToken) {
|
||||
public static SelfLinkMessage facebook(final @NonNull String oauthToken) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLink(com.heroiclabs.nakama.Api.TLink.newBuilder()
|
||||
@@ -60,7 +60,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfLinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfLinkMessage gameCenter(final @NonNull String playerId, final @NonNull String bundleId,
|
||||
public static SelfLinkMessage gameCenter(final @NonNull String playerId, final @NonNull String bundleId,
|
||||
final long timestamp, final @NonNull String salt,
|
||||
final @NonNull String signature, final @NonNull String publicKeyUrl) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
@@ -77,7 +77,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfLinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfLinkMessage google(final @NonNull String oauthToken) {
|
||||
public static SelfLinkMessage google(final @NonNull String oauthToken) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLink(com.heroiclabs.nakama.Api.TLink.newBuilder()
|
||||
@@ -85,7 +85,7 @@ public interface SelfLinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfLinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfLinkMessage steam(final @NonNull String sessionToken) {
|
||||
public static SelfLinkMessage steam(final @NonNull String sessionToken) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setLink(com.heroiclabs.nakama.Api.TLink.newBuilder()
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static SelfUnlinkMessage custom(final @NonNull String id) {
|
||||
public static SelfUnlinkMessage custom(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
@@ -33,7 +33,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfUnlinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfUnlinkMessage device(final @NonNull String id) {
|
||||
public static SelfUnlinkMessage device(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
@@ -41,7 +41,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfUnlinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfUnlinkMessage email(final @NonNull String email) {
|
||||
public static SelfUnlinkMessage email(final @NonNull String email) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
@@ -49,7 +49,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfUnlinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfUnlinkMessage facebook(final @NonNull String id) {
|
||||
public static SelfUnlinkMessage facebook(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
@@ -57,7 +57,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfUnlinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfUnlinkMessage gameCenter(final @NonNull String playerId) {
|
||||
public static SelfUnlinkMessage gameCenter(final @NonNull String playerId) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
@@ -65,7 +65,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfUnlinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfUnlinkMessage google(final @NonNull String id) {
|
||||
public static SelfUnlinkMessage google(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
@@ -73,7 +73,7 @@ public interface SelfUnlinkMessage extends CollatedMessage<Boolean> {
|
||||
return new DefaultSelfUnlinkMessage(payload);
|
||||
}
|
||||
|
||||
static SelfUnlinkMessage steam(final @NonNull String id) {
|
||||
public static SelfUnlinkMessage steam(final @NonNull String id) {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setUnlink(com.heroiclabs.nakama.Api.TUnlink.newBuilder()
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface SelfUpdateMessage extends CollatedMessage<Boolean> {
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder() {
|
||||
public static Builder newBuilder() {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TSelfUpdate.newBuilder());
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface StorageFetchMessage extends CollatedMessage<ResultSet<StorageRe
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder() {
|
||||
public static Builder newBuilder() {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TStorageFetch.newBuilder());
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ public interface StorageListMessage extends CollatedMessage<ResultSet<StorageRec
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder(final @NonNull byte[] userId) {
|
||||
public static Builder newBuilder(final @NonNull byte[] userId) {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TStorageList.newBuilder()
|
||||
.setUserId(ByteString.copyFrom(userId)));
|
||||
}
|
||||
|
||||
static Builder newBuilder(final @NonNull String bucket) {
|
||||
public static Builder newBuilder(final @NonNull String bucket) {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TStorageList.newBuilder()
|
||||
.setBucket(bucket));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface StorageRemoveMessage extends CollatedMessage<Boolean> {
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder() {
|
||||
public static Builder newBuilder() {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TStorageRemove.newBuilder());
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder() {
|
||||
public static Builder newBuilder() {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TStorageUpdate.newBuilder());
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class OpBuilder {
|
||||
|
||||
static OpBuilder newBuilder() {
|
||||
public static OpBuilder newBuilder() {
|
||||
return new OpBuilder(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder());
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface StorageWriteMessage extends CollatedMessage<ResultSet<RecordId>
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder() {
|
||||
public static Builder newBuilder() {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TStorageWrite.newBuilder());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The object which represents a chat topic in the server.
|
||||
*/
|
||||
public interface Topic {
|
||||
/**
|
||||
* @return the ID associated with this topic.
|
||||
*/
|
||||
TopicId getTopicId();
|
||||
|
||||
/**
|
||||
* @return list of users currently active on this topic.
|
||||
*/
|
||||
List<UserPresence> getPresences();
|
||||
|
||||
/**
|
||||
* @return presence information of the current user.
|
||||
*/
|
||||
UserPresence getSelf();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface TopicId {
|
||||
enum TopicType { DirectMessage, Room, Group }
|
||||
|
||||
/**
|
||||
* @return Topic ID
|
||||
*/
|
||||
byte[] getId();
|
||||
|
||||
/**
|
||||
* @return Type of Topic this is - DM, Group, Room
|
||||
*/
|
||||
TopicType getTopicType();
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface TopicJoinMessage extends CollatedMessage<ResultSet<Topic>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static TopicJoinMessage.Builder newBuilder() {
|
||||
return new TopicJoinMessage.Builder(com.heroiclabs.nakama.Api.TTopicsJoin.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TTopicsJoin.Builder joins;
|
||||
|
||||
public TopicJoinMessage.Builder topicDirectMessage(final @NonNull byte[] userId) {
|
||||
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
|
||||
topicJoinBuilder.setUserId(ByteString.copyFrom(userId));
|
||||
joins.addJoins(topicJoinBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicJoinMessage.Builder topicRoom(final @NonNull byte[] room) {
|
||||
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
|
||||
topicJoinBuilder.setRoom(ByteString.copyFrom(room));
|
||||
joins.addJoins(topicJoinBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicJoinMessage.Builder topicGroup(final @NonNull byte[] group) {
|
||||
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
|
||||
topicJoinBuilder.setGroupId(ByteString.copyFrom(group));
|
||||
joins.addJoins(topicJoinBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicJoinMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setTopicsJoin(joins);
|
||||
return new DefaultTopicJoinMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface TopicLeaveMessage extends CollatedMessage<Boolean> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static TopicLeaveMessage.Builder newBuilder() {
|
||||
return new TopicLeaveMessage.Builder(com.heroiclabs.nakama.Api.TTopicsLeave.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TTopicsLeave.Builder leaves;
|
||||
|
||||
public TopicLeaveMessage.Builder Leave(final @NonNull TopicId topicId) {
|
||||
com.heroiclabs.nakama.Api.TTopicsLeave.Builder topicLeave = com.heroiclabs.nakama.Api.TTopicsLeave.newBuilder();
|
||||
com.heroiclabs.nakama.Api.TopicId.Builder topicBuilder = null;
|
||||
switch (topicId.getTopicType()) {
|
||||
case Room:
|
||||
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setRoom(ByteString.copyFrom(topicId.getId()));
|
||||
break;
|
||||
case Group:
|
||||
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setGroupId(ByteString.copyFrom(topicId.getId()));
|
||||
break;
|
||||
case DirectMessage:
|
||||
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setDm(ByteString.copyFrom(topicId.getId()));
|
||||
break;
|
||||
}
|
||||
topicLeave.addTopics(topicBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicLeaveMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setTopicsLeave(leaves);
|
||||
return new DefaultTopicLeaveMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface TopicMessage {
|
||||
enum TopicMessageType {
|
||||
Chat,
|
||||
GroupJoin,
|
||||
GroupAdd,
|
||||
GroupLeave,
|
||||
GroupKick,
|
||||
GroupPromoted;
|
||||
|
||||
static TopicMessageType fromProto(int type) {
|
||||
switch(type) {
|
||||
case 0:
|
||||
return TopicMessageType.Chat;
|
||||
case 1:
|
||||
return TopicMessageType.GroupJoin;
|
||||
case 2:
|
||||
return TopicMessageType.GroupAdd;
|
||||
case 3:
|
||||
return TopicMessageType.GroupLeave;
|
||||
case 4:
|
||||
return TopicMessageType.GroupKick;
|
||||
case 5:
|
||||
return TopicMessageType.GroupPromoted;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Topic ID associated with this message.
|
||||
*/
|
||||
TopicId getTopic();
|
||||
|
||||
/**
|
||||
* @return User ID associated with this message.
|
||||
*/
|
||||
byte[] getUserId();
|
||||
|
||||
/**
|
||||
* @return Message ID.
|
||||
*/
|
||||
byte[] getMessageId();
|
||||
|
||||
/**
|
||||
* @return When message was created.
|
||||
*/
|
||||
long getCreatedAt();
|
||||
|
||||
/**
|
||||
* @return When message expires.
|
||||
*/
|
||||
long getExpiresAt();
|
||||
|
||||
/**
|
||||
* @return User Handle associated with this message.
|
||||
*/
|
||||
String getHandle();
|
||||
|
||||
/**
|
||||
* @return Message Type.
|
||||
*/
|
||||
TopicMessageType getType();
|
||||
|
||||
/**
|
||||
* @return Data in the message.
|
||||
*/
|
||||
byte[] getData();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface TopicMessageAck {
|
||||
/**
|
||||
* @return ID of this message acked;
|
||||
*/
|
||||
byte[] getMessageId();
|
||||
|
||||
/**
|
||||
* @return User Handle;
|
||||
*/
|
||||
String getHandle();
|
||||
|
||||
/**
|
||||
* @return When the message was created;
|
||||
*/
|
||||
long getCreatedAt();
|
||||
|
||||
/**
|
||||
* @return When the message expires;
|
||||
*/
|
||||
long getExpiresAt();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface TopicMessageSendMessage extends CollatedMessage<TopicMessageAck> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static TopicMessageSendMessage build(final @NonNull TopicId topicId, final @NonNull byte[] data) {
|
||||
com.heroiclabs.nakama.Api.TTopicMessageSend.Builder msg = com.heroiclabs.nakama.Api.TTopicMessageSend.newBuilder();
|
||||
|
||||
msg.setData(ByteString.copyFrom(data));
|
||||
switch (topicId.getTopicType()) {
|
||||
case Room:
|
||||
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setRoom(ByteString.copyFrom(topicId.getId())));
|
||||
break;
|
||||
case Group:
|
||||
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setGroupId(ByteString.copyFrom(topicId.getId())));
|
||||
break;
|
||||
case DirectMessage:
|
||||
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setDm(ByteString.copyFrom(topicId.getId())));
|
||||
break;
|
||||
}
|
||||
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setTopicMessageSend(msg);
|
||||
return new DefaultTopicMessageSendMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface TopicMessagesListMessage extends CollatedMessage<ResultSet<TopicMessage>> {
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
public static TopicMessagesListMessage.Builder newBuilder() {
|
||||
return new TopicMessagesListMessage.Builder(com.heroiclabs.nakama.Api.TTopicMessagesList.newBuilder());
|
||||
}
|
||||
|
||||
private final @NonNull
|
||||
com.heroiclabs.nakama.Api.TTopicMessagesList.Builder lists;
|
||||
|
||||
public TopicMessagesListMessage.Builder forward(final boolean forward) {
|
||||
lists.setForward(forward);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicMessagesListMessage.Builder cursor(final @NonNull Cursor cursor) {
|
||||
lists.setCursor(ByteString.copyFrom(cursor.getValue()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicMessagesListMessage.Builder limit(final long limit) {
|
||||
lists.setLimit(limit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicMessagesListMessage.Builder topicDirectMessage(final @NonNull byte[] userId) {
|
||||
lists.setUserId(ByteString.copyFrom(userId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicMessagesListMessage.Builder topicRoom(final @NonNull byte[] room) {
|
||||
lists.setRoom(ByteString.copyFrom(room));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicMessagesListMessage.Builder topicGroup(final @NonNull byte[] groupId) {
|
||||
lists.setGroupId(ByteString.copyFrom(groupId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TopicMessagesListMessage build() {
|
||||
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
|
||||
com.heroiclabs.nakama.Api.Envelope.newBuilder()
|
||||
.setTopicMessagesList(lists);
|
||||
return new DefaultTopicMessagesListMessage(payload);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TopicPresence {
|
||||
/**
|
||||
* @return The topic ID associated with this presence update
|
||||
*/
|
||||
TopicId getTopic();
|
||||
|
||||
/**
|
||||
* @return Users that have joined
|
||||
*/
|
||||
List<UserPresence> getJoin();
|
||||
|
||||
/**
|
||||
* @return Users that have left
|
||||
*/
|
||||
List<UserPresence> getLeave();
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ package com.heroiclabs.nakama;
|
||||
/**
|
||||
* A message which requires no acknowledgement by the server.
|
||||
*/
|
||||
public interface Message {
|
||||
public interface UncollatedMessage {
|
||||
/**
|
||||
* @return The serialized format of the message.
|
||||
*/
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
public interface UserPresence {
|
||||
/**
|
||||
* @return User ID
|
||||
*/
|
||||
byte[] getUserId();
|
||||
|
||||
/**
|
||||
* @return Session ID associated with this presence
|
||||
*/
|
||||
byte[] getSessionId();
|
||||
|
||||
/**
|
||||
* @return User Handle
|
||||
*/
|
||||
String getHandle();
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public interface UsersFetchMessage extends CollatedMessage<ResultSet<User>> {
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class Builder {
|
||||
|
||||
static Builder newBuilder() {
|
||||
public static Builder newBuilder() {
|
||||
return new Builder(com.heroiclabs.nakama.Api.TUsersFetch.newBuilder());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright 2017 The Nakama Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.heroiclabs.nakama;
|
||||
|
||||
import com.stumbleupon.async.Callback;
|
||||
import com.stumbleupon.async.Deferred;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MatchmakeAddMessageTest {
|
||||
|
||||
private Client client1;
|
||||
private Client client2;
|
||||
|
||||
private CountDownLatch latch1;
|
||||
private CountDownLatch latch2;
|
||||
private MatchToken token1;
|
||||
private MatchToken token2;
|
||||
|
||||
private CountDownLatch latch3;
|
||||
private MatchData data;
|
||||
|
||||
private MatchmakeMatched matched1;
|
||||
private MatchmakeMatched matched2;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
client1 = DefaultClient.builder("defaultkey").listener(new ClientListener() {
|
||||
@Override public void onDisconnect() {}
|
||||
@Override public void onTopicMessage(TopicMessage message) {}
|
||||
@Override public void onTopicPresence(TopicPresence presence) {}
|
||||
@Override public void onMatchmakeMatched(MatchmakeMatched matched) {
|
||||
token1 = matched.getToken();
|
||||
matched1 = matched;
|
||||
latch1.countDown();
|
||||
}
|
||||
@Override public void onMatchData(MatchData matchData) {
|
||||
data = matchData;
|
||||
latch3.countDown();
|
||||
}
|
||||
@Override public void onMatchPresence(MatchPresence matchPresence) {}
|
||||
}).build();
|
||||
Assert.assertNotNull(client1);
|
||||
latch1 = new CountDownLatch(1);
|
||||
|
||||
client2 = DefaultClient.builder("defaultkey").listener(new ClientListener() {
|
||||
@Override public void onDisconnect() {}
|
||||
@Override public void onTopicMessage(TopicMessage message) {}
|
||||
@Override public void onTopicPresence(TopicPresence presence) {}
|
||||
@Override public void onMatchmakeMatched(MatchmakeMatched matched) {
|
||||
token2 = matched.getToken();
|
||||
matched2 = matched;
|
||||
latch2.countDown();
|
||||
}
|
||||
@Override public void onMatchData(MatchData matchData) {}
|
||||
@Override public void onMatchPresence(MatchPresence matchPresence) {}
|
||||
}).build();
|
||||
Assert.assertNotNull(client2);
|
||||
latch2 = new CountDownLatch(1);
|
||||
|
||||
latch3 = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
client1.disconnect().join(2000);
|
||||
client2.disconnect().join(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void add() throws Exception {
|
||||
final String deviceId1 = UUID.randomUUID().toString();
|
||||
final AuthenticateMessage auth1 = AuthenticateMessage.Builder.device(deviceId1);
|
||||
final String deviceId2 = UUID.randomUUID().toString();
|
||||
final AuthenticateMessage auth2 = AuthenticateMessage.Builder.device(deviceId2);
|
||||
|
||||
final Deferred<Session> deferred = client1.register(auth1);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.register(auth2);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<MatchmakeTicket>, Session>() {
|
||||
@Override
|
||||
public Deferred<MatchmakeTicket> call(Session session) throws Exception {
|
||||
final CollatedMessage<MatchmakeTicket> add = MatchmakeAddMessage.Builder.newBuilder(2)
|
||||
.addProperty("rank", 12)
|
||||
.addProperty("modes", new HashSet<>(Arrays.asList("tdm", "ffa")))
|
||||
.addProperty("divisions", new HashSet<>(Arrays.asList("silver1")))
|
||||
.addRangeFilter("rank", 10, 15)
|
||||
.addTermFilter("modes", new HashSet<>(Arrays.asList("tdm", "ffa")), false)
|
||||
.addTermFilter("divisions", new HashSet<>(Arrays.asList("bronze3","silver1", "silver2")), false) // like RocketLeague
|
||||
.build();
|
||||
return client1.send(add);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<MatchmakeTicket>, MatchmakeTicket>() {
|
||||
@Override
|
||||
public Deferred<MatchmakeTicket> call(MatchmakeTicket ticket) throws Exception {
|
||||
final CollatedMessage<MatchmakeTicket> add = MatchmakeAddMessage.Builder.newBuilder(2)
|
||||
.addProperty("rank", 10)
|
||||
.addProperty("modes", new HashSet<>(Arrays.asList("tdm", "ffa")))
|
||||
.addProperty("divisions", new HashSet<>(Arrays.asList("bronze3")))
|
||||
.addRangeFilter("rank", 8, 12)
|
||||
.addTermFilter("modes", new HashSet<>(Arrays.asList("tdm", "ffa")), false)
|
||||
.addTermFilter("divisions", new HashSet<>(Arrays.asList("bronze2","bronze3", "silver1")), false)
|
||||
.build();
|
||||
return client2.send(add);
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
latch1.await(2, TimeUnit.SECONDS);
|
||||
latch2.await(2, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(token1);
|
||||
Assert.assertNotNull(token2);
|
||||
|
||||
MatchmakeUserProperty c1Props = matched1.getProperties().get(0);
|
||||
if (!Arrays.equals(matched1.getSelf().getUserId(), matched1.getProperties().get(0).getUserId()))
|
||||
{
|
||||
c1Props = matched1.getProperties().get(1);
|
||||
}
|
||||
|
||||
Assert.assertEquals(((long)c1Props.getProperties().get("rank")), 12);
|
||||
Assert.assertEquals(((MatchmakeRangeFilter)c1Props.getFilters().get("rank")).getLowerbound(), 10);
|
||||
|
||||
final CollatedMessage<ResultSet<Match>> matchJoin = MatchesJoinMessage.Builder.newBuilder().token(token1).build();
|
||||
final Deferred<ResultSet<Match>> deferred2 = client1.send(matchJoin);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<ResultSet<Match>>, ResultSet<Match>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<Match>> call(ResultSet<Match> matches) throws Exception {
|
||||
Assert.assertEquals(1, matches.getResults().size());
|
||||
|
||||
final CollatedMessage<ResultSet<Match>> matchJoin = MatchesJoinMessage.Builder.newBuilder().token(token2).build();
|
||||
return client2.send(matchJoin);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Match>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Match> matches) throws Exception {
|
||||
Assert.assertEquals(1, matches.getResults().size());
|
||||
|
||||
final UncollatedMessage data = MatchDataSendMessage.Builder
|
||||
.newBuilder(matches.getResults().get(0).getId())
|
||||
.data("test".getBytes())
|
||||
.build();
|
||||
return client2.send(data);
|
||||
}
|
||||
});
|
||||
deferred2.join(2000);
|
||||
latch3.await(2, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -113,12 +113,18 @@ public class RpcMessageTest {
|
||||
.build();
|
||||
return client.send(rpc);
|
||||
}
|
||||
}).addErrback(new Callback<RpcResult, RpcResult>() {
|
||||
}).addCallback(new Callback<RpcResult, RpcResult>() {
|
||||
@Override
|
||||
public RpcResult call(RpcResult result) throws Exception {
|
||||
Assert.assertArrayEquals(payload, result.getPayload());
|
||||
return result;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ public class SelfUpdateMessageTest {
|
||||
public void testUpdateHandleTooLong() throws Exception {
|
||||
final String deviceId = UUID.randomUUID().toString();
|
||||
final AuthenticateMessage auth = AuthenticateMessage.Builder.device(deviceId);
|
||||
final String newHandle = UUID.randomUUID().toString();
|
||||
final String newHandle = UUID.randomUUID().toString() + UUID.randomUUID().toString() +
|
||||
UUID.randomUUID().toString() + UUID.randomUUID().toString() +
|
||||
UUID.randomUUID().toString();
|
||||
|
||||
final Deferred<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
|
||||
Reference in new issue
Block a user