-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to maintain nat punch port open
- Loading branch information
Showing
11 changed files
with
239 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
using Fika.Core.Networking.NatPunch; | ||
using Comfort.Common; | ||
using Fika.Core.Networking; | ||
|
||
namespace Fika.Core.Coop.Components | ||
{ | ||
public class FikaServerStunQuery : MonoBehaviour | ||
{ | ||
private Coroutine stunQueryRoutine; | ||
|
||
public void StartServerStunQueryRoutine() | ||
{ | ||
stunQueryRoutine = StartCoroutine(StunQuery()); | ||
} | ||
|
||
public void StopServerStunQueryRoutine() | ||
{ | ||
if (stunQueryRoutine != null) | ||
{ | ||
StopCoroutine(stunQueryRoutine); | ||
stunQueryRoutine = null; | ||
} | ||
} | ||
|
||
private IEnumerator StunQuery() | ||
{ | ||
while (true) | ||
{ | ||
var fikaServer = Singleton<FikaServer>.Instance; | ||
|
||
while (fikaServer == null || fikaServer.NetServer == null || fikaServer.NatPunchServer == null) | ||
yield return null; | ||
|
||
fikaServer.NetServer.Stop(); | ||
|
||
var localPort = 0; | ||
var currentStunIpEndPoint = fikaServer.NatPunchServer.StunIpEndpoint; | ||
|
||
if (currentStunIpEndPoint != null) | ||
localPort = currentStunIpEndPoint.Local.Port; | ||
|
||
var stunIpEndPoint = NatPunchUtils.CreateStunEndPoint(localPort); | ||
|
||
fikaServer.NatPunchServer.StunIpEndpoint = stunIpEndPoint; | ||
|
||
fikaServer.NetServer.Start(stunIpEndPoint.Local.Port); | ||
|
||
yield return new WaitForSeconds(60); | ||
} | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
StopServerStunQueryRoutine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.