Skip to content

Commit

Permalink
Revert "Fixed NatHelper"
Browse files Browse the repository at this point in the history
This reverts commit 1675b79.
  • Loading branch information
trippyone committed Feb 2, 2024
1 parent 1675b79 commit 667132d
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions Source/Networking/NatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,60 +90,63 @@ private void WebSocket_OnError(object sender, WebSocketSharp.ErrorEventArgs e)

private void ProcessMessage(string message)
{
JObject msgObj = JObject.Parse(message);

if(msgObj.ContainsKey("requestId") && msgObj.ContainsKey("requestType"))
{
var requestId = msgObj["requestId"].ToString();
var requestType = msgObj["requestType"].ToString();
var profileId = msgObj["profileId"].ToString();
JObject msgObj = JObject.Parse(message);

if (requestType == "getEndPointsRequest")
if(msgObj.ContainsKey("requestId") && msgObj.ContainsKey("requestType"))
{
var getServerEndPointsResponse = new Dictionary<string, object>
var requestId = msgObj["requestId"].ToString();
var requestType = msgObj["requestType"].ToString();
var profileId = msgObj["profileId"].ToString();

if (requestType == "getEndPointsRequest")
{
{ "requestId", requestId },
{ "requestType", "getEndPointsResponse" },
{ "profileId", profileId },
{ "publicEndPoints", PublicEndPoints }
};
var getServerEndPointsResponse = new Dictionary<string, object>
{
{ "requestId", requestId },
{ "requestType", "getEndPointsResponse" },
{ "profileId", profileId },
{ "publicEndPoints", PublicEndPoints }
};

WebSocket.Send(JsonConvert.SerializeObject(getServerEndPointsResponse));
}

WebSocket.Send(JsonConvert.SerializeObject(getServerEndPointsResponse));
}
if (requestType == "natPunchRequest")
{
var publicEndPoints = msgObj["publicEndPoints"].ToObject<Dictionary<string, string>>();

if (requestType == "natPunchRequest")
{
var publicEndPoints = msgObj["publicEndPoints"].ToObject<Dictionary<string, string>>();
if (publicEndPoints.ContainsKey("stun"))
{
PunchNat(publicEndPoints["stun"]);
}

if (publicEndPoints.ContainsKey("stun"))
{
PunchNat(publicEndPoints["stun"]);
var natPunchResponse = new Dictionary<string, object>
{
{ "requestId", requestId },
{ "requestType", "natPunchResponse" },
{ "profileId", profileId },
};

WebSocket.Send(JsonConvert.SerializeObject(natPunchResponse));
}

var natPunchResponse = new Dictionary<string, object>
if (requestType == "getEndPointsResponse")
{
{ "requestId", requestId },
{ "requestType", "natPunchResponse" },
{ "profileId", profileId },
};

WebSocket.Send(JsonConvert.SerializeObject(natPunchResponse));
}
var publicEndPoints = msgObj["publicEndPoints"].ToObject<Dictionary<string, string>>();

if (requestType == "getEndPointsResponse")
{
var publicEndPoints = msgObj["publicEndPoints"].ToObject<Dictionary<string, string>>();
if(RequestCompletionSourceList.ContainsKey(requestId))
RequestCompletionSourceList[requestId].SetResult(publicEndPoints);
}

if(RequestCompletionSourceList.ContainsKey(requestId))
RequestCompletionSourceList[requestId].SetResult(publicEndPoints);
if (requestType == "natPunchResponse")
{
if (RequestCompletionSourceList.ContainsKey(requestId))
RequestCompletionSourceList[requestId].SetResult(true);
}
}

if (requestType == "natPunchResponse")
{
if (RequestCompletionSourceList.ContainsKey(requestId))
RequestCompletionSourceList[requestId].SetResult(true);
}
}

}

public async Task<Dictionary<string, string>> GetEndpointsRequestAsync(string serverId, string profileId)
Expand Down

0 comments on commit 667132d

Please sign in to comment.