package ludo import ( "server/msg" "github.com/name5566/leaf/gate" ) //根据玩家要匹配的对局,给玩家寻找和的房间 func matchRoom(matchInfo *msg.MatchLudo, userId string, user_agent gate.Agent) { roomList := GetRoomsByLevel(matchInfo, msg.RoomStatus_AWAIT) if len(roomList) == 0 { // Create new room if none available room_info := CreateRoom(matchInfo, userId) if room_info == nil { sendMatchErrorMsg(user_agent, 101, "not find player") } } else { // 如果房间具备开始的条件 isFullPlayer, err_info := JoinRoom(roomList[0], matchInfo, userId) if err_info != nil { if isFullPlayer { startGame(roomList[0]) } } else { sendMatchErrorMsg(user_agent, 101, "not find player") } } } func sendMatchErrorMsg(user_agent gate.Agent, error_code int32, msg_str string) { if user_agent != nil { user_agent.WriteMsg(&msg.ResMatchLudo{ Success: false, ErrMsg: &msg.MsgError{ ErrorCode: error_code, ErrorMsg: msg_str, }, }) } }