안녕하세요 개발자님.
현재 제공해주신 구현 코드를 참고하여 매칭 인원이 8명이라는 가정하에 테스트를 진행하고 있습니다.
허나 테스트상에서는 문제가 재현되지 않아 추가적으로 SDK에서 발생하는 에러케이스의 확인이 필요할 것 같습니다.
아래와 같이 개발자님이 보내주신 기존 코드에서 에러 로그로 확인이 불가한 부분에 에러가 발생할만한 부분에 Debug.Log 조치를 취했습니다.
아래 코드를 이용하여 플레이 중 동일 증상이 발생하신다면 빠르게 에러케이스와 로그 대조하여 확인해보도록 하곘습니다. 명쾌한 해결 방법 드리지 못하여 죄송합니다.(추가된 코드는 [뒤끝] 디버깅 주석 참조)
- OnJoinMatchMaking에서 에러가 발생하여 CreateRoom이 안되는 케이스를 위한 Debug.Log(Not Connected 발생 부분)
- 접속한 세션에 문제가 발생하여 OnSessionJoinInServer에서 에러하는 것을 확인하기 위한 Debug.Log
- OnMatchInGameStart 호출을 확인하기 위한 Debug.Log
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BackEnd;
using BackEnd.Tcp;
using UnityEngine.SceneManagement;
public class BackEndMatch : MonoBehaviour
{
ErrorInfo errorinfo;
[SerializeField]
bool isConnectMatchServer;
string RoomToken;
WaitForSeconds repeatTime = new WaitForSeconds(0.1f);
MatchUserGameRecord MyStartData, EnemyStartData;
[SerializeField]
GameObject WaitStartGame;
AsyncOperation op;
bool isReCreateMatchRoom = false;
private void Awake()
{
{
//WaitStartGame.SetActive(true);
//GameObject.FindWithTag("MyStart").GetComponent<StartProfile>().Init("운영자", 1024, Skin.None);
//GameObject.FindWithTag("EnemyStart").GetComponent<StartProfile>().Init("시", 1402, Skin.None);
}
try//전판 인게임서버에서 나오지 못했을 경우를 대비
{
Backend.Match.LeaveGameServer();
}
catch
{
}
//StartCoroutine(Poller());
Matchready();
Backend.Match.OnMatchMakingRoomCreate = (args) =>
{
Debug.Log("OnMatchMakingRoomCreate : " + args.ErrInfo); // [뒤끝] - 디버깅
print("매칭룸");
};
Backend.Match.OnMatchMakingResponse = (args) =>
{
print(args.ErrInfo);
switch (args.ErrInfo)
{
case ErrorCode.Match_InProgress:
print("매칭 신청 성공");
MatchingEventScript.Instance.MatchMaking();
break;
case ErrorCode.Success:
print("매칭 성공");
JoinInGameServer(args.RoomInfo.m_inGameServerEndPoint.m_address, args.RoomInfo.m_inGameServerEndPoint.m_port);//1단계
RoomToken = args.RoomInfo.m_inGameRoomToken;//인게임 서버접속시 안쓰이고 게임방 입장에 쓰임
break;
case ErrorCode.Match_MatchMakingCanceled:
print("매칭 취소");
MatchingEventScript.Instance.MatchMakingStop();
break;
default:
print(args.ErrInfo);
break;
}
};
void JoinInGameServer(string serverAddress, ushort serverPort) // 임의의 함수
{
bool isReconnect = false;//재접속한건지. 디폴트값은 false
//ErrorInfo errorInfo = null;
if (!Backend.Match.JoinGameServer(serverAddress, serverPort, isReconnect, out ErrorInfo errorInfo))//2단계
StopMatching();
}
Backend.Match.OnSessionJoinInServer = (args) =>
{
if (args.ErrInfo != ErrorInfo.Success)
{
Debug.LogError(args.ErrInfo); // [뒤끝] - 디버깅
}
Backend.Match.JoinGameRoom(RoomToken);//3단계
};
Backend.Match.OnMatchMakingRoomCreate = (args) =>
{
isReCreateMatchRoom = false;
Backend.Match.RequestMatchMaking(MatchType.Random, MatchModeType.OneOnOne, "2022-02-10T04:34:45.143Z");
};
Backend.Match.OnSessionListInServer = (args) =>//겜방 들어가자마자
{
MatchDoor.instance.isClose(true);
op = SceneManager.LoadSceneAsync("Ingame");
op.allowSceneActivation = false;
CharacterFromWeb.Instance.userRecord = new List<MatchUserGameRecord>(args.GameRecords);
foreach (var a in args.GameRecords)
{
print(a.m_sessionId);
}
if (args.GameRecords.Count == CharacterFromWeb.FullCount)
{
CharacterFromWeb.Instance.isLast = true;
print("im last");
CharacterFromWeb.Instance.SetUserCharacters(2);
}
};
Backend.Match.OnMatchInGameAccess = (args) =>//다른애들 들어올 때마다
{
print(args.GameRecord.m_sessionId);
if (!CharacterFromWeb.Instance.userRecord.Exists(x => x.m_nickname == args.GameRecord.m_nickname))//중복시 넣지않음
CharacterFromWeb.Instance.userRecord.Add(args.GameRecord);
};
Backend.Match.OnMatchInGameStart = () =>
{
Debug.Log("OnMatchInGameStart 호출"); // [뒤끝] - 디버깅
op.allowSceneActivation = true;
};
Backend.Match.OnJoinMatchMakingServer = (args) =>
{
if (args.ErrInfo != ErrorInfo.Success)
{
Debug.LogError($"OnJoinMatchMakingServer : {args.ErrInfo}"); // [뒤끝] - 디버깅
}
isConnectMatchServer = true;
print("매칭서버 입장(람다식)");
if (isReCreateMatchRoom)
{
FastMatchMaking();
}
};
Backend.Match.OnLeaveMatchMakingServer = (args) =>
{
if (args.ErrInfo != ErrorInfo.Success)
{
Debug.LogError($"OnLeaveMatchMakingServer : {args.ErrInfo}"); // [뒤끝] - 디버깅
}
isConnectMatchServer = false;
print("매칭서버 퇴장(람다식)");
if (isReCreateMatchRoom)
{
Matchready();
}
};
}
void Poll()
{
Backend.Match.Poll();
}
public void Matchready()
{
if (Backend.Match.JoinMatchMakingServer(out errorinfo))
{
Debug.Log("매칭서버진입성공");
Debug.Log(errorinfo);
}
else
{
Debug.LogError($"에러 : {errorinfo.ToString()}"); // [뒤끝] - 디버깅
Debug.Log(errorinfo);
isReCreateMatchRoom = false;
}
}
public void FastMatchMaking()
{
//if (!isConnectMatchServer)
// Matchready();
try
{
Backend.Match.CreateMatchRoom();
}
catch (System.Exception e)
{
Debug.LogError(e.Message);
ReCreateMatchRoom();
//SceneManager.LoadScene("startscene");
}
}
public void ReCreateMatchRoom()
{
isReCreateMatchRoom = true;
Backend.Match.LeaveMatchMakingServer();
}
public void StopMatching()
{
Backend.Match.CancelMatchMaking();
}
// IEnumerator Poller()
// {
// while (true)
// {
// Backend.Match.Poll();
// //print(Backend.Match.Poll());
// yield return repeatTime;
// }
// }
private void OnDestroy()
{
Backend.Match.LeaveMatchRoom();
}
}