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

104 lines
2.0 KiB

1 year ago
package game
import (
"server/call"
"server/common"
"server/pb"
"github.com/liangdas/mqant/gate"
"github.com/liangdas/mqant/log"
)
func DisConnect(data *pb.ClientDisConnectNotify) {
p := GetPlayer(int(data.UserID))
if p == nil {
return
}
p.T.PutQueue("nf", func() {
p.Disconnect()
})
}
func OptPlayer(data *pb.InnerOptPlayer) {
p := GetPlayer(int(data.UID))
if p == nil {
return
}
switch data.Opt {
case common.OptPlayerTypeKick:
p.T.PutQueue("nf", func() {
p.Disconnect()
})
}
}
func OnTableInfo(session gate.Session, req *pb.GameCommonReq) (string, error) {
p := FindPlayer(session)
if p == nil {
log.Error("player %v not found", session.GetUserID())
return "", nil
}
p.T.PutQueue("nf", func() {
p.SubPlayer.TableInfo()
})
return "", nil
}
func Enter(session gate.Session, req *pb.GameMsgEnterGameReq) (string, error) {
p := FindPlayer(session)
if p == nil {
uid := session.GetUserIDInt64()
if uid <= 0 {
return "", nil
}
rid := findRoom(int(req.SubID))
gameRoom := GetRoom(rid)
if gameRoom == nil {
return "", nil
}
gameRoom.Enter(int(uid), session, common.CurrencyType(req.CurrencyType))
return "", nil
}
p.T.PutQueue("nf", func() {
p.Send(int(pb.GameProtocol_EnterGameResp), &pb.GameCommonResp{})
p.SubPlayer.TableInfo()
})
return "", nil
}
func findRoom(room int) (roomID int) {
list := call.GetConfigGameRoom(ThisGameID)
practice := []*common.ConfigGameRoom{}
for i := len(list) - 1; i >= 0; i-- {
one := list[i]
rid := one.RoomID
if room > 0 && rid != room {
continue
}
if !one.Open {
continue
}
if one.RoomType == RoomTypePractice {
practice = append(practice, one)
continue
}
return rid
}
// 以上找不到合适的,进入练习场
for _, v := range practice {
return v.RoomID
}
return
}
func OnLeave(session gate.Session, req *pb.GameCommonReq) (string, error) {
p := FindPlayer(session)
if p == nil {
return "", nil
}
p.T.PutQueue("nf", func() {
p.Leave()
})
return "", nil
}