private void ExecutePacketAsync(GameClient Session, ClientMessage Packet, IPacketEvent Pak) { DateTime Start = DateTime.Now; var CancelSource = new CancellationTokenSource(); var Token = CancelSource.Token; Task t = _eventDispatcher.StartNew(() => { Pak.Parse(Session, Packet); Token.ThrowIfCancellationRequested(); }, Token); this._runningTasks.TryAdd(t.Id, t); try { if (!t.Wait(MaximumRunTimeInSec * 1000, Token)) { CancelSource.Cancel(); } } catch (AggregateException ex) { foreach (var e in ex.Flatten().InnerExceptions) { if (ThrowUserErrors) { throw e; } else { //log.Fatal("Unhandled Error: " + e.Message + " - " + e.StackTrace); Session.Disconnect(); } } } catch (OperationCanceledException) { Session.Disconnect(); } finally { Task RemovedTask = null; this._runningTasks.TryRemove(t.Id, out RemovedTask); CancelSource.Dispose(); //log.Debug("Event took " + (DateTime.Now - Start).Milliseconds + "ms to complete."); } }
internal void BanUser(GameClient Client, string Moderator, Double LengthSeconds, string Reason, Boolean IpBan, Boolean Machine) { ModerationBanType Type = ModerationBanType.USERNAME; string Var = Client.GetHabbo().Username; string RawVar = "user"; Double Expire = SilverwaveEnvironment.GetUnixTimestamp() + LengthSeconds; if (IpBan) { Type = ModerationBanType.IP; using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT ip_last FROM users WHERE username='******' LIMIT 1"); Var = dbClient.getString(); } RawVar = "ip"; } if (Machine) { Type = ModerationBanType.MACHINE; RawVar = "machine"; Var = Client.MachineId; } ModerationBan ban = new ModerationBan(Type, Var, Reason, Expire); if (ban.Type == ModerationBanType.IP) { if (bannedIPs.ContainsKey(Var)) bannedIPs[Var] = ban; else bannedIPs.Add(Var, ban); } else if (ban.Type == ModerationBanType.MACHINE) { if (bannedMachines.ContainsKey(Var)) bannedMachines[Var] = ban; else bannedMachines.Add(Var, ban); } else { if (bannedUsernames.ContainsKey(Var)) bannedUsernames[Var] = ban; else bannedUsernames.Add(Var, ban); } using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO bans (bantype,value,reason,expire,added_by,added_date) VALUES (@rawvar,@var,@reason,'" + Expire + "',@mod,'" + DateTime.Now.ToLongDateString() + "')"); dbClient.addParameter("rawvar", RawVar); dbClient.addParameter("var", Var); dbClient.addParameter("reason", Reason); dbClient.addParameter("mod", Moderator); dbClient.runQuery(); } if (IpBan) { DataTable UsersAffected = null; using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE ip_last = @var"); dbClient.addParameter("var", Var); UsersAffected = dbClient.getTable(); } if (UsersAffected != null) { using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { foreach (DataRow Row in UsersAffected.Rows) { dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Convert.ToUInt32(Row["id"])); } } } BanUser(Client, Moderator, LengthSeconds, Reason, false, false); } else { using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Client.GetHabbo().Id); } Client.Disconnect(); } }