コード例 #1
0
ファイル: Watchers.cs プロジェクト: elshaikh-amir/TheGame
        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);
        }
コード例 #2
0
ファイル: Processor.cs プロジェクト: elshaikh-amir/TheGame
        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
            }
        }