private void ClientsWatcher() // Heartbeats { bool check = false; short c = 0; do { Thread.Sleep(watch_delay); if (Globals.Clients.Count > 0) { if (c > 99) { foreach (Clientplayer temp in Globals.Clients.GetList()) { Clientplayer.CodeEvent(temp); } c = 0; } else { foreach (Clientplayer temp in Globals.Clients.GetList()) { if (check) { if (Clientplayer.IsAlive(temp)) { //lock(temp) if (!Clientplayer.Key(temp).Equals(Cryption.Decrypt( getkey(Clientplayer.GetRemoteEndPointIntPort(temp)), Clientplayer.GetRemoteEndPointString(temp), Clientplayer.GetCode16(temp), "SHA1", 10, Clientplayer.GetCodeByte(temp), 192))) { Warning.AddWarningToClient(Clientplayer.GetWarning(temp), true); } } } else { Clientplayer.Send(temp, UpdateKey(Clientplayer.GetRemoteEndPointIntPort(temp)), (byte)Enums.PacketID.key); } } check = !check; c++; } } } while (true); }
private void RunProcessor() { while (process) { Clientplayer client = null; lock (Globals.ConnectionPool.SyncRoot) { if (Globals.ConnectionPool.Count > 0) { client = Globals.ConnectionPool.Dequeue(); } } if (client != null) { client.Process(); if (Clientplayer.IsAlive(client)) { Globals.ConnectionPool.Enqueue(client); } } //Monitor.Pulse(this); if (Monitor.TryEnter(Globals.ServerFullClients.SyncRoot, 10))//fix bug, holding processors from client handling by full server { //lock (Globals.ServerFullClients.SyncRoot) //{ while (Globals.ServerFullClients.Count > 0) { Clientplayer.SendServerFull(Globals.ServerFullClients.DequeueT()); } //} Monitor.Exit(Globals.ServerFullClients.SyncRoot); } Thread.Sleep(100); // save CPU XDD } }