rematch complete

This commit is contained in:
2026-05-04 23:57:56 +05:30
parent 82287d74fb
commit 184d4fbc04
8 changed files with 1489 additions and 1166 deletions
File diff suppressed because one or more lines are too long
+79 -61
View File
@@ -1,62 +1,80 @@
Logger initiated at 5/4/2026 5:31:47 PM Logger initiated at 5/4/2026 11:49:38 PM
[5/4/2026 5:31:47 PM] Cupid init success [5/4/2026 11:49:38 PM] Cupid init success
[5/4/2026 5:31:48 PM] Starting matchmake as warlock2 [5/4/2026 11:49:44 PM] Starting matchmake as warlock2
[5/4/2026 5:31:49 PM] Starting matchmake as warlock [5/4/2026 11:49:45 PM] Starting matchmake as warlock
[5/4/2026 5:31:52 PM] Still waiting: {"ok":true,"entry_fee":21,"rc_prize":37,"for_red":{"Players":[{"Name":"warlock2","LastSeen":1777896112344,"UserId":5,"l10_wins":3,"l10_losses":4}],"GameName":"soccar","Port":26825,"InitTime":1777896112344,"entry_fee":21,"match_id":248,"rc_prize":37,"your_team":"red"},"for_blue":null} [5/4/2026 11:49:47 PM] Still waiting: {"ok":true,"entry_fee":21,"rc_prize":37,"for_red":{"Players":[{"Name":"warlock","LastSeen":1777918787128,"UserId":4,"l10_wins":4,"l10_losses":2}],"GameName":"soccar","Port":26271,"InitTime":1777918787128,"entry_fee":21,"match_id":256,"rc_prize":37,"your_team":"red"},"for_blue":null}
[5/4/2026 5:31:53 PM] Got into a room [5/4/2026 11:49:48 PM] Got into a room
[5/4/2026 5:31:53 PM] {"ok":true,"entry_fee":21,"rc_prize":37,"for_red":{"Players":[{"Name":"warlock2","LastSeen":1777896112344,"UserId":5,"l10_wins":3,"l10_losses":4},{"Name":"warlock","LastSeen":1777896113172,"UserId":4,"l10_wins":4,"l10_losses":3}],"GameName":"soccar","Port":26825,"InitTime":1777896112344,"entry_fee":21,"match_id":248,"instance_started":true,"rc_prize":37,"your_team":"red"},"for_blue":{"Players":[{"Name":"warlock2","LastSeen":1777896112344,"UserId":5,"l10_wins":3,"l10_losses":4},{"Name":"warlock","LastSeen":1777896113172,"UserId":4,"l10_wins":4,"l10_losses":3}],"GameName":"soccar","Port":26825,"InitTime":1777896112344,"entry_fee":21,"match_id":248,"instance_started":true,"rc_prize":37,"your_team":"blue"}} [5/4/2026 11:49:48 PM] {"ok":true,"entry_fee":21,"rc_prize":37,"for_red":{"Players":[{"Name":"warlock","LastSeen":1777918787128,"UserId":4,"l10_wins":4,"l10_losses":2},{"Name":"warlock2","LastSeen":1777918788243,"UserId":5,"l10_wins":2,"l10_losses":4}],"GameName":"soccar","Port":26271,"InitTime":1777918787128,"entry_fee":21,"match_id":256,"instance_started":true,"rc_prize":37,"your_team":"red"},"for_blue":{"Players":[{"Name":"warlock","LastSeen":1777918787128,"UserId":4,"l10_wins":4,"l10_losses":2},{"Name":"warlock2","LastSeen":1777918788243,"UserId":5,"l10_wins":2,"l10_losses":4}],"GameName":"soccar","Port":26271,"InitTime":1777918787128,"entry_fee":21,"match_id":256,"instance_started":true,"rc_prize":37,"your_team":"blue"}}
[5/4/2026 5:31:53 PM] Configured dedicated match reporting for match id 248 with secret 38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328 and internal api base https://kickkingsapi.playpoolstudios.com [5/4/2026 11:49:48 PM] Configured dedicated match reporting for match id 256 with secret 38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328 and internal api base https://kickkingsapi.playpoolstudios.com
[5/4/2026 5:31:53 PM] Setting cupid to load game scene [5/4/2026 11:49:48 PM] Setting cupid to load game scene
[5/4/2026 5:31:53 PM] Loading game scene [5/4/2026 11:49:48 PM] Loading game scene
[5/4/2026 5:31:53 PM] Got into a room [5/4/2026 11:49:48 PM] Got into a room
[5/4/2026 5:31:53 PM] {"ok":true,"entry_fee":21,"rc_prize":37,"for_red":{"Players":[{"Name":"warlock2","LastSeen":1777896113824,"UserId":5,"l10_wins":3,"l10_losses":4},{"Name":"warlock","LastSeen":1777896113172,"UserId":4,"l10_wins":4,"l10_losses":3}],"GameName":"soccar","Port":26825,"InitTime":1777896112344,"entry_fee":21,"match_id":248,"instance_started":true,"rc_prize":37,"your_team":"red"},"for_blue":{"Players":[{"Name":"warlock2","LastSeen":1777896113824,"UserId":5,"l10_wins":3,"l10_losses":4},{"Name":"warlock","LastSeen":1777896113172,"UserId":4,"l10_wins":4,"l10_losses":3}],"GameName":"soccar","Port":26825,"InitTime":1777896112344,"entry_fee":21,"match_id":248,"instance_started":true,"rc_prize":37,"your_team":"blue"}} [5/4/2026 11:49:48 PM] {"ok":true,"entry_fee":21,"rc_prize":37,"for_red":{"Players":[{"Name":"warlock","LastSeen":1777918788612,"UserId":4,"l10_wins":4,"l10_losses":2},{"Name":"warlock2","LastSeen":1777918788243,"UserId":5,"l10_wins":2,"l10_losses":4}],"GameName":"soccar","Port":26271,"InitTime":1777918787128,"entry_fee":21,"match_id":256,"instance_started":true,"rc_prize":37,"your_team":"red"},"for_blue":{"Players":[{"Name":"warlock","LastSeen":1777918788612,"UserId":4,"l10_wins":4,"l10_losses":2},{"Name":"warlock2","LastSeen":1777918788243,"UserId":5,"l10_wins":2,"l10_losses":4}],"GameName":"soccar","Port":26271,"InitTime":1777918787128,"entry_fee":21,"match_id":256,"instance_started":true,"rc_prize":37,"your_team":"blue"}}
[5/4/2026 5:31:53 PM] Configured dedicated match reporting for match id 248 with secret 38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328 and internal api base https://kickkingsapi.playpoolstudios.com [5/4/2026 11:49:48 PM] Configured dedicated match reporting for match id 256 with secret 38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328 and internal api base https://kickkingsapi.playpoolstudios.com
[5/4/2026 5:31:53 PM] Setting cupid to load game scene [5/4/2026 11:49:48 PM] Setting cupid to load game scene
[5/4/2026 5:31:53 PM] Loading game scene [5/4/2026 11:49:48 PM] Loading game scene
[5/4/2026 5:32:00 PM] Starting client at $kickkingsapi.playpoolstudios.com:26825 [5/4/2026 11:49:55 PM] Starting client at $kickkingsapi.playpoolstudios.com:26271
[5/4/2026 5:32:00 PM] Client connected [5/4/2026 11:49:55 PM] Starting client at $kickkingsapi.playpoolstudios.com:26271
[5/4/2026 5:32:00 PM] Starting client at $kickkingsapi.playpoolstudios.com:26825 [5/4/2026 11:49:55 PM] Client connected
[5/4/2026 5:32:00 PM] Client connected [5/4/2026 11:49:55 PM] Client connected
[5/4/2026 5:32:08 PM] Selected team changed from Red to Blue [5/4/2026 11:50:05 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:08 PM] Selected team changed from Red to Blue [5/4/2026 11:50:05 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:14 PM] Selected team changed from Blue to Red [5/4/2026 11:50:11 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:14 PM] Selected team changed from Blue to Red [5/4/2026 11:50:11 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:20 PM] Selected team changed from Red to Blue [5/4/2026 11:50:15 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:20 PM] Selected team changed from Red to Blue [5/4/2026 11:50:15 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:25 PM] Selected team changed from Blue to Red [5/4/2026 11:50:24 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:26 PM] Selected team changed from Blue to Red [5/4/2026 11:50:24 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:28 PM] Score changed from 0 to 1 [5/4/2026 11:50:28 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:28 PM] Score changed from 0 to 1 [5/4/2026 11:50:28 PM] Score changed from 0 to 1
[5/4/2026 5:32:31 PM] Selected team changed from Red to Blue [5/4/2026 11:50:28 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:31 PM] Selected team changed from Red to Blue [5/4/2026 11:50:28 PM] Score changed from 0 to 1
[5/4/2026 5:32:39 PM] Selected team changed from Blue to Red [5/4/2026 11:50:31 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:39 PM] Selected team changed from Blue to Red [5/4/2026 11:50:31 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:45 PM] Selected team changed from Red to Blue [5/4/2026 11:50:38 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:45 PM] Selected team changed from Red to Blue [5/4/2026 11:50:38 PM] Selected team changed from Red to Blue
[5/4/2026 5:32:52 PM] Selected team changed from Blue to Red [5/4/2026 11:50:43 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:52 PM] Selected team changed from Blue to Red [5/4/2026 11:50:43 PM] Selected team changed from Blue to Red
[5/4/2026 5:32:57 PM] Selected team changed from Red to Blue [5/4/2026 11:50:48 PM] Score changed from 0 to 1
[5/4/2026 5:32:57 PM] Selected team changed from Red to Blue [5/4/2026 11:50:48 PM] Score changed from 0 to 1
[5/4/2026 5:33:08 PM] Selected team changed from Blue to Red [5/4/2026 11:50:51 PM] Selected team changed from Red to Blue
[5/4/2026 5:33:08 PM] Selected team changed from Blue to Red [5/4/2026 11:50:51 PM] Selected team changed from Red to Blue
[5/4/2026 5:33:13 PM] Selected team changed from Red to Blue [5/4/2026 11:50:58 PM] Selected team changed from Blue to Red
[5/4/2026 5:33:13 PM] Selected team changed from Red to Blue [5/4/2026 11:50:58 PM] Selected team changed from Blue to Red
[5/4/2026 5:33:17 PM] Score changed from 0 to 1 [5/4/2026 11:51:00 PM] Score changed from 1 to 2
[5/4/2026 5:33:17 PM] Score changed from 0 to 1 [5/4/2026 11:51:00 PM] Score changed from 1 to 2
[5/4/2026 5:33:20 PM] Selected team changed from Blue to Red [5/4/2026 11:51:03 PM] Selected team changed from Red to Blue
[5/4/2026 5:33:20 PM] Selected team changed from Blue to Red [5/4/2026 11:51:03 PM] Selected team changed from Red to Blue
[5/4/2026 5:33:29 PM] Selected team changed from Red to Blue [5/4/2026 11:51:10 PM] Selected team changed from Blue to Red
[5/4/2026 5:33:30 PM] Selected team changed from Red to Blue [5/4/2026 11:51:10 PM] Selected team changed from Blue to Red
[5/4/2026 5:33:35 PM] Selected team changed from Blue to Red [5/4/2026 11:51:13 PM] Score changed from 2 to 3
[5/4/2026 5:33:35 PM] Selected team changed from Blue to Red [5/4/2026 11:51:13 PM] Score changed from 2 to 3
[5/4/2026 5:33:39 PM] Score changed from 1 to 2 [5/4/2026 11:51:28 PM] Configured dedicated match reporting for match id 257 with secret 38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328 and internal api base https://kickkingsapi.playpoolstudios.com
[5/4/2026 5:33:39 PM] Score changed from 1 to 2 [5/4/2026 11:51:28 PM] Configured dedicated match reporting for match id 257 with secret 38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328 and internal api base https://kickkingsapi.playpoolstudios.com
[5/4/2026 5:33:42 PM] Selected team changed from Red to Blue [5/4/2026 11:51:28 PM] Client disconnected
[5/4/2026 5:33:42 PM] Selected team changed from Red to Blue [5/4/2026 11:51:28 PM] Client disconnected
[5/4/2026 5:33:52 PM] Selected team changed from Blue to Red [5/4/2026 11:51:32 PM] Starting client at $kickkingsapi.playpoolstudios.com:26667
[5/4/2026 5:33:52 PM] Selected team changed from Blue to Red [5/4/2026 11:51:32 PM] Starting client at $kickkingsapi.playpoolstudios.com:26667
[5/4/2026 5:33:57 PM] Score changed from 2 to 3 [5/4/2026 11:51:32 PM] Client connected
[5/4/2026 5:33:57 PM] Score changed from 2 to 3 [5/4/2026 11:51:32 PM] Client connected
[5/4/2026 5:34:39 PM] Client disconnected [5/4/2026 11:51:40 PM] Selected team changed from Red to Blue
[5/4/2026 5:34:42 PM] Client disconnected [5/4/2026 11:51:40 PM] Selected team changed from Red to Blue
[5/4/2026 11:51:46 PM] Selected team changed from Blue to Red
[5/4/2026 11:51:46 PM] Selected team changed from Blue to Red
[5/4/2026 11:51:49 PM] Score changed from 0 to 1
[5/4/2026 11:51:49 PM] Score changed from 0 to 1
[5/4/2026 11:51:52 PM] Selected team changed from Red to Blue
[5/4/2026 11:51:52 PM] Selected team changed from Red to Blue
[5/4/2026 11:51:58 PM] Selected team changed from Blue to Red
[5/4/2026 11:51:58 PM] Selected team changed from Blue to Red
[5/4/2026 11:52:02 PM] Score changed from 1 to 2
[5/4/2026 11:52:02 PM] Score changed from 1 to 2
[5/4/2026 11:52:05 PM] Selected team changed from Red to Blue
[5/4/2026 11:52:05 PM] Selected team changed from Red to Blue
[5/4/2026 11:52:12 PM] Selected team changed from Blue to Red
[5/4/2026 11:52:12 PM] Selected team changed from Blue to Red
[5/4/2026 11:52:17 PM] Score changed from 2 to 3
[5/4/2026 11:52:17 PM] Score changed from 2 to 3
[5/4/2026 11:52:50 PM] Cupid init success
[5/4/2026 11:52:50 PM] Cupid init success
+1 -1
View File
@@ -2590,7 +2590,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &784446025213843339 --- !u!224 &784446025213843339
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
+3 -3
View File
@@ -3913,7 +3913,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 21300000, guid: 6c479edfcb1b91a40985f500f098607b, type: 3} m_Sprite: {fileID: 21300000, guid: 6dcecbde18a194443ae02809015d0c66, type: 3}
m_Type: 0 m_Type: 0
m_PreserveAspect: 0 m_PreserveAspect: 0
m_FillCenter: 1 m_FillCenter: 1
@@ -4128,7 +4128,7 @@ MonoBehaviour:
preview: 0 preview: 0
isPlaying: 1 isPlaying: 1
loop: 1 loop: 1
currentFrame: 62 currentFrame: 67
--- !u!1 &239916595 --- !u!1 &239916595
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -18418,7 +18418,7 @@ MonoBehaviour:
p2_winner: {fileID: 1432157637} p2_winner: {fileID: 1432157637}
btnRematch: {fileID: 945131286} btnRematch: {fileID: 945131286}
btnLeave: {fileID: 81707919} btnLeave: {fileID: 81707919}
rematchWarningLoser: {fileID: 1744675598} rematchWarningLoser: {fileID: 1744675600}
txtRewardRC: {fileID: 488058062} txtRewardRC: {fileID: 488058062}
txtRewardCC: {fileID: 30708566} txtRewardCC: {fileID: 30708566}
countdownTxt: {fileID: 2054440054} countdownTxt: {fileID: 2054440054}
+133 -1
View File
@@ -33,6 +33,109 @@ public class GameManager : NetworkBehaviour
Logger.Log($"Configured dedicated match reporting for match id {matchId} with secret {DedicatedMatchSecret} and internal api base {DedicatedInternalApiBase}"); Logger.Log($"Configured dedicated match reporting for match id {matchId} with secret {DedicatedMatchSecret} and internal api base {DedicatedInternalApiBase}");
} }
/// <summary>Outcome of <see cref="RequestDedicatedRematch"/> (POST <c>/internal/rematch</c>).</summary>
public readonly struct DedicatedRematchResult
{
public readonly bool Success;
public readonly long HttpStatusCode;
public readonly MatchmadeResponse Response;
public readonly string ErrorMessage;
public DedicatedRematchResult(bool success, long httpStatusCode, MatchmadeResponse response, string errorMessage)
{
Success = success;
HttpStatusCode = httpStatusCode;
Response = response;
ErrorMessage = errorMessage ?? "";
}
}
/// <summary>
/// Dedicated server only: POST <c>/internal/rematch</c> with <c>X-Dedicated-Server-Secret</c>.
/// Blocks until the request finishes (same pattern as <see cref="ReportDedicatedMatchRoomClosed"/>).
/// On HTTP 200, returns the same JSON envelope as a successful matchmaker GET room fill: <see cref="MatchmadeResponse"/>.
/// </summary>
/// <param name="userRedId"><c>users.id</c> for red.</param>
/// <param name="userBlueId"><c>users.id</c> for blue; must differ from red.</param>
/// <param name="entryFee">RC stake per player (non-negative).</param>
/// <param name="secret">Overrides <see cref="DedicatedMatchSecret"/> when non-empty.</param>
/// <param name="internalApiBaseUrl">Overrides <see cref="DedicatedInternalApiBase"/> when non-empty.</param>
public static DedicatedRematchResult RequestDedicatedRematch(int userRedId, int userBlueId, int entryFee, string secret = null, string internalApiBaseUrl = null)
{
string s = string.IsNullOrEmpty(secret) ? DedicatedMatchSecret : secret;
string baseUrl = string.IsNullOrEmpty(internalApiBaseUrl) ? DedicatedInternalApiBase : internalApiBaseUrl.TrimEnd('/');
if (string.IsNullOrEmpty(s))
return new DedicatedRematchResult(false, 0, null, "Missing dedicated server secret");
if (string.IsNullOrEmpty(baseUrl))
return new DedicatedRematchResult(false, 0, null, "Missing internal API base URL");
string json = JsonUtility.ToJson(new DedicatedRematchRequestBody
{
user_red_id = userRedId,
user_blue_id = userBlueId,
entry_fee = entryFee
});
using (var req = DedicatedMatschInternalApi.BuildRematchRequest(baseUrl, s, json))
{
var op = req.SendWebRequest();
while (!op.isDone)
System.Threading.Thread.Sleep(16);
string text = req.downloadHandler != null ? req.downloadHandler.text : "";
long code = req.responseCode;
if (req.result != UnityWebRequest.Result.Success &&
req.result != UnityWebRequest.Result.ProtocolError)
{
string netErr = string.IsNullOrEmpty(req.error) ? "Network error" : req.error;
Logger.Log("Dedicated rematch POST failed (transport): " + netErr + " " + req.url);
return new DedicatedRematchResult(false, code, null, netErr);
}
if (code == 200)
{
try
{
var env = JsonUtility.FromJson<MatchmadeResponse>(text);
if (env != null && env.ok)
return new DedicatedRematchResult(true, code, env, "");
string apiErr = TryParseRematchErrorMessage(text);
Logger.Log("Dedicated rematch POST 200 but ok=false or parse issue: " + text);
return new DedicatedRematchResult(false, code, env, string.IsNullOrEmpty(apiErr) ? "Unexpected response" : apiErr);
}
catch (Exception e)
{
Logger.Log("Dedicated rematch POST: could not parse success body: " + e.Message + " body=" + text);
return new DedicatedRematchResult(false, code, null, e.Message);
}
}
string err = TryParseRematchErrorMessage(text);
if (string.IsNullOrEmpty(err))
err = string.IsNullOrEmpty(text) ? "HTTP " + code : text;
Logger.Log("Dedicated rematch POST failed: " + code + " " + err);
return new DedicatedRematchResult(false, code, null, err);
}
}
static string TryParseRematchErrorMessage(string json)
{
if (string.IsNullOrEmpty(json))
return "";
try
{
var err = JsonUtility.FromJson<DedicatedRematchErrorEnvelope>(json);
if (err != null && !string.IsNullOrEmpty(err.error))
return err.error;
}
catch
{
/* ignore */
}
return "";
}
/// <summary>Sets match <c>status</c> to <c>-1</c> (room closed). Safe to call from shutdown paths; runs synchronously so it completes before <c>Application.Quit</c>.</summary> /// <summary>Sets match <c>status</c> to <c>-1</c> (room closed). Safe to call from shutdown paths; runs synchronously so it completes before <c>Application.Quit</c>.</summary>
public static void ReportDedicatedMatchRoomClosed() public static void ReportDedicatedMatchRoomClosed()
{ {
@@ -704,7 +807,7 @@ public class GameManager : NetworkBehaviour
} }
void StopClient(){ public void StopClient(){
try{ try{
NetworkManager.singleton.StopClient(); NetworkManager.singleton.StopClient();
}catch(Exception e){ }catch(Exception e){
@@ -833,6 +936,20 @@ static class DedicatedMatschInternalApi
return BuildPatchJson(url, secret, jsonBody); return BuildPatchJson(url, secret, jsonBody);
} }
public static UnityWebRequest BuildRematchRequest(string baseUrl, string secret, string jsonBody)
{
string url = baseUrl.TrimEnd('/') + "/internal/rematch";
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonBody);
var req = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST)
{
uploadHandler = new UploadHandlerRaw(bodyRaw),
downloadHandler = new DownloadHandlerBuffer()
};
req.SetRequestHeader("Content-Type", "application/json");
req.SetRequestHeader("X-Dedicated-Server-Secret", secret);
return req;
}
static UnityWebRequest BuildPatchJson(string url, string secret, string jsonBody) static UnityWebRequest BuildPatchJson(string url, string secret, string jsonBody)
{ {
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonBody); byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonBody);
@@ -906,3 +1023,18 @@ class DedicatedWinnerPatchResponse
public int winner_id; public int winner_id;
public DedicatedWinnerPatchEconomy economy; public DedicatedWinnerPatchEconomy economy;
} }
[Serializable]
class DedicatedRematchRequestBody
{
public int user_red_id;
public int user_blue_id;
public int entry_fee;
}
[Serializable]
class DedicatedRematchErrorEnvelope
{
public bool ok;
public string error;
}
+30 -3
View File
@@ -33,7 +33,7 @@ public class GameOverCanvas : MonoBehaviour
[Header("Game Over Data")] [Header("Game Over Data")]
public Button btnRematch; public Button btnRematch;
public Button btnLeave; public Button btnLeave;
public GameObject rematchWarningLoser; public TMP_Text rematchWarningLoser;
public TMP_Text txtRewardRC; public TMP_Text txtRewardRC;
public TMP_Text txtRewardCC; public TMP_Text txtRewardCC;
public TMP_Text countdownTxt; public TMP_Text countdownTxt;
@@ -79,6 +79,21 @@ public class GameOverCanvas : MonoBehaviour
btnLeave.onClick.AddListener(OnBtnLeaveGameClicked); btnLeave.onClick.AddListener(OnBtnLeaveGameClicked);
betSlider.onValueChanged.AddListener(OnBetSliderValueChanged); betSlider.onValueChanged.AddListener(OnBetSliderValueChanged);
btnConfirmBet.onClick.AddListener(OnBetAccepted);
btnCancelBet.onClick.AddListener(OnBetCancelled);
}
void OnBetAccepted(){
NetPlayer.localPlayer.AcceptRematch((int)betSlider.value);
rematchPanel.interactable=false;
}
void OnBetCancelled(){
NetPlayer.localPlayer.AcceptRematch(0);
rematchPanel.interactable=false;
rematchPanel.blocksRaycasts=false;
rematchPanel.DOFade(0,0.3f).SetEase(Ease.InOutBack);
} }
void OnBetSliderValueChanged(float value){ void OnBetSliderValueChanged(float value){
@@ -95,6 +110,8 @@ public class GameOverCanvas : MonoBehaviour
if(winningTeam == myTeam){ if(winningTeam == myTeam){
//Only i can initiate the rematch, so here we go //Only i can initiate the rematch, so here we go
ShowRematchPanel(); ShowRematchPanel();
}else{
rematchWarningLoser.text = "Waiting for opponent to accept";
} }
} }
@@ -232,7 +249,11 @@ public class GameOverCanvas : MonoBehaviour
} }
btnRematch.interactable = winningTeam != myTeam; btnRematch.interactable = winningTeam != myTeam;
rematchWarningLoser.SetActive(winningTeam == myTeam); if(winningTeam == myTeam){
rematchWarningLoser.text = "Only the loser can request a rematch";
}else{
rematchWarningLoser.text = "";
}
StartCoroutine(CoroutineShow()); StartCoroutine(CoroutineShow());
@@ -330,8 +351,14 @@ public class GameOverCanvas : MonoBehaviour
public void OnRematchCancelled(){ public void OnRematchCancelled(){
SetRematchPendingState(false); btnRematch.interactable=false;
btnLeave.interactable=true;
rematchWarningLoser.text = "Rematch declined.";
StartCoroutine(CoroutineHideRematchPanel()); StartCoroutine(CoroutineHideRematchPanel());
countdownCoroutine = StartCoroutine(CoroutineCountdown());
} }
IEnumerator CoroutineHideRematchPanel(){ IEnumerator CoroutineHideRematchPanel(){
+127 -18
View File
@@ -1,9 +1,13 @@
using UnityEngine; using UnityEngine;
using Mirror; using Mirror;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using System.Collections;
public class NetPlayer : NetworkBehaviour public class NetPlayer : NetworkBehaviour
{ {
[SyncVar]
public int userId;
[SyncVar] [SyncVar]
public Team myTeam; public Team myTeam;
// set the team to red if there are no other players, if not set blue // set the team to red if there are no other players, if not set blue
@@ -17,16 +21,37 @@ public class NetPlayer : NetworkBehaviour
//Without cupid, set the team to red //Without cupid, set the team to red
bool cloneWorkspace = LoginManager.EditorWorkspaceLooksLikeClone(); bool cloneWorkspace = LoginManager.EditorWorkspaceLooksLikeClone();
SetMyTeam(cloneWorkspace ? Team.Red : Team.Blue); SetMyTeam(cloneWorkspace ? Team.Red : Team.Blue);
SetMyData(cloneWorkspace ? 0: 1 );
}else{ }else{
SetMyTeam(GameManager.MyTeam); SetMyTeam(GameManager.MyTeam);
SetMyData(GameManager.MyTeam == Team.Red ? GameManager.RedPlayer.UserId : GameManager.BluePlayer.UserId);
} }
#else #else
SetMyTeam(GameManager.MyTeam); SetMyTeam(GameManager.MyTeam);
SetMyData(GameManager.MyTeam == Team.Red ? GameManager.RedPlayer.UserId : GameManager.BluePlayer.UserId);
#endif #endif
TeamSpecificEffects.instance.SetTeamSpecificEffects(myTeam); TeamSpecificEffects.instance.SetTeamSpecificEffects(myTeam);
} }
void SetMyData(int uid){
if(isServer){
setMyData(uid);
}else{
CmdSetMyData(uid);
setMyData(uid);
}
}
void setMyData(int uid){
userId= uid;
}
[Command]
void CmdSetMyData(int uid){
userId=uid;
}
void SetMyTeam(Team team){ void SetMyTeam(Team team){
if(isServer){ if(isServer){
setMyTeam(team); setMyTeam(team);
@@ -47,10 +72,18 @@ public class NetPlayer : NetworkBehaviour
setMyTeam(team); setMyTeam(team);
Logger.Log($"Client {netId} set team to {team}"); Logger.Log($"Client {netId} set team to {team}");
if(team == Team.Red){
RedPlayer = this;
}else{
BluePlayer = this;
}
} }
public static NetPlayer localPlayer; public static NetPlayer localPlayer;
public static NetPlayer RedPlayer;
public static NetPlayer BluePlayer;
public static Vector2 curPosition; public static Vector2 curPosition;
public Vector2 startPosition; public Vector2 startPosition;
public float curPuckPullForce; public float curPuckPullForce;
@@ -248,35 +281,111 @@ public class NetPlayer : NetworkBehaviour
} }
public void AcceptRematch(float betRc){ public void AcceptRematch( int betRcCoins){
if(isServer){ if(isServer){
OnRematchAccepted(betRc); OnRematchAcceptedServer(betRcCoins);
RpcAcceptRematch(betRc);
}else{ }else{
CmdAcceptRematch(betRc); CmdAcceptRematch(betRcCoins);
} }
} }
[Command] [Command]
void CmdAcceptRematch(float betRc){ void CmdAcceptRematch(int betRcCoins){
OnRematchAccepted(betRc); OnRematchAcceptedServer(betRcCoins);
RpcAcceptRematch(betRc);
} }
[ClientRpc] void OnRematchAcceptedServer(int betRcCoins ){
void RpcAcceptRematch(float betRc){ if(!isServer){ return; }
OnRematchAccepted(betRc);
}
void OnRematchAccepted(float betRc){ if(betRcCoins <= 0){
//Implement here OnRematchCancelledServer();
if(betRc == 0){
//Cancel signal
GameOverCanvas.instance.OnRematchCancelled();
return; return;
} }
GameManager.DedicatedRematchResult resp = GameManager.RequestDedicatedRematch(RedPlayer.userId, BluePlayer.userId, betRcCoins);
if(resp.Success && resp.Response != null){
string matchmadeResponseString = JsonUtility.ToJson(resp.Response);
RpcRematchConfirmed(matchmadeResponseString);
Logger.Log("Rematch was confirmed, closing in 5 secs. new room :");
Logger.Log(matchmadeResponseString);
StartCoroutine(CoroutineOnRematchConfirmedServer());
}
}
IEnumerator CoroutineOnRematchConfirmedServer(){
yield return new WaitForSeconds(5f);
Logger.Log("Exiting for rematch.");
GameManager.ReportDedicatedMatchRoomClosed();
Application.Quit();
}
[ClientRpc]
void RpcRematchConfirmed(string matchmadeResponseString){
if (string.IsNullOrEmpty(matchmadeResponseString))
return;
MatchmadeResponse env = JsonUtility.FromJson<MatchmadeResponse>(matchmadeResponseString);
if (env == null || !env.ok)
return;
Team? teamHint = LoginManager.MatchYourTeam;
if (!teamHint.HasValue)
teamHint = GameManager.MyTeam;
int userId = localPlayer != null ? localPlayer.userId : (LoginManager.CurrentUser != null ? LoginManager.CurrentUser.id : 0);
MatchmadeTeamPayload branch = MatchmadeResponse.SelectTeamPayload(env, userId, teamHint);
if (branch == null || !MatchmadeResponse.TryResolveMyAndOpponent(env, branch, userId, out MatchmadePlayer myPlayer, out MatchmadePlayer opponentPlayer))
{
Debug.LogWarning("RpcRematchConfirmed: could not resolve roster for rematch UI");
return;
}
string yt = (branch.your_team ?? "").Trim().ToLowerInvariant();
Team myTeam = yt == "blue" ? Team.Blue : Team.Red;
if (myTeam == Team.Red)
{
GameManager.RedPlayer = myPlayer;
GameManager.BluePlayer = opponentPlayer;
}
else
{
GameManager.BluePlayer = myPlayer;
GameManager.RedPlayer = opponentPlayer;
}
GameManager.MyTeam = myTeam;
int rcPrizeCoins = env.rc_prize > 0 ? env.rc_prize : branch.rc_prize;
GameManager.MatchRcPrizeCoins = rcPrizeCoins;
if (LevelLoadManager.instance != null)
LevelLoadManager.instance.SetupMatchMade(myTeam, myPlayer, opponentPlayer, CoinHelper.FormatString(rcPrizeCoins) + " RC");
GameManager.ConfigureDedicatedMatchReporting(branch.match_id);
Cupid.RoomPort = branch.Port;
LoginManager.SetMatchYourTeam(branch.your_team);
GameManager.instance.StopClient();
LevelLoadManager.LoadLevel("Game");
}
void OnRematchCancelledServer(){
if(!isServer){ return; }
RpcCancelRematch();
if(!isServerOnly){
CancelRematch();
}
}
[ClientRpc]
void RpcCancelRematch(){
CancelRematch();
}
void CancelRematch(){
GameOverCanvas.instance.OnRematchCancelled();
}
} }
}
@@ -85,6 +85,12 @@ public class LevelLoadManager : MonoBehaviour
} }
Team myTeam = Team.Red; Team myTeam = Team.Red;
public void SetupRematch(int rc_prize, int port, int gameId){
txtRcPrize.text = CoinHelper.FormatString(rc_prize) + " RC";
}
public void SetupMatchMade(Team myTeam_, string opponentName, string myName, string myL10, string opponentL10, string rcPrize){ public void SetupMatchMade(Team myTeam_, string opponentName, string myName, string myL10, string opponentL10, string rcPrize){
myTeam = myTeam_; myTeam = myTeam_;
matchmadeUI.SetActive(true); matchmadeUI.SetActive(true);