forked from lonng/nanoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
76 lines (61 loc) · 1.17 KB
/
helper.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
package game
import (
"runtime"
"strings"
"github.com/lonnng/nanoserver/internal/errutil"
"github.com/lonnng/nanoserver/internal/protocol"
"github.com/lonnng/nano/session"
)
const (
ModeTrios = 3 // 三人模式
ModeFours = 4 // 四人模式
)
func verifyOptions(opts *protocol.DeskOptions) bool {
if opts == nil {
return false
}
if opts.Mode != ModeTrios && opts.Mode != 4 {
return false
}
if opts.MaxRound != 1 && opts.MaxRound != 4 && opts.MaxRound != 8 && opts.MaxRound != 16 {
return false
}
return true
}
func requireCardCount(round int) int {
if c, ok := consume[round]; ok {
return c
}
c := 2
switch round {
case 8:
c = 3
case 16:
c = 4
}
return c
}
func playerWithSession(s *session.Session) (*Player, error) {
p, ok := s.Value(kCurPlayer).(*Player)
if !ok {
return nil, errutil.YXErrPlayerNotFound
}
return p, nil
}
func stack() string {
buf := make([]byte, 10000)
n := runtime.Stack(buf, false)
buf = buf[:n]
s := string(buf)
// skip nano frames lines
const skip = 7
count := 0
index := strings.IndexFunc(s, func(c rune) bool {
if c != '\n' {
return false
}
count++
return count == skip
})
return s[index+1:]
}