Compare commits

..
12 Commits
108 changed files with 3397 additions and 161 deletions

No files matched your search

+22
View File
@@ -4,6 +4,28 @@ 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/).
## [Unreleased]
## [0.4.0] - 2017-11-07
### Changed
- Expose a simpler interface for identifier fields.
## [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.
+3
View File
@@ -24,6 +24,9 @@ repositories {
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"
}
}
```
+5 -1
View File
@@ -25,7 +25,7 @@ plugins {
}
group = 'com.heroiclabs.nakama'
version = '0.1.2'
version = '0.4.0'
def description = 'Android optimized Java client for Nakama server.'
sourceCompatibility = 1.7
@@ -107,6 +107,10 @@ gitPublish {
preserve {
include '0.1.0/**'
include '0.1.1/**'
include '0.1.2/**'
include '0.2.0/**'
include '0.3.0/**'
include '0.4.0/**'
}
commitMessage = "Published javadoc '$project.version' via Gradle ${GradleVersion.current().version}."
}
+1 -1
Submodule server updated: 15dc7ba786...b6f073bb4e.
@@ -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);
}
@@ -23,7 +23,7 @@ public interface Cursor {
/**
* @return The encoded pointer which represents a position in the database records.
*/
byte[] getValue();
String getValue();
/**
* @return Encode the cursor so it can be cached.
@@ -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()));
@@ -272,8 +287,8 @@ public class DefaultClient implements Client {
records.add(DefaultStorageRecord.fromProto(data));
}
Cursor cursor = null;
if (envelope.getStorageData().getCursor() != null && envelope.getStorageData().getCursor().size() > 0) {
cursor = new DefaultCursor(envelope.getStorageData().getCursor().toByteArray());
if (envelope.getStorageData().getCursor() != null && envelope.getStorageData().getCursor().length() > 0) {
cursor = new DefaultCursor(envelope.getStorageData().getCursor());
}
def.callback(new DefaultResultSet<StorageRecord>(cursor, records));
break;
@@ -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()), 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()), 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()), 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,17 +20,16 @@ import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import okio.ByteString;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class DefaultCursor implements Cursor {
private final byte[] value;
private final String value;
public String serialize() {
return ByteString.of(value).base64();
return value;
}
/**
@@ -38,7 +37,6 @@ public class DefaultCursor implements Cursor {
* @return A new cursor which was stored.
*/
public static Cursor restore(final String serializedCursor) {
final byte[] cursor = ByteString.decodeBase64(serializedCursor).toByteArray();
return new DefaultCursor(cursor);
return new DefaultCursor(serializedCursor);
}
}
@@ -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 String id;
private final boolean authoritative;
private final long sort;
private final long count;
private final String resetSchedule;
private final String metadata;
private final String nextId;
private final String prevId;
public <T> T getMetadata(final Class<T> clazz) {
return DefaultClient.GSON.fromJson(metadata, clazz);
}
static Leaderboard fromProto(final @NonNull com.heroiclabs.nakama.Api.Leaderboard leaderboard) {
return new DefaultLeaderboard(
leaderboard.getId(),
leaderboard.getAuthoritative(),
leaderboard.getSort(),
leaderboard.getCount(),
leaderboard.getResetSchedule(),
leaderboard.getMetadata(),
leaderboard.getNextId(),
leaderboard.getPrevId()
);
}
}
@@ -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 String leaderboardId;
private final String 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 String 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(),
record.getOwnerId(),
record.getHandle(),
record.getLang(),
record.getLocation(),
record.getTimezone(),
record.getRank(),
record.getScore(),
record.getNumScore(),
record.getMetadata(),
record.getRankedAt(),
record.getUpdatedAt(),
record.getExpiresAt()
);
}
public <T> T getMetadata(final Class<T> clazz) {
return DefaultClient.GSON.fromJson(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 String 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(), 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,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 DefaultMatchData implements MatchData {
private final String 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(), 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 String 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(), 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 String token;
static MatchToken fromProto(final @NonNull String 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()),
userPresences,
DefaultMatchToken.fromProto(matched.getToken()),
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 String ticket;
static MatchmakeTicket fromProto(final @NonNull com.heroiclabs.nakama.Api.TMatchmakeTicket matchmakeTicket) {
return new DefaultMatchmakeTicket(matchmakeTicket.getTicket());
}
static MatchmakeTicket fromProto(final @NonNull String matchmakeTicket) {
return new DefaultMatchmakeTicket(matchmakeTicket);
}
}
@@ -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 lombok.*;
import java.util.HashMap;
import java.util.Map;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchmakeUserProperty implements MatchmakeUserProperty {
private final String 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(), props, filters);
}
}
@@ -29,9 +29,9 @@ class DefaultRecordId implements RecordId {
private final String key;
private final byte[] version;
private final String version;
static RecordId fromProto(final @NonNull com.heroiclabs.nakama.Api.TStorageKeys.StorageKey key) {
return new DefaultRecordId(key.getBucket(), key.getCollection(), key.getRecord(), key.getVersion().toByteArray());
return new DefaultRecordId(key.getBucket(), key.getCollection(), key.getRecord(), key.getVersion());
}
}
@@ -25,15 +25,15 @@ class DefaultRpcResult implements RpcResult {
private final String id;
private final byte[] payload;
private final String payload;
@Override
public <T> T getPayload(Class<T> clazz) {
return DefaultClient.GSON.fromJson(new String(payload), clazz);
return DefaultClient.GSON.fromJson(payload, clazz);
}
static RpcResult fromProto(final @NonNull com.heroiclabs.nakama.Api.TRpc rpc) {
return new DefaultRpcResult(rpc.getId(), rpc.getPayload().toByteArray());
return new DefaultRpcResult(rpc.getId(), rpc.getPayload());
}
}
@@ -33,7 +33,7 @@ class DefaultSelf implements Self {
private final String handle;
private final byte[] id;
private final String id;
private final String lang;
@@ -41,7 +41,7 @@ class DefaultSelf implements Self {
private final String location;
private final byte[] metadata;
private final String metadata;
private final String timezone;
@@ -64,14 +64,14 @@ class DefaultSelf implements Self {
private final boolean verified;
public <T> T getMetadata(final Class<T> clazz) {
return DefaultClient.GSON.fromJson(new String(metadata), clazz);
return DefaultClient.GSON.fromJson(metadata, clazz);
}
static Self fromProto(final @NonNull com.heroiclabs.nakama.Api.Self self) {
return new DefaultSelf(self.getUser().getAvatarUrl(), self.getUser().getCreatedAt(),
self.getUser().getFullname(), self.getUser().getHandle(), self.getUser().getId().toByteArray(),
self.getUser().getFullname(), self.getUser().getHandle(), self.getUser().getId(),
self.getUser().getLang(), self.getUser().getLastOnlineAt(), self.getUser().getLocation(),
self.getUser().getMetadata().toByteArray(), self.getUser().getTimezone(), self.getUser().getUpdatedAt(),
self.getUser().getMetadata(), self.getUser().getTimezone(), self.getUser().getUpdatedAt(),
self.getCustomId(), self.getDeviceIdsList(), self.getEmail(), self.getFacebookId(),
self.getGamecenterId(), self.getGoogleId(), self.getSteamId(), self.getVerified());
}
@@ -21,12 +21,10 @@ import lombok.Data;
import lombok.ToString;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
import okio.*;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.UUID;
@Data
@ToString(includeFieldNames = true)
@@ -38,7 +36,7 @@ public class DefaultSession implements Session {
private final String handle;
private final byte[] id;
private final String id;
private final String token;
@@ -54,12 +52,7 @@ public class DefaultSession implements Session {
createdAt = System.currentTimeMillis();
expiresAt = Math.round(((Double) jsonMap.get("exp")) * 1000L);
handle = jsonMap.get("han").toString();
final UUID uid = UUID.fromString(jsonMap.get("uid").toString());
final ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uid.getMostSignificantBits());
bb.putLong(uid.getLeastSignificantBits());
id = bb.array();
id = jsonMap.get("uid").toString();
this.token = token;
}
@@ -37,23 +37,23 @@ class DefaultStorageRecord implements StorageRecord {
private final PermissionWrite permissionWrite;
private final byte[] value;
private final String value;
private final byte[] version;
private final String version;
private final long updatedAt;
private final byte[] userId;
private final String userId;
@Override
public <T> T getValue(Class<T> clazz) {
return DefaultClient.GSON.fromJson(new String(value), clazz);
return DefaultClient.GSON.fromJson(value, clazz);
}
static StorageRecord fromProto(final @NonNull com.heroiclabs.nakama.Api.TStorageData.StorageData data) {
return new DefaultStorageRecord(data.getBucket(), data.getCreatedAt(), data.getCollection(),
data.getExpiresAt(), data.getRecord(), PermissionRead.fromInt(data.getPermissionRead()),
PermissionWrite.fromInt(data.getPermissionWrite()), data.getValue().toByteArray(),
data.getVersion().toByteArray(), data.getUpdatedAt(), data.getUserId().toByteArray());
PermissionWrite.fromInt(data.getPermissionWrite()), data.getValue(),
data.getVersion(), data.getUpdatedAt(), data.getUserId());
}
}
@@ -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 String 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(), TopicType.DirectMessage);
case ROOM:
return new DefaultTopicId(topicId.getRoom(), TopicType.Room);
case GROUP_ID:
return new DefaultTopicId(topicId.getGroupId(), 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 String userId;
private final String messageId;
private final long createdAt;
private final long expiresAt;
private final String handle;
private final TopicMessageType type;
private final String data;
static TopicMessage fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicMessage message) {
return new DefaultTopicMessage(
DefaultTopicId.fromProto(message.getTopic()),
message.getUserId(),
message.getMessageId(),
message.getCreatedAt(),
message.getExpiresAt(),
message.getHandle(),
TopicMessageType.fromProto((int)message.getType()),
message.getData()
);
}
}
@@ -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 String 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(), 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);
}
}
@@ -31,7 +31,7 @@ class DefaultUser implements User {
private final String handle;
private final byte[] id;
private final String id;
private final String lang;
@@ -39,21 +39,21 @@ class DefaultUser implements User {
private final String location;
private final byte[] metadata;
private final String metadata;
private final String timezone;
private final long updatedAt;
public <T> T getMetadata(final Class<T> clazz) {
return DefaultClient.GSON.fromJson(new String(metadata), clazz);
return DefaultClient.GSON.fromJson(metadata, clazz);
}
static User fromProto(final @NonNull com.heroiclabs.nakama.Api.User user) {
return new DefaultUser(user.getAvatarUrl(), user.getCreatedAt(),
user.getFullname(), user.getHandle(), user.getId().toByteArray(),
user.getFullname(), user.getHandle(), user.getId(),
user.getLang(), user.getLastOnlineAt(), user.getLocation(),
user.getMetadata().toByteArray(), user.getTimezone(), user.getUpdatedAt());
user.getMetadata(), user.getTimezone(), user.getUpdatedAt());
}
}
@@ -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.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultUserPresence implements UserPresence {
private final String userId;
private final String sessionId;
private final String handle;
static UserPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.UserPresence presence) {
return new DefaultUserPresence(presence.getUserId(), presence.getSessionId(), presence.getHandle());
}
}
@@ -36,6 +36,13 @@ 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.
*/
@@ -108,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.
*/
String 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.
*/
String 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);
String getNextId();
String 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.
*/
String getLeaderboardId();
/**
* @return User ID that owns this record.
*/
String 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.
*/
String 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,99 @@
/*
* 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;
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 String leaderboardId) {
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder b = com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.newBuilder();
b.setLeaderboardId(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 String metadata) {
write.setMetadata(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,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 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 String leaderboardId) {
fetch.addLeaderboardIds(leaderboardId);
return this;
}
public LeaderboardRecordsFetchMessage.Builder limit(final long limit) {
fetch.setLimit(limit);
return this;
}
public LeaderboardRecordsFetchMessage.Builder cursor(final @NonNull String cursor) {
fetch.setCursor(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,81 @@
/*
* 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;
public interface LeaderboardRecordsListMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static LeaderboardRecordsListMessage.Builder newBuilder(final @NonNull String leaderboardId) {
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Builder b = com.heroiclabs.nakama.Api.TLeaderboardRecordsList.newBuilder();
b.setLeaderboardId(leaderboardId);
return new DefaultLeaderboardRecordsListMessage.Builder(b);
}
private final @NonNull
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Builder listing;
public LeaderboardRecordsListMessage.Builder filterByPagingToOwnerId(final @NonNull String ownerId) {
listing.setOwnerId(ownerId);
return this;
}
public LeaderboardRecordsListMessage.Builder filterByPagingToOwnerIds(final @NonNull List<String> ownerIds) {
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Owners.Builder o = com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Owners.newBuilder();
for (String b : ownerIds) {
o.addOwnerIds(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 String cursor) {
listing.setCursor(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,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 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 String leaderboardId) {
listing.addFilterLeaderboardId(leaderboardId);
return this;
}
public LeaderboardsListMessage.Builder cursor(final @NonNull String cursor) {
listing.setCursor(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,7 +19,7 @@ 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 {
@@ -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.
*/
String 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,42 @@
/*
* 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 match data.
*/
public interface MatchData {
/**
* @return Match ID.
*/
String 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 String matchId) {
return new DefaultMatchDataSendMessage.Builder(com.heroiclabs.nakama.Api.MatchDataSend.newBuilder()
.setMatchId(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(p.getSessionId());
up.setUserId(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
*/
String 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.
*/
String getToken();
}
@@ -0,0 +1,57 @@
/*
* 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;
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 String matchId) {
com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.newBuilder();
topicJoinBuilder.setMatchId(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(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,48 @@
/*
* 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;
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 String matchId) {
leaves.addMatchIds(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,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 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(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
*/
String getTicket();
}
@@ -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.Map;
/**
* Properties associated with each matched user
*/
public interface MatchmakeUserProperty {
/**
* @return Matchmake user ID
*/
String 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) {}
}
@@ -38,5 +38,5 @@ public interface RecordId {
/**
* @return The version of the record which has been fetched.
*/
byte[] getVersion();
String getVersion();
}
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -32,8 +31,8 @@ public interface RpcMessage extends CollatedMessage<RpcResult> {
private final @NonNull com.heroiclabs.nakama.Api.TRpc.Builder rpc;
public Builder payload(final @NonNull byte[] payload) {
rpc.setPayload(ByteString.copyFrom(payload));
public Builder payload(final @NonNull String payload) {
rpc.setPayload(payload);
return this;
}
@@ -28,7 +28,7 @@ public interface RpcResult {
/**
* @return The payload result sent back from the function call. May be {@code null}.
*/
byte[] getPayload();
String getPayload();
/**
* @param clazz A hint for the type of the class.
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -57,8 +56,8 @@ public interface SelfUpdateMessage extends CollatedMessage<Boolean> {
return this;
}
public Builder metadata(final @NonNull byte[] metadata) {
update.setMetadata(ByteString.copyFrom(metadata));
public Builder metadata(final @NonNull String metadata) {
update.setMetadata(metadata);
return this;
}
@@ -38,7 +38,7 @@ public interface Session {
/**
* @return The ID of the user.
*/
byte[] getId();
String getId();
/**
* @return The session token returned by the server after register or login.
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -33,14 +32,14 @@ public interface StorageFetchMessage extends CollatedMessage<ResultSet<StorageRe
private final @NonNull com.heroiclabs.nakama.Api.TStorageFetch.Builder fetch;
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final byte[] userId) {
final String userId) {
com.heroiclabs.nakama.Api.TStorageFetch.StorageKey.Builder record =
com.heroiclabs.nakama.Api.TStorageFetch.StorageKey.newBuilder()
.setBucket(bucket)
.setCollection(collection)
.setRecord(key);
if (userId != null) {
record = record.setUserId(ByteString.copyFrom(userId));
record = record.setUserId(userId);
}
fetch.addKeys(record);
return this;
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -26,20 +25,20 @@ public interface StorageListMessage extends CollatedMessage<ResultSet<StorageRec
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static Builder newBuilder(final @NonNull byte[] userId) {
public static Builder newBuilderUserId(final @NonNull String userId) {
return new Builder(com.heroiclabs.nakama.Api.TStorageList.newBuilder()
.setUserId(ByteString.copyFrom(userId)));
.setUserId(userId));
}
public static Builder newBuilder(final @NonNull String bucket) {
public static Builder newBuilderBucket(final @NonNull String bucket) {
return new Builder(com.heroiclabs.nakama.Api.TStorageList.newBuilder()
.setBucket(bucket));
}
private final @NonNull com.heroiclabs.nakama.Api.TStorageList.Builder list;
public Builder userId(final @NonNull byte[] userId) {
list.setUserId(ByteString.copyFrom(userId));
public Builder userId(final @NonNull String userId) {
list.setUserId(userId);
return this;
}
@@ -59,7 +58,7 @@ public interface StorageListMessage extends CollatedMessage<ResultSet<StorageRec
}
public Builder cursor(final @NonNull Cursor cursor) {
list.setCursor(ByteString.copyFrom(cursor.getValue()));
list.setCursor(cursor.getValue());
return this;
}
@@ -20,10 +20,6 @@ import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* A record from the storage engine in the server.
*/
@@ -102,7 +98,7 @@ public interface StorageRecord extends RecordId {
/**
* @return The value (content) of the record.
*/
byte[] getValue();
String getValue();
/**
* @param clazz A hint for the type of the class.
@@ -119,5 +115,5 @@ public interface StorageRecord extends RecordId {
/**
* @return The Id of the user who owns the record.
*/
byte[] getUserId();
String getUserId();
}
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -43,14 +42,14 @@ public interface StorageRemoveMessage extends CollatedMessage<Boolean> {
}
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final byte[] version) {
final String version) {
com.heroiclabs.nakama.Api.TStorageRemove.StorageKey.Builder record =
com.heroiclabs.nakama.Api.TStorageRemove.StorageKey.newBuilder()
.setBucket(bucket)
.setCollection(collection)
.setRecord(key);
if (version != null) {
record = record.setVersion(ByteString.copyFrom(version));
record = record.setVersion(version);
}
remove.addKeys(record);
return this;
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NonNull;
@@ -33,7 +32,7 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
private final @NonNull com.heroiclabs.nakama.Api.TStorageUpdate.Builder updates;
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final @NonNull OpBuilder ops, final byte[] version,
final @NonNull OpBuilder ops, final String version,
final StorageRecord.PermissionRead read,
final StorageRecord.PermissionWrite write) {
com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.StorageKey.Builder updateKey =
@@ -42,7 +41,7 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
.setCollection(collection)
.setRecord(key);
if (version != null) {
updateKey = updateKey.setVersion(ByteString.copyFrom(version));
updateKey = updateKey.setVersion(version);
}
com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.Builder record =
com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.newBuilder()
@@ -70,7 +69,7 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
}
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final @NonNull OpBuilder ops, final byte[] version) {
final @NonNull OpBuilder ops, final String version) {
return record(bucket, collection, key, ops, version, null, null);
}
@@ -92,19 +91,19 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
final @NonNull com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.Builder ops;
public OpBuilder add(final @NonNull String path, final @NonNull byte[] value) {
public OpBuilder add(final @NonNull String path, final @NonNull String value) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.ADD.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value)));
.setValue(value));
return this;
}
public OpBuilder append(final @NonNull String path, final @NonNull byte[] value) {
public OpBuilder append(final @NonNull String path, final @NonNull String value) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.APPEND.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value)));
.setValue(value));
return this;
}
@@ -120,23 +119,23 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.INCR.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(Long.toString(value).getBytes())));
.setValue(Long.toString(value)));
return this;
}
public OpBuilder init(final @NonNull String path, final @NonNull byte[] value) {
public OpBuilder init(final @NonNull String path, final @NonNull String value) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.INIT.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value)));
.setValue(value));
return this;
}
public OpBuilder merge(final @NonNull String path, final @NonNull byte[] value) {
public OpBuilder merge(final @NonNull String path, final @NonNull String value) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.MERGE.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value)));
.setValue(value));
return this;
}
@@ -158,27 +157,27 @@ public interface StorageUpdateMessage extends CollatedMessage<ResultSet<RecordId
return this;
}
public OpBuilder replace(final @NonNull String path, final @NonNull byte[] value) {
public OpBuilder replace(final @NonNull String path, final @NonNull String value) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.REPLACE.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value)));
.setValue(value));
return this;
}
public OpBuilder test(final @NonNull String path, final @NonNull byte[] value) {
public OpBuilder test(final @NonNull String path, final @NonNull String value) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.TEST.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value)));
.setValue(value));
return this;
}
public OpBuilder compare(final @NonNull String path, final @NonNull byte[] value, final long assertValue) {
public OpBuilder compare(final @NonNull String path, final @NonNull String value, final long assertValue) {
ops.addOps(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.newBuilder()
.setOp(com.heroiclabs.nakama.Api.TStorageUpdate.StorageUpdate.UpdateOp.UpdateOpCode.COMPARE.getNumber())
.setPath(path)
.setValue(ByteString.copyFrom(value))
.setValue(value)
.setAssert(assertValue));
return this;
}
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -33,7 +32,7 @@ public interface StorageWriteMessage extends CollatedMessage<ResultSet<RecordId>
private final @NonNull com.heroiclabs.nakama.Api.TStorageWrite.Builder writes;
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final @NonNull byte[] value, final byte[] version,
final @NonNull String value, final String version,
final StorageRecord.PermissionRead read,
final StorageRecord.PermissionWrite write) {
com.heroiclabs.nakama.Api.TStorageWrite.StorageData.Builder record =
@@ -41,9 +40,9 @@ public interface StorageWriteMessage extends CollatedMessage<ResultSet<RecordId>
.setBucket(bucket)
.setCollection(collection)
.setRecord(key)
.setValue(ByteString.copyFrom(value));
.setValue(value);
if (version != null) {
record = record.setVersion(ByteString.copyFrom(version));
record = record.setVersion(version);
}
if (read != null) {
record = record.setPermissionRead(read.getCode());
@@ -56,18 +55,18 @@ public interface StorageWriteMessage extends CollatedMessage<ResultSet<RecordId>
}
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final @NonNull byte[] value) {
final @NonNull String value) {
return record(bucket, collection, key, value, null, null, null);
}
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final @NonNull byte[] value, final StorageRecord.PermissionRead read,
final @NonNull String value, final StorageRecord.PermissionRead read,
final StorageRecord.PermissionWrite write) {
return record(bucket, collection, key, value, null, read, write);
}
public Builder record(final @NonNull String bucket, final @NonNull String collection, final @NonNull String key,
final @NonNull byte[] value, final byte[] version) {
final @NonNull String value, final String version) {
return record(bucket, collection, key, value, version, null, null);
}
@@ -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
*/
String getId();
/**
* @return Type of Topic this is - DM, Group, Room
*/
TopicType getTopicType();
}
@@ -0,0 +1,64 @@
/*
* 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;
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 String userId) {
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
topicJoinBuilder.setUserId(userId);
joins.addJoins(topicJoinBuilder);
return this;
}
public TopicJoinMessage.Builder topicRoom(final @NonNull String room) {
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
topicJoinBuilder.setRoom(room);
joins.addJoins(topicJoinBuilder);
return this;
}
public TopicJoinMessage.Builder topicGroup(final @NonNull String groupId) {
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
topicJoinBuilder.setGroupId(groupId);
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,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.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(topicId.getId());
break;
case Group:
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setGroupId(topicId.getId());
break;
case DirectMessage:
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setDm(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.
*/
String getUserId();
/**
* @return Message ID.
*/
String 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.
*/
String 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;
*/
String getMessageId();
/**
* @return User Handle;
*/
String getHandle();
/**
* @return When the message was created;
*/
long getCreatedAt();
/**
* @return When the message expires;
*/
long getExpiresAt();
}
@@ -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.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 String data) {
com.heroiclabs.nakama.Api.TTopicMessageSend.Builder msg = com.heroiclabs.nakama.Api.TTopicMessageSend.newBuilder();
msg.setData(data);
switch (topicId.getTopicType()) {
case Room:
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setRoom(topicId.getId()));
break;
case Group:
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setGroupId(topicId.getId()));
break;
case DirectMessage:
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setDm(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,74 @@
/*
* 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;
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(cursor.getValue());
return this;
}
public TopicMessagesListMessage.Builder limit(final long limit) {
lists.setLimit(limit);
return this;
}
public TopicMessagesListMessage.Builder topicDirectMessage(final @NonNull String userId) {
lists.setUserId(userId);
return this;
}
public TopicMessagesListMessage.Builder topicRoom(final @NonNull String room) {
lists.setRoom(room);
return this;
}
public TopicMessagesListMessage.Builder topicGroup(final @NonNull String groupId) {
lists.setGroupId(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();
}
@@ -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.
*/
@@ -43,7 +43,7 @@ public interface User {
/**
* @return The ID of the user.
*/
byte[] getId();
String getId();
/**
* @return The (BCP-47) lang tag set by the user.
@@ -63,7 +63,7 @@ public interface User {
/**
* @return The metadata stored for the user.
*/
byte[] getMetadata();
String getMetadata();
/**
* @param clazz A hint for the type of the class.
@@ -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
*/
String getUserId();
/**
* @return Session ID associated with this presence
*/
String getSessionId();
/**
* @return User Handle
*/
String getHandle();
}
@@ -16,7 +16,6 @@
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -32,9 +31,9 @@ public interface UsersFetchMessage extends CollatedMessage<ResultSet<User>> {
private final @NonNull com.heroiclabs.nakama.Api.TUsersFetch.Builder usersFetches;
public Builder id(final @NonNull byte[] id) {
public Builder id(final @NonNull String id) {
usersFetches.addUsers(com.heroiclabs.nakama.Api.TUsersFetch.UsersFetch.newBuilder()
.setUserId(ByteString.copyFrom(id)));
.setUserId(id));
return this;
}
@@ -19,9 +19,6 @@ package com.heroiclabs.nakama;
import org.junit.Assert;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.util.UUID;
public final class DefaultSessionTest {
private static final String JWT_TOKEN =
@@ -31,7 +28,7 @@ public final class DefaultSessionTest {
private static final String JWT_TOKEN_HANDLE = "XaFTAVsJQf";
private static final UUID JWT_TOKEN_ID = UUID.fromString("f13ac73a-904a-45ce-87f6-ef2db37ff91a");
private static final String JWT_TOKEN_ID = "f13ac73a-904a-45ce-87f6-ef2db37ff91a";
@Test
public void sessionRestore() {
@@ -39,11 +36,7 @@ public final class DefaultSessionTest {
Assert.assertEquals(JWT_TOKEN, session.getToken());
Assert.assertEquals(JWT_TOKEN_HANDLE, session.getHandle());
ByteBuffer byteBuffer = ByteBuffer.wrap(session.getId());
Long high = byteBuffer.getLong();
Long low = byteBuffer.getLong();
Assert.assertEquals(JWT_TOKEN_ID, new UUID(high, low));
Assert.assertEquals(JWT_TOKEN_ID, session.getId());
}
@Test
@@ -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 (!matched1.getSelf().getUserId().equals(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);
}
}
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff. Show more