-
Notifications
You must be signed in to change notification settings - Fork 13
/
meseeks.go
722 lines (619 loc) · 20.3 KB
/
meseeks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
package bus
import (
"context"
"errors"
"fmt"
"strings"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/proto"
"github.com/domino14/liwords/pkg/entity"
"github.com/domino14/liwords/pkg/gameplay"
"github.com/domino14/liwords/pkg/mod"
"github.com/domino14/liwords/pkg/user"
pb "github.com/domino14/liwords/rpc/api/proto/ipc"
ms "github.com/domino14/liwords/rpc/api/proto/mod_service"
macondopb "github.com/domino14/macondo/gen/api/proto/macondo"
"github.com/domino14/macondo/game"
)
var BootedReceiversMax = 5
func (b *Bus) seekRequest(ctx context.Context, auth, userID, connID string,
data []byte) error {
if auth == "anon" {
// Require login for now (forever?)
return errors.New("please log in to start a game")
}
err := b.errIfGamesDisabled(ctx)
if err != nil {
return err
}
req := &pb.SeekRequest{}
err = proto.Unmarshal(data, req)
if err != nil {
return err
}
if len(req.BootedReceivers) > BootedReceiversMax {
return fmt.Errorf("cannot boot more than %d players", BootedReceiversMax)
}
if req.ReceivingUser != nil && receiverIsBooted(req.BootedReceivers, req.ReceivingUser.UserId) {
return fmt.Errorf("player %s has been booted", req.ReceivingUser.DisplayName)
}
gameRequest, lastOpp, err := b.gameRequestForSeek(ctx, req, userID)
if err != nil {
return err
}
err = actionExists(ctx, b.userStore, userID, gameRequest)
if err != nil {
return err
}
exists, err := b.soughtGameStore.ExistsForUser(ctx, gameRequest.RequestId)
if err != nil {
return err
}
if exists {
log.Debug().Str("user", userID).Msg("updating-seek-request")
err = b.updateSeekRequest(ctx, auth, userID, connID, req)
} else {
log.Debug().Str("user", userID).Msg("new-seek-request")
err = b.newSeekRequest(ctx, auth, userID, connID, req, gameRequest, lastOpp)
}
return err
}
func ratingKey(gameRequest *pb.GameRequest) (entity.VariantKey, error) {
timefmt, variant, err := entity.VariantFromGameReq(gameRequest)
if err != nil {
return "", err
}
return entity.ToVariantKey(gameRequest.Lexicon, variant, timefmt), nil
}
func (b *Bus) newSeekRequest(ctx context.Context, auth, userID, connID string,
req *pb.SeekRequest, gameRequest *pb.GameRequest, lastOpp string) error {
if gameRequest == nil {
return errors.New("no game request was found")
}
if req.GameRequest == nil {
req.GameRequest = gameRequest
}
// Note that the seek request should not come with a requesting user;
// instead this is in the topic/subject. It is HERE in the API server that
// we set the requesting user's display name, rating, etc.
reqUser := &pb.MatchUser{}
reqUser.IsAnonymous = auth == "anon" // this is never true here anymore, see check above
reqUser.UserId = userID
req.User = reqUser
err := entity.ValidateGameRequest(ctx, gameRequest)
if err != nil {
return err
}
// Look up user.
ratingKey, err := ratingKey(gameRequest)
if err != nil {
return err
}
req.RatingKey = string(ratingKey)
u, err := b.userStore.GetByUUID(ctx, reqUser.UserId)
if err != nil {
return err
}
reqUser.RelevantRating = u.GetRelevantRating(ratingKey)
reqUser.DisplayName = u.Username
req.SeekerConnectionId = connID
if gameRequest.PlayerVsBot {
// There is no user being matched. Find a bot to play instead.
// No need to create a match request in the store.
botToPlay := ""
if req.RematchFor != "" {
botToPlay = lastOpp
log.Debug().Str("bot", botToPlay).Msg("forcing-bot")
}
return b.newBotGame(ctx, req, botToPlay)
}
if req.ReceiverIsPermanent && req.ReceivingUser == nil {
return errors.New("receiver is marked as permanent but is nil")
}
if req.ReceivingUser != nil {
req.ReceivingUser.DisplayName = strings.TrimSpace(req.ReceivingUser.DisplayName)
receiver, err := b.userStore.Get(ctx, req.ReceivingUser.DisplayName)
if err != nil {
// No such user, most likely.
return err
}
requester, err := b.userStore.GetByUUID(ctx, reqUser.UserId)
if err != nil {
return err
}
err = checkForBlock(ctx, b, connID, requester, receiver)
if err != nil {
return err
}
req.ReceivingUser.UserId = receiver.UUID
}
sg, err := gameplay.NewSoughtGame(ctx, b.soughtGameStore, req)
if err != nil {
return err
}
log.Debug().Interface("sought-game", sg).Msg("new seek request")
return publishSeek(ctx, b, sg, userID, connID, pb.SeekState_ABSENT)
}
func (b *Bus) updateSeekRequest(ctx context.Context, auth, userID, connID string,
newReq *pb.SeekRequest) error {
// If we are here the seek exists and the game request is not nil
if newReq.GameRequest == nil {
return errors.New("nil game request for seek to update")
}
reqId := newReq.GameRequest.RequestId
sg, err := b.soughtGameStore.Get(ctx, reqId)
if err != nil {
return err
}
oldReceiverState := sg.SeekRequest.ReceiverState
seekerUserID, err := sg.SeekerUserID()
if err != nil {
return err
}
receiverUserID, err := sg.ReceiverUserID()
if err != nil {
return err
}
receiverDisplayName, err := sg.ReceiverDisplayName()
if err != nil {
return err
}
sg.SeekRequest.ReceivingUser.DisplayName = strings.TrimSpace(receiverDisplayName)
receiver, err := b.userStore.Get(ctx, receiverDisplayName)
if err != nil {
// No such user, most likely.
return err
}
requester, err := b.userStore.GetByUUID(ctx, seekerUserID)
if err != nil {
return err
}
err = checkForBlock(ctx, b, connID, receiver, requester)
if err != nil {
return err
}
if userID == seekerUserID {
sg.SeekRequest.UserState = newReq.UserState
sg.SeekRequest.BootedReceivers = newReq.BootedReceivers
} else if receiverUserID == "" || userID == receiverUserID {
sg.SeekRequest.ReceiverState = newReq.ReceiverState
} else {
return errors.New("you are not a seeker or receiver for this seek")
}
return publishSeek(ctx, b, sg, userID, connID, oldReceiverState)
}
func publishSeek(ctx context.Context, b *Bus, sg *entity.SoughtGame, userID string, connID string, oldReceiverState pb.SeekState) error {
// If both players are ready, start the game
// If the receiver is absent, send a new seek to everyone
// Otherwise, only send it to the two players
if sg.SeekRequest.ReceiverState == pb.SeekState_READY &&
sg.SeekRequest.UserState == pb.SeekState_READY {
reqId, err := sg.ID()
if err != nil {
return err
}
return b.gameAccepted(ctx, &pb.SoughtGameProcessEvent{RequestId: reqId}, userID, connID)
} else if sg.SeekRequest.ReceiverIsPermanent || sg.SeekRequest.ReceiverState != pb.SeekState_ABSENT {
log.Debug().Interface("sought-game", sg).Msg("processing seek as match")
// Update the current seek request
seekerUserID, err := sg.SeekerUserID()
if err != nil {
return err
}
receiverUserID, err := sg.ReceiverUserID()
if err != nil {
return err
}
seekerConnId, err := sg.SeekerConnID()
if err != nil {
return err
}
receiverConnId, err := sg.ReceiverConnID()
if err != nil {
return err
}
publishSeekToPlayers(b, sg, seekerUserID, seekerConnId, receiverUserID, receiverConnId)
} else {
log.Debug().Interface("sought-game", sg).Msg("publishing to lobby")
// If the receiver is absent or not permanent and this is not a match request, resend or send to everyone to let them
// know that this seek is open. If the old receiver state was absent
// and the new receiver state is not absent, this seek is no longer
// open and everyone must be notified.
publishSeekToLobby(b, sg)
}
return nil
}
func publishSeekToLobby(b *Bus, sg *entity.SoughtGame) error {
evt := entity.WrapEvent(sg.SeekRequest, pb.MessageType_SEEK_REQUEST)
outdata, err := evt.Serialize()
if err != nil {
return err
}
log.Debug().Interface("evt", evt).Msg("republishing seek request that was abandoned to lobby topic")
b.natsconn.Publish("lobby.seekRequest", outdata)
return nil
}
func publishSeekToPlayers(b *Bus, sg *entity.SoughtGame, seekerID, seekerConnID, receiverID, receiverConnID string) error {
evt := entity.WrapEvent(sg.SeekRequest, pb.MessageType_SEEK_REQUEST)
b.pubToConnectionID(seekerConnID, seekerID, evt)
if receiverConnID != "" {
log.Debug().Interface("evt", evt).Str("receiver-conn-id", receiverConnID).Msg("publishing to receiver on connID")
b.pubToConnectionID(receiverConnID, receiverID, evt)
} else {
log.Debug().Interface("evt", evt).Str("receiver", receiverID).Msg("publishing to receiver on username")
b.pubToUser(receiverID, evt, "")
}
return nil
}
func receiverIsBooted(bootedPlayers []string, receiverID string) bool {
for _, bootedPlayer := range bootedPlayers {
if bootedPlayer == receiverID {
return true
}
}
return false
}
func (b *Bus) gameRequestForSeek(ctx context.Context, req *pb.SeekRequest,
userID string) (*pb.GameRequest, string, error) {
// Get the game request from the passed in "rematchFor", if it
// is provided. Otherwise, the game request must have been provided
// in the request itself.
var gameRequest *pb.GameRequest
gameID := req.RematchFor
lastOpp := ""
if gameID == "" {
gameRequest = req.GameRequest
} else { // It's a rematch.
gm, err := b.gameStore.GetMetadata(ctx, gameID)
if err != nil {
return nil, "", err
}
// Figure out who we played against.
for _, u := range gm.Players {
if u.UserId == userID {
continue
}
lastOpp = u.UserId
}
// If this game is a rematch, set the OriginalRequestId
// to the previous game's OriginalRequestId. In this way,
// we maintain a constant OriginalRequestId value across
// rematch streaks. The OriginalRequestId is set in
// NewSoughtGame in sought_game.go
// if it is not set here. We copy the whole game request which includes
// the OriginalRequestId
gameRequest = proto.Clone(gm.GameRequest).(*pb.GameRequest)
// This will get overwritten later:
gameRequest.RequestId = ""
}
return gameRequest, lastOpp, nil
}
func validateCELLexicon(lexicon string, botType macondopb.BotRequest_BotCode) error {
// If the lexicon is not an english-language one, it is not compatible with CEL.
if strings.HasPrefix(lexicon, "NWL") ||
strings.HasPrefix(lexicon, "CSW") {
// Ironically, the CEL lexicon itself is not compatible with CEL bots,
// because CEL bots work on a word list that is a subset of the actual
// list. Just use the regular probability bots if the user is using the
// CEL lexicon.
return nil
}
if botType == macondopb.BotRequest_LEVEL1_CEL_BOT ||
botType == macondopb.BotRequest_LEVEL2_CEL_BOT ||
botType == macondopb.BotRequest_LEVEL3_CEL_BOT ||
botType == macondopb.BotRequest_LEVEL4_CEL_BOT {
return errors.New("CEL bots are not compatible with this lexicon")
}
return nil
}
func (b *Bus) newBotGame(ctx context.Context, req *pb.SeekRequest, botUserID string) error {
// NewBotGame creates and starts a new game against a bot!
var err error
var accUser *entity.User
if req.GameRequest != nil && req.GameRequest.Rules != nil &&
req.GameRequest.Rules.VariantName == string(game.VarWordSmog) {
return errors.New("the WordSmog variant is currently not supported by our bot")
}
if botUserID == "" {
accUser, err = b.userStore.GetBot(ctx, req.GameRequest.BotType)
} else {
accUser, err = b.userStore.GetByUUID(ctx, botUserID)
}
if err != nil {
return err
}
err = validateCELLexicon(req.GameRequest.Lexicon, req.GameRequest.BotType)
if err != nil {
return err
}
sg := entity.NewSoughtGame(req)
return b.instantiateAndStartGame(ctx, accUser, req.User.UserId, req.GameRequest,
sg, BotRequestID, "")
}
func (b *Bus) sendSoughtGameDeletion(ctx context.Context, sg *entity.SoughtGame) error {
return b.broadcastSeekDeletion(sg)
}
func (b *Bus) gameAccepted(ctx context.Context, evt *pb.SoughtGameProcessEvent,
userID, connID string) error {
sg, err := b.soughtGameStore.Get(ctx, evt.RequestId)
if err != nil {
return err
}
requester := sg.SeekRequest.User.UserId
gameReq := sg.SeekRequest.GameRequest
err = actionExists(ctx, b.userStore, userID, gameReq)
if err != nil {
return err
}
if requester == userID {
log.Info().Str("sender", requester).Msg("canceling seek")
err := gameplay.CancelSoughtGame(ctx, b.soughtGameStore, evt.RequestId)
if err != nil {
return err
}
// broadcast a seek deletion.
return b.sendSoughtGameDeletion(ctx, sg)
}
accUser, err := b.userStore.GetByUUID(ctx, userID)
if err != nil {
return err
}
if !sg.SeekRequest.ReceiverIsPermanent {
// If the receiver is not permanent, then we need to check that the
// requester's rating is within the range of the receiver's minimum and
// maximum ratings.
ratingKey, err := ratingKey(gameReq)
if err != nil {
return err
}
reqUser, err := b.userStore.GetByUUID(ctx, requester)
if err != nil {
return err
}
accRating, err := accUser.GetRating(ratingKey)
if err != nil {
return err
}
reqRating, err := reqUser.GetRating(ratingKey)
if err != nil {
return err
}
log.Debug().Int32("minRatRange", sg.SeekRequest.MinimumRatingRange).
Int32("maxRatRange", sg.SeekRequest.MaximumRatingRange).
Float64("accRating", accRating.Rating).
Float64("reqRating", reqRating.Rating).
Msg("ratingsinfo")
// assume min rating range is negative
if accRating.Rating < reqRating.Rating+float64(sg.SeekRequest.MinimumRatingRange) ||
accRating.Rating > reqRating.Rating+float64(sg.SeekRequest.MaximumRatingRange) {
return errors.New("your rating is not within the requested range")
}
}
// Otherwise create a game
// If the ACCEPTOR of the seek has a seek request open, we must cancel it.
err = b.deleteSoughtForUser(ctx, userID)
if err != nil {
return err
}
return b.instantiateAndStartGame(ctx, accUser, requester, gameReq, sg, evt.RequestId, connID)
}
func checkForBlock(ctx context.Context, b *Bus, connID string, accUser *entity.User, reqUser *entity.User) error {
block, err := b.blockExists(ctx, reqUser, accUser)
if err != nil {
return err
}
if block == 0 {
// requesting user is blocking the accepting user.
evt := entity.WrapEvent(&pb.ErrorMessage{
Message: "You are not able to accept " + reqUser.Username + "'s requests.",
}, pb.MessageType_ERROR_MESSAGE)
b.pubToConnectionID(connID, accUser.UUID, evt)
return nil
} else if block == 1 {
// accepting user is blocking requesting user. They should not be able to
// see their requests but maybe they didn't refresh after blocking.
evt := entity.WrapEvent(&pb.ErrorMessage{
Message: reqUser.Username + " is on your block list, thus you cannot play against them.",
}, pb.MessageType_ERROR_MESSAGE)
b.pubToConnectionID(connID, accUser.UUID, evt)
}
return nil
}
func (b *Bus) seekDeclined(ctx context.Context, evt *pb.DeclineSeekRequest, userID string) error {
// the sending user declined the match request. Send this declination
// to the matcher and delete the request.
sg, err := b.soughtGameStore.Get(ctx, evt.RequestId)
if err != nil {
return err
}
if sg.SeekRequest.ReceivingUser.UserId != userID {
return errors.New("request userID does not match")
}
err = gameplay.CancelSoughtGame(ctx, b.soughtGameStore, evt.RequestId)
if err != nil {
return err
}
requester := sg.SeekRequest.User.UserId
decliner := userID
wrapped := entity.WrapEvent(evt, pb.MessageType_DECLINE_SEEK_REQUEST)
// Publish decline to requester
err = b.pubToUser(requester, wrapped, "")
if err != nil {
return err
}
wrapped = entity.WrapEvent(&pb.SoughtGameProcessEvent{RequestId: evt.RequestId},
pb.MessageType_SOUGHT_GAME_PROCESS_EVENT)
return b.pubToUser(decliner, wrapped, "")
}
func (b *Bus) broadcastSeekDeletion(sg *entity.SoughtGame) error {
id, err := sg.ID()
if err != nil {
return err
}
toSend := entity.WrapEvent(&pb.SoughtGameProcessEvent{RequestId: id},
pb.MessageType_SOUGHT_GAME_PROCESS_EVENT)
data, err := toSend.Serialize()
if err != nil {
return err
}
p, err := sg.ReceiverIsPermanent()
if err != nil {
return err
}
if !p {
return b.natsconn.Publish("lobby.soughtGameProcess", data)
}
if sg.SeekRequest == nil {
return errors.New("seek-request-nil")
}
if sg.SeekRequest.ReceivingUser == nil {
return errors.New("seek-request-receiving-user-nil")
}
if sg.SeekRequest.User == nil {
return errors.New("seek-request-user-nil")
}
// If it's a permanent receiver, we need to publish to both users only.
err = b.pubToUser(sg.SeekRequest.ReceivingUser.UserId, toSend, "")
if err != nil {
return err
}
return b.pubToUser(sg.SeekRequest.User.UserId, toSend, "")
}
func (b *Bus) sendReceiverAbsent(ctx context.Context, req *entity.SoughtGame) error {
isMatch, err := req.ReceiverIsPermanent()
if err != nil {
return err
}
if isMatch {
seekerConnID, err := req.SeekerConnID()
if err != nil {
return err
}
seekerID, err := req.SeekerUserID()
if err != nil {
return err
}
evt := entity.WrapEvent(req.SeekRequest, pb.MessageType_SEEK_REQUEST)
return b.pubToConnectionID(seekerConnID, seekerID, evt)
} else {
evt := entity.WrapEvent(req.SeekRequest, pb.MessageType_SEEK_REQUEST)
outdata, err := evt.Serialize()
if err != nil {
return err
}
return b.natsconn.Publish("lobby.soughtGameProcess", outdata)
}
}
func (b *Bus) broadcastGameCreation(g *entity.Game, acceptor, requester *entity.User) error {
timefmt, variant, err := entity.VariantFromGameReq(g.GameReq)
if err != nil {
return err
}
ratingKey := entity.ToVariantKey(g.GameReq.Lexicon, variant, timefmt)
players := []*pb.PlayerInfo{
{Rating: acceptor.GetRelevantRating(ratingKey),
UserId: acceptor.UUID,
Nickname: acceptor.Username},
{Rating: requester.GetRelevantRating(ratingKey),
UserId: requester.UUID,
Nickname: requester.Username},
}
gameInfo := &pb.GameInfoResponse{Players: players,
GameRequest: g.GameReq, GameId: g.GameID()}
if g.TournamentData != nil {
gameInfo.TournamentDivision = g.TournamentData.Division
gameInfo.TournamentId = g.TournamentData.Id
gameInfo.TournamentRound = int32(g.TournamentData.Round)
gameInfo.TournamentGameIndex = int32(g.TournamentData.GameIndex)
}
toSend := entity.WrapEvent(gameInfo, pb.MessageType_ONGOING_GAME_EVENT)
data, err := toSend.Serialize()
if err != nil {
return err
}
err = b.natsconn.Publish("lobby.newLiveGame", data)
if err != nil {
return err
}
// Also publish to tournament channel if this is a tournament game.
if g.TournamentData != nil && g.TournamentData.Id != "" {
channelName := "tournament." + g.TournamentData.Id + ".newLiveGame"
err = b.natsconn.Publish(channelName, data)
if err != nil {
return err
}
}
return nil
}
func (b *Bus) deleteSoughtForUser(ctx context.Context, userID string) error {
req, err := b.soughtGameStore.DeleteForUser(ctx, userID)
if err != nil {
return err
}
if req == nil {
return nil
}
log.Debug().Interface("req", req).Str("userID", userID).Msg("deleting-sought")
err = b.sendSoughtGameDeletion(ctx, req)
if err != nil {
return err
}
req, err = b.soughtGameStore.UpdateForReceiver(ctx, userID)
if err != nil {
return err
}
if req == nil {
return nil
}
log.Debug().Interface("req", req).Str("userID", userID).Msg("deleting-sought")
return b.sendReceiverAbsent(ctx, req)
}
func (b *Bus) deleteSoughtForConnID(ctx context.Context, connID string) error {
req, err := b.soughtGameStore.DeleteForSeekerConnID(ctx, connID)
if err != nil {
return err
}
if req == nil {
return nil
}
log.Debug().Interface("req", req).Str("connID", connID).Msg("deleting-sought-for-connid")
err = b.sendSoughtGameDeletion(ctx, req)
if err != nil {
return err
}
req, err = b.soughtGameStore.UpdateForReceiverConnID(ctx, connID)
if err != nil {
return err
}
if req == nil {
return nil
}
log.Debug().Interface("req", req).Str("connID", connID).Msg("updating-receiver-for-connid")
return b.sendReceiverAbsent(ctx, req)
}
func (b *Bus) openSeeks(ctx context.Context, receiverID string, tourneyID string) (*entity.EventWrapper, error) {
sgs, err := b.soughtGameStore.ListOpenSeeks(ctx, receiverID, tourneyID)
if err != nil {
return nil, err
}
log.Debug().Str("receiver", receiverID).Interface("open-matches", sgs).Msg("open-matches")
pbobj := &pb.SeekRequests{Requests: []*pb.SeekRequest{}}
for _, sg := range sgs {
pbobj.Requests = append(pbobj.Requests, sg.SeekRequest)
}
evt := entity.WrapEvent(pbobj, pb.MessageType_SEEK_REQUESTS)
return evt, nil
}
func actionExists(ctx context.Context, us user.Store, userID string, req *pb.GameRequest) error {
_, err := mod.ActionExists(ctx, us, userID, false, []ms.ModActionType{ms.ModActionType_SUSPEND_ACCOUNT, ms.ModActionType_SUSPEND_GAMES})
if err != nil {
return err
}
if req.RatingMode == pb.RatingMode_RATED {
_, err = mod.ActionExists(ctx, us, userID, false, []ms.ModActionType{ms.ModActionType_SUSPEND_RATED_GAMES})
if err != nil {
return err
}
}
return nil
}