ping reporting
This commit is contained in:
@@ -8,6 +8,7 @@ using UnityEngine.InputSystem;
|
||||
#endif
|
||||
public class NetPlayer : NetworkBehaviour
|
||||
{
|
||||
const float PingReportIntervalSeconds = 30f;
|
||||
|
||||
[SyncVar]
|
||||
public int userId;
|
||||
@@ -99,6 +100,7 @@ public class NetPlayer : NetworkBehaviour
|
||||
bool isDragging;
|
||||
Vector2 lastDragScreenPosition;
|
||||
bool serverDragActive;
|
||||
Coroutine pingReportCoroutine;
|
||||
|
||||
#region EMOTES
|
||||
public void SendTextEmote(string txtName){
|
||||
@@ -158,10 +160,16 @@ public class NetPlayer : NetworkBehaviour
|
||||
if(isLocalPlayer){
|
||||
localPlayer = this;
|
||||
SetupInputPanel();
|
||||
pingReportCoroutine = StartCoroutine(CoReportPingPeriodically());
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy(){
|
||||
if (pingReportCoroutine != null)
|
||||
{
|
||||
StopCoroutine(pingReportCoroutine);
|
||||
pingReportCoroutine = null;
|
||||
}
|
||||
if(localPlayer == this){
|
||||
localPlayer = null;
|
||||
}
|
||||
@@ -555,4 +563,29 @@ public class NetPlayer : NetworkBehaviour
|
||||
GameOverCanvas.instance.OnRematchCancelled();
|
||||
}
|
||||
|
||||
IEnumerator CoReportPingPeriodically()
|
||||
{
|
||||
var wait = new WaitForSecondsRealtime(PingReportIntervalSeconds);
|
||||
while (isLocalPlayer)
|
||||
{
|
||||
yield return wait;
|
||||
|
||||
if (!NetworkClient.active || !NetworkClient.isConnected)
|
||||
continue;
|
||||
if (LoginManager.instance == null || string.IsNullOrEmpty(LoginManager.AuthToken))
|
||||
continue;
|
||||
|
||||
int matchId = GameManager.DedicatedMatchId;
|
||||
if (matchId <= 0)
|
||||
continue;
|
||||
|
||||
int pingMs = Mathf.Max(0, Mathf.RoundToInt((float)(NetworkTime.rtt * 1000.0)));
|
||||
LoginManager.instance.ReportPing(matchId, pingMs, (ok, err, report) =>
|
||||
{
|
||||
if (!ok && !string.IsNullOrEmpty(err))
|
||||
Logger.Log("Ping report failed: " + err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user