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"); }
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(); } }
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)); } } } }
async Task <FancyContextBase> IFancyContextProvider.Connect() { return(await FancyContext.Connect()); }