Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-userProxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-userProxy
Commits
62f6240b
Commit
62f6240b
authored
Jul 21, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:进房离房心跳
parent
01804402
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
153 additions
and
0 deletions
+153
-0
coder.go
common/coder.go
+3
-0
main.go
main.go
+105
-0
userCenter.proto
protocol/userCenter.proto
+30
-0
userProxy.proto
protocol/userProxy.proto
+15
-0
No files found.
common/coder.go
View file @
62f6240b
...
...
@@ -69,6 +69,9 @@ const (
MsgTypeMatchV2Confirm
=
141
// 匹配-v2-确认
MsgTypeMatchV2CallReady
=
142
// 匹配-v2-callReady
MsgTypeMatchV2AddTimeGift
=
143
// 匹配-v2-送礼加时长
MsgTypeEnterRoom
=
152
// 用户进房
MsgTypeLeaveRoom
=
153
// 用户离房
MsgTypeRoomHeartbeat
=
154
// 房间心跳
)
const
(
...
...
main.go
View file @
62f6240b
...
...
@@ -241,6 +241,18 @@ func serverWebsocket(w http.ResponseWriter, r *http.Request) {
}
}
}
}
else
if
msgType
==
common
.
MsgTypeEnterRoom
{
if
err
:=
processEnterRoom
(
logger
,
ci
.
Uid
,
pbData
);
err
!=
nil
{
logger
.
Errorf
(
"processEnterRoom fail:%v"
,
err
)
}
}
else
if
msgType
==
common
.
MsgTypeLeaveRoom
{
if
err
:=
processLeaveRoom
(
logger
,
ci
.
Uid
,
pbData
);
err
!=
nil
{
logger
.
Errorf
(
"processLeaveRoom fail:%v"
,
err
)
}
}
else
if
msgType
==
common
.
MsgTypeRoomHeartbeat
{
if
err
:=
processRoomHeartbeat
(
logger
,
ci
.
Uid
,
pbData
);
err
!=
nil
{
logger
.
Errorf
(
"processRoomHeartbeat fail:%v"
,
err
)
}
}
else
{
logger
.
Warnf
(
"Unknown message type %d"
,
msgType
)
}
...
...
@@ -401,6 +413,54 @@ func processBizRequest(logger *log.Entry, uid uint64, pbData []byte) (*userProxy
}
}
func
processEnterRoom
(
logger
*
log
.
Entry
,
uid
uint64
,
pbData
[]
byte
)
error
{
msg
:=
&
userProxy
.
EnterRoom
{}
err
:=
proto
.
Unmarshal
(
pbData
,
msg
)
if
err
==
nil
{
err
,
status
:=
doEnterRoom
(
uid
,
msg
.
GroupId
)
if
err
==
nil
&&
status
==
common
.
Login_success
{
logger
.
Infof
(
"enter room success,uid:%v,group:%v"
,
uid
,
msg
.
GroupId
)
}
else
{
logger
.
Warnf
(
"login RPC failed for %d, %v"
,
status
,
err
)
}
return
err
}
else
{
return
err
}
}
func
processLeaveRoom
(
logger
*
log
.
Entry
,
uid
uint64
,
pbData
[]
byte
)
error
{
msg
:=
&
userProxy
.
LeaveRoom
{}
err
:=
proto
.
Unmarshal
(
pbData
,
msg
)
if
err
==
nil
{
err
,
status
:=
doLeaveRoom
(
uid
,
msg
.
GroupId
)
if
err
==
nil
&&
status
==
common
.
Login_success
{
logger
.
Infof
(
"leave room success,uid:%v,group:%v"
,
uid
,
msg
.
GroupId
)
}
else
{
logger
.
Warnf
(
"login RPC failed for %d, %v"
,
status
,
err
)
}
return
err
}
else
{
return
err
}
}
func
processRoomHeartbeat
(
logger
*
log
.
Entry
,
uid
uint64
,
pbData
[]
byte
)
error
{
msg
:=
&
userProxy
.
RoomHeartBeat
{}
err
:=
proto
.
Unmarshal
(
pbData
,
msg
)
if
err
==
nil
{
err
,
status
:=
doRoomHeartbeat
(
uid
,
msg
.
GroupId
)
if
err
==
nil
&&
status
==
common
.
Login_success
{
logger
.
Infof
(
"room heartbeat success,uid:%v,group:%v"
,
uid
,
msg
.
GroupId
)
}
else
{
logger
.
Warnf
(
"login RPC failed for %d, %v"
,
status
,
err
)
}
return
err
}
else
{
return
err
}
}
// 直接发匹配成功消息,调试用
func
homePage
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
rsp
:=
"Home Page"
...
...
@@ -568,6 +628,51 @@ func doBizRequest(uid uint64, msgType uint32, payLoad string) (uint32, error) {
}
}
func
doEnterRoom
(
uid
uint64
,
groupId
string
)
(
error
,
uint32
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
3
)
defer
cancel
()
r
,
err
:=
userClient
.
EnterRoom
(
ctx
,
&
userCenter
.
EnterRoomMessage
{
Uid
:
uid
,
GroupId
:
groupId
,
})
if
err
==
nil
&&
r
!=
nil
{
return
err
,
r
.
Status
}
else
{
return
err
,
0
}
}
func
doLeaveRoom
(
uid
uint64
,
groupId
string
)
(
error
,
uint32
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
3
)
defer
cancel
()
r
,
err
:=
userClient
.
LeaveRoom
(
ctx
,
&
userCenter
.
LeaveRoomMessage
{
Uid
:
uid
,
GroupId
:
groupId
,
})
if
err
==
nil
&&
r
!=
nil
{
return
err
,
r
.
Status
}
else
{
return
err
,
0
}
}
func
doRoomHeartbeat
(
uid
uint64
,
groupId
string
)
(
error
,
uint32
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
3
)
defer
cancel
()
r
,
err
:=
userClient
.
RoomHeartbeat
(
ctx
,
&
userCenter
.
RoomHeartbeatMessage
{
Uid
:
uid
,
GroupId
:
groupId
,
})
if
err
==
nil
&&
r
!=
nil
{
return
err
,
r
.
Status
}
else
{
return
err
,
0
}
}
var
kacp
=
keepalive
.
ClientParameters
{
Time
:
10
*
time
.
Second
,
// send pings every 10 seconds if there is no activity
Timeout
:
time
.
Second
,
// wait 1 second for ping ack before considering the connection dead
...
...
protocol/userCenter.proto
View file @
62f6240b
...
...
@@ -85,6 +85,33 @@ message BizMessageRsp {
uint32
status
=
1
;
}
message
EnterRoomMessage
{
uint64
uid
=
1
;
string
groupId
=
2
;
}
message
EnterRoomMessageRsp
{
uint32
status
=
1
;
}
message
LeaveRoomMessage
{
uint64
uid
=
1
;
string
groupId
=
2
;
}
message
LeaveRoomMessageRsp
{
uint32
status
=
1
;
}
message
RoomHeartbeatMessage
{
uint64
uid
=
1
;
string
groupId
=
2
;
}
message
RoomHeartbeatMessageRsp
{
uint32
status
=
1
;
}
service
Router
{
rpc
route
(
RouteMessage
)
returns
(
RouteMessageRsp
)
{}
rpc
kickUser
(
KickMessage
)
returns
(
KickMessageRsp
)
{}
...
...
@@ -96,4 +123,7 @@ service User {
rpc
multicast
(
MulticastMessage
)
returns
(
MulticastMessageRsp
)
{}
rpc
broadcast
(
BroadcastMessage
)
returns
(
BroadcastMessageRsp
)
{}
rpc
transmit
(
BizMessage
)
returns
(
BizMessageRsp
)
{}
rpc
enterRoom
(
EnterRoomMessage
)
returns
(
EnterRoomMessageRsp
)
{}
rpc
leaveRoom
(
LeaveRoomMessage
)
returns
(
LeaveRoomMessageRsp
)
{}
rpc
roomHeartbeat
(
RoomHeartbeatMessage
)
returns
(
RoomHeartbeatMessageRsp
)
{}
}
\ No newline at end of file
protocol/userProxy.proto
View file @
62f6240b
...
...
@@ -411,4 +411,19 @@ message SvipUpgrade {
User
user
=
1
;
uint32
svip_level
=
2
;
string
group_id
=
3
;
}
/* id == 152 用户进房 */
message
EnterRoom
{
string
group_id
=
1
;
}
/* id == 153 用户离房 */
message
LeaveRoom
{
string
group_id
=
1
;
}
/* id == 154 房间心跳 */
message
RoomHeartBeat
{
string
group_id
=
1
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment