Esempio n. 1
0
        public static async Task UpdateClansAsync()
        {
            Console.WriteLine("Requesting clans from database.");
            string response = await SendRequestAsync("ClanCharacters", "");

            Console.WriteLine("Received clans.");
            ClansOutput result = JsonSerializer.Deserialize <ClansOutput>(response);

            ConQue.Enqueue(() => UpdateClansWithInfo(result));
        }
Esempio n. 2
0
        public static void UpdateClansWithInfo(ClansOutput result)
        {
            CharacterIds.Clear();
            CharacterClans.Clear();
            ClanLeaders.Clear();
            ClanNames.Clear();

            Players.ForEach(player => player.ClanId = 0);

            foreach (var row in result.Clans)
            {
                CharacterIds.Add(row.CharacterName, row.CharacterId);
                CharacterClans.Add(row.CharacterId, row.ClanId);
                if (row.IsLeader)
                {
                    ClanLeaders.Add(row.CharacterId);
                }

                if (!ClanNames.ContainsKey(row.ClanId))
                {
                    ClanNames.Add(row.ClanId, row.ClanName);
                }

                Player foundPlayer = Players.FirstOrDefault(x => x.Name == row.CharacterName);
                if (foundPlayer != null)
                {
                    foundPlayer.Id           = row.CharacterId;
                    foundPlayer.ClanId       = row.ClanId;
                    foundPlayer.IsClanLeader = row.IsLeader;
                }
            }

            byte[] message = MergeByteArrays(ToBytes(Command.ClanUpdate)); // inform game servers that they need to update clans from db by themselves

            foreach (Socket gameServer in GameServers)
            {
                gameServer.SendOrFail(message);
            }
        }