Ejemplo n.º 1
0
        public bool AssignPlayerToHouse(Guid sessionId, int slot, string userId)
        {
            var session = gameData.GetSession(sessionId);
            var village = gameData.GetOrCreateVillageBySession(session);
            var houses  = gameData.GetOrCreateVillageHouses(village);

            var targetHouse = houses.FirstOrDefault(x => x.Slot == slot);

            if (targetHouse == null)
            {
                return(false);
            }

            var player = gameData.GetCharacterBySession(session.Id, userId);

            if (player == null)
            {
                return(false);
            }

            var existingHouse = houses.FirstOrDefault(x => x.UserId == player.UserId);

            if (existingHouse != null)
            {
                existingHouse.UserId = null;
            }

            targetHouse.UserId = player.UserId;
            return(true);
        }
Ejemplo n.º 2
0
        public WebsitePlayer GetActivePlayer(string broadcasterId)
        {
            var activeSession = gameData.GetOwnedSessionByUserId(broadcasterId);

            if (activeSession == null)
            {
                return(null);
            }

            if (TryGetSession(out var si))
            {
                var activeCharacter = gameData.GetCharacterBySession(activeSession.Id, si.UserId);
                var user            = gameData.GetUser(si.AccountId);
                return(activeCharacter == null || user == null
                    ? null : playerManager.GetWebsitePlayer(user, activeCharacter));
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Only used with the twitch extension
        /// </summary>
        /// <param name="twitchUserId"></param>
        /// <returns></returns>
        public async Task <SessionInfo> CreateTwitchUserSessionAsync(string sessionId, string broadcasterId, string twitchUserId)
        {
            var si = new SessionInfo();

            if (string.IsNullOrEmpty(twitchUserId) || string.IsNullOrEmpty(broadcasterId))
            {
                return(si);
            }

            if (twitchUserId.StartsWith("u", StringComparison.OrdinalIgnoreCase))
            {
                twitchUserId = twitchUserId.Substring(1); // remove starting U
            }
            var broadcaster = gameData.GetUserByTwitchId(broadcasterId);

            if (broadcaster == null)
            {
                return(new SessionInfo());
            }

            var user = gameData.GetUserByTwitchId(twitchUserId);

            if (user == null)
            {
                return(new SessionInfo());
            }

            //var activeSession = gameData.GetActiveSessions().FirstOrDefault(x => x.UserId == broadcaster.Id);
            var activeSession = gameData.GetSessions().FirstOrDefault(x => x.UserId == broadcaster.Id);

            if (activeSession == null)
            {
                return(new SessionInfo());
            }

            var activeCharacter = gameData.GetCharacterBySession(activeSession.Id, twitchUserId, false);

            if (activeCharacter != null)
            {
                foreach (var sd in sessions.Values)
                {
                    if (sd.SessionInfo != null && sd.SessionInfo.ActiveCharacterId == activeCharacter.Id && sd.SessionInfo.Extension)
                    {
                        si = sd.SessionInfo;
                        RemoveSessionData(si.SessionId);
                        break;
                    }
                }

                si.ActiveCharacterId = activeCharacter.Id;
            }

            si.Extension = true;
            si.SessionId = sessionId;
            UpdateSessionInfoData(si, user);

            var sessionState = JSON.Stringify(si);

            GetSessionData(sessionId).SessionInfo = si;
            SetString(sessionId, AuthState, sessionState);
            return(si);
        }