xy 1 semana atrás
pai
commit
503fc52ce2
2 arquivos alterados com 17 adições e 5 exclusões
  1. 3 2
      src/server/game/ludo/match.go
  2. 14 3
      src/server/game/ludo/room.go

+ 3 - 2
src/server/game/ludo/match.go

@@ -27,8 +27,9 @@ func matchRoom(matchInfo *msg.MatchLudo, userId string, user_agent gate.Agent) {
 	if len(roomList) == 0 {
 		// Create new room if none available
 		fmt.Printf("没找到房间匹配一个!\n")
-		room_info := CreateRoom(matchInfo, userId)
-		if room_info == nil {
+		_, err := CreateRoom(matchInfo, userId)
+		if err != nil {
+			fmt.Printf("%s\n", err.Error())
 			sendMatchErrorMsg(user_agent, 101, "not find player")
 		}
 	} else {

+ 14 - 3
src/server/game/ludo/room.go

@@ -68,10 +68,10 @@ func GetRoomsByLevel(matchInfo *msg.MatchLudo, roomStatus msg.RoomStatus) []*msg
 	return result
 }
 
-func CreateRoom(matchInfo *msg.MatchLudo, userId string) *msg.RoomInfo {
+func CreateRoom(matchInfo *msg.MatchLudo, userId string) (*msg.RoomInfo, error) {
 	userInfo, err_info := redismgr.GetUserInfoFromRedis(userId)
 	if err_info != nil {
-		return nil
+		return nil, errors.New("没在Redis找到该玩家 :" + userId)
 	}
 	// 生成房间ID(不加锁)
 	roomId := generateRoomID()
@@ -96,10 +96,21 @@ func CreateRoom(matchInfo *msg.MatchLudo, userId string) *msg.RoomInfo {
 			},
 		},
 	}
+	user_agent := getAgentByUserId(userId)
+	if user_agent == nil {
+		return nil, errors.New("getAgentByUserId 失败 :" + userId)
+	}
+	user_agent.SetUserData(&msg.UserInfo{
+		UserId: userInfo.UserId,
+		Name:   userInfo.Name,
+		MCoin:  userInfo.MCoin,
+		MHead:  userInfo.MHead,
+		RoomId: roomId,
+	})
 	gameConfig.mu.Lock()
 	defer gameConfig.mu.Unlock()
 	gameConfig.RoomMap[newRoom.Id] = newRoom
-	return newRoom
+	return newRoom, nil
 }
 
 func JoinRoom(room *msg.RoomInfo, matchInfo *msg.MatchLudo, userId string) (bool, error) {