package mafiaserver;

/**
 * ServerClientConnector.java
 * Contains the server client connector class
 * @author Cory Gehr (cmg5573)
 */
public class ServerClientConnector extends Thread {
    
    private final MafiaServer serverObject; // MafiaServer object
    private final Participant client;    // The client we're connected to
    
    /**
     * ServerClientConnector()
     * Constructor for the ServerClientConnector class
     * @param client Participant object
     * @param serverObject IMServer Object
     */
    public ServerClientConnector(Participant client, MafiaServer serverObject) {
        this.client = client;
        this.serverObject = serverObject;
    }
    
    /**
     * run()
     * Main thread execution procedures
     */
    @Override
    public void run() {
        while(true) {
            // Wait for a message from the participant
            this.parseInput(client.getInput());
        }
    }
    
    /**
     * parseInput()
     * Determines an action to perform based on user input
     * @param input User Input
     */
    public void parseInput(String input) {
        // Separator string
        String separator = "---------------";
        // input Cases
        if(input.equals("SHOW USERS")) {
            client.pushOutput(separator);
            client.pushOutput("CURRENTLY CONNECTED USERS:");
            client.pushOutput(separator);
            client.pushOutput(this.serverObject.getClientList());
        }
        else if(input.startsWith("PLAYER")) {
            // Check status of player
        }
        else if(input.equals("STATUS")) {
            // Get game status
        }
        else if(input.startsWith("VOTE")) {
            // If player can vote
            // Run vote action
        }
        else {
            // Broadcast message
            ServerMessageBroadcaster broadcast = 
                    new ServerMessageBroadcaster(this.client, 
                            this.serverObject.clients, input);
            broadcast.start();
        }
    }
}

@@ -1733,85 +1733,314 @@
     
-// Run vote action%0A        %7D%0A        else %7B%0A            // Broadcast message%0A
+if(client.canVote()) %7B%0A                // Run vote action%0A            %7D%0A            else %7B%0A                client.pushOutput(%22You are not currently allowed to vote.%22);%0A            %7D%0A        %7D%0A        else %7B%0A            // Broadcast message if user is allowed to chat%0A            if(client.canTalk()) %7B%0A    
     
@@ -2105,16 +2105,20 @@
         
+    
 new Serv
@@ -2172,32 +2172,36 @@
                 
+    
 this.serverObjec
@@ -2219,16 +2219,20 @@
 input);%0A
+    
         
@@ -2254,16 +2254,140 @@
 tart();%0A
+            %7D%0A            else %7B%0A                client.pushOutput(%22You are not currently allowed to chat.%22);%0A            %7D%0A
         

Check if user can vote/talk before acting