match.go 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package ludo
  2. import (
  3. "server/msg"
  4. "github.com/name5566/leaf/gate"
  5. )
  6. //根据玩家要匹配的对局,给玩家寻找和的房间
  7. func matchRoom(matchInfo *msg.MatchLudo, userId string, user_agent gate.Agent) {
  8. roomList := GetRoomsByLevel(matchInfo, msg.RoomStatus_AWAIT)
  9. if len(roomList) == 0 {
  10. // Create new room if none available
  11. room_info := CreateRoom(matchInfo, userId)
  12. if room_info == nil {
  13. sendMatchErrorMsg(user_agent, 101, "not find player")
  14. }
  15. } else {
  16. // 如果房间具备开始的条件
  17. isFullPlayer, err_info := JoinRoom(roomList[0], matchInfo, userId)
  18. if err_info != nil {
  19. if isFullPlayer {
  20. startGame(roomList[0])
  21. }
  22. } else {
  23. sendMatchErrorMsg(user_agent, 101, "not find player")
  24. }
  25. }
  26. }
  27. func sendMatchErrorMsg(user_agent gate.Agent, error_code int32, msg_str string) {
  28. if user_agent != nil {
  29. user_agent.WriteMsg(&msg.ResMatchLudo{
  30. Success: false,
  31. ErrMsg: &msg.MsgError{
  32. ErrorCode: error_code,
  33. ErrorMsg: msg_str,
  34. },
  35. })
  36. }
  37. }