Ejemplo n.º 1
0
        private async Task GetAttackHistory()
        {
            history.Clear();

            var attackRecordsTable = database.GetTable <AttackRecord>();
            var playersTable       = database.GetTable <Server.Player>();

            var entities = await attackRecordsTable
                           .Where(r => r.VictimId == currentPlayer.Id)
                           .Take(5)
                           .ToEnumerableAsync();

            foreach (var entity in entities)
            {
                var attackerNames = await playersTable
                                    .Where(p => p.Id == entity.AttackerId)
                                    .Select(p => p.Username)
                                    .ToListAsync();

                if (attackerNames.Count == 0)
                {
                    continue;
                }

                entity.AttackerName = attackerNames[0];
                history.Add(entity);
            }
        }
Ejemplo n.º 2
0
        private async Task DeleteOldReplays()
        {
            var replaysTable       = azureDatabase.GetTable <AttackRecord>();
            var replaysToBeDeleted = await replaysTable.Where(r => r.VictimId == currentPlayer.Id).ToEnumerableAsync();

            foreach (var record in replaysToBeDeleted)
            {
                await replaysTable.DeleteAsync(record);
            }
        }
        protected override async Task <string> GetTargetId()
        {
            var playerId   = playerData.Id;
            var usersTable = database.GetTable <Server.Player>();

            //TODO query not the whole table, but a limited chunck of players selected randomly
            var otherPlayers = await usersTable.Where(u => u.Id != playerId).ToListAsync();

            var result = otherPlayers[Random.Range(0, otherPlayers.Count)];

            database.CachePlayer(result);

            return(result.Id);
        }
Ejemplo n.º 4
0
        private async Task AzureInit()
        {
            var playersTable        = database.GetTable <Server.Player>();
            var playerQuery         = playersTable.Where(u => u.DeviceId == SystemInfo.deviceUniqueIdentifier);
            var currentPlayerEntity = (await playersTable.ReadAsync(playerQuery)).FirstOrDefault();

            if (currentPlayerEntity != null)
            {
                id = currentPlayerEntity.Id;
            }
            else
            {
                var playerName = await GetPlayerNameInput();

                currentPlayerEntity = CreateNewUser(playerName);
                await playersTable.InsertAsync(currentPlayerEntity);

                id = currentPlayerEntity.Id;
            }

            database.CachePlayer(currentPlayerEntity);
        }
Ejemplo n.º 5
0
 public async Task InsertTable(string attackerId, string victimId, string replayname)
 {
     var currentAttackHistoryEntity = CreateAttackRecord(attackerId, victimId, replayname);
     var tableInsert = database.GetTable <AttackRecord>();
     await tableInsert.InsertAsync(currentAttackHistoryEntity);
 }