Skip to content

Commit 0e67a1f

Browse files
committed
DB defaults update, friend and group state cleanup.
1 parent eae1877 commit 0e67a1f

14 files changed

+462
-356
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ All notable changes to this project are documented below.
44
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).
55

66
## [Unreleased]
7+
### Added
8+
- New runtime function to send raw realtime envelope data through streams.
9+
10+
### Changed
11+
- Change error message on database errors raised during authentication operations.
12+
- New default for maximum number of open database connections.
13+
- Friend state indicators are no longer offset when sent to clients.
14+
- Group state indicators are no longer offset when sent to clients.
15+
716
### Fixed
17+
- Correctly handle optional parameters in runtime functions to update account information.
818
- Correctly handle context cancellation in single-statement database operations.
919

1020
## [2.1.3] - 2018-11-02

api/api.pb.go

Lines changed: 261 additions & 274 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/api.proto

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,20 @@ message DeleteStorageObjectsRequest {
292292
message Friend {
293293
// The friendship status.
294294
enum State {
295-
// Default case. Assumed as FRIEND state.
296-
STATE_UNSPECIFIED = 0;
297295
// The user is a friend of the current user.
298-
FRIEND = 1;
299-
// The user has sent an invite to the current user.
300-
INVITE_SENT = 2;
301-
// The current user has sent an invite to this user.
302-
INVITE_RECEIVED = 3;
296+
FRIEND = 0;
297+
// The current user has sent an invite to the user.
298+
INVITE_SENT = 1;
299+
// The current user has received an invite from this user.
300+
INVITE_RECEIVED = 2;
303301
// The current user has blocked this user.
304-
BLOCKED = 4;
302+
BLOCKED = 3;
305303
}
306304

307305
// The user object.
308306
User user = 1;
309307
// The friend status.
310-
int32 state = 2; // one of "Friend.State".
308+
google.protobuf.Int32Value state = 2; // one of "Friend.State".
311309
}
312310

313311
// A collection of zero or more friends of the user.
@@ -368,22 +366,20 @@ message GroupUserList {
368366
message GroupUser {
369367
// The group role status.
370368
enum State {
371-
// Default case. Assumed as SUPERADMIN state.
372-
STATE_UNSPECIFIED = 0;
373369
// The user is a superadmin with full control of the group.
374-
SUPERADMIN = 1;
370+
SUPERADMIN = 0;
375371
// The user is an admin with additional privileges.
376-
ADMIN = 2;
372+
ADMIN = 1;
377373
// The user is a regular member.
378-
MEMBER = 3;
374+
MEMBER = 2;
379375
// The user has requested to join the group
380-
JOIN_REQUEST = 4;
376+
JOIN_REQUEST = 3;
381377
}
382378

383379
// User.
384380
User user = 1;
385381
// Their relationship to the group.
386-
int32 state = 2;
382+
google.protobuf.Int32Value state = 2;
387383
}
388384

389385
// User-role pairs for a group.
@@ -872,22 +868,20 @@ message UserGroupList {
872868
message UserGroup {
873869
// The group role status.
874870
enum State {
875-
// Default case. Assumed as SUPERADMIN state.
876-
STATE_UNSPECIFIED = 0;
877871
// The user is a superadmin with full control of the group.
878-
SUPERADMIN = 1;
872+
SUPERADMIN = 0;
879873
// The user is an admin with additional privileges.
880-
ADMIN = 2;
874+
ADMIN = 1;
881875
// The user is a regular member.
882-
MEMBER = 3;
876+
MEMBER = 2;
883877
// The user has requested to join the group
884-
JOIN_REQUEST = 4;
878+
JOIN_REQUEST = 3;
885879
}
886880

887881
// Group.
888882
Group group = 1;
889883
// The user's relationship to the group.
890-
int32 state = 2;
884+
google.protobuf.Int32Value state = 2;
891885
}
892886

893887
// Group-role pairs for a user.

apigrpc/apigrpc.pb.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apigrpc/apigrpc.swagger.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@
13711371
},
13721372
"/v2/leaderboard/{leaderboard_id}/owner/{owner_id}": {
13731373
"get": {
1374+
"summary": "List leaderboard records that belong to a user.",
13741375
"operationId": "ListLeaderboardRecordsAroundOwner",
13751376
"responses": {
13761377
"200": {
@@ -1947,6 +1948,7 @@
19471948
},
19481949
"/v2/tournament/{tournament_id}/join": {
19491950
"post": {
1951+
"summary": "Attempt to join an open and running tournament.",
19501952
"operationId": "JoinTournament",
19511953
"responses": {
19521954
"200": {
@@ -1972,6 +1974,7 @@
19721974
},
19731975
"/v2/tournament/{tournament_id}/owner/{owner_id}": {
19741976
"get": {
1977+
"summary": "List tournament records for a given owner.",
19751978
"operationId": "ListTournamentRecordsAroundOwner",
19761979
"responses": {
19771980
"200": {

migrate/sql/20180103142001_initial_schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS user_edge (
6464
position BIGINT NOT NULL, -- Used for sort order on rows.
6565
update_time TIMESTAMPTZ DEFAULT now() NOT NULL,
6666
destination_id UUID NOT NULL,
67-
state SMALLINT DEFAULT 0 NOT NULL, -- friend(0), invite(1), invited(2), blocked(3), deleted(4), archived(5)
67+
state SMALLINT DEFAULT 0 NOT NULL, -- friend(0), invite_sent(1), invite_received(2), blocked(3), deleted(4), archived(5)
6868

6969
UNIQUE (source_id, destination_id)
7070
);

server/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,18 @@ func NewSocketConfig() *SocketConfig {
390390

391391
// DatabaseConfig is configuration relevant to the Database storage.
392392
type DatabaseConfig struct {
393-
Addresses []string `yaml:"address" json:"address" usage:"List of CockroachDB servers (username:password@address:port/dbname)."`
394-
ConnMaxLifetimeMs int `yaml:"conn_max_lifetime_ms" json:"conn_max_lifetime_ms" usage:"Time in milliseconds to reuse a database connection before the connection is killed and a new one is created."`
395-
MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns" usage:"Maximum number of allowed open connections to the database."`
396-
MaxIdleConns int `yaml:"max_idle_conns" json:"max_idle_conns" usage:"Maximum number of allowed open but unused connections to the database."`
393+
Addresses []string `yaml:"address" json:"address" usage:"List of database servers (username:password@address:port/dbname). Default '[email protected]:26257'."`
394+
ConnMaxLifetimeMs int `yaml:"conn_max_lifetime_ms" json:"conn_max_lifetime_ms" usage:"Time in milliseconds to reuse a database connection before the connection is killed and a new one is created. Default 0 (unlimited)."`
395+
MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns" usage:"Maximum number of allowed open connections to the database. Default 100."`
396+
MaxIdleConns int `yaml:"max_idle_conns" json:"max_idle_conns" usage:"Maximum number of allowed open but unused connections to the database. Default 100."`
397397
}
398398

399399
// NewDatabaseConfig creates a new DatabaseConfig struct.
400400
func NewDatabaseConfig() *DatabaseConfig {
401401
return &DatabaseConfig{
402402
Addresses: []string{"[email protected]:26257"},
403403
ConnMaxLifetimeMs: 0,
404-
MaxOpenConns: 0,
404+
MaxOpenConns: 100,
405405
MaxIdleConns: 100,
406406
}
407407
}

server/core_authenticate.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func AuthenticateCustom(ctx context.Context, logger *zap.Logger, db *sql.DB, cus
5151
if err == sql.ErrNoRows {
5252
found = false
5353
} else {
54-
logger.Error("Cannot find user with custom ID.", zap.Error(err), zap.String("customID", customID), zap.String("username", username), zap.Bool("create", create))
54+
logger.Error("Error looking up user by custom ID.", zap.Error(err), zap.String("customID", customID), zap.String("username", username), zap.Bool("create", create))
5555
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
5656
}
5757
}
@@ -112,7 +112,7 @@ func AuthenticateDevice(ctx context.Context, logger *zap.Logger, db *sql.DB, dev
112112
// No user account found.
113113
//return "", "", status.Error(codes.NotFound, "Device ID not found.")
114114
} else {
115-
logger.Error("Cannot find user with device ID.", zap.Error(err), zap.String("deviceID", deviceID), zap.String("username", username), zap.Bool("create", create))
115+
logger.Error("Error looking up user by device ID.", zap.Error(err), zap.String("deviceID", deviceID), zap.String("username", username), zap.Bool("create", create))
116116
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
117117
}
118118
}
@@ -125,7 +125,7 @@ func AuthenticateDevice(ctx context.Context, logger *zap.Logger, db *sql.DB, dev
125125
var dbDisableTime pq.NullTime
126126
err = db.QueryRowContext(ctx, query, dbUserID).Scan(&dbUsername, &dbDisableTime)
127127
if err != nil {
128-
logger.Error("Cannot find user with device ID.", zap.Error(err), zap.String("deviceID", deviceID), zap.String("username", username), zap.Bool("create", create))
128+
logger.Error("Error looking up user by device ID.", zap.Error(err), zap.String("deviceID", deviceID), zap.String("username", username), zap.Bool("create", create))
129129
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
130130
}
131131

@@ -221,7 +221,7 @@ func AuthenticateEmail(ctx context.Context, logger *zap.Logger, db *sql.DB, emai
221221
if err == sql.ErrNoRows {
222222
found = false
223223
} else {
224-
logger.Error("Cannot find user with email.", zap.Error(err), zap.String("email", email), zap.String("username", username), zap.Bool("create", create))
224+
logger.Error("Error looking up user by email.", zap.Error(err), zap.String("email", email), zap.String("username", username), zap.Bool("create", create))
225225
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
226226
}
227227
}
@@ -293,7 +293,7 @@ func AuthenticateFacebook(ctx context.Context, logger *zap.Logger, db *sql.DB, c
293293
if err == sql.ErrNoRows {
294294
found = false
295295
} else {
296-
logger.Error("Cannot find user with Facebook ID.", zap.Error(err), zap.String("facebookID", facebookProfile.ID), zap.String("username", username), zap.Bool("create", create))
296+
logger.Error("Error looking up user by Facebook ID.", zap.Error(err), zap.String("facebookID", facebookProfile.ID), zap.String("username", username), zap.Bool("create", create))
297297
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
298298
}
299299
}
@@ -359,7 +359,7 @@ func AuthenticateGameCenter(ctx context.Context, logger *zap.Logger, db *sql.DB,
359359
if err == sql.ErrNoRows {
360360
found = false
361361
} else {
362-
logger.Error("Cannot find user with GameCenter ID.", zap.Error(err), zap.String("gameCenterID", playerID), zap.String("username", username), zap.Bool("create", create))
362+
logger.Error("Error looking up user by GameCenter ID.", zap.Error(err), zap.String("gameCenterID", playerID), zap.String("username", username), zap.Bool("create", create))
363363
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
364364
}
365365
}
@@ -425,7 +425,7 @@ func AuthenticateGoogle(ctx context.Context, logger *zap.Logger, db *sql.DB, cli
425425
if err == sql.ErrNoRows {
426426
found = false
427427
} else {
428-
logger.Error("Cannot find user with Google ID.", zap.Error(err), zap.String("googleID", googleProfile.Sub), zap.String("username", username), zap.Bool("create", create))
428+
logger.Error("Error looking up user by Google ID.", zap.Error(err), zap.String("googleID", googleProfile.Sub), zap.String("username", username), zap.Bool("create", create))
429429
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
430430
}
431431
}
@@ -492,7 +492,7 @@ func AuthenticateSteam(ctx context.Context, logger *zap.Logger, db *sql.DB, clie
492492
if err == sql.ErrNoRows {
493493
found = false
494494
} else {
495-
logger.Error("Cannot find user with Steam ID.", zap.Error(err), zap.String("steamID", steamID), zap.String("username", username), zap.Bool("create", create))
495+
logger.Error("Error looking up user by Steam ID.", zap.Error(err), zap.String("steamID", steamID), zap.String("username", username), zap.Bool("create", create))
496496
return "", "", false, status.Error(codes.Internal, "Error finding user account.")
497497
}
498498
}

server/core_friend.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22+
"github.com/golang/protobuf/ptypes/wrappers"
2223
"time"
2324

2425
"context"
@@ -60,8 +61,10 @@ FROM users, user_edge WHERE id = destination_id AND source_id = $1`
6061
}
6162

6263
friends = append(friends, &api.Friend{
63-
User: user,
64-
State: int32(state.Int64),
64+
User: user,
65+
State: &wrappers.Int32Value{
66+
Value: int32(state.Int64),
67+
},
6568
})
6669
}
6770
if err = rows.Err(); err != nil {
@@ -127,8 +130,10 @@ FROM users, user_edge WHERE id = destination_id AND source_id = $1`
127130
}
128131

129132
friends = append(friends, &api.Friend{
130-
User: user,
131-
State: int32(state.Int64) + 1,
133+
User: user,
134+
State: &wrappers.Int32Value{
135+
Value: int32(state.Int64),
136+
},
132137
})
133138
}
134139
if err = rows.Err(); err != nil {

server/core_group.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -773,17 +773,13 @@ WHERE u.id = ge.source_id AND ge.destination_id = $1 AND u.disable_time = '1970-
773773
Online: tracker.StreamExists(PresenceStream{Mode: StreamModeNotifications, Subject: userID}),
774774
}
775775

776-
groupUser := &api.GroupUserList_GroupUser{User: user}
777-
switch state.Int64 {
778-
case 0:
779-
groupUser.State = int32(api.GroupUserList_GroupUser_SUPERADMIN)
780-
case 1:
781-
groupUser.State = int32(api.GroupUserList_GroupUser_ADMIN)
782-
case 2:
783-
groupUser.State = int32(api.GroupUserList_GroupUser_MEMBER)
784-
case 3:
785-
groupUser.State = int32(api.GroupUserList_GroupUser_JOIN_REQUEST)
776+
groupUser := &api.GroupUserList_GroupUser{
777+
User: user,
778+
State: &wrappers.Int32Value{
779+
Value: int32(state.Int64),
780+
},
786781
}
782+
787783
groupUsers = append(groupUsers, groupUser)
788784
}
789785

@@ -855,16 +851,11 @@ WHERE group_edge.destination_id = $1 AND disable_time = '1970-01-01 00:00:00'`
855851
UpdateTime: &timestamp.Timestamp{Seconds: updateTime.Time.Unix()},
856852
}
857853

858-
userGroup := &api.UserGroupList_UserGroup{Group: group}
859-
switch userState.Int64 {
860-
case 0:
861-
userGroup.State = int32(api.UserGroupList_UserGroup_SUPERADMIN)
862-
case 1:
863-
userGroup.State = int32(api.UserGroupList_UserGroup_ADMIN)
864-
case 2:
865-
userGroup.State = int32(api.UserGroupList_UserGroup_MEMBER)
866-
case 3:
867-
userGroup.State = int32(api.UserGroupList_UserGroup_JOIN_REQUEST)
854+
userGroup := &api.UserGroupList_UserGroup{
855+
Group: group,
856+
State: &wrappers.Int32Value{
857+
Value: int32(userState.Int64),
858+
},
868859
}
869860

870861
userGroups = append(userGroups, userGroup)

0 commit comments

Comments
 (0)