Exemple #1
0
        /// <summary>
        /// Returns a user from the given id
        /// </summary>
        public async Task <ClientPlanetMember> GetPlanetMemberAsync(ulong user_id, ulong planet_id)
        {
            if (user_id == 0)
            {
                return(new ClientPlanetMember()
                {
                    Id = 0,
                    Planet_Id = planet_id,
                });
            }

            string key = $"{planet_id}-{user_id}";

            // Attempt to retrieve from cache
            if (PlanetMemberCache.ContainsKey(key))
            {
                return(PlanetMemberCache[key]);
            }

            // Retrieve from server
            ClientPlanetMember member = await ClientPlanetMember.GetClientPlanetMemberAsync(user_id, planet_id);

            if (member == null)
            {
                Console.WriteLine($"Failed to fetch planet user with user id {user_id} and planet id {planet_id}.");
                return(null);
            }

            Console.WriteLine($"Fetched planet user {user_id} for planet {planet_id}");

            // Add to cache
            PlanetMemberCache.TryAdd(key, member);

            return(member);
        }
Exemple #2
0
        public async Task <List <ClientPlanetMember> > GetPlanetMemberInfoAsync(ulong planet_id)
        {
            string json = await ClientUserManager.Http.GetStringAsync($"Planet/GetPlanetMemberInfo?planet_id={planet_id}&token={ClientUserManager.UserSecretToken}");

            //Console.WriteLine(json);

            TaskResult <List <PlanetMemberInfo> > result = JsonConvert.DeserializeObject <TaskResult <List <PlanetMemberInfo> > >(json);

            List <ClientPlanetMember> memberList = new List <ClientPlanetMember>();

            foreach (PlanetMemberInfo info in result.Data)
            {
                ClientPlanetMember member = ClientPlanetMember.FromBase(info.Member);
                member.SetCacheValues(info);

                string key = $"{planet_id}-{member.User_Id}";

                if (PlanetMemberCache.ContainsKey(key) == false)
                {
                    PlanetMemberCache.TryAdd(key, member);
                }

                memberList.Add(member);
            }

            return(memberList);
        }
Exemple #3
0
        public async Task UpdateMember(string json)
        {
            ClientPlanetMember member = JsonConvert.DeserializeObject <ClientPlanetMember>(json);

            if (member == null)
            {
                Console.WriteLine("Failed to deserialize member in member update.");
                return;
            }

            Console.WriteLine("RECIEVE: Planet member update ping");
            Console.WriteLine(json);
            await SetUpdatedMember(member);

            if (OnMemberUpdate != null)
            {
                await OnMemberUpdate.Invoke(member);
            }
        }
Exemple #4
0
        public async Task SetUpdatedMember(ClientPlanetMember member)
        {
            string key = $"{member.Planet_Id}-{member.User_Id}";

            PlanetMemberCache.AddOrUpdate(key, member, (key, old) => member);
        }
Exemple #5
0
 /// <summary>
 /// Returns the member for a given user id
 /// </summary>
 public async Task <ClientPlanetMember> GetMemberAsync(ulong user_id)
 {
     return(await ClientPlanetMember.GetClientPlanetMemberAsync(user_id, Id));
 }