Пример #1
0
        public async Task AddPlanetAsync(ClientPlanet planet)
        {
            PlanetCache.AddOrUpdate(planet.Id, planet, (key, old) => planet);

            // Pre-cache roles
            await GetPlanetRoles(planet.Id);
        }
Пример #2
0
        /// <summary>
        /// Returns a user from the given id
        /// </summary>
        public async Task <ClientPlanet> GetPlanetAsync(ulong id)
        {
            // Attempt to retrieve from cache
            if (PlanetCache.ContainsKey(id))
            {
                return(PlanetCache[id]);
            }

            // Retrieve from server
            ClientPlanet planet = await ClientPlanet.GetClientPlanetAsync(id);

            // Load planet roles into cache
            await LoadPlanetRoles(planet);

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

            // Add to cache
            PlanetCache.TryAdd(id, planet);

            return(planet);
        }
Пример #3
0
        public async Task ClosePlanet(ClientPlanet planet)
        {
            // Joins planet via SignalR
            await signalRManager.hubConnection.SendAsync("LeavePlanet", planet.Id);

            // Remove from list
            OpenPlanets.Remove(planet.Id);

            Console.WriteLine($"Left SignalR group for planet {planet.Id}");
        }
Пример #4
0
        public async Task OpenPlanet(ClientPlanet planet)
        {
            if (OpenPlanets.ContainsKey(planet.Id))
            {
                // Already opened
                return;
            }

            // Joins planet via SignalR
            await signalRManager.hubConnection.SendAsync("JoinPlanet", planet.Id, ClientUserManager.UserSecretToken);

            // Add to open planet list
            OpenPlanets.Add(planet.Id, planet);

            Console.WriteLine($"Joined SignalR group for planet {planet.Id}");
        }
Пример #5
0
        public async Task SetCurrentPlanet(ClientPlanet planet)
        {
            if (planet == null || (CurrentPlanet != null && CurrentPlanet.Id == planet.Id))
            {
                return;
            }

            CurrentPlanet = planet;

            Console.WriteLine($"Set current planet to {planet.Id}");

            if (OnPlanetChange != null)
            {
                Console.WriteLine($"Invoking planet change event");
                await OnPlanetChange?.Invoke();
            }
        }
Пример #6
0
        public async Task OpenPlanetChatChannel(ChannelWindowComponent window)
        {
            ClientPlanetChatChannel channel = window.Channel;

            if (!OpenPlanetChatChannels.ContainsKey(channel.Id))
            {
                ClientPlanet planet = await channel.GetPlanetAsync();

                // Ensure planet is opened
                await OpenPlanet(planet);

                // Joins channel via SignalR
                await signalRManager.hubConnection.SendAsync("JoinChannel", channel.Id, ClientUserManager.UserSecretToken);

                // Add to open channel list
                OpenPlanetChatChannels.Add(channel.Id, window.Channel);

                Console.WriteLine($"Joined SignalR group for channel {channel.Id}");
            }

            OpenPlanetChatWindows.Add(window);
        }
Пример #7
0
 /// <summary>
 /// Loads all of the roles for a given planet
 /// </summary>
 public async Task LoadPlanetRoles(ClientPlanet planet)
 {
     await LoadPlanetRoles(planet.Id);
 }