Compare commits

...
5 Commits
Author SHA1 Message Date
Chris Molozian 8cd7bd7e71 Nakama Java 0.3.0 release. 2017-10-17 13:32:34 +01:00
Andrei Mihu d9c2ffe343 Fix test regression 2017-10-16 13:00:24 +01:00
Mo Firouz 5f044e2cf7 Add advanced matchmaker. Merged #2 2017-10-09 21:31:59 +01:00
Chris Molozian 55119792d9 Set new development version. 2017-09-24 21:44:41 +01:00
Chris Molozian 38362c56ef Fix broken javadoc. 2017-09-24 21:41:38 +01:00
28 changed files with 521 additions and 55 deletions

No files matched your search

+7
View File
@@ -4,6 +4,13 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).
## [0.3.0] - 2017-10-17
### Added
- Advanced Matchmaking with custom filters and user properties.
### Fixed
- Improved errors to contain the underlying error reason.
## [0.2.0] - 2017-09-24
### Added
- Leaderboard messages.
+2 -1
View File
@@ -25,7 +25,7 @@ plugins {
}
group = 'com.heroiclabs.nakama'
version = '0.2.0'
version = '0.3.0'
def description = 'Android optimized Java client for Nakama server.'
sourceCompatibility = 1.7
@@ -108,6 +108,7 @@ gitPublish {
include '0.1.0/**'
include '0.1.1/**'
include '0.1.2/**'
include '0.2.0/**'
}
commitMessage = "Published javadoc '$project.version' via Gradle ${GradleVersion.current().version}."
}
+1 -1
Submodule server updated: 15dc7ba786...e0a93a8615.
@@ -27,26 +27,36 @@ public interface ClientListener {
/**
* 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);
}
@@ -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;
}
}
@@ -269,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()));
@@ -347,7 +347,7 @@ public class DefaultClient implements Client {
def.callback(new DefaultResultSet<LeaderboardRecord>(new DefaultCursor(envelope.getLeaderboardRecords().getCursor().toByteArray()), leaderboardRecords));
break;
default:
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode()));
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode(), collationId));
break;
}
}
@@ -420,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;
}
@@ -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,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;
}
@@ -29,6 +29,7 @@ class DefaultMatchmakeMatched implements MatchmakeMatched {
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>();
@@ -36,11 +37,17 @@ class DefaultMatchmakeMatched implements MatchmakeMatched {
userPresences.add(DefaultUserPresence.fromProto(u));
}
List<MatchmakeUserProperty> userProperties = new ArrayList<MatchmakeUserProperty>();
for (com.heroiclabs.nakama.Api.MatchmakeMatched.UserProperty u : matched.getPropertiesList()) {
userProperties.add(DefaultMatchmakeUserProperty.fromProto(u));
}
return new DefaultMatchmakeMatched(
DefaultMatchmakeTicket.fromProto(matched.getTicket().toByteArray()),
userPresences,
DefaultMatchToken.fromProto(matched.getToken().toByteArray()),
DefaultUserPresence.fromProto(matched.getSelf())
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,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,67 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import lombok.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
@ToString(includeFieldNames = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class DefaultMatchmakeUserProperty implements MatchmakeUserProperty {
private final byte[] userId;
private final Map<String, Object> properties;
private final Map<String, MatchmakeFilter> filters;
static DefaultMatchmakeUserProperty fromProto(final @NonNull com.heroiclabs.nakama.Api.MatchmakeMatched.UserProperty p) {
Map<String, Object> props = new HashMap<>();
for (com.heroiclabs.nakama.Api.PropertyPair pp : p.getPropertiesList()) {
switch (pp.getValueCase()) {
case INTVALUE:
props.put(pp.getKey(), pp.getIntValue());
break;
case BOOLVALUE:
props.put(pp.getKey(), pp.getBoolValue());
break;
case STRINGSET:
props.put(pp.getKey(), pp.getStringSet().getValuesList());
break;
}
}
Map<String, MatchmakeFilter> filters = new HashMap<>();
for (com.heroiclabs.nakama.Api.MatchmakeFilter f : p.getFiltersList()) {
switch (f.getValueCase()) {
case TERM:
filters.put(f.getName(), DefaultMatchmakeTermFilter.fromProto(f.getTerm()));
break;
case RANGE:
filters.put(f.getName(), DefaultMatchmakeRangeFilter.fromProto(f.getRange()));
break;
case CHECK:
filters.put(f.getName(), new DefaultMatchmakeCheckFilter(f.getCheck()));
break;
}
}
return new DefaultMatchmakeUserProperty(p.getUserId().toByteArray(), props, filters);
}
}
@@ -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();
}
@@ -21,32 +21,32 @@ package com.heroiclabs.nakama;
*/
public interface Leaderboard {
/**
* @returns Leaderboard ID
* @return Leaderboard ID.
*/
byte[] getId();
/**
* @returns Whether leaderboard is server authoritative or not.
* @return Whether leaderboard is server authoritative or not.
*/
boolean isAuthoritative();
/**
* @returns Sort order for the record
* @return Sort order for the record.
*/
long getSort();
/**
* @returns Record count
* @return Record count.
*/
long getCount();
/**
* @returns Reset schedule
* @return Reset schedule.
*/
String getResetSchedule();
/**
* @returns Metadata associated with the leaderboard
* @return Metadata associated with the leaderboard.
*/
byte[] getMetadata();
@@ -24,32 +24,32 @@ import java.util.List;
public interface LeaderboardRecord {
/**
* @returns Leaderboard ID.
* @return Leaderboard ID.
*/
byte[] getLeaderboardId();
/**
* @returns User ID that owns this record.
* @return User ID that owns this record.
*/
byte[] getOwnerId();
/**
* @returns User handle.
* @return User handle.
*/
String getHandle();
/**
* @returns Language associated with the record.
* @return Language associated with the record.
*/
String getLang();
/**
* @returns Location associated with the record.
* @return Location associated with the record.
*/
String getLocation();
/**
* @returns Timezone associated with the record.
* @return Timezone associated with the record.
*/
String getTimezone();
@@ -60,7 +60,7 @@ public interface LeaderboardRecord {
long getNumScore();
/**
* @returns Metadata associated with the leaderboard record.
* @return Metadata associated with the leaderboard record.
*/
byte[] getMetadata();
@@ -74,12 +74,12 @@ public interface LeaderboardRecord {
long getRankedAt();
/**
* @returns When the record was last updated
* @return When the record was last updated
*/
long getUpdatedAt();
/**
* @returns When the record expires.
* @return When the record expires.
*/
long getExpiresAt();
@@ -19,21 +19,21 @@ package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a match object.
* The object which represents a match.
*/
public interface Match {
/**
* @returns Match ID
* @return Match ID.
*/
byte[] getId();
/**
* @returns List of presences in this match.
* @return List of presences in this match.
*/
List<UserPresence> getPresence();
/**
* @returns Match presence for the current user.
* @return Match presence for the current user.
*/
UserPresence getSelf();
}
@@ -19,26 +19,26 @@ package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a match data object.
* The object which represents match data.
*/
public interface MatchData {
/**
* @returns Match ID
* @return Match ID.
*/
byte[] getId();
/**
* @returns Match Data
* @return Match Data.
*/
byte[] getData();
/**
* @returns Data opcode
* @return Data opcode.
*/
long getOpCode();
/**
* @returns Presence for the current match data.
* @return Presence for the current match data.
*/
UserPresence getPresence();
}
@@ -17,11 +17,11 @@
package com.heroiclabs.nakama;
/**
* The object which represents a match token object.
* The object which represents a match token.
*/
public interface MatchToken {
/**
* @returns Match Token
* @return Match Token.
*/
byte[] getToken();
}
@@ -17,13 +17,89 @@
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);
@@ -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 { }
@@ -19,26 +19,31 @@ package com.heroiclabs.nakama;
import java.util.List;
/**
* The object which represents a matchmake matched object.
* The object which represents a matchmake matched.
*/
public interface MatchmakeMatched {
/**
* @returns Matchmaking Ticket.
* @return Matchmaking Ticket.
*/
MatchmakeTicket getTicket();
/**
* @returns List of presences in this match.
* @return List of presences in this match.
*/
List<UserPresence> getPresence();
/**
* @returns Match token.
* @return Match token.
*/
MatchToken getToken();
/**
* @returns Match presence for the current user.
* @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,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();
}
@@ -17,11 +17,11 @@
package com.heroiclabs.nakama;
/**
* The object which represents a matchmake object.
* The object which represents a matchmake.
*/
public interface MatchmakeTicket {
/**
* @returns Matchmake Ticket
* @return Matchmake Ticket
*/
byte[] getTicket();
}
@@ -0,0 +1,40 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.heroiclabs.nakama;
import java.util.List;
import java.util.Map;
/**
* Properties associated with each matched user
*/
public interface MatchmakeUserProperty {
/**
* @return Matchmake user ID
*/
byte[] getUserId();
/**
* @return Matchmake user properties
*/
Map<String, Object> getProperties();
/**
* @return Matchmake user filters
*/
Map<String, MatchmakeFilter> getFilters();
}
@@ -46,42 +46,42 @@ public interface TopicMessage {
}
/**
* @returns Topic ID associated with this message
* @return Topic ID associated with this message.
*/
TopicId getTopic();
/**
* @returns User ID associcated with this message
* @return User ID associated with this message.
*/
byte[] getUserId();
/**
* @returns Message ID
* @return Message ID.
*/
byte[] getMessageId();
/**
* @returns When message was created
* @return When message was created.
*/
long getCreatedAt();
/**
* @returns When message expires
* @return When message expires.
*/
long getExpiresAt();
/**
* @returns User Handle associated with this message
* @return User Handle associated with this message.
*/
String getHandle();
/**
* @returns Message Type
* @return Message Type.
*/
TopicMessageType getType();
/**
* @returns Data in the message
* @return Data in the message.
*/
byte[] getData();
}
@@ -23,6 +23,8 @@ 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;
@@ -40,6 +42,9 @@ public class MatchmakeAddMessageTest {
private CountDownLatch latch3;
private MatchData data;
private MatchmakeMatched matched1;
private MatchmakeMatched matched2;
@Before
public void init() {
client1 = DefaultClient.builder("defaultkey").listener(new ClientListener() {
@@ -48,6 +53,7 @@ public class MatchmakeAddMessageTest {
@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) {
@@ -65,6 +71,7 @@ public class MatchmakeAddMessageTest {
@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) {}
@@ -108,13 +115,27 @@ public class MatchmakeAddMessageTest {
}).addCallbackDeferring(new Callback<Deferred<MatchmakeTicket>, Session>() {
@Override
public Deferred<MatchmakeTicket> call(Session session) throws Exception {
final CollatedMessage<MatchmakeTicket> add = MatchmakeAddMessage.Builder.build(2);
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.build(2);
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);
}
});
@@ -124,6 +145,15 @@ public class MatchmakeAddMessageTest {
Assert.assertNotNull(token1);
Assert.assertNotNull(token2);
MatchmakeUserProperty c1Props = matched1.getProperties().get(0);
if (!Arrays.equals(matched1.getSelf().getUserId(), matched1.getProperties().get(0).getUserId()))
{
c1Props = matched1.getProperties().get(1);
}
Assert.assertEquals(((long)c1Props.getProperties().get("rank")), 12);
Assert.assertEquals(((MatchmakeRangeFilter)c1Props.getFilters().get("rank")).getLowerbound(), 10);
final CollatedMessage<ResultSet<Match>> matchJoin = MatchesJoinMessage.Builder.newBuilder().token(token1).build();
final Deferred<ResultSet<Match>> deferred2 = client1.send(matchJoin);
deferred2.addCallbackDeferring(new Callback<Deferred<ResultSet<Match>>, ResultSet<Match>>() {
@@ -81,7 +81,9 @@ public class SelfUpdateMessageTest {
public void testUpdateHandleTooLong() throws Exception {
final String deviceId = UUID.randomUUID().toString();
final AuthenticateMessage auth = AuthenticateMessage.Builder.device(deviceId);
final String newHandle = UUID.randomUUID().toString();
final String newHandle = UUID.randomUUID().toString() + UUID.randomUUID().toString() +
UUID.randomUUID().toString() + UUID.randomUUID().toString() +
UUID.randomUUID().toString();
final Deferred<Session> deferred = client.register(auth);
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {