public void GetAccountIDFromAvatar(uint avatarID, VMAsyncAccountUserIDFromAvatarCallback callback) { callback(1); }
public override void OnConnection(VMEODClient client) { if (client.Avatar != null) { User = client; var currentTime = Server.vm.Context.Clock.UTCNow; // arguments - [0] is type of cooldown: VMEODCooldownEventPluginModes; [1] is cooldown HOURS; [2] is cooldown MINUTES, [3] is cooldown SECONDS var args = client.Invoker.Thread.TempRegisters; CooldownLength = new TimeSpan(args[1], args[2], args[3]); // check cooldown type switch (args[0]) { case (int)VMEODCooldownEventPluginModes.AvatarThisLotOnly: { UsePluginPersistOnly = true; break; } case (int)VMEODCooldownEventPluginModes.AccountThisLotOnly: { UsePluginPersistOnly = true; LimitByUserAccount = true; break; } case (int)VMEODCooldownEventPluginModes.AccountGlobal: { LimitByUserAccount = true; break; } case (int)VMEODCooldownEventPluginModes.AvatarByCategory: { ConsiderLotCategory = true; break; } case (int)VMEODCooldownEventPluginModes.AvatarByCategorySansCommunity: { ConsiderLotCategory = true; AlternateCommunityLotRules = true; break; } case (int)VMEODCooldownEventPluginModes.AccountByCategory: { ConsiderLotCategory = true; LimitByUserAccount = true; break; } case (int)VMEODCooldownEventPluginModes.AccountByCategorySansCommunity: { ConsiderLotCategory = true; LimitByUserAccount = true; AlternateCommunityLotRules = true; break; } } VMAsyncAccountUserIDFromAvatarCallback callback = null; if (UsePluginPersistOnly || AlternateCommunityLotRules && Server.vm.TSOState.CommunityLot) { // this lot only, use LoadPluginPersist callback = (uint userID) => { Server.vm.GlobalLink.LoadPluginPersist(Server.vm, Server.Object.PersistID, Server.PluginID, (byte[] data) => { lock (CommunityLock) { if (data == null) { Data = new VMEODCooldownEventPluginCommunityData(); } else { Data = new VMEODCooldownEventPluginCommunityData(data); // data found, look for my avatar id or my user id Tuple <uint, uint, long> tuple = null; if (LimitByUserAccount) { tuple = Data.AvatarIDUserIDTimeStamps.FirstOrDefault(entry => entry.Item2 == userID); } else { tuple = Data.AvatarIDUserIDTimeStamps.FirstOrDefault(entry => entry.Item1 == client.Avatar.PersistID); } if (tuple != null) { var timeStamp = new DateTime(tuple.Item3); // entry found, check if cooldown has passed since timestamp if (currentTime < timeStamp) { // the specified cooldown has not passed yet SimanticsResponse((LimitByUserAccount) ? VMEODCooldownEventPluginEvents.LocalFailureForAccount : VMEODCooldownEventPluginEvents.LocalFailureForAvatar, GetRemainingTime(timeStamp - currentTime)); return; } // the cooldown has passed - go to success below Data.AvatarIDUserIDTimeStamps.Remove(tuple); } // my persist ID was not found - go to success below } // my persist ID wasn't found or there was no data loaded from the DB or the cooldown passed Data.AvatarIDUserIDTimeStamps.Add(new Tuple <uint, uint, long>(client.Avatar.PersistID, userID, currentTime.Ticks + CooldownLength.Ticks)); Server.vm.GlobalLink.SavePluginPersist(Server.vm, Server.Object.PersistID, Server.PluginID, Data.Save()); SimanticsResponse((LimitByUserAccount) ? VMEODCooldownEventPluginEvents.LocalSuccessForAccount : VMEODCooldownEventPluginEvents.LocalSuccessForAvatar, GetRemainingTime(CooldownLength)); } }); }; } else // global or categorical { callback = (uint userID) => { lock (CooldownDBQueryLock) { // try to get the data from the database Server.vm.GlobalLink.GetObjectGlobalCooldown(Server.vm, OBJGUID, client.Avatar.PersistID, userID, CooldownLength, LimitByUserAccount, ConsiderLotCategory, (bool?cooldownHasPassed, DateTime cooldownExpiry) => { if (cooldownHasPassed == null) { SimanticsResponse(VMEODCooldownEventPluginEvents.DatabaseError, 0); } else if ((bool)cooldownHasPassed) { if (LimitByUserAccount) { SimanticsResponse((ConsiderLotCategory) ? VMEODCooldownEventPluginEvents.CategorySuccessForAccount : VMEODCooldownEventPluginEvents.GlobalSuccessForAccount, GetRemainingTime(CooldownLength)); } else { SimanticsResponse((ConsiderLotCategory) ? VMEODCooldownEventPluginEvents.CategorySuccessForAvatar : VMEODCooldownEventPluginEvents.GlobalSuccessForAvatar, GetRemainingTime(CooldownLength)); } } else { if (LimitByUserAccount) { SimanticsResponse((ConsiderLotCategory) ? VMEODCooldownEventPluginEvents.CategoryFailureForAccount : VMEODCooldownEventPluginEvents.GlobalFailureForAccount, GetRemainingTime(cooldownExpiry - currentTime)); } else { SimanticsResponse((ConsiderLotCategory) ? VMEODCooldownEventPluginEvents.CategoryFailureForAvatar : VMEODCooldownEventPluginEvents.GlobalFailureForAvatar, GetRemainingTime(cooldownExpiry - currentTime)); } } }); } }; } // finally execute lock (GetAccountIDLock) { if (!LimitByUserAccount) { callback.Invoke(0); } else { Server.vm.GlobalLink.GetAccountIDFromAvatar(client.Avatar.PersistID, callback); } } } base.OnConnection(client); }