本文整理汇总了C#中System.Collections.Queue.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Clear方法的具体用法?C# Queue.Clear怎么用?C# Queue.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PacketReceiver
internal PacketReceiver(string LocalAddress) : base (LocalAddress)
{
packetReceiver = new Queue();
tokenSource = new CancellationTokenSource();
readerWriterLock = new ReaderWriterLockSlim();
tokenSource.Token.Register(() => {
// Clear on cancel
packetReceiver.Clear();
});
var thReceiveQueue = Task.Factory.StartNew(() => {
while (tokenSource.Token.IsCancellationRequested == false)
{
readerWriterLock.EnterUpgradeableReadLock();
if (packetReceiver.Count > 0)
{
readerWriterLock.EnterWriteLock();
byte[] data = (byte[])packetReceiver.Dequeue();
readerWriterLock.ExitWriteLock();
if (OnNewPacketReceived != null)
OnNewPacketReceived(this, new NewPacketEventArgs(data));
}
readerWriterLock.ExitUpgradeableReadLock();
}
});
}
示例2: Main
static void Main(string[] args)
{
Queue<Action> action_queue = new Queue<Action>();
action_queue.Enqueue(new Action(1));
action_queue.Enqueue(new Action(2));
action_queue.Enqueue(new Action(3));
Console.Write("ActionQueue : ");
foreach (Action action in action_queue)
{
Console.Write("{0} ", action.action_no_);
}
Console.WriteLine();
{
Action action = action_queue.Dequeue();
Console.WriteLine("Dequeue {0} : ", action.action_no_);
}
Console.Write("ActionQueue : ");
foreach (Action action in action_queue)
{
Console.Write("{0} ", action.action_no_);
}
Console.WriteLine();
{
Console.WriteLine("Clear");
action_queue.Clear();
}
Console.Write("ActionQueue : ");
foreach (Action action in action_queue)
{
Console.Write("{0} ", action.action_no_);
}
Console.WriteLine();
}
示例3: Start
// Use this for initialization
void Start()
{
Debug.Log("START");
cf = new ConnectionFactory();
cf.HostName = serverip;
conn = cf.CreateConnection();
conn.ConnectionShutdown += new ConnectionShutdownEventHandler(LogConnClose);
ch = conn.CreateModel();
ch.ExchangeDeclare(exchange, "fanout");
string queueName = ch.QueueDeclare();
ch.QueueBind(queueName, exchange, "");
//ch.QueueBind(queueName,exchange,"",false,null); //version shup
consumer = new QueueingBasicConsumer(ch);
ch.BasicConsume(queueName, true, consumer);
//ch.BasicConsume(queueName,null,consumer); //version shup
queue = new System.Collections.Queue();
queue.Clear();
}
示例4: HackerCheckerThreadLoop
public void HackerCheckerThreadLoop()
{
Double checkedPlayers = 0;
Double playersWithStats = 0;
try {
this.DebugWrite("HCKCHK: Starting Hacker Checker Thread", 1);
Thread.CurrentThread.Name = "HackerChecker";
Queue<AdKatsPlayer> playerCheckingQueue = new Queue<AdKatsPlayer>();
Queue<AdKatsPlayer> repeatCheckingQueue = new Queue<AdKatsPlayer>();
while (true) {
try {
this.DebugWrite("HCKCHK: Entering Hacker Checker Thread Loop", 7);
if (!this._IsEnabled) {
playerCheckingQueue.Clear();
repeatCheckingQueue.Clear();
this.DebugWrite("HCKCHK: Detected AdKats not enabled. Exiting thread " + Thread.CurrentThread.Name, 6);
break;
}
try {
//Get all unchecked players
if (this._HackerCheckerQueue.Count > 0) {
this.DebugWrite("HCKCHK: Preparing to lock hackerCheckerMutex to retrive new players", 6);
lock (this._HackerCheckerMutex) {
this.DebugWrite("HCKCHK: Inbound players found. Grabbing.", 5);
//Grab all players in the queue
playerCheckingQueue = new Queue<AdKatsPlayer>(this._HackerCheckerQueue.ToArray());
//Clear the queue for next run
this._HackerCheckerQueue.Clear();
}
}
else {
this.DebugWrite("HCKCHK: No inbound hacker checks. Waiting 10 seconds or for input.", 4);
//Wait for input
this._HackerCheckerWaitHandle.Reset();
//Either loop when handle is set, or after 3 minutes
this._HackerCheckerWaitHandle.WaitOne(180000 / ((repeatCheckingQueue.Count > 0) ? (repeatCheckingQueue.Count) : (1)));
}
}
catch (Exception e) {
this.HandleException(new AdKatsException("Error while fetching new players to check.", e));
}
//Current player being checked
AdKatsPlayer aPlayer = null;
try {
//Check one player from the repeat checking queue
if (repeatCheckingQueue.Count > 0) {
//Only keep players still in the server in the repeat checking list
Boolean stillInServer = true;
do {
if (!this._IsEnabled) {
break;
}
aPlayer = repeatCheckingQueue.Dequeue();
if (!this._PlayerDictionary.ContainsKey(aPlayer.player_name)) {
stillInServer = false;
}
} while (!stillInServer && repeatCheckingQueue.Count > 0);
if (aPlayer != null) {
//Fetch their stats from appropriate source
this.FetchPlayerStats(aPlayer);
//check for dmg mod if stats available
if (aPlayer.stats != null && aPlayer.stats.StatsException == null) {
playersWithStats++;
this.ConsoleSuccess(aPlayer.player_name + " now has stats. Checking.");
if (this._UseHackerChecker) {
if (!this.PlayerProtected(aPlayer)) {
this.RunStatSiteHackCheck(aPlayer, false);
}
}
else {
this.DebugWrite("Player removed from check list after disabling hacker checker.", 2);
}
this.DebugWrite("Players with " + this._GameVersion + "Stats: " + String.Format("{0:0.00}", (playersWithStats / checkedPlayers) * 100) + "%", 3);
}
else {
aPlayer.stats = null;
//If they still dont have stats, add them back to the queue
repeatCheckingQueue.Enqueue(aPlayer);
}
}
}
}
catch (Exception e) {
this.HandleException(new AdKatsException("Error while in repeat checking queue handler", e));
}
//Get all checks in order that they came in
while (playerCheckingQueue.Count > 0) {
if (!this._IsEnabled) {
break;
}
//Grab first/next player
aPlayer = playerCheckingQueue.Dequeue();
if (aPlayer != null) {
this.DebugWrite("HCKCHK: begin reading player", 4);
//.........这里部分代码省略.........
示例5: ProcessMessagesThreadProc
//.........这里部分代码省略.........
LocalRecipient.MessageAvailableSignal();
}
}
else
{
Debug.Assert( Recipient is RemoteConnection );
// If the recipient is remote, send the message via SendMessage
// unless the message is a Task being sent back, which is sent
// via the dedicated Task API
RemoteConnection RemoteRecipient = Recipient as RemoteConnection;
if( NextMessage is AgentTaskSpecification )
{
// All new Tasks are sent via the dedicated Task API
AgentTaskSpecification TaskSpecification = NextMessage as AgentTaskSpecification;
Hashtable RemoteInParameters = new Hashtable();
RemoteInParameters["Version"] = ESwarmVersionValue.VER_1_0;
RemoteInParameters["Specification"] = TaskSpecification;
Hashtable RemoteOutParameters = null;
Int32 Error = RemoteRecipient.Interface.AddTask( RemoteRecipient.Handle, RemoteInParameters, ref RemoteOutParameters );
if( Error >= 0 )
{
// Perhaps we should be sending an accept message back?
}
else
{
AgentTaskState UpdateMessage;
if( Error == Constants.ERROR_CONNECTION_DISCONNECTED )
{
// Special case of the connection dropping while we're adding the
// task, say it's been killed to requeue
UpdateMessage = new AgentTaskState( TaskSpecification.JobGuid,
TaskSpecification.TaskGuid,
EJobTaskState.TASK_STATE_KILLED );
}
else
{
// All other error cases will be rejections
UpdateMessage = new AgentTaskState( TaskSpecification.JobGuid,
TaskSpecification.TaskGuid,
EJobTaskState.TASK_STATE_REJECTED );
}
AgentJob Job;
if( ActiveJobs.TryGetValue( TaskSpecification.JobGuid, out Job ) )
{
Job.UpdateTaskState( UpdateMessage );
}
}
}
else
{
// All standard messages are sent via the SendMessage API
Hashtable RemoteInParameters = new Hashtable();
RemoteInParameters["Version"] = ESwarmVersionValue.VER_1_0;
RemoteInParameters["Message"] = NextMessage;
Hashtable RemoteOutParameters = null;
RemoteRecipient.Interface.SendMessage( NextMessage.To, RemoteInParameters, ref RemoteOutParameters );
}
string NewLogMessage = String.Format( "Step 2 of 2 for message: ({0:X8} -> {1:X8}), {2}, (Remote Connection)",
NextMessage.To,
NextMessage.From,
NextMessage.Type );
Log( EVerbosityLevel.SuperVerbose, ELogColour.Green, NewLogMessage );
}
}
else
{
Log( EVerbosityLevel.Informative, ELogColour.Orange, "ProcessMessage: Message sent to invalid connection, ignoring: " + NextMessage.Type.ToString() );
}
}
// If there are any responses to the message, send them
if( ResponseMessageQueue.Count > 0 )
{
foreach( AgentMessage NextResponse in ResponseMessageQueue )
{
// For each one of the messages, set the routing fields properly
NextResponse.To = NextMessage.From;
NextResponse.From = NextMessage.To;
// And then queue the message back up immediately
MessageQueuePM.Enqueue( NextResponse );
}
ResponseMessageQueue.Clear();
}
}
StopTiming();
// Wait for a message to become available and once unlocked, swap the queues
// and check for messages to process. Set a timeout, so we'll wake up every
// now and then to check for a quit signal at least
MessageQueueReady.WaitOne( 500 );
}
}
示例6: UpdateRightNodes
private void UpdateRightNodes(Node openNode, IList<Node> visitedNodes,
Queue<Node> openNodes, IList<Pair<Node>> parent)
{
foreach (var rightNode in _rightNodes)
{
bool freeNodeFound = true;
if (HasEdge(openNode, rightNode) && !visitedNodes.Contains(rightNode))
{
if (_matching.Any(matchingPair => matchingPair.Second.Equals(rightNode)))
{
openNodes.Enqueue(rightNode);
freeNodeFound = false;
}
UpdateParentList(parent, rightNode, openNode);
if (freeNodeFound)
{
UpdateMatching(parent, rightNode);
openNodes.Clear();
break;
}
}
}
}
示例7: Load
public bool Load(Queue<Token> tokens, Type tokenizerType,TemplateGroup group)
{
Token t = tokens.Dequeue();
Queue<Token> toks = new Queue<Token>();
Match m;
if (regSimpleStyle.IsMatch(t.Content)){
m = regSimpleStyle.Match(t.Content);
toks.Enqueue(new Token(m.Groups[1].Value.Trim(), TokenType.COMPONENT));
_left = ComponentExtractor.ExtractComponent(toks,tokenizerType,group);
toks.Clear();
switch (m.Groups[2].Value.ToUpper())
{
case "NE":
_type = CompareType.NOT_EQUAL;
break;
case "GT":
_type = CompareType.GREATER_THAN;
break;
case "GE":
_type = CompareType.GREATER_THAN_OR_EQUAL_TO;
break;
case "LT":
_type = CompareType.LESS_THAN;
break;
case "LE":
_type = CompareType.LESS_THAN_OR_EQUAL_TO;
break;
case "ST":
_type = CompareType.SIMILAR_TO;
break;
case "NS":
_type = CompareType.NOT_SIMILAR_TO;
break;
}
if (m.Groups[11].Value.Trim().StartsWith("'")||m.Groups[11].Value.Trim().StartsWith("\""))
toks.Enqueue(new Token(m.Groups[11].Value.Trim().Substring(1,m.Groups[11].Value.Trim().Length-2), TokenType.TEXT));
else
toks.Enqueue(new Token(m.Groups[11].Value.Trim(),TokenType.COMPONENT));
_right = ComponentExtractor.ExtractComponent(toks,tokenizerType,group);
}else{
m = regFunctionStyle.Match(t.Content);
switch (m.Groups[1].Value.ToUpper())
{
case "NOTEQUAL":
_type = CompareType.NOT_EQUAL;
break;
case "GREATERTHAN":
_type = CompareType.GREATER_THAN;
break;
case "GREATERTHANOREQUALTO":
_type = CompareType.GREATER_THAN_OR_EQUAL_TO;
break;
case "LESSTHAN":
_type = CompareType.LESS_THAN;
break;
case "LESSTHANOREQUALTO":
_type = CompareType.LESS_THAN_OR_EQUAL_TO;
break;
case "SIMILARTO":
_type = CompareType.SIMILAR_TO;
break;
case "NOTSIMILARTO":
_type = CompareType.NOT_SIMILAR_TO;
break;
}
toks.Enqueue(new Token(m.Groups[12].Value,TokenType.COMPONENT));
_left = ComponentExtractor.ExtractComponent(toks, tokenizerType, group);
toks.Clear();
if (m.Groups[13].Value.Trim().StartsWith("'") || m.Groups[13].Value.Trim().StartsWith("\""))
toks.Enqueue(new Token(m.Groups[12].Value.Trim().Substring(1, m.Groups[13].Value.Trim().Length - 2), TokenType.TEXT));
else
toks.Enqueue(new Token(m.Groups[13].Value.Trim(), TokenType.COMPONENT));
_right = ComponentExtractor.ExtractComponent(toks, tokenizerType, group);
}
return true;
}
示例8: CompleteAllOnDispose
void CompleteAllOnDispose (Queue queue)
{
object [] pending = queue.ToArray ();
queue.Clear ();
WaitCallback cb;
for (int i = 0; i < pending.Length; i++) {
SocketAsyncResult ares = (SocketAsyncResult) pending [i];
cb = new WaitCallback (ares.CompleteDisposed);
ThreadPool.QueueUserWorkItem (cb, null);
}
}
示例9: ParseOptions
//.........这里部分代码省略.........
case "template":
try
{
options.TemplateName = Path.GetFullPath(optarg);
}
catch
{
options.TemplateName = optarg;
}
optname = null;
break;
case "datasource":
try
{
options.DataSourceName = Path.GetFullPath(optarg);
}
catch
{
options.DataSourceName = optarg;
}
optname = null;
break;
case "savedir":
options.SaveDir = Path.GetFullPath(optarg);
optname = null;
break;
case "record":
options.Names.Add(optarg);
break;
case "help":
help = true;
break;
case "?":
goto case "help";
default:
goto case "help";
}
}
else
{
unnamed.Enqueue(optarg);
}
}
if (options.TemplateName == null && unnamed.Count != 0)
{
string name = unnamed.Peek();
if (name.ToLower().EndsWith(".pub"))
{
name = unnamed.Dequeue();
}
else if (name.ToLower().EndsWith(".xls") ||
name.ToLower().EndsWith(".xlsx") ||
name.ToLower().EndsWith(".xlsb") ||
name.ToLower().EndsWith(".xlsm"))
{
options.DataSourceName = unnamed.Dequeue();
name = options.DataSourceName.Substring(0, options.DataSourceName.LastIndexOf('.')) + ".pub";
}
else
{
name = null;
help = true;
}
try
{
if (name != null)
{
options.TemplateName = Path.GetFullPath(name);
}
}
catch
{
options.TemplateName = name;
}
}
if (unnamed.Count != 0)
{
options.Names.AddRange(unnamed);
unnamed.Clear();
}
if (String.IsNullOrEmpty(options.SaveDir))
{
if (options.TemplateName != null)
{
options.SaveDir = Path.GetDirectoryName(Path.GetFullPath(options.TemplateName));
}
else
{
options.SaveDir = progdir;
}
}
return !help;
}
示例10: DoFracture
public bool DoFracture(ref Particle other, ref Particle me)
{
bool somethingBroke = false;
double len = (other.goal - goal).Length();
double rest = (other.x0 - x0).Length();
double off = Math.Abs((len / rest) - 1.0);
if (off > LsmBody.fractureLengthTolerance)
{
somethingBroke = true;
Testbed.PostMessage("Length fracture: Rest = " + rest + ", actual = " + len);
}
if (!somethingBroke)
{
Vector2 a = new Vector2(other.R[0, 0], other.R[1, 0]);
Vector2 b = new Vector2(R[0, 0], R[1, 0]);
a.Normalize();
b.Normalize();
double angleDifference = Math.Acos(a.Dot(b));
if (angleDifference > LsmBody.fractureAngleTolerance)
{
somethingBroke = true;
Testbed.PostMessage("Angle fracture: angle difference = " + angleDifference);
}
}
if (somethingBroke)
{
Particle saved = other;
me = null;
other = null;
// Check if the chunks are still connected
Queue<Particle> edge = new Queue<Particle>();
List<Particle> found = new List<Particle>();
edge.Enqueue(this);
bool connected = false;
while (edge.Count > 0)
{
Particle p = edge.Dequeue();
if (!found.Contains(p))
{
found.Add(p);
if (p == saved)
{
// Connected
connected = true;
break;
}
if (p.xPos != null)
edge.Enqueue(p.xPos);
if (p.xNeg != null)
edge.Enqueue(p.xNeg);
if (p.yPos != null)
edge.Enqueue(p.yPos);
if (p.yNeg != null)
edge.Enqueue(p.yNeg);
}
}
if (connected == false)
{
// The chunks broke - there are now two separate chunks (maximally connected subgraphs)
chunk.particles.Clear();
chunk.particles.AddRange(found);
chunk.CalculateInvariants();
Chunk newChunk = new Chunk();
edge.Clear();
found.Clear();
edge.Enqueue(saved);
while (edge.Count > 0)
{
Particle p = edge.Dequeue();
if (!found.Contains(p))
{
found.Add(p);
p.chunk = newChunk;
if (p.xPos != null)
edge.Enqueue(p.xPos);
if (p.xNeg != null)
edge.Enqueue(p.xNeg);
if (p.yPos != null)
edge.Enqueue(p.yPos);
if (p.yNeg != null)
edge.Enqueue(p.yNeg);
}
}
newChunk.particles.AddRange(found);
newChunk.CalculateInvariants();
body.chunks.Add(newChunk);
Testbed.PostMessage("Chunk broken: the original chunk now has " + chunk.particles.Count + " particles, the new chunk has " + newChunk.particles.Count + " particles.");
Testbed.PostMessage("Number of chunks / particles: " + body.chunks.Count + " / " + body.particles.Count);
}
}
return somethingBroke;
//.........这里部分代码省略.........
示例11: Validation
// [Test]
public void Validation() {
Queue events = new Queue();
FormCustom form = new FormCustom("form1", true, events);
ContainerControlCustom container1 = new ContainerControlCustom("container1", true, events);
ContainerControlCustom container2 = new ContainerControlCustom("container2", true, events);
ContainerControlCustom container3 = new ContainerControlCustom("container3", true, events);
UserControlCustom userctl1 = new UserControlCustom("userctl1", true, events);
UserControlCustom userctl2 = new UserControlCustom("userctl2", true, events);
UserControlCustom userctl3 = new UserControlCustom("userctl3", true, events);
container2.Controls.Add(userctl2);
container2.Controls.Add(userctl3);
container1.Controls.Add(userctl1);
form.Controls.Add(container1);
form.Controls.Add(container2);
form.Controls.Add(container3);
form.Show();
object s;
events.Enqueue("START");
container3.Select();
events.Enqueue("END");
events.Enqueue("START");
container1.Select();
events.Enqueue("END");
events.Enqueue("START");
container2.Select();
events.Enqueue("END");
events.Enqueue("START");
userctl1.Select();
events.Enqueue("END");
events.Enqueue("START");
userctl2.Select();
events.Enqueue("END");
events.Enqueue("START");
userctl2.Select();
events.Enqueue("END");
while (events.Count > 0) {
s = events.Dequeue();
Console.WriteLine(s.ToString());
}
events.Clear();
form.Close();
userctl1.Dispose();
userctl2.Dispose();
userctl3.Dispose();
container1.Dispose();
container1.Dispose();
form.Dispose();
}
示例12: HandleComm
//.........这里部分代码省略.........
switch ( path )
{
// yes it should be this way
case PacketPath.ClientToServer:
{
blocked = !PacketPlayer.ClientPacket( p );
if ( !blocked )
blocked = PacketHandler.OnClientPacket( buff[0], pr, p );
break;
}
case PacketPath.ServerToClient:
{
if ( !PacketPlayer.Playing )
{
blocked = PacketHandler.OnServerPacket( buff[0], pr, p );
}
else
{
blocked = true;
if ( p != null && p.PacketID == 0x1C )
{
// 0, 1, 2
Serial serial = p.ReadUInt32(); // 3, 4, 5, 6
ushort body = p.ReadUInt16(); // 7, 8
MessageType type = (MessageType)p.ReadByte(); // 9
ushort hue = p.ReadUInt16(); // 10, 11
ushort font = p.ReadUInt16();
string name = p.ReadStringSafe( 30 );
string text = p.ReadStringSafe();
if ( World.Player != null && serial == Serial.Zero && body == 0 && type == MessageType.Regular && hue == 0xFFFF && font == 0xFFFF && name == "SYSTEM" )
{
p.Seek( 3, SeekOrigin.Begin );
p.WriteAsciiFixed( "", (int)p.Length-3 );
// CHEAT UO.exe 1/2 251--
// 1 = 2d
// 2 = 3d!
DoFeatures( World.Player.Features );
}
}
}
if ( !blocked )
blocked = !PacketPlayer.ServerPacket( p );
break;
}
}
if ( filter )
{
byte[] data = p.Compile();
fixed ( byte *ptr = data )
{
Packet.Log( path, ptr, data.Length, blocked );
if ( !blocked )
CopyToBuffer( outBuff, ptr, data.Length );
}
}
else
{
Packet.Log( path, buff, len, blocked );
if ( !blocked )
CopyToBuffer( outBuff, buff, len );
}
if ( !PacketPlayer.Playing )
{
while ( queue.Count > 0 )
{
p = (Packet)queue.Dequeue();
if ( PacketPlayer.Recording )
{
switch ( path )
{
case PacketPath.ClientToServer:
PacketPlayer.ClientPacket( p );
break;
case PacketPath.ServerToClient:
PacketPlayer.ServerPacket( p );
break;
}
}
byte[] data = p.Compile();
fixed ( byte *ptr = data )
{
CopyToBuffer( outBuff, ptr, data.Length );
Packet.Log( (PacketPath)(((int)path)+1), ptr, data.Length );
}
}
}
else
{
queue.Clear();
}
}
CommMutex.ReleaseMutex();
}
示例13: SendThreadEntryPoint
public void SendThreadEntryPoint(object state)
{
try
{
Queue workQueue = new Queue();
// loop...
while (true)
{
WaitHandle[] handles = new WaitHandle[2];
handles[0] = StopEvent;
handles[1] = DataReady;
if (WaitHandle.WaitAny(handles) == 0)
{
break;
}
else if (_Socket != null && _Socket.Connected)
{
// not disconnected
// go through the queue...
TransmitLock.AcquireWriterLock(-1);
try
{
workQueue.Clear();
foreach (string message in TransmitQueue)
{
workQueue.Enqueue(message);
}
TransmitQueue.Clear();
}
catch { }
finally
{
TransmitLock.ReleaseWriterLock();
}
// loop the outbound messages...
foreach (string message in workQueue)
{
SocketStateObject so2 = new SocketStateObject(_Socket);
byte[] buff = Encoding.ASCII.GetBytes(message);
// send it...
System.IAsyncResult iar;
iar = _Socket.BeginSend(buff, 0, buff.Length, 0, new AsyncCallback(AsynchSendCallback), so2);
}
}
}
}
catch { }
}
示例14: HackerCheckerThreadLoop
public void HackerCheckerThreadLoop() {
Double checkedPlayers = 0;
Double playersWithStats = 0;
try {
DebugWrite("HCKCHK: Starting Hacker Checker Thread", 1);
Thread.CurrentThread.Name = "HackerChecker";
var playerCheckingQueue = new Queue<AdKatsPlayer>();
var repeatCheckingQueue = new Queue<AdKatsPlayer>();
DateTime loopStart;
while (true) {
loopStart = DateTime.UtcNow;
try {
DebugWrite("HCKCHK: Entering Hacker Checker Thread Loop", 7);
if (!_pluginEnabled) {
playerCheckingQueue.Clear();
repeatCheckingQueue.Clear();
DebugWrite("HCKCHK: Detected AdKats not enabled. Exiting thread " + Thread.CurrentThread.Name, 6);
break;
}
try {
//Get all unchecked players
if (_HackerCheckerQueue.Count > 0) {
DebugWrite("HCKCHK: Preparing to lock hackerCheckerMutex to retrive new players", 6);
if (_isTestingAuthorized)
PushThreadDebug(DateTime.Now.Ticks, (String.IsNullOrEmpty(Thread.CurrentThread.Name) ? ("mainthread") : (Thread.CurrentThread.Name)), Thread.CurrentThread.ManagedThreadId, new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(), "");
lock (_HackerCheckerQueue) {
DebugWrite("HCKCHK: Inbound players found. Grabbing.", 5);
//Grab all players in the queue
playerCheckingQueue = new Queue<AdKatsPlayer>(_HackerCheckerQueue.ToArray());
//Clear the queue for next run
_HackerCheckerQueue.Clear();
}
}
else {
DebugWrite("HCKCHK: No inbound hacker checks. Waiting 10 seconds or for input.", 4);
//Wait for input
_HackerCheckerWaitHandle.Reset();
//Either loop when handle is set, or after 3 minutes
_HackerCheckerWaitHandle.WaitOne(180000 / ((repeatCheckingQueue.Count > 0) ? (repeatCheckingQueue.Count) : (1)));
}
}
catch (Exception e) {
HandleException(new AdKatsException("Error while fetching new players to check.", e));
}
//Current player being checked
AdKatsPlayer aPlayer = null;
try {
if (!_UseHackerChecker) {
repeatCheckingQueue.Clear();
}
//Check one player from the repeat checking queue
if (repeatCheckingQueue.Count > 0) {
//Only keep players still in the server in the repeat checking list
Boolean stillInServer = true;
do {
if (!_pluginEnabled) {
break;
}
aPlayer = repeatCheckingQueue.Dequeue();
if (!_PlayerDictionary.ContainsKey(aPlayer.player_name)) {
stillInServer = false;
}
} while (!stillInServer && repeatCheckingQueue.Count > 0);
if (aPlayer != null) {
//Fetch their stats from appropriate source
FetchPlayerStats(aPlayer);
if (aPlayer.stats != null && aPlayer.stats.StatsException == null) {
playersWithStats++;
ConsoleSuccess(aPlayer.player_name + " now has stats. Checking.");
if (!PlayerProtected(aPlayer)) {
RunStatSiteHackCheck(aPlayer, false);
}
DebugWrite("Players with " + _gameVersion + "Stats: " + String.Format("{0:0.00}", (playersWithStats / checkedPlayers) * 100) + "%", 3);
}
else {
aPlayer.stats = null;
//If they still dont have stats, add them back to the queue
repeatCheckingQueue.Enqueue(aPlayer);
}
}
}
}
catch (Exception e) {
HandleException(new AdKatsException("Error while in repeat checking queue handler", e));
}
//Get all checks in order that they came in
while (playerCheckingQueue.Count > 0) {
if (!_pluginEnabled) {
break;
}
//Grab first/next player
aPlayer = playerCheckingQueue.Dequeue();
if (aPlayer != null) {
DebugWrite("HCKCHK: begin reading player", 4);
if (!PlayerProtected(aPlayer)) {
//.........这里部分代码省略.........
示例15: ExecuteAlgorithm
private void ExecuteAlgorithm(int x, int y, IsValidHandler isValid, PointActionHandler action)
{
///Flood-Fill algorithm
Queue<Point> q = new Queue<Point>();
if (regionMask[x, y])
return;
q.Enqueue(new Point(x, y));
while (q.Count > 0)
{
Point p = q.Peek();
int x1 = p.X;
int y1 = p.Y;
if (isValid.Invoke(p))
{
action.Invoke(p.X, p.Y);
}
if (isValid.Invoke(new Point(x1, y1 + 1)))
{
action.Invoke(x1, y1 + 1);
q.Enqueue(new Point(x1, y1 + 1));
}
if (isValid.Invoke(new Point(x1, y1 - 1)))
{
action.Invoke(x1, y1 - 1);
q.Enqueue(new Point(x1, y1 - 1));
}
if (isValid.Invoke(new Point(x1 + 1, y1)))
{
action.Invoke(x1 + 1, y1);
q.Enqueue(new Point(x1 + 1, y1));
}
if (isValid.Invoke(new Point(x1 - 1, y1)))
{
action.Invoke(x1 - 1, y1);
q.Enqueue(new Point(x1 - 1, y1));
}
q.Dequeue();
if (border)
{
q.Clear();
depth = Int32.MaxValue;
}
}
///end of Flood-Fill algorithm
}