Beispiel #1
0
        async Task <IUserSteamAdapter> IUser.GetSteamAdapter()
        {
            long?steamid;

            using (var context = new FancyContext())
                steamid = await context.Users.Where(x => x.Id == User.userid).Select(x => x.Membership.SteamId).SingleAsync();
            return(steamid.HasValue ? new UserSteamAdapter(SteamListener, steamid.Value) : null);
        }
Beispiel #2
0
        public async Task SetSteamId(IUser user, long steam64)
        {
            using (var context = await FancyContext.Connect())
                using (var transact = context.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                {
                    var dbUser = await context.Users.Include(x => x.Membership).SingleAsync(x => x.Id == user.UserId);

                    dbUser.Membership.SteamId = steam64;
                    await context.SaveChangesAsync();

                    transact.Commit();
                }

            var steamAdapter = await user.GetSteamAdapter();

            ((UserSteamAdapter)steamAdapter).SteamListener.AddFriend(new SteamID(unchecked ((ulong)steam64)));

            Trace.WriteLine(steam64, "SteamIntegration added");
        }
Beispiel #3
0
        async Task ISteamEventForwarder.OnChatMessage(SteamListener steamListener, SteamID sender, string message)
        {
            using (var context = await FancyContext.Connect())
                using (var transact = context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    var steam64     = unchecked ((long)sender.ConvertToUInt64());
                    var currentGame = unchecked ((int)(steamListener.GetCurrentGameId(sender) ?? 0));
                    var user        = await context.Users.Where(x => x.Membership.SteamId == steam64).SingleAsync();

                    if (message == "@fancy-ng forward")
                    {
                        context.SteamChatForwardingAssociations.Add(new Model.SteamChatForwardingAssociation
                        {
                            User  = user,
                            AppId = currentGame,
                        });
                    }
                    else if (message == "@fancy-ng noforward")
                    {
                        var assoc = await context.SteamChatForwardingAssociations.FindAsync(user.Id, currentGame);

                        if (assoc != null)
                        {
                            context.SteamChatForwardingAssociations.Remove(assoc);
                        }
                    }
                    else if (message.StartsWith("@fancy-ng "))
                    {
                        steamListener.SendMessage(sender, "Unknown command. Commands are: forward, noforward");
                    }
                    else
                    {
                        // foward to mumble
                        var mumbleUser = (await Server.GetUsers()).Values.Single(x => x.userid == user.Id);
                        await Server.SendMessageChannel(mumbleUser.channel, false, user.Name + "(via Steam): " + message);
                    }

                    await context.SaveChangesAsync();

                    transact.Commit();
                }
        }
Beispiel #4
0
        public async override Task OnChatMessage(IUser sender, IEnumerable <IChannelShim> channels, string message)
        {
            var allUsers = await Server.GetOnlineUsers();

            foreach (var user in allUsers.Where(u => channels.Any(c => u.CurrentChannel.ChannelId == c.ChannelId)))
            {
                var steamAdapter = await user.GetSteamAdapter();

                if (steamAdapter != null)
                {
                    var gaim = (await steamAdapter.GetCurrentGame()) ?? 0;

                    bool shouldForward;
                    using (var context = await FancyContext.Connect())
                        shouldForward = null != await context.SteamChatForwardingAssociations.FindAsync(user.UserId, unchecked ((int)gaim));
                    if (shouldForward)
                    {
                        await steamAdapter.SendMessage(string.Format("[Chat] {0}: {1}", sender.Name, message));
                    }
                }
            }
        }
Beispiel #5
0
 async Task <FancyContextBase> IFancyContextProvider.Connect()
 {
     return(await FancyContext.Connect());
 }
Beispiel #6
0
 public FancyTextCompositionRepo(FancyContext context)
 {
     _dbContext = context;
 }
Beispiel #7
0
 public FancyTextRepo(FancyContext context)
 {
     _context = context;
 }