Send Game Related Data (Game Logs)

To calculate the actual game score or detect invalid score submitted by the player, we need some game related data at the end of the game. This also helps us to simulate games on our server. This will also help us to track the game played by the user in case of any mismatch in score, false claim by the user etc.

There are two methods for transmitting game logs to the WinZO server:

  1. Batching: This method involves sending game logs in batches. The game is configured with a specified time interval, and once initiated, it begins collecting game logs. After the defined interval elapses, the accumulated logs are sent to the WinZO server.

  2. All Logs at Once: Unlike the batching method, this approach sends all game logs in a single transmission. Upon game initiation, logging begins, and upon completion of the game, along with the submission of the final score i.e SubmitScore event, all the accumulated game logs are sent to the WinZO server simultaneously.

Each method has its advantages and may be chosen based on factors such as data volume, network efficiency, and server compatibility.

Game will get these config data for game logs in the SetUpGame event:

  1. sendGameLogs = type bool (true - send game logs, false, do not send game logs)

  2. batchType: type int a. 0, // send game logs in submit score only b. 1, // send game logs in batches only c. 2 // send game logs in both

  3. batchInterval = float (in sec) : this is the time interval in which game needs to send the game logs

Game logs will be send via two methods:

  1. Send in Submit Score: send complete game logs at once

  2. Batchmode: (send game logs in batches)

Parent key name should be “gameLogs”: Add two keys in the game logs

  1. batchCount: It will be the count of every batch and it will be an incremental value from 1 to N. where 1 is the START packet and N is the END packet.

  2. packetType: It is a string value. a. START: The very first packet b. RUNNING: In between the game (2 to N-1) c. END: Nth packet d. FINAL: complete game logs sending in submit score

 {
   batchCount: int // number of current batch (incremental) 1 to N,
   packetType(string),
   {
       START, // for the first packet
       RUNNING, // in between game packets
       END,  // Last batch
       FINAL // Along submit score packet in needed
   },
   finalScore,
   gameData:{ gamelogs}
}

Send game logs along with submit score data.

// This is an example you can have  
   // any name of this class and keys according to your game
   // use namespace for this class as well
   // Game data example


   [Serializable]
   public class GameLogs
   {
       public int finalScore;
       public int batchCount;
       public string packetType;


       public RecordedGameLogs gameLogs = new RecordedGameLogs(); // Key name must be "gameLogs"
   }


   [Serializable]
   public class RecordedGameLogs
   {
       public List<RecordData> recordGameData = new List<RecordData>();
   }


   [Serializable]
   public class RecordData
   {
       public int respinLeft;
       public int disconnectionCount;
       public List<int> tokenArray = new List<int>();
       public int diceRollCount;
       public int NumberOfMoveToken;
       public string Challengeid;
   }


   // On Game Over // At submit score call
   //Add gameData in the submit score packet on gameover.
   Dictionary<string, IList> scoreData = new Dictionary<string, IList>();


   //Mandatory Keys


   //Add Scene Info
   List<string> scenename = new List<string>();
   scenename.Add(SceneNames.WINZO_GAME_SCENE);


    //Add Time Elapsed Info
    List<int> timelist = new List<int>();
   timelist.Add(timeElapsed); // Add elapsed here




    //Add Player Score Array
    List<ObscuredInt> score = scores;


   //Add all other player scores, get opponent ids in
   //SetUpGame Event Data 
   List<object> oppoPlayerScores = new List<object>();
   //1st opponent
   MultipleOpponentScore oppoPlayerScore1 = new
   MultipleOpponentScore(opponentId1, opponentScore1);
   oppoPlayerScores.Add(oppoPlayerScore1);
   //2nd opponent
   MultipleOpponentScore oppoPlayerScore2 = new
   MultipleOpponentScore(opponentId2, opponentScore2);
   oppoPlayerScores.Add(oppoPlayerScore2);


   List<object> allGameData = new List<object>();
   //Add all data to this object
   GameLogs gameLogs = new GameLogs();


   // Convert json into string of collected game data
   allGameData.Add(gameLogs);


   scoreData.Add(IntegrationEvents.SceneName, scenename);
   scoreData.Add(IntegrationEvents.Scores, score);
   scoreData.Add(IntegrationEvents.TimeElapsed, timelist);
   scoreData.Add(IntegrationEvents.GameData, allGameData);
   scoreData.Add(IntegrationEvents.OppPlayerScore,oppoPlayerScores);     
   WinzoEventManager.TriggerEvent(IntegrationEvents.SubmitScore, scoreData);

Batchmode: (send game logs in batches)

namespace WinzoGame
{
   [Serializable]
   public class GameLogs
   {
       public int finalScore;
       public int batchCount;
       public string packetType;
       
public RecordedGameLogs gameLogs = new RecordedGameLogs(); // Key name must be "gameLogs"
   }


 [Serializable]
   public class RecordedGameLogs
   {
       public List<RecordData> recordGameData = new List<RecordData>();
   }


   [Serializable]
   public class RecordData
   {
       public int currentTime;
       public bool undoBtnClicked;
       public bool finishBtnClicked;
       public bool canDrag;
       public Vector2 mousePos;
       public List<Vector3> previousMousePosArray = new List<Vector3>();
   }
}
public void SendGameLogs()
  {
 StartCoroutine(SendLogsPeriodically());
   }


   int batchCount = 0;
   private IEnumerator SendLogsPeriodically()
   {
       while (true)
       {
           float delay = FruitSliceGameController.Instance.batchInterval;
           yield return new WaitForSeconds(delay);
           SendLogsToWinZO();
       }
   }
   void SendLogsToWinZO(bool endPacket = false)
   {
       batchCount++;
       gameRecordData.batchCount = batchCount;
       if (batchCount == 1)
       {
           gameRecordData.packetType = packetType.START.ToString();
       }
       else
       {
           if(endPacket)
           {
               gameRecordData.packetType = packetType.END.ToString();
           }
           else
           {
               gameRecordData.packetType = packetType.RUNNING.ToString();
           }
       }
       gameRecordData.finalScore = currentScore;
       List<object> allGameData = new List<object>();
       allGameData.Add(gameRecordData);
       Dictionary<string, object> gameLogs = new Dictionary<string, object>();
       gameLogs.Add(IntegrationEvents.GameData, allGameData);
       WinzoEventManager.SendAnalyticsToWinzo(IntegrationEvents.GameData, gameLogs);
   }

Last updated