feedback report 3 done

This commit is contained in:
2026-09-24 13:12:15 +05:30
parent 5ac8f92006
commit d4c7f5dd46
21 changed files with 11867 additions and 153 deletions
+77 -9
View File
@@ -165,6 +165,8 @@ public class NetPlayer : NetworkBehaviour
}
void OnDestroy(){
bool opponentLeft = localPlayer != null && localPlayer != this;
if (pingReportCoroutine != null)
{
StopCoroutine(pingReportCoroutine);
@@ -173,6 +175,13 @@ public class NetPlayer : NetworkBehaviour
if(localPlayer == this){
localPlayer = null;
}
if (ReferenceEquals(RedPlayer, this))
RedPlayer = null;
if (ReferenceEquals(BluePlayer, this))
BluePlayer = null;
if (opponentLeft && GameOverCanvas.instance != null)
GameOverCanvas.instance.NotifyOpponentDisconnected();
}
void SetupInputPanel(){
@@ -426,12 +435,25 @@ public class NetPlayer : NetworkBehaviour
}
/// <summary>
public const string RematchDeclinedMessage = "Rematch declined.";
public const string OpponentLeftRematchMessage = "Opponent left.";
/// <summary>Server-only. True after a rematch is requested until it is accepted, declined, or fails.</summary>
static bool rematchRequestPending;
/// <summary>
/// Request a rematch with the opponent.
/// </summary>
public void RequestRematch(){
int maxBetLimitCoins = GameOverCanvas.GetPersonalBetLimit();
if(isServer){
if (CountConnectedPlayers() < 2)
{
rematchRequestPending = false;
OnRematchCancelledServer(OpponentLeftRematchMessage);
return;
}
rematchRequestPending = true;
GameOverCanvas.instance.OnRematchRequested(maxBetLimitCoins);
RpcRequestRematch(maxBetLimitCoins);
}else{
@@ -442,6 +464,13 @@ public class NetPlayer : NetworkBehaviour
[Command]
void CmdRequestRematch(int maxBetLimitCoins){
Logger.Log("Rematch requested, max bet limit coins: " + maxBetLimitCoins);
if (CountConnectedPlayers() < 2)
{
rematchRequestPending = false;
OnRematchCancelledServer(OpponentLeftRematchMessage);
return;
}
rematchRequestPending = true;
if(isServerOnly){
//server
@@ -473,8 +502,15 @@ public class NetPlayer : NetworkBehaviour
void OnRematchAcceptedServer(int betRcCoins ){
if(!isServer){ return; }
rematchRequestPending = false;
if(betRcCoins <= 0){
OnRematchCancelledServer();
OnRematchCancelledServer(RematchDeclinedMessage);
return;
}
if(RedPlayer == null || BluePlayer == null){
OnRematchCancelledServer(OpponentLeftRematchMessage);
return;
}
@@ -562,22 +598,54 @@ public class NetPlayer : NetworkBehaviour
MessageBoxDialog.Show("Rematch failed", string.IsNullOrEmpty(errorMessage) ? "Could not start a rematch." : errorMessage);
}
void OnRematchCancelledServer(){
static int CountConnectedPlayers()
{
if (!NetworkServer.active)
return 0;
int count = 0;
foreach (NetworkConnectionToClient conn in NetworkServer.connections.Values)
{
if (conn != null && conn.identity != null && conn.identity.GetComponent<NetPlayer>() != null)
count++;
}
return count;
}
/// <summary>
/// Server-only. If a rematch request is still pending, cancel it before the disconnecting player is destroyed.
/// </summary>
public static void CancelPendingRematchOnDisconnect(NetPlayer disconnectingPlayer)
{
if (!NetworkServer.active || !rematchRequestPending)
return;
rematchRequestPending = false;
NetPlayer messenger = disconnectingPlayer;
if (messenger == null)
messenger = RedPlayer != null ? RedPlayer : BluePlayer;
if (messenger != null)
messenger.OnRematchCancelledServer(OpponentLeftRematchMessage);
}
void OnRematchCancelledServer(string message){
if(!isServer){ return; }
RpcCancelRematch();
RpcCancelRematch(message);
if(!isServerOnly){
CancelRematch();
CancelRematch(message);
}
}
[ClientRpc]
void RpcCancelRematch(){
CancelRematch();
void RpcCancelRematch(string message){
CancelRematch(message);
}
void CancelRematch(){
GameOverCanvas.instance.OnRematchCancelled();
void CancelRematch(string message){
if (GameOverCanvas.instance != null)
GameOverCanvas.instance.OnRematchCancelled(message);
}
IEnumerator CoReportPingPeriodically()