|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using System.Threading;
- using GamecraftModdingAPI.App;
- using Unity.Collections;
- using Unity.Jobs;
- using Unity.Mathematics;
-
- using GamecraftModdingAPI.Utility;
-
- using Leadercraft.Server;
-
- namespace Leadercraft.Scoring
- {
- public struct UploadJob
- {
- private int points;
-
- private int time;
-
- private float[] location;
-
- private ulong player;
-
- private string playerName;
-
- private ulong game;
-
- public UploadJob(int score, double timespan, float3 position, ulong playerId, string playerName, ulong gameId)
- {
- this.points = score;
- this.time = (int)Math.Ceiling(timespan);
- this.location = new float[3] { position.x, position.y, position.z};
- this.player = playerId;
- this.playerName = playerName;
- this.game = gameId;
- LeadercraftPlugin.BuildApi();
- }
-
- public void RunInNewThread()
- {
- Thread job = new Thread(new ThreadStart(Execute));
- job.Start();
- }
-
- private void Execute()
- {
- if (Game.CurrentGame().Name == "Leadercraft's sucky game") game = 2;
- if (player < 1000 || game == 0) return; // offline game
- LeadercraftResult<KeyStruct> tokenResult = LeadercraftPlugin.Api.RequestPOSTToken(playerName);
- if (tokenResult.IsError)
- {
- Logging.LogWarning($"Leadercraft API token web request failed with status {tokenResult.StatusCode}");
- try
- {
- Logging.LogWarning($"API Error Response: {tokenResult.ParseError().Items[0]}");
- }
- catch (Exception) { }
- return;
- }
- string token = tokenResult.ParseResult().Items[0].Token;
- CriteriaStruct criteria = new CriteriaStruct
- {
- Location = new float[][] { location, location },
- Time = time,
- GameID = game,
- PlayerID = player,
- Complete = true,
- Points = points
- };
- LeadercraftResult<string> criteriaResult = LeadercraftPlugin.Api.RequestPOSTCriteria(criteria, token);
- if (criteriaResult.IsError)
- {
- Logging.LogWarning($"Leadercraft API criteria web request failed with status {criteriaResult.StatusCode}");
- try
- {
- Logging.LogWarning($"API Error Response: {criteriaResult.ParseError().Items[0]}");
- }
- catch (Exception) { }
- return;
- }
- Logging.MetaLog($"Criteria request succeeded with status {criteriaResult.StatusCode}");
- }
- }
- }
|