Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
xuzhenhao
/
rlw-dev
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 10edf9c6
authored
Dec 09, 2017
by
xuzhenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了返回个人排行信息的时候可以看到前后玩家信息的功能
1 parent
22da6d98
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
11 deletions
ranklist/ranklist.go
sdkredis/ice_gametopREDIS.go
ranklist/ranklist.go
View file @
10edf9c
...
...
@@ -50,6 +50,7 @@ func main() {
sdkhttp
.
RegisterFunc
(
"RankList"
,
RankList
)
sdkhttp
.
RegisterFunc
(
"SubmitScore"
,
SubmitScore
)
sdkhttp
.
RegisterFunc
(
"SingleRank"
,
SingleRank
)
sdkhttp
.
RegisterFunc
(
"SingleRangeRank"
,
SingleRangeRank
)
// web
sdkhttp
.
RegisterFunc
(
"CreateRank"
,
CreateRank
)
...
...
@@ -137,12 +138,45 @@ func SingleRank(c *gin.Context) {
gtid
:=
c
.
Query
(
"gtid"
)
gid
:=
c
.
Query
(
"gid"
)
toptype
:=
c
.
Query
(
"toptype"
)
log
.
Printf
(
"SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s]
\n
"
,
uid
,
gtid
,
gid
,
toptype
)
igt
:=
sdkredis
.
IceGameTopRedisGetSingleUserRankInfo
(
uid
,
gtid
,
gid
,
toptype
)
fmt
.
Println
(
igt
)
msg
:=
new
(
Msg
)
if
igt
==
nil
{
err
:=
errors
.
New
(
"gametop name or game name not exist"
)
msg
.
ErrMsg
=
err
.
Error
()
msg
.
ErrCode
=
"105101"
}
else
{
msg
.
ErrCode
=
"0"
msg
.
ErrMsg
=
"success"
msg
.
Obj
=
igt
}
jsonByte
,
jsonerr
:=
json
.
Marshal
(
msg
)
if
jsonerr
!=
nil
{
log
.
Printf
(
"marshal err[%v]
\n
"
,
jsonerr
)
}
jsonStr
:=
string
(
jsonByte
)
c
.
String
(
http
.
StatusOK
,
jsonStr
)
}
/**
* 获得单个用户以及前后用户的排行信息
*/
func
SingleRangeRank
(
c
*
gin
.
Context
)
{
uid
:=
c
.
Query
(
"uid"
)
gtid
:=
c
.
Query
(
"gtid"
)
gid
:=
c
.
Query
(
"gid"
)
toptype
:=
c
.
Query
(
"toptype"
)
prerank
:=
c
.
Query
(
"prerank"
)
nextrank
:=
c
.
Query
(
"nextrank"
)
log
.
Printf
(
"SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s] prerank[%s] nextrank[%s]
\n
"
,
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
igt
:=
sdkredis
.
IceGameTopRedisGetSingleUserRankInfo
(
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
igt
:=
sdkredis
.
IceGameTopRedisGetSingleUserRan
geRan
kInfo
(
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
fmt
.
Println
(
igt
)
infoList
:=
make
(
map
[
string
]
interface
{},
0
)
infoList
[
"icesimbaRuoLianWangGameUserGameTopRankInfoList"
]
=
igt
msg
:=
new
(
Msg
)
if
igt
==
nil
{
err
:=
errors
.
New
(
"gametop name or game name not exist"
)
...
...
@@ -151,7 +185,7 @@ func SingleRank(c *gin.Context) {
}
else
{
msg
.
ErrCode
=
"0"
msg
.
ErrMsg
=
"success"
msg
.
Obj
=
i
g
t
msg
.
Obj
=
i
nfoLis
t
}
jsonByte
,
jsonerr
:=
json
.
Marshal
(
msg
)
if
jsonerr
!=
nil
{
...
...
sdkredis/ice_gametopREDIS.go
View file @
10edf9c
...
...
@@ -269,7 +269,98 @@ func IceGametopRedisSubmitScore(uid string, gtid string, gid string, score strin
/**
* 获取单个用户的排名信息
*/
func
IceGameTopRedisGetSingleUserRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
,
prerank
string
,
nextrank
string
)
(
igt
*
IGT
)
{
func
IceGameTopRedisGetSingleUserRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
)
(
igt
*
IGT
)
{
// 连接redis
redisConn
:=
RedisClient
.
GetConn
()
defer
RedisClose
(
redisConn
)
// 获取当前排行榜是正序还是反序/
var
sorceorder
string
iceGameTopSet
,
_
,
err
:=
sdkdb
.
IceGameTopSetQueryOne
(
gtid
,
gid
,
toptype
)
if
err
==
nil
{
if
iceGameTopSet
!=
nil
{
sorceorder
=
iceGameTopSet
.
SORCEORDER
toptype
=
iceGameTopSet
.
TOPTYPE
//不需要对传入的toptype做判断,根据gid和gtid就可以获得排行
}
else
{
return
}
}
else
{
return
}
// 排序
var
strList
[]
string
var
sorterr
error
if
sorceorder
==
"0"
{
strList
,
sorterr
=
RedisSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
}
else
if
sorceorder
==
"1"
{
strList
,
sorterr
=
RedisReverseSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
}
if
sorterr
!=
nil
{
log
.
Println
(
"RedisSort err[%v]"
,
sorterr
)
return
}
else
if
len
(
strList
)
==
0
{
log
.
Println
(
"rank has no data"
)
}
igt
=
new
(
IGT
)
index
:=
1
var
resultstr
string
var
valuecount
=
2
_
,
err
=
RedisDBSelect
(
redisConn
,
4
)
if
err
!=
nil
{
log
.
Printf
(
"select db err:"
,
err
)
}
for
i
:=
0
;
i
<
len
(
strList
);
i
+=
2
{
startIndex
:=
strings
.
Index
(
strList
[
i
],
"uid:"
)
+
4
endIndex
:=
strings
.
Index
(
strList
[
i
],
":gtid"
)
currUID
:=
common
.
Substr2
(
strList
[
i
],
startIndex
,
endIndex
)
if
currUID
==
uid
{
igt
.
UID
=
uid
igt
.
RankIndex
=
index
igt
.
MyKey
=
strList
[
i
+
1
]
//查询储存昵称以及头像url的redis
var
err
error
resultstr
,
err
=
RedisGetKV
(
redisConn
,
"GUID:"
+
igt
.
UID
)
if
err
!=
nil
{
log
.
Println
(
"get redis err:"
,
err
)
}
r
,
err
:=
regexp
.
Compile
(
`\|([^\|])*\|`
)
if
err
!=
nil
{
log
.
Println
(
"err:"
,
err
)
}
// 使用正则匹配需要的值
result
:=
r
.
FindAllString
(
resultstr
,
valuecount
)
//去除用来匹配的特殊字符“|“
if
result
!=
nil
{
for
key
,
value
:=
range
result
{
value
=
value
[
1
:
len
(
value
)
-
1
]
log
.
Println
(
value
)
result
[
key
]
=
value
}
//result 为切片,储存了所有匹配到的特定值
igt
.
NickName
=
result
[
0
]
//第一个为昵称
igt
.
HeadPortraitURL
=
result
[
1
]
//第二个为头像url
}
}
index
++
}
_
,
err
=
RedisDBSelect
(
redisConn
,
2
)
if
err
!=
nil
{
log
.
Printf
(
"select db err:"
,
err
)
}
return
}
/**
* 获取单个用户以及前后用户的排名信息
*/
func
IceGameTopRedisGetSingleUserRangeRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
,
prerank
string
,
nextrank
string
)
(
igt
[]
*
IGT
)
{
// 连接redis
redisConn
:=
RedisClient
.
GetConn
()
defer
RedisClose
(
redisConn
)
...
...
@@ -344,7 +435,7 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
log
.
Println
(
"rank has no data"
)
}
igt
=
new
(
IGT
)
igt
=
make
([]
IGT
,
len
(
strList
)
/
2
)
index
:=
1
var
resultstr
string
var
valuecount
=
2
...
...
@@ -357,12 +448,12 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
// endIndex := strings.Index(strList[i], ":gtid")
// currUID := common.Substr2(strList[i], startIndex, endIndex)
igt
.
UID
=
uid
igt
.
RankIndex
=
index
igt
.
MyKey
=
strList
[
i
+
1
]
igt
[
i
/
2
]
.
UID
=
uid
igt
[
i
/
2
]
.
RankIndex
=
index
igt
[
i
/
2
]
.
MyKey
=
strList
[
i
+
1
]
//查询储存昵称以及头像url的redis
var
err
error
resultstr
,
err
=
RedisGetKV
(
redisConn
,
"GUID:"
+
igt
.
UID
)
resultstr
,
err
=
RedisGetKV
(
redisConn
,
"GUID:"
+
igt
[
i
/
2
]
.
UID
)
if
err
!=
nil
{
log
.
Println
(
"get redis err:"
,
err
)
}
...
...
@@ -381,8 +472,8 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
result
[
key
]
=
value
}
//result 为切片,储存了所有匹配到的特定值
igt
.
NickName
=
result
[
0
]
//第一个为昵称
igt
.
HeadPortraitURL
=
result
[
1
]
//第二个为头像url
igt
[
i
/
2
]
.
NickName
=
result
[
0
]
//第一个为昵称
igt
[
i
/
2
]
.
HeadPortraitURL
=
result
[
1
]
//第二个为头像url
}
index
++
...
...
@@ -394,7 +485,6 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
return
}
func
IceGameTopRedisCreateRank
(
gtid
string
,
gid
string
,
toptype
string
,
gtname
string
,
sorcetype
string
,
sorcesub
string
,
sorceorder
string
)
error
{
// 连接redis
redisConn
:=
RedisClient
.
GetConn
()
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment