private static async Task PunishUsers(PunishmentAction action, ProtectionType pt, params IGuildUser[] gus) { _log.Info($"[{pt}] - Punishing [{gus.Length}] users with [{action}] in {gus[0].Guild.Name} guild"); foreach (var gu in gus) { switch (action) { case PunishmentAction.Mute: try { await MuteCommands.MuteUser(gu).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Kick: try { await gu.KickAsync().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Softban: try { await gu.Guild.AddBanAsync(gu, 7).ConfigureAwait(false); try { await gu.Guild.RemoveBanAsync(gu).ConfigureAwait(false); } catch { await gu.Guild.RemoveBanAsync(gu).ConfigureAwait(false); // try it twice, really don't want to ban user if // only kick has been specified as the punishement } } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; case PunishmentAction.Ban: try { await gu.Guild.AddBanAsync(gu, 7).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; } } await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false); }
public void handleCommand(LogCommands cmd, byte[] cmddata) { if (cmd == LogCommands.UPDATE) { // decode basic block key/value writes BlockAccessor ba = new BlockAccessor(cmddata); ISegmentBlockDecoder decoder = new SegmentBlockBasicDecoder(ba); foreach (KeyValuePair<RecordKey, RecordUpdate> kvp in decoder.sortedWalk()) { // add the updates to our working segment... lock (mylayer.segmentlayers) { #if false // some status debug code... if (RangemapManager.RangeKey.isRangeKey(kvp.Key)) { System.Console.WriteLine("LayerManager.handleCommand : setValue() {0} => {1}", kvp.Key.ToString(), kvp.Value.ToString()); if (kvp.Value.type != RecordUpdateTypes.DELETION_TOMBSTONE && kvp.Value.data.Length != 16) { throw new Exception("!!! corrupted rangekey appeared in handleCommand"); } } #endif mylayer.workingSegment.setRecord(kvp.Key, kvp.Value); } } } else if (cmd == LogCommands.CHECKPOINT_START) { // here we move aside the checkpoint segment... // - if this is during live operation, the checkpoint is running as soon as we return. // - if this is during recovery, there is no checkpoint running and we'll need to // TODO: we need some kind of key/checksum to be sure that we CHECKPOINT and DROP the right dataF checkpointSegment = mylayer.workingSegment; SegmentMemoryBuilder newsegment = new SegmentMemoryBuilder(); lock (mylayer.segmentlayers) { mylayer.workingSegment = newsegment; mylayer.segmentlayers.Insert(0, mylayer.workingSegment); } } else if (cmd == LogCommands.CHECKPOINT_DROP) { // TODO: we need some kind of key/checksum to be sure that we CHECKPOINT and DROP the right data if (checkpointSegment != null) { lock (mylayer.segmentlayers) { mylayer.segmentlayers.Remove(checkpointSegment); checkpointSegment = null; } } else { throw new Exception("can't drop, no segment to drop"); } } else { throw new Exception("unimplemented command"); } }
private async Task PunishUsers(PunishmentAction action, IRole muteRole, ProtectionType pt, params IGuildUser[] gus) { foreach (var gu in gus) { switch (action) { case PunishmentAction.Mute: try { await gu.AddRolesAsync(muteRole); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Kick: try { await gu.Guild.AddBanAsync(gu, 7); try { await gu.Guild.RemoveBanAsync(gu); } catch { await gu.Guild.RemoveBanAsync(gu); // try it twice, really don't want to ban user if // only kick has been specified as the punishement } } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; case PunishmentAction.Ban: try { await gu.Guild.AddBanAsync(gu, 7); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; default: break; } } await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false); }
private void InitializeLoggers() { LogPhysics.SetLogging(logPhysics); LogCommands.SetLogging(logCommand); }
private void addCommand(LogCommands cmd, byte[] cmddata) { if (this.type == WriteGroupType.DISK_INCREMENTAL) { // if we are allowed to add each write to the disk log, then do it now mylayer.logwriter.addCommand(cmd, cmddata, out this.last_logwaitnumber); } else if (this.type == WriteGroupType.DISK_ATOMIC_FLUSH) { // add it to our pending list of commands to flush at the end... pending_cmds.Add(new LogCmd(cmd, cmddata)); } else if (this.type == WriteGroupType.MEMORY_ONLY) { // we don't need to add to the log at all, but it still needs to be pushed // through the LogWriter so it can be applied to the working segment mylayer.logwriter.addCommand_NoLog(cmd, cmddata); } else if (this.type == WriteGroupType.DISK_ATOMIC_NOFLUSH) { // add it to our pending list of commands to flush at the end... pending_cmds.Add(new LogCmd(cmd, cmddata)); } else { throw new Exception("unknown write group type in addCommand() " + type.ToString()); } }
internal void _addCommand(LogCommands cmdtype, byte[] cmdbytes, out long logWaitNumber) { lock (this) { this._processCommand(cmdtype, cmdbytes); nextChunkBuffer.Write((UInt32)cmdbytes.Length); nextChunkBuffer.Write((byte)cmdtype); nextChunkBuffer.Write(cmdbytes, 0, cmdbytes.Length); logWaitNumber = this._logWaitSequenceNumber; } }
private void _processCommand(LogCommands cmdtype, byte[] cmdbytes) { if (cmdtype == LogCommands.CHECKPOINT_START) { // (1) make sure there is no pending checkpoint if (checkpoint_log_segments != null) { throw new Exception("can't process two checkpoints at once!"); } // setup for the checkpoint.. checkpoint_log_segments = new List<RootBlockLogSegment>(); checkpointReady = false; // (2) make a record of the "freeable" log segments lock (this) { foreach (RootBlockLogSegment seg in active_log_segments) { // skip the currently active segment because we can only drop whole log segments if (!seg.Equals(currentLogSegmentInfo)) { checkpoint_log_segments.Add(seg); } } } } // this happens in the lock to be sure the flag and the drop end up in the same packet if (cmdtype == LogCommands.CHECKPOINT_DROP) { // (1) match the checkpoint number against our current pending checkpoint info... // (2) "drop" the old log segments by moving them to the pending-free-list checkpointReady = true; // the actual flush will take care of the drop } }
public LogCmd(LogCommands cmd, byte[] cmddata) { this.cmd = cmd; this.cmddata = cmddata; }
// --- basic add commands --- public void addCommand_NoLog(LogCommands cmdtype, byte[] cmdbytes) { receiver.handleCommand(cmdtype, cmdbytes); }
public void addCommand(LogCommands cmdtype, byte[] cmdbytes, out long logWaitNumber) { lock (log_handler) { log_handler._addCommand(cmdtype, cmdbytes, out logWaitNumber); } // we always expect the ILogReceiver to actually apply the command receiver.handleCommand(cmdtype, cmdbytes); }
public void handleCommand(LogCommands cmd, byte[] cmdbytes) { LogCmd newcmd = new LogCmd(); newcmd.cmd = cmd; newcmd.cmddata = cmdbytes; // accumulate the command this.cmds.Add(newcmd); }
public void handleCommand(LogCommands cmd, byte[] cmddata) { // do nothing! }