示例#1
0
        private void TCP_Server()
        {
            TcpListener listener = null;

            Log.Write("Launching TCP Server and Initializing the Network....");
            try
            {
                listener = new TcpListener(IPAddress.Parse(IP), port);
                listener.Start();
                Log.Write("Network Initialized, listening for Connections on: {0}", listener.LocalEndpoint.ToString());

                Processor.Run(procesors);

                new ProcessorWatcher().Start(watch);
                new ClientWatcher().Start(watchclient);

                Log.Write("Mission Completed Generel, you can go now!");
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("**================================================================================================**");

                while (this.Online)
                {
                    TcpClient NewClient = listener.AcceptTcpClient();

                    if (Globals.Shield.IsBlocked(Clientplayer.GetRemoteEndPointInt(NewClient)))
                    {
                        try
                        {
                            NewClient.Close();
                        }
                        catch { }
                        continue;
                    }

                    if (Functions.IsServerFull)
                    {
                        Log.Write("New Player Queued, Server is FULL! ----- RemoteEndPoint: {0}", Clientplayer.GetRemoteEndPointString(NewClient));
                        Globals.ServerFullClients.Enqueue(NewClient);
                    }
                    else
                    {
                        Log.Write("New Player Connected! ----- RemoteEndPoint: {0}", Clientplayer.GetRemoteEndPointString(NewClient));
                        Globals.ConnectionPool.Enqueue(new Clientplayer(NewClient));
                    }
                }
                Shutdown(listener);
            }
            catch (Exception e)
            {
                Log.Write(e.ToString());
                Shutdown(listener);
            }
        }
示例#2
0
        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);
        }