Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Title = "BlackCarp";
            ChatServer.Init();
            int LogFile = 0;

            StartThread(() => {
                while (true)
                {
                    while (Lobby.GetCount() < 2)
                    {
                        Thread.Sleep(100);
                    }

                    ChatClient A = Lobby.Dequeue();
                    ChatClient B = Lobby.Dequeue();

                    string LogFileName = "log_" + LogFile + ".txt";
                    LogFile++;

                    A.OnMessageEvent = CreateMessageRoute(B, LogFileName);
                    A.OnClosedEvent  = CreateClosedRoute(B);
                    B.OnMessageEvent = CreateMessageRoute(A, LogFileName);
                    B.OnClosedEvent  = CreateClosedRoute(A);

                    Print("{0} and {1} linked", A, B);
                    ChatServer.SendMessage("Found partner", MessageType.ServerInfo, new[] { A, B });
                }
            });

            StartThread(() => {
                while (true)
                {
                    Thread.Sleep(10000);
                    ChatServer.Purge();
                }
            });

            Print("Server started");
            while (true)
            {
                Thread.Sleep(1000);
            }
        }