Exemplo n.º 1
0
        public override async void Execute(RaftServer server, bool AsLeader)
        {
            lock (server)
            {
                server.HasGameStarted        = false;
                server.GameStartRequest      = false;
                server.SessionClientsAddress = new List <Uri>();
                //send end to all clients in game
            }

            //sending info to clients
            if (AsLeader)
            {
                foreach (IClient client in server.SessionClients)
                {
                    await Task.Run(() =>
                    {
                        try
                        {
                            client.End(server.StateMachine.GetTopPlayer());
                        }
                        catch (Exception ee)
                        {
                        }
                        ;
                    });
                }
            }

            lock (server)
            {
                server.SessionClients = new List <IClient>();

                if (AsLeader)
                {
                    if (!server.HasGameStarted && !server.GameStartRequest &&
                        server.PendingClients.Count >= server.NumPlayers)
                    {
                        StartCommand startCommand = new StartCommand()
                        {
                            Name = "Start"
                        };

                        bool response;
                        int  commitAt;

                        server.OnCommand(startCommand);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Execute(RaftServer server, bool AsLeader)
        {
            Console.WriteLine("Join Commited.");
            IClient client = (IClient)Activator.GetObject(
                typeof(IClient),
                address.ToString() + "Client");

            server.PendingClients.Add(client);
            Console.WriteLine("ADDDED NOW PENDING: " + server.PendingClients.Count);

            if (AsLeader)
            {
                Console.WriteLine("AS LEADER");

                //Have enough players
                if (!server.HasGameStarted && !server.GameStartRequest &&
                    server.PendingClients.Count >= server.NumPlayers)
                {
                    server.GameStartRequest = true; // this is used to make sure no more startgame logs are created before the startgame entry is commited

                    //Make start Log

                    StartCommand startCommand = new StartCommand()
                    {
                        Name = "Start"
                    };

                    bool accepted;
                    int  commitedAt;
                    server.OnCommand(startCommand);

                    /*
                     * if (server.PeerURIs.Count == 1)
                     * {
                     *  //I'm the only one, I can commit everything
                     *  server.CommitIndex = server.Log.Count - 1;
                     *  Task.Run(() => server.StateMachine(server.Log[server.CommitIndex].Command));
                     * }*/

                    //Task.Run(() => server.OnHeartbeatTimerOrSendTrigger());
                }
            }
        }