You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.0 KiB
Go

package room
import (
"dcg/game/manager"
pbRoom "dcg/game/pb/room"
"git.noahlan.cn/northlan/ngs/component"
"git.noahlan.cn/northlan/ngs/session"
)
type (
Logic struct {
component.Base
}
)
func NewRoomLogic() *Logic {
return &Logic{}
}
func (m *Logic) CMD() string {
return "room"
}
func (m *Logic) Init() {
}
func (m *Logic) AfterInit() {
session.Lifetime.OnClosed(func(s *session.Session) {
manager.GameManager.RoomManager.LeaveRoom(s)
})
}
func (m *Logic) Shutdown() {
manager.GameManager.RoomManager.Clean()
}
func (m *Logic) Join(s *session.Session, msg *pbRoom.JoinRoomReq) error {
// uid - liveRoomId
err := s.Bind(msg.LiveRoomId)
if err != nil {
return err
}
manager.GameManager.DataManager.SetSessionData(s, manager.NewGameData(msg.LiveRoomId))
if err = manager.GameManager.JoinRoom(s, msg.GameType, msg.LiveRoomId); err != nil {
return s.Response(&pbRoom.JoinRoomResp{
Code: 500,
Result: err.Error(),
})
}
return s.Response(&pbRoom.JoinRoomResp{
Code: 200,
Result: "success",
})
}