Esempio n. 1
0
 public GameSimulation(GameQueue _queue)
 {
     RequestShutdown = false;
     queue           = _queue;
     execute         = new Action <PlayerSocketController, PlayerSocketController>(Simulation);
     tFactory        = new TaskFactory();
 }
Esempio n. 2
0
        public SocketCommunicator(GameQueue masterQueue)
        {
            RequestShutdown = false;
            Queue           = masterQueue;
            SocketInfo      = new SocketInformation();

            ipHost        = Dns.GetHostEntry(Dns.GetHostName());
            ipAddr        = ipHost.AddressList[0];
            localEndPoint = new IPEndPoint(ipAddr, 0);

            PrimarySocket = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
        }
Esempio n. 3
0
        public void StartServer()
        {
            Console.WriteLine("Server initialized");



            Console.WriteLine("Opening Matchmaking Queue...");
            GameQueue      queue            = new GameQueue();
            GameSimulation matchMaker       = new GameSimulation(queue);
            Thread         MatchmakerThread = new Thread(matchMaker.Run);

            MatchmakerThread.Start();
            Console.WriteLine("Queue Opened.");


            Console.WriteLine("Opening Socket Communication...");
            SocketCommunicator communicator = new SocketCommunicator(queue);
            Thread             SocketThread = new Thread(communicator.listen);

            SocketThread.Start();
            Console.WriteLine("Communication Started.");

            Thread.Sleep(100);

            while (true)
            {
                Console.WriteLine("\nOptions:");
                Console.WriteLine("1: Check the queue size");
                Console.WriteLine("2: Shutdown the server");

                string a = Console.ReadLine();

                if (a == "1")
                {
                    Console.WriteLine($"Queue Size is {queue.queue.Count}");
                }
                else
                {
                    communicator.RequestShutdown = true;
                    matchMaker.RequestShutdown   = true;

                    MatchmakerThread.Join();
                    SocketThread.Join();
                    break;
                }
            }
        }