Skip to content

Commit

Permalink
Merge pull request #128 from SeoulTechTCPGame/develop-LANMulti
Browse files Browse the repository at this point in the history
같은 네트워크 내에서 상대방 탐색 구현
  • Loading branch information
seong0929 authored Oct 16, 2023
2 parents 3b692db + 57d70c6 commit 9d67aed
Show file tree
Hide file tree
Showing 12 changed files with 1,747 additions and 284 deletions.
5 changes: 3 additions & 2 deletions Assets/Common Scripts/BlockItUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public BlockItUser()
byte[] randomNumber = new byte[4];
rng.GetBytes(randomNumber);

string randomHash = BitConverter.ToString(randomNumber).Replace("-", "").Substring(0, 8);
_nickname = "Guest#" + randomHash;
string randomHash = BitConverter.ToString(randomNumber).Replace("-", "");
_id = "Guest#" + randomHash;
_nickname = "Guest#" + randomHash.Substring(0, 8);
}
}

Expand Down
17 changes: 10 additions & 7 deletions Assets/Common Scripts/BlockItUserDataManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Diagnostics.Eventing.Reader;
using System.Transactions;
using UnityEngine;
using UnityEngine.Networking;

Expand Down Expand Up @@ -119,12 +119,12 @@ private IEnumerator RegisterCoroutine(string json)
#endregion

#region 유저 정보 요청 POST
public void GetUserData(BlockItUser targetUser)
public void GetUserData(BlockItUser targetUser, System.Action onComplete = default)
{
StartCoroutine(GetUserDataCoroutine(targetUser));
StartCoroutine(GetUserDataCoroutine(targetUser, onComplete));
}

private IEnumerator GetUserDataCoroutine(BlockItUser targetUser)
private IEnumerator GetUserDataCoroutine(BlockItUser targetUser, System.Action onComplete)
{
using (UnityWebRequest www = new UnityWebRequest(userDataRequestUrl, "POST"))
{
Expand All @@ -151,6 +151,8 @@ private IEnumerator GetUserDataCoroutine(BlockItUser targetUser)
Debug.LogError("Server Error: " + www.error);
}
}

onComplete?.Invoke();
}
#endregion

Expand Down Expand Up @@ -233,12 +235,12 @@ private IEnumerator UploadProfileImageCoroutine(BlockItUser targetUser, byte[] i
#endregion

#region 프로필 사진 요청 POST
public void GetProfileImage(BlockItUser targetUser)
public void GetProfileImage(BlockItUser targetUser, System.Action onComplete = default)
{
StartCoroutine(GetProfileImageCoroutine(targetUser));
StartCoroutine(GetProfileImageCoroutine(targetUser, onComplete));
}

private IEnumerator GetProfileImageCoroutine(BlockItUser targetUser)
private IEnumerator GetProfileImageCoroutine(BlockItUser targetUser, System.Action onComplete)
{
UnityWebRequest www = UnityWebRequest.Get(userProfileImageRequestUrl + "/" + targetUser.Id);
yield return www.SendWebRequest();
Expand All @@ -252,6 +254,7 @@ private IEnumerator GetProfileImageCoroutine(BlockItUser targetUser)
{
Debug.LogError("Firebase GID '" + CurrentLoginSession.Singleton.User.Id + "'(닉네임: " + CurrentLoginSession.Singleton.User.Nickname + ") 프로필 사진 다운로드 실패");
}
onComplete?.Invoke();
}
#endregion
}
59 changes: 7 additions & 52 deletions Assets/Common Scripts/NetworkMessage/UserNetworkMessage.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,20 @@
using Mirror;
using System;

#region 유저 정보를 요청송신할 메세지 약속
#region 클라이언트에서 유저 정보 전송 시 메세지
[Serializable]
public struct RequestUserDataMessage : NetworkMessage
public struct OpponentUserDataMessage : NetworkMessage
{
public string userId;
}

[Serializable]
public struct ResponseUserDataMessage : NetworkMessage
{
public string nickname;
public int totalUserCount;
public int userRank;
public int playCount;
public int winCount;
public byte[] profileImage;
public bool success;
}
#endregion

#region 회원 가입 시 송신할 메세지 약속
[Serializable]
public struct RequestUserSignUpMessage : NetworkMessage
{
public string userId;
public string nickname;
}

[Serializable]
public struct ResponseUserSignUpMessage : NetworkMessage
{
public bool success;
public string userName;
public bool isGuest;
}
#endregion

#region 이미지 업로드 시 송수신할 메세지 정의
#region 해당 도전 수락 메세지
[Serializable]
public struct RequestProfileImageUploadMessage : NetworkMessage
{
public string userId;
public byte[] image;
}

public struct ResponseProfileImageUploadMessage : NetworkMessage
{
public bool success;
}
#endregion

#region 닉네임 변경 시 송수신할 메세지 정의
public struct RequestChangeUserNameMessage: NetworkMessage
{
public string userId;
public string nickname;
}

public struct ResponseChangeUserNameMessage : NetworkMessage
public struct ConnectionAcceptanceMessage : NetworkMessage
{
public bool success;
public bool isDupcliate;
public bool doAccept;
}
#endregion
1 change: 1 addition & 0 deletions Assets/Scenes/Loading/Loading.unity
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
serverUrl:
_usePropertyField: 0
--- !u!1 &187667802
GameObject:
m_ObjectHideFlags: 0
Expand Down
Loading

0 comments on commit 9d67aed

Please sign in to comment.