Compare commits

...
4 Commits
67 changed files with 2830 additions and 18 deletions

No files matched your search

+9
View File
@@ -4,6 +4,15 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).
## [0.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"
}
}
```
+2 -1
View File
@@ -25,7 +25,7 @@ plugins {
}
group = 'com.heroiclabs.nakama'
version = '0.1.2'
version = '0.2.0'
def description = 'Android optimized Java client for Nakama server.'
sourceCompatibility = 1.7
@@ -107,6 +107,7 @@ gitPublish {
preserve {
include '0.1.0/**'
include '0.1.1/**'
include '0.1.2/**'
}
commitMessage = "Published javadoc '$project.version' via Gradle ${GradleVersion.current().version}."
}
@@ -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,29 @@ public interface ClientListener {
* Called when the client socket disconnects.
*/
void onDisconnect();
/**
* Called when a new topic message has been received.
*/
void onTopicMessage(TopicMessage message);
/**
* Called when a new topic presence update has been received.
*/
void onTopicPresence(TopicPresence presence);
/**
* Called when a matchmaking has found a match.
*/
void onMatchmakeMatched(MatchmakeMatched matched);
/**
* Called when a new match data is received.
*/
void onMatchData(MatchData matchData);
/**
* Called when a new match presence update is received.
*/
void onMatchPresence(MatchPresence matchPresence);
}
@@ -62,9 +62,9 @@ public class DefaultClient implements Client {
private long serverTime;
private DefaultClient(final String serverKey, final String host, final int port, final String lang,
final boolean ssl, final int connectTimeout, final int timeout, final boolean trace,
final ClientListener listener) {
private DefaultClient(final @NonNull String serverKey, final @NonNull String host, final int port,
final @NonNull String lang, final boolean ssl, final int connectTimeout, final int timeout,
final boolean trace, final @NonNull ClientListener listener) {
this.host = host;
this.port = port;
this.serverKey = serverKey;
@@ -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;
}
@@ -287,6 +302,50 @@ public class DefaultClient implements Client {
case RPC:
def.callback(DefaultRpcResult.fromProto(envelope.getRpc()));
break;
case TOPICS:
final List<Topic> topics = new ArrayList<>();
for (final com.heroiclabs.nakama.Api.TTopics.Topic topic : envelope.getTopics().getTopicsList()) {
topics.add(DefaultTopic.fromProto(topic));
}
def.callback(new DefaultResultSet<Topic>(null, topics));
break;
case TOPIC_MESSAGE_ACK:
def.callback(DefaultTopicMessageAck.fromProto(envelope.getTopicMessageAck()));
break;
case TOPIC_MESSAGES:
final List<TopicMessage> messages = new ArrayList<>();
for (final com.heroiclabs.nakama.Api.TopicMessage m : envelope.getTopicMessages().getMessagesList()) {
messages.add(DefaultTopicMessage.fromProto(m));
}
def.callback(new DefaultResultSet<TopicMessage>(new DefaultCursor(envelope.getTopicMessages().getCursor().toByteArray()), messages));
break;
case MATCH:
def.callback(DefaultMatch.fromProto(envelope.getMatch()));
break;
case MATCHES:
final List<Match> matches = new ArrayList<>();
for (final com.heroiclabs.nakama.Api.Match m : envelope.getMatches().getMatchesList()) {
matches.add(DefaultMatch.fromProto(m));
}
def.callback(new DefaultResultSet<Match>(null, matches));
break;
case MATCHMAKE_TICKET:
def.callback(DefaultMatchmakeTicket.fromProto(envelope.getMatchmakeTicket()));
break;
case LEADERBOARDS:
final List<Leaderboard> leaderboards = new ArrayList<>();
for (final com.heroiclabs.nakama.Api.Leaderboard l : envelope.getLeaderboards().getLeaderboardsList()) {
leaderboards.add(DefaultLeaderboard.fromProto(l));
}
def.callback(new DefaultResultSet<Leaderboard>(new DefaultCursor(envelope.getLeaderboards().getCursor().toByteArray()), leaderboards));
break;
case LEADERBOARD_RECORDS:
final List<LeaderboardRecord> leaderboardRecords = new ArrayList<>();
for (final com.heroiclabs.nakama.Api.LeaderboardRecord r : envelope.getLeaderboardRecords().getRecordsList()) {
leaderboardRecords.add(DefaultLeaderboardRecord.fromProto(r));
}
def.callback(new DefaultResultSet<LeaderboardRecord>(new DefaultCursor(envelope.getLeaderboardRecords().getCursor().toByteArray()), leaderboardRecords));
break;
default:
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode()));
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();
}
});
@@ -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;
}
@@ -0,0 +1,51 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultLeaderboard implements Leaderboard {
private final byte[] id;
private final boolean authoritative;
private final long sort;
private final long count;
private final String resetSchedule;
private final byte[] metadata;
private final byte[] nextId;
private final byte[] prevId;
public <T> T getMetadata(final Class<T> clazz) {
return DefaultClient.GSON.fromJson(new String(metadata), clazz);
}
static Leaderboard fromProto(final @NonNull com.heroiclabs.nakama.Api.Leaderboard leaderboard) {
return new DefaultLeaderboard(
leaderboard.getId().toByteArray(),
leaderboard.getAuthoritative(),
leaderboard.getSort(),
leaderboard.getCount(),
leaderboard.getResetSchedule(),
leaderboard.getMetadata().toByteArray(),
leaderboard.getNextId().toByteArray(),
leaderboard.getPrevId().toByteArray()
);
}
}
@@ -0,0 +1,61 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultLeaderboardRecord implements LeaderboardRecord {
private final byte[] leaderboardId;
private final byte[] ownerId;
private final String handle;
private final String lang;
private final String location;
private final String timezone;
private final long rank;
private final long score;
private final long numScore;
private final byte[] metadata;
private final long rankedAt;
private final long updatedAt;
private final long expiresAt;
static LeaderboardRecord fromProto(final @NonNull com.heroiclabs.nakama.Api.LeaderboardRecord record) {
return new DefaultLeaderboardRecord(
record.getLeaderboardId().toByteArray(),
record.getOwnerId().toByteArray(),
record.getHandle(),
record.getLang(),
record.getLocation(),
record.getTimezone(),
record.getRank(),
record.getScore(),
record.getNumScore(),
record.getMetadata().toByteArray(),
record.getRankedAt(),
record.getUpdatedAt(),
record.getExpiresAt()
);
}
public <T> T getMetadata(final Class<T> clazz) {
return DefaultClient.GSON.fromJson(new String(metadata), clazz);
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultLeaderboardRecordWriteMessage implements LeaderboardRecordWriteMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultLeaderboardRecordsFetchMessage implements LeaderboardRecordsFetchMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultLeaderboardRecordsListMessage implements LeaderboardRecordsListMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultLeaderboardsListMessage implements LeaderboardsListMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,45 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatch implements Match {
private final byte[] id;
private final List<UserPresence> presence;
private final UserPresence self;
static Match fromProto(final @NonNull com.heroiclabs.nakama.Api.TMatch match) {
return DefaultMatch.fromProto(match.getMatch());
}
static Match fromProto(final @NonNull com.heroiclabs.nakama.Api.Match match) {
List<UserPresence> userPresences = new ArrayList<UserPresence>();
for (com.heroiclabs.nakama.Api.UserPresence u : match.getPresencesList()) {
userPresences.add(DefaultUserPresence.fromProto(u));
}
return new DefaultMatch(match.getMatchId().toByteArray(), userPresences, DefaultUserPresence.fromProto(match.getSelf()));
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchCreateMessage implements MatchCreateMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchData implements MatchData {
private final byte[] id;
private final byte[] data;
private final long opCode;
private final UserPresence presence;
static MatchData fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchData matchData) {
return new DefaultMatchData(matchData.getMatchId().toByteArray(), matchData.getData().toByteArray(), matchData.getOpCode(), DefaultUserPresence.fromProto(matchData.getPresence()));
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchDataSendMessage implements MatchDataSendMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes() {
return payload.clone().build().toByteArray();
}
}
@@ -0,0 +1,46 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class DefaultMatchPresence implements MatchPresence {
private final byte[] id;
private final List<UserPresence> join;
private final List<UserPresence> leave;
static MatchPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchPresence matchPresence) {
List<UserPresence> joins = new ArrayList<UserPresence>();
for (com.heroiclabs.nakama.Api.UserPresence u : matchPresence.getJoinsList()) {
joins.add(DefaultUserPresence.fromProto(u));
}
List<UserPresence> leaves = new ArrayList<UserPresence>();
for (com.heroiclabs.nakama.Api.UserPresence u : matchPresence.getLeavesList()) {
leaves.add(DefaultUserPresence.fromProto(u));
}
return new DefaultMatchPresence(matchPresence.getMatchId().toByteArray(), joins, leaves);
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchToken implements MatchToken {
private final byte[] token;
static MatchToken fromProto(final @NonNull byte[] token) {
return new DefaultMatchToken(token);
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchesJoinMessage implements MatchesJoinMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchesLeaveMessage implements MatchesLeaveMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchmakeAddMessage implements MatchmakeAddMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,47 @@
/*
* 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;
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));
}
return new DefaultMatchmakeMatched(
DefaultMatchmakeTicket.fromProto(matched.getTicket().toByteArray()),
userPresences,
DefaultMatchToken.fromProto(matched.getToken().toByteArray()),
DefaultUserPresence.fromProto(matched.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 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,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchmakeTicket implements MatchmakeTicket {
private final byte[] ticket;
static MatchmakeTicket fromProto(final @NonNull com.heroiclabs.nakama.Api.TMatchmakeTicket matchmakeTicket) {
return new DefaultMatchmakeTicket(matchmakeTicket.getTicket().toByteArray());
}
static MatchmakeTicket fromProto(final @NonNull byte[] matchmakeTicket) {
return new DefaultMatchmakeTicket(matchmakeTicket);
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopic implements Topic {
private final TopicId topicId;
private final List<UserPresence> presences;
private final UserPresence self;
static Topic fromProto(final @NonNull com.heroiclabs.nakama.Api.TTopics.Topic topic) {
List<UserPresence> userPresences = new ArrayList<UserPresence>();
for (com.heroiclabs.nakama.Api.UserPresence u : topic.getPresencesList()) {
userPresences.add(DefaultUserPresence.fromProto(u));
}
return new DefaultTopic(DefaultTopicId.fromProto(topic.getTopic()), userPresences, DefaultUserPresence.fromProto(topic.getSelf()));
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopicId implements TopicId {
private final byte[] Id;
private final TopicType topicType;
static TopicId fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicId topicId) {
switch (topicId.getIdCase()) {
case DM:
return new DefaultTopicId(topicId.getDm().toByteArray(), TopicType.DirectMessage);
case ROOM:
return new DefaultTopicId(topicId.getRoom().toByteArray(), TopicType.Room);
case GROUP_ID:
return new DefaultTopicId(topicId.getGroupId().toByteArray(), TopicType.Group);
default:
return null;
}
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopicJoinMessage implements TopicJoinMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopicLeaveMessage implements TopicLeaveMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,46 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class DefaultTopicMessage implements TopicMessage {
private final TopicId topic;
private final byte[] userId;
private final byte[] messageId;
private final long createdAt;
private final long expiresAt;
private final String handle;
private final TopicMessageType type;
private final byte[] data;
static TopicMessage fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicMessage message) {
return new DefaultTopicMessage(
DefaultTopicId.fromProto(message.getTopic()),
message.getUserId().toByteArray(),
message.getMessageId().toByteArray(),
message.getCreatedAt(),
message.getExpiresAt(),
message.getHandle(),
TopicMessageType.fromProto((int)message.getType()),
message.getData().toByteArray()
);
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopicMessageAck implements TopicMessageAck {
private final byte[] messageId;
private final String handle;
private final long createdAt;
private final long expiresAt;
static TopicMessageAck fromProto(final @NonNull com.heroiclabs.nakama.Api.TTopicMessageAck ack) {
return new DefaultTopicMessageAck(ack.getMessageId().toByteArray(), ack.getHandle(), ack.getCreatedAt(), ack.getExpiresAt());
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopicMessageSendMessage implements TopicMessageSendMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultTopicMessagesListMessage implements TopicMessagesListMessage {
private final com.heroiclabs.nakama.Api.Envelope.Builder payload;
public byte[] asBytes(final @NonNull String collationId) {
return payload.clone().setCollationId(collationId).build().toByteArray();
}
}
@@ -0,0 +1,46 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class DefaultTopicPresence implements TopicPresence {
private final TopicId topic;
private final List<UserPresence> join;
private final List<UserPresence> leave;
static TopicPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.TopicPresence topicPresence) {
List<UserPresence> joins = new ArrayList<UserPresence>();
for (com.heroiclabs.nakama.Api.UserPresence u : topicPresence.getJoinsList()) {
joins.add(DefaultUserPresence.fromProto(u));
}
List<UserPresence> leaves = new ArrayList<UserPresence>();
for (com.heroiclabs.nakama.Api.UserPresence u : topicPresence.getLeavesList()) {
leaves.add(DefaultUserPresence.fromProto(u));
}
return new DefaultTopicPresence(DefaultTopicId.fromProto(topicPresence.getTopic()), joins, leaves);
}
}
@@ -0,0 +1,35 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultUserPresence implements UserPresence {
private final byte[] userId;
private final byte[] sessionId;
private final String handle;
static UserPresence fromProto(final @NonNull com.heroiclabs.nakama.Api.UserPresence presence) {
return new DefaultUserPresence(presence.getUserId().toByteArray(), presence.getSessionId().toByteArray(), presence.getHandle());
}
}
@@ -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 {
/**
* @returns Leaderboard ID
*/
byte[] getId();
/**
* @returns Whether leaderboard is server authoritative or not.
*/
boolean isAuthoritative();
/**
* @returns Sort order for the record
*/
long getSort();
/**
* @returns Record count
*/
long getCount();
/**
* @returns Reset schedule
*/
String getResetSchedule();
/**
* @returns Metadata associated with the leaderboard
*/
byte[] getMetadata();
/**
* @param clazz A hint for the type of the class.
* @param <T> A type parameter for the metadata to decode.
* @return Metadata associated with the leaderboard.
*/
<T> T getMetadata(final Class<T> clazz);
byte[] getNextId();
byte[] getPrevId();
}
@@ -0,0 +1,86 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a leaderboard record.
*/
public interface LeaderboardRecord {
/**
* @returns Leaderboard ID.
*/
byte[] getLeaderboardId();
/**
* @returns User ID that owns this record.
*/
byte[] getOwnerId();
/**
* @returns User handle.
*/
String getHandle();
/**
* @returns Language associated with the record.
*/
String getLang();
/**
* @returns Location associated with the record.
*/
String getLocation();
/**
* @returns Timezone associated with the record.
*/
String getTimezone();
long getRank();
long getScore();
long getNumScore();
/**
* @returns Metadata associated with the leaderboard record.
*/
byte[] getMetadata();
/**
* @param clazz A hint for the type of the class.
* @param <T> A type parameter for the metadata to decode.
* @return Metadata associated with the leaderboard.
*/
<T> T getMetadata(final Class<T> clazz);
long getRankedAt();
/**
* @returns When the record was last updated
*/
long getUpdatedAt();
/**
* @returns When the record expires.
*/
long getExpiresAt();
}
@@ -0,0 +1,100 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface LeaderboardRecordWriteMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class LeaderboardRecordWrite {
private final @NonNull
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder write;
public static LeaderboardRecordWriteMessage.LeaderboardRecordWrite newBuilder(final @NonNull byte[] leaderboardId) {
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder b = com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.newBuilder();
b.setLeaderboardId(ByteString.copyFrom(leaderboardId));
return new LeaderboardRecordWriteMessage.LeaderboardRecordWrite(b);
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite location(final @NonNull String location) {
write.setLocation(location);
return this;
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite timezone(final @NonNull String timezone) {
write.setTimezone(timezone);
return this;
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite metadata(final @NonNull byte[] metadata) {
write.setMetadata(ByteString.copyFrom(metadata));
return this;
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite increment(final long value) {
write.setIncr(value);
return this;
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite decrement(final long value) {
write.setDecr(value);
return this;
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite set(final long value) {
write.setSet(value);
return this;
}
public LeaderboardRecordWriteMessage.LeaderboardRecordWrite best(final long value) {
write.setBest(value);
return this;
}
private com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.LeaderboardRecordWrite.Builder build() {
return write;
}
}
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static LeaderboardRecordWriteMessage.Builder newBuilder() {
return new LeaderboardRecordWriteMessage.Builder(com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TLeaderboardRecordsWrite.Builder writes;
public LeaderboardRecordWriteMessage.Builder add(final @NonNull LeaderboardRecordWrite write) {
writes.addRecords(write.build());
return this;
}
public LeaderboardRecordWriteMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setLeaderboardRecordsWrite(writes);
return new DefaultLeaderboardRecordWriteMessage(payload);
}
}
}
@@ -0,0 +1,59 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface LeaderboardRecordsFetchMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static LeaderboardRecordsFetchMessage.Builder newBuilder() {
return new LeaderboardRecordsFetchMessage.Builder(com.heroiclabs.nakama.Api.TLeaderboardRecordsFetch.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TLeaderboardRecordsFetch.Builder fetch;
public LeaderboardRecordsFetchMessage.Builder fetch(final @NonNull byte[] leaderboardId) {
fetch.addLeaderboardIds(ByteString.copyFrom(leaderboardId));
return this;
}
public LeaderboardRecordsFetchMessage.Builder limit(final long limit) {
fetch.setLimit(limit);
return this;
}
public LeaderboardRecordsFetchMessage.Builder cursor(final @NonNull byte[] cursor) {
fetch.setCursor(ByteString.copyFrom(cursor));
return this;
}
public LeaderboardRecordsFetchMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setLeaderboardRecordsFetch(fetch);
return new DefaultLeaderboardRecordsFetchMessage(payload);
}
}
}
@@ -0,0 +1,82 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
public interface LeaderboardRecordsListMessage extends CollatedMessage<ResultSet<LeaderboardRecord>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static LeaderboardRecordsListMessage.Builder newBuilder(final @NonNull byte[] leaderboardId) {
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Builder b = com.heroiclabs.nakama.Api.TLeaderboardRecordsList.newBuilder();
b.setLeaderboardId(ByteString.copyFrom(leaderboardId));
return new DefaultLeaderboardRecordsListMessage.Builder(b);
}
private final @NonNull
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Builder listing;
public LeaderboardRecordsListMessage.Builder filterByPagingToOwnerId(final @NonNull byte[] ownerId) {
listing.setOwnerId(ByteString.copyFrom(ownerId));
return this;
}
public LeaderboardRecordsListMessage.Builder filterByPagingToOwnerIds(final @NonNull List<byte[]> ownerIds) {
com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Owners.Builder o = com.heroiclabs.nakama.Api.TLeaderboardRecordsList.Owners.newBuilder();
for (byte[] b : ownerIds) {
o.addOwnerIds(ByteString.copyFrom(b));
}
listing.setOwnerIds(o);
return this;
}
public LeaderboardRecordsListMessage.Builder filterByLang(final @NonNull String lang) {
listing.setLang(lang);
return this;
}
public LeaderboardRecordsListMessage.Builder filterByTimezone(final @NonNull String tz) {
listing.setTimezone(tz);
return this;
}
public LeaderboardRecordsListMessage.Builder limit(final long limit) {
listing.setLimit(limit);
return this;
}
public LeaderboardRecordsListMessage.Builder cursor(final @NonNull byte[] cursor) {
listing.setCursor(ByteString.copyFrom(cursor));
return this;
}
public LeaderboardRecordsListMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setLeaderboardRecordsList(listing);
return new DefaultLeaderboardRecordsListMessage(payload);
}
}
}
@@ -0,0 +1,59 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface LeaderboardsListMessage extends CollatedMessage<ResultSet<Leaderboard>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static LeaderboardsListMessage.Builder newBuilder() {
return new LeaderboardsListMessage.Builder(com.heroiclabs.nakama.Api.TLeaderboardsList.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TLeaderboardsList.Builder listing;
public LeaderboardsListMessage.Builder limit(final long limit) {
listing.setLimit(limit);
return this;
}
public LeaderboardsListMessage.Builder addFilter(final @NonNull byte[] leaderboardId) {
listing.addFilterLeaderboardId(ByteString.copyFrom(leaderboardId));
return this;
}
public LeaderboardsListMessage.Builder cursor(final @NonNull byte[] cursor) {
listing.setCursor(ByteString.copyFrom(cursor));
return this;
}
public LeaderboardsListMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setLeaderboardsList(listing);
return new DefaultLeaderboardsListMessage(payload);
}
}
}
@@ -19,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 object.
*/
public interface Match {
/**
* @returns Match ID
*/
byte[] getId();
/**
* @returns List of presences in this match.
*/
List<UserPresence> getPresence();
/**
* @returns Match presence for the current user.
*/
UserPresence getSelf();
}
@@ -0,0 +1,36 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
public interface MatchCreateMessage extends CollatedMessage<Match> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static MatchCreateMessage build() {
com.heroiclabs.nakama.Api.TMatchCreate.Builder builder = com.heroiclabs.nakama.Api.TMatchCreate.newBuilder();
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setMatchCreate(builder);
return new DefaultMatchCreateMessage(payload);
}
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a match data object.
*/
public interface MatchData {
/**
* @returns Match ID
*/
byte[] getId();
/**
* @returns Match Data
*/
byte[] getData();
/**
* @returns Data opcode
*/
long getOpCode();
/**
* @returns Presence for the current match data.
*/
UserPresence getPresence();
}
@@ -0,0 +1,66 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface MatchDataSendMessage extends UncollatedMessage {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static MatchDataSendMessage.Builder newBuilder(final @NonNull byte[] matchId) {
return new DefaultMatchDataSendMessage.Builder(com.heroiclabs.nakama.Api.MatchDataSend.newBuilder()
.setMatchId(ByteString.copyFrom(matchId)));
}
private final @NonNull
com.heroiclabs.nakama.Api.MatchDataSend.Builder matchData;
public MatchDataSendMessage.Builder opCode(final long opcode) {
matchData.setOpCode(opcode);
return this;
}
public MatchDataSendMessage.Builder data(final @NonNull byte[] data) {
matchData.setData(ByteString.copyFrom(data));
return this;
}
public MatchDataSendMessage.Builder presences(final @NonNull UserPresence[] presences) {
for (UserPresence p : presences) {
com.heroiclabs.nakama.Api.UserPresence.Builder up = com.heroiclabs.nakama.Api.UserPresence.newBuilder();
up.setHandle(p.getHandle());
up.setSessionId(ByteString.copyFrom(p.getSessionId()));
up.setUserId(ByteString.copyFrom(p.getUserId()));
matchData.addPresences(up);
}
return this;
}
public MatchDataSendMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setMatchDataSend(matchData);
return new DefaultMatchDataSendMessage(payload);
}
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
public interface MatchPresence {
/**
* @return The ID associated with this presence update
*/
byte[] getId();
/**
* @return Users that have joined
*/
List<UserPresence> getJoin();
/**
* @return Users that have left
*/
List<UserPresence> getLeave();
}
@@ -0,0 +1,27 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
/**
* The object which represents a match token object.
*/
public interface MatchToken {
/**
* @returns Match Token
*/
byte[] getToken();
}
@@ -0,0 +1,58 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface MatchesJoinMessage extends CollatedMessage<ResultSet<Match>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static MatchesJoinMessage.Builder newBuilder() {
return new DefaultMatchesJoinMessage.Builder(com.heroiclabs.nakama.Api.TMatchesJoin.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TMatchesJoin.Builder joins;
public MatchesJoinMessage.Builder matchId(final @NonNull byte[] matchId) {
com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.newBuilder();
topicJoinBuilder.setMatchId(ByteString.copyFrom(matchId));
joins.addMatches(topicJoinBuilder);
return this;
}
public MatchesJoinMessage.Builder token(final @NonNull MatchToken token) {
com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TMatchesJoin.MatchJoin.newBuilder();
topicJoinBuilder.setToken(ByteString.copyFrom(token.getToken()));
joins.addMatches(topicJoinBuilder);
return this;
}
public MatchesJoinMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setMatchesJoin(joins);
return new DefaultMatchesJoinMessage(payload);
}
}
}
@@ -0,0 +1,49 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface MatchesLeaveMessage extends CollatedMessage<Boolean> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static MatchesLeaveMessage.Builder newBuilder() {
return new DefaultMatchesLeaveMessage.Builder(com.heroiclabs.nakama.Api.TMatchesLeave.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TMatchesLeave.Builder leaves;
public MatchesLeaveMessage.Builder matchId(final @NonNull byte[] matchId) {
leaves.addMatchIds(ByteString.copyFrom(matchId));
return this;
}
public MatchesLeaveMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setMatchesLeave(leaves);
return new DefaultMatchesLeaveMessage(payload);
}
}
}
@@ -0,0 +1,38 @@
/*
* 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 MatchmakeAddMessage extends CollatedMessage<MatchmakeTicket> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
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,44 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a matchmake matched object.
*/
public interface MatchmakeMatched {
/**
* @returns Matchmaking Ticket.
*/
MatchmakeTicket getTicket();
/**
* @returns List of presences in this match.
*/
List<UserPresence> getPresence();
/**
* @returns Match token.
*/
MatchToken getToken();
/**
* @returns Match presence for the current user.
*/
UserPresence 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 com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface MatchmakeRemoveMessage extends CollatedMessage<Boolean> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static MatchmakeRemoveMessage build(@NonNull MatchmakeTicket ticket) {
com.heroiclabs.nakama.Api.TMatchmakeRemove.Builder remove = com.heroiclabs.nakama.Api.TMatchmakeRemove.newBuilder();
remove.setTicket(ByteString.copyFrom(ticket.getTicket()));
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setMatchmakeRemove(remove);
return new DefaultMatchmakeRemoveMessage(payload);
}
}
}
@@ -0,0 +1,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 object.
*/
public interface MatchmakeTicket {
/**
* @returns Matchmake Ticket
*/
byte[] getTicket();
}
@@ -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) {}
}
@@ -0,0 +1,39 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a chat topic in the server.
*/
public interface Topic {
/**
* @return the ID associated with this topic.
*/
TopicId getTopicId();
/**
* @return list of users currently active on this topic.
*/
List<UserPresence> getPresences();
/**
* @return presence information of the current user.
*/
UserPresence getSelf();
}
@@ -0,0 +1,31 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
public interface TopicId {
enum TopicType { DirectMessage, Room, Group }
/**
* @return Topic ID
*/
byte[] getId();
/**
* @return Type of Topic this is - DM, Group, Room
*/
TopicType getTopicType();
}
@@ -0,0 +1,65 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface TopicJoinMessage extends CollatedMessage<ResultSet<Topic>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static TopicJoinMessage.Builder newBuilder() {
return new TopicJoinMessage.Builder(com.heroiclabs.nakama.Api.TTopicsJoin.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TTopicsJoin.Builder joins;
public TopicJoinMessage.Builder topicDirectMessage(final @NonNull byte[] userId) {
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
topicJoinBuilder.setUserId(ByteString.copyFrom(userId));
joins.addJoins(topicJoinBuilder);
return this;
}
public TopicJoinMessage.Builder topicRoom(final @NonNull byte[] room) {
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
topicJoinBuilder.setRoom(ByteString.copyFrom(room));
joins.addJoins(topicJoinBuilder);
return this;
}
public TopicJoinMessage.Builder topicGroup(final @NonNull byte[] group) {
com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.Builder topicJoinBuilder = com.heroiclabs.nakama.Api.TTopicsJoin.TopicJoin.newBuilder();
topicJoinBuilder.setGroupId(ByteString.copyFrom(group));
joins.addJoins(topicJoinBuilder);
return this;
}
public TopicJoinMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setTopicsJoin(joins);
return new DefaultTopicJoinMessage(payload);
}
}
}
@@ -0,0 +1,62 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface TopicLeaveMessage extends CollatedMessage<Boolean> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static TopicLeaveMessage.Builder newBuilder() {
return new TopicLeaveMessage.Builder(com.heroiclabs.nakama.Api.TTopicsLeave.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TTopicsLeave.Builder leaves;
public TopicLeaveMessage.Builder Leave(final @NonNull TopicId topicId) {
com.heroiclabs.nakama.Api.TTopicsLeave.Builder topicLeave = com.heroiclabs.nakama.Api.TTopicsLeave.newBuilder();
com.heroiclabs.nakama.Api.TopicId.Builder topicBuilder = null;
switch (topicId.getTopicType()) {
case Room:
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setRoom(ByteString.copyFrom(topicId.getId()));
break;
case Group:
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setGroupId(ByteString.copyFrom(topicId.getId()));
break;
case DirectMessage:
topicBuilder = com.heroiclabs.nakama.Api.TopicId.newBuilder().setDm(ByteString.copyFrom(topicId.getId()));
break;
}
topicLeave.addTopics(topicBuilder);
return this;
}
public TopicLeaveMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setTopicsLeave(leaves);
return new DefaultTopicLeaveMessage(payload);
}
}
}
@@ -0,0 +1,87 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
public interface TopicMessage {
enum TopicMessageType {
Chat,
GroupJoin,
GroupAdd,
GroupLeave,
GroupKick,
GroupPromoted;
static TopicMessageType fromProto(int type) {
switch(type) {
case 0:
return TopicMessageType.Chat;
case 1:
return TopicMessageType.GroupJoin;
case 2:
return TopicMessageType.GroupAdd;
case 3:
return TopicMessageType.GroupLeave;
case 4:
return TopicMessageType.GroupKick;
case 5:
return TopicMessageType.GroupPromoted;
}
return null;
}
}
/**
* @returns Topic ID associated with this message
*/
TopicId getTopic();
/**
* @returns User ID associcated with this message
*/
byte[] getUserId();
/**
* @returns Message ID
*/
byte[] getMessageId();
/**
* @returns When message was created
*/
long getCreatedAt();
/**
* @returns When message expires
*/
long getExpiresAt();
/**
* @returns User Handle associated with this message
*/
String getHandle();
/**
* @returns Message Type
*/
TopicMessageType getType();
/**
* @returns Data in the message
*/
byte[] getData();
}
@@ -0,0 +1,39 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
public interface TopicMessageAck {
/**
* @return ID of this message acked;
*/
byte[] getMessageId();
/**
* @return User Handle;
*/
String getHandle();
/**
* @return When the message was created;
*/
long getCreatedAt();
/**
* @return When the message expires;
*/
long getExpiresAt();
}
@@ -0,0 +1,52 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface TopicMessageSendMessage extends CollatedMessage<TopicMessageAck> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static TopicMessageSendMessage build(final @NonNull TopicId topicId, final @NonNull byte[] data) {
com.heroiclabs.nakama.Api.TTopicMessageSend.Builder msg = com.heroiclabs.nakama.Api.TTopicMessageSend.newBuilder();
msg.setData(ByteString.copyFrom(data));
switch (topicId.getTopicType()) {
case Room:
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setRoom(ByteString.copyFrom(topicId.getId())));
break;
case Group:
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setGroupId(ByteString.copyFrom(topicId.getId())));
break;
case DirectMessage:
msg.setTopic(com.heroiclabs.nakama.Api.TopicId.newBuilder().setDm(ByteString.copyFrom(topicId.getId())));
break;
}
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setTopicMessageSend(msg);
return new DefaultTopicMessageSendMessage(payload);
}
}
}
@@ -0,0 +1,75 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import com.google.protobuf.ByteString;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
public interface TopicMessagesListMessage extends CollatedMessage<ResultSet<TopicMessage>> {
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class Builder {
public static TopicMessagesListMessage.Builder newBuilder() {
return new TopicMessagesListMessage.Builder(com.heroiclabs.nakama.Api.TTopicMessagesList.newBuilder());
}
private final @NonNull
com.heroiclabs.nakama.Api.TTopicMessagesList.Builder lists;
public TopicMessagesListMessage.Builder forward(final boolean forward) {
lists.setForward(forward);
return this;
}
public TopicMessagesListMessage.Builder cursor(final @NonNull Cursor cursor) {
lists.setCursor(ByteString.copyFrom(cursor.getValue()));
return this;
}
public TopicMessagesListMessage.Builder limit(final long limit) {
lists.setLimit(limit);
return this;
}
public TopicMessagesListMessage.Builder topicDirectMessage(final @NonNull byte[] userId) {
lists.setUserId(ByteString.copyFrom(userId));
return this;
}
public TopicMessagesListMessage.Builder topicRoom(final @NonNull byte[] room) {
lists.setRoom(ByteString.copyFrom(room));
return this;
}
public TopicMessagesListMessage.Builder topicGroup(final @NonNull byte[] groupId) {
lists.setGroupId(ByteString.copyFrom(groupId));
return this;
}
public TopicMessagesListMessage build() {
final com.heroiclabs.nakama.Api.Envelope.Builder payload =
com.heroiclabs.nakama.Api.Envelope.newBuilder()
.setTopicMessagesList(lists);
return new DefaultTopicMessagesListMessage(payload);
}
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
public interface TopicPresence {
/**
* @return The topic ID associated with this presence update
*/
TopicId getTopic();
/**
* @return Users that have joined
*/
List<UserPresence> getJoin();
/**
* @return Users that have left
*/
List<UserPresence> getLeave();
}
@@ -19,7 +19,7 @@ package com.heroiclabs.nakama;
/**
* A message which requires no acknowledgement by the server.
*/
public interface Message {
public interface UncollatedMessage {
/**
* @return The serialized format of the message.
*/
@@ -0,0 +1,34 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
public interface UserPresence {
/**
* @return User ID
*/
byte[] getUserId();
/**
* @return Session ID associated with this presence
*/
byte[] getSessionId();
/**
* @return User Handle
*/
String getHandle();
}
@@ -0,0 +1,156 @@
/*
* 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.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;
@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();
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();
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.build(2);
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.build(2);
return client2.send(add);
}
});
deferred.join(2000);
latch1.await(2, TimeUnit.SECONDS);
latch2.await(2, TimeUnit.SECONDS);
Assert.assertNotNull(token1);
Assert.assertNotNull(token2);
final CollatedMessage<ResultSet<Match>> matchJoin = MatchesJoinMessage.Builder.newBuilder().token(token1).build();
final Deferred<ResultSet<Match>> deferred2 = client1.send(matchJoin);
deferred2.addCallbackDeferring(new Callback<Deferred<ResultSet<Match>>, ResultSet<Match>>() {
@Override
public Deferred<ResultSet<Match>> call(ResultSet<Match> matches) throws Exception {
Assert.assertEquals(1, matches.getResults().size());
final CollatedMessage<ResultSet<Match>> matchJoin = MatchesJoinMessage.Builder.newBuilder().token(token2).build();
return client2.send(matchJoin);
}
}).addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Match>>() {
@Override
public Deferred<Boolean> call(ResultSet<Match> matches) throws Exception {
Assert.assertEquals(1, matches.getResults().size());
final UncollatedMessage data = MatchDataSendMessage.Builder
.newBuilder(matches.getResults().get(0).getId())
.data("test".getBytes())
.build();
return client2.send(data);
}
});
deferred2.join(2000);
latch3.await(2, TimeUnit.SECONDS);
Assert.assertNotNull(data);
}
}
@@ -113,12 +113,18 @@ public class RpcMessageTest {
.build();
return client.send(rpc);
}
}).addErrback(new Callback<RpcResult, RpcResult>() {
}).addCallback(new Callback<RpcResult, RpcResult>() {
@Override
public RpcResult call(RpcResult result) throws Exception {
Assert.assertArrayEquals(payload, result.getPayload());
return result;
}
}).addErrback(new Callback<Error, Error>() {
@Override
public Error call(Error error) throws Exception {
Assert.fail("Should not reach this point.");
return error;
}
});
deferred.join(2000);
}