public static void DismissNotification(BigDB bigDb, string connectUserId, string notificationId, EENotification[] ignoreList) { var ignoreIds = ignoreList.Select(i => i.Key).ToArray(); bigDb.LoadOrCreate("Dismisses", connectUserId, obj => { if (!obj.Contains("Notifications")) { obj.Set("Notifications", new DatabaseArray()); } var notifications = obj.GetArray("Notifications"); notifications.Add(notificationId); // remove all unused notifications for (var i = 0; i < notifications.Count; i++) { if (!ignoreIds.Contains(notifications[0])) { notifications.RemoveAt(i); } } obj.Save(); }); }
private static void IsBlocked(BigDB bigDb, string blockingUser, string blockedId, string blockAllProp, string blockProp, Callback <bool> callback) { bigDb.Load(BlockingTable, blockingUser, blockingTable => { if (blockingTable == null) { callback(false); return; } if (blockingTable.GetBool(blockAllProp, false)) { callback(true); return; } var blockingObject = blockingTable.GetObject(blockProp); if (blockingObject == null) { callback(false); return; } callback(blockingObject.GetBool(blockedId, false)); }); }
public static Task <DatabaseObject> LoadAsync(this BigDB bigDB, string table, string key) { var tcs = new TaskCompletionSource <DatabaseObject>(); bigDB.Load(table, key, tcs.SetResult, tcs.SetException); return(tcs.Task); }
public AchievementManager(BigDB db, Player player) { bigDB = db; owner = player; // load data for all achievements from Database bigDB.LoadRange("Achievements", "IDs", null, null, null, 100, delegate(DatabaseObject[] results) { if (results != null) { foreach (DatabaseObject achievData in results) { if (owner.achievements.Contains(achievData.Key)) { continue; } Achievement achiev = achievList[achievData.Key]; achiev.init(achievData, this); achievements.Add(achiev); achiev.checkConditions(); } } else { // todo } }, delegate(PlayerIOError error) { // todo Console.WriteLine(error.Message); }); }
public static Task <DatabaseObject[]> LoadKeysAsync(this BigDB bigDB, string table, params string[] keys) { var tcs = new TaskCompletionSource <DatabaseObject[]>(); bigDB.LoadKeys(table, keys, tcs.SetResult, tcs.SetException); return(tcs.Task); }
public static Task <DatabaseObject> LoadMyPlayerObjectAsync(this BigDB bigDB) { var tcs = new TaskCompletionSource <DatabaseObject>(); bigDB.LoadMyPlayerObject(tcs.SetResult, tcs.SetException); return(tcs.Task); }
public static Task <DatabaseObject> LoadSingleAsync(this BigDB bigDB, string table, string index, params object[] indexValue) { var tcs = new TaskCompletionSource <DatabaseObject>(); bigDB.LoadSingle(table, index, indexValue, tcs.SetResult, tcs.SetException); return(tcs.Task); }
public static Task <DatabaseObject[]> LoadRangeAsync(this BigDB bigDB, string table, string index, object[] indexPath, object start, object stop, int limit) { var tcs = new TaskCompletionSource <DatabaseObject[]>(); bigDB.LoadRange(table, index, indexPath, start, stop, limit, tcs.SetResult, tcs.SetException); return(tcs.Task); }
private static void Block(BigDB bigDb, string userId, string blockId, bool block, string blockProp, Callback callback) { bigDb.LoadOrCreate(BlockingTable, userId, blockingTable => { var blockingObject = blockingTable.GetObject(blockProp); if (blockingObject == null) { blockingObject = new DatabaseObject(); blockingTable.Set(blockProp, blockingObject); } if (block) { blockingObject.Set(blockId, true); } else { blockingObject.Remove(blockId); } blockingTable.Save(); callback(); }); }
public static void GetInvitationsFrom(BigDB bigDb, InvitationType type, string sender, Callback <Invitation[]> callback) { bigDb.LoadRange(InvitationsTable, "BySender", new object[] { (int)type, sender }, null, null, 100, invitations => { callback(invitations.Select(dbo => new Invitation(dbo)).ToArray()); }); }
public static void GetInvitationsTo(BigDB bigDb, InvitationType type, string recipient, Callback <Invitation[]> callback) { bigDb.LoadRange(InvitationsTable, "ByRecipient", new object[] { (int)type, recipient }, null, null, 100, invitations => { callback(invitations.Select(dbo => new Invitation(dbo)).ToArray()); }); }
public static void DeleteInvitation(BigDB bigDb, InvitationType type, string sender, string recipient, Callback <bool> callback) { bigDb.DeleteRange(InvitationsTable, "BySenderAndRecipient", new object[] { (int)type, sender, recipient }, null, null, () => callback(true), error => callback(false)); }
public static void BlockAll(BigDB bigDb, string userId, bool block, string blockProp) { bigDb.LoadOrCreate(BlockingTable, userId, blockingTable => { blockingTable.Set(blockProp, block); blockingTable.Save(); }); }
private static EEMail[] DeleteMails(BigDB bigDb, EEMail[] mail) { if (mail.Length <= InboxSize) { return(mail); } bigDb.DeleteKeys("Mails", mail.Skip(InboxSize).Select(n => n.Key).ToArray()); return(mail.Take(InboxSize).ToArray()); }
private static EENotification[] DeleteNotifications(BigDB bigDb, EENotification[] eeNotifications) { if (eeNotifications.Length <= MaxNotifications) { return(eeNotifications); } bigDb.DeleteKeys("Notifications", eeNotifications.Skip(MaxNotifications).Select(n => n.Key).ToArray()); return(eeNotifications.Take(MaxNotifications).ToArray()); }
public static void SendMail(BigDB bigDb, string from, string to, string subject, string body) { SendMail(bigDb, new EEMail { From = from, To = to, Subject = subject, Body = body, Date = DateTime.UtcNow }, o => { }); }
public static void CreateInvitation(BigDB bigDb, InvitationType type, string sender, string recipient, Callback <DatabaseObject> callback) { var newInvite = new DatabaseObject() .Set("Type", (int)type) .Set("Sender", sender) .Set("Recipient", recipient) .Set("Status", (int)InvitationStatus.Pending); bigDb.CreateObject(InvitationsTable, null, newInvite, callback); }
public static void DeleteMail(BigDB bigDb, string connectUserId, string mailId) { // Check if the user actually owns this mail GetMail(bigDb, connectUserId, mails => { var mailToDelete = mails.SingleOrDefault(it => it.Key == mailId); if (mailToDelete != null) { DeleteMail(bigDb, mailToDelete); } }); }
public static void PublishNotification(BigDB bigDb, EENotification eeNotification, Callback <DatabaseObject> callback) { var obj = new DatabaseObject() .Set("Channel", eeNotification.Channel) .Set("PublishDate", eeNotification.PublishDate) .Set("Title", eeNotification.Title) .Set("RoomId", eeNotification.RoomId) .Set("ImageUrl", eeNotification.ImageUrl) .Set("Body", eeNotification.Body); bigDb.CreateObject("Notifications", null, obj, callback ?? (db => { })); }
public static void GetId(BigDB bigDb, string username, Callback <string> callback) { bigDb.Load("Usernames", username, name => { if (name == null || name.GetString("owner", "none") == "none") { callback(null); } else { callback(name.GetString("owner")); } }); }
private static void SendMail(BigDB bigDb, EEMail mail, Callback <DatabaseObject> callback) { var obj = new DatabaseObject() .Set("From", mail.From) .Set("To", mail.To) .Set("Date", mail.Date) .Set("Subject", mail.Subject) .Set("Body", mail.Body); bigDb.CreateObject("Mails", null, obj, callback ?? (db => { })); // Delete mail if the inbox got too full GetMail(bigDb, mail.To, m => { }); }
public static void GetNotifications(BigDB bigDb, string[] channels, Callback <EENotification[]> callback) { if (channels.Length == 0) { callback(new EENotification[0]); return; } GetNotifications(bigDb, channels[0], nots => { GetNotifications(bigDb, channels.Skip(1).ToArray(), nots2 => { callback(nots.Concat(nots2).ToArray()); }); }); }
public static void GetMail(BigDB bigDb, string connectUserId, Callback <EEMail[]> callback) { bigDb.LoadRange("Mails", "MyMails", new object[] { connectUserId }, null, null, 1000, objs => { callback(DeleteMails(bigDb, objs.Select(obj => new EEMail { Key = obj.Key, From = obj.GetString("From"), To = obj.GetString("To"), Date = obj.GetDateTime("Date", default(DateTime)), Subject = obj.GetString("Subject", ""), Body = obj.GetString("Body", "") }).ToArray())); }); }
private static void GetNotifications(BigDB bigDb, string channel, Callback <EENotification[]> callback) { bigDb.LoadRange("Notifications", "ByChannel", new object[] { channel }, null, null, 1000, items => { callback(DeleteNotifications(bigDb, items.Select(i => new EENotification { Key = i.Key, Channel = i.GetString("Channel"), PublishDate = i.GetDateTime("PublishDate"), Title = i.GetString("Title", ""), RoomId = i.GetString("RoomId", ""), ImageUrl = i.GetString("ImageUrl", ""), Body = i.GetString("Body") }).ToArray())); }); }
public static void GetSubscriptions(BigDB bigDb, string connectUserId, Callback <string[]> callback) { bigDb.Load("Subscriptions", connectUserId, obj => { var defaultChannels = new[] { "news", "creweverybodyeditsstaff" }; if (obj == null) { callback(defaultChannels); } else { var subs = (from sub in obj where (bool)sub.Value select sub.Key).Concat(defaultChannels).ToArray(); callback(subs); } }); }
public static void GetDismissedNotifications(BigDB bigDb, string connectUserId, Action <string[]> callback) { bigDb.Load("Dismisses", connectUserId, obj => { if (obj == null) { callback(new string[] { }); } else { if (!obj.Contains("Notifications")) { obj.Set("Notifications", new DatabaseArray()); } var notifications = obj.GetArray("Notifications"); callback(notifications.Select(i => i.ToString()).ToArray()); } }); }
virtual public void Init(BigDB db) { Object tmp; if (JoinData.ContainsKey("Guest") && Convert.ToBoolean(JoinData["Guest"])) { username = JoinData["Name"]; isGuest = true; } if (!isGuest) { // if username exists, we have registered user so we take that as his name, if it is not set // we have guest so we take his name from ConnectUserId if (PlayerObject.TryGetValue("Username", out tmp)) { username = (String)tmp; } if (username == null && JoinData.ContainsKey("Name")) { username = JoinData["Name"]; } InitializeDB(); PayVault.Refresh(null); bigDB = db; achievManager = new Achievements.AchievementManager(bigDB, this); } else { savingFinished(); rankingOriginal = 0; rankingGS = -1500 / 173.7178f; rankingDeviation = 350; rankingDeviationGS = rankingDeviation / 173.7178f; } //messageTimer = AddTimer(messageTimerTick, 3000); }
public static void RemoveSubscription(BigDB bigDb, string connectUserId, string channel, Callback <bool> callback) { bigDb.Load("Subscriptions", connectUserId, obj => { if (obj != null) { if (obj.GetBool(channel, false)) { obj.Set(channel, false); obj.Save(); callback(true); } else { callback(false); } } else { callback(false); } }); }
private static void GetBlocked(BigDB bigDb, string userId, string blockProp, Callback <List <string> > callback) { bigDb.Load(BlockingTable, userId, blockingTable => { var rtn = new List <string>(); if (blockingTable == null) { callback(rtn); return; } var blockingObject = blockingTable.GetObject(blockProp); if (blockingObject == null || blockingObject.Count == 0) { callback(rtn); return; } rtn.AddRange(from blockedUser in blockingObject where (bool)blockedUser.Value select blockedUser.Key); callback(rtn); }); }
public static void AddSubscription(BigDB bigDb, string connectUserId, string channel, Callback <bool> callback = null) { bigDb.LoadOrCreate("Subscriptions", connectUserId, obj => { if (!obj.GetBool(channel, false)) { obj.Set(channel, true); obj.Save(); if (callback != null) { callback.Invoke(true); } } else { if (callback != null) { callback.Invoke(false); } } }); }