protected virtual void ServerUpdate()
    {
        if (gameRule != null && canUpdateGameRule)
        {
            gameRule.OnUpdate();
        }

        if (Time.unscaledTime - updateScoreTime >= 1f)
        {
            if (gameRule == null || !gameRule.IsMatchEnded)
            {
                var msgSendScores = new OpMsgSendScores();
                msgSendScores.scores = GetSortedScores();
                NetworkServer.SendToAll(msgSendScores.OpId, msgSendScores);
            }
            updateScoreTime = Time.unscaledTime;
        }

        if (gameRule != null && Time.unscaledTime - updateMatchTime >= 1f)
        {
            RemainsMatchTime = gameRule.RemainsMatchTime;
            var msgMatchStatus = new OpMsgMatchStatus();
            msgMatchStatus.remainsMatchTime = gameRule.RemainsMatchTime;
            msgMatchStatus.isMatchEnded     = gameRule.IsMatchEnded;
            NetworkServer.SendToAll(msgMatchStatus.OpId, msgMatchStatus);

            if (!IsMatchEnded && gameRule.IsMatchEnded)
            {
                IsMatchEnded = true;
                MatchEndedAt = Time.unscaledTime;
            }

            updateMatchTime = Time.unscaledTime;
        }
    }
    protected void UpdateMatchStatus()
    {
        var msgMatchStatus = new OpMsgMatchStatus();

        msgMatchStatus.remainsMatchTime = gameRule.RemainsMatchTime;
        msgMatchStatus.isMatchEnded     = gameRule.IsMatchEnded;
        ServerSendPacketToAllConnections(0, DeliveryMethod.ReliableOrdered, msgMatchStatus.OpId, msgMatchStatus);
    }
Esempio n. 3
0
    public override void OnServerReady(NetworkConnection conn)
    {
        base.OnServerReady(conn);
        var msgSendScores = new OpMsgSendScores();

        msgSendScores.scores = GetSortedScores();
        NetworkServer.SendToClient(conn.connectionId, msgSendScores.OpId, msgSendScores);
        if (gameRule != null)
        {
            var msgGameRule = new OpMsgGameRule();
            msgGameRule.gameRuleName = gameRule.name;
            NetworkServer.SendToClient(conn.connectionId, msgGameRule.OpId, msgGameRule);
            var msgMatchTime = new OpMsgMatchStatus();
            msgMatchTime.remainsMatchTime = gameRule.RemainsMatchTime;
            msgMatchTime.isMatchEnded     = gameRule.IsMatchEnded;
            NetworkServer.SendToClient(conn.connectionId, msgMatchTime.OpId, msgMatchTime);
        }
    }
 protected override UniTaskVoid HandleClientReadyRequest(RequestHandlerData requestHandler, EmptyMessage request, RequestProceedResultDelegate <EmptyMessage> result)
 {
     // Send game rule data before spawn player's character
     if (gameRule == null || !gameRule.IsMatchEnded)
     {
         var msgSendScores = new OpMsgSendScores();
         msgSendScores.scores = GetSortedScores();
         ServerSendPacket(requestHandler.ConnectionId, 0, DeliveryMethod.ReliableOrdered, msgSendScores.OpId, msgSendScores);
     }
     if (gameRule != null)
     {
         var msgGameRule = new OpMsgGameRule();
         msgGameRule.gameRuleName = gameRule.name;
         ServerSendPacket(requestHandler.ConnectionId, 0, DeliveryMethod.ReliableOrdered, msgGameRule.OpId, msgGameRule);
         var msgMatchTime = new OpMsgMatchStatus();
         msgMatchTime.remainsMatchTime = gameRule.RemainsMatchTime;
         msgMatchTime.isMatchEnded     = gameRule.IsMatchEnded;
         ServerSendPacket(requestHandler.ConnectionId, 0, DeliveryMethod.ReliableOrdered, msgMatchTime.OpId, msgMatchTime);
     }
     return(base.HandleClientReadyRequest(requestHandler, request, result));
 }