Here's the scenario.
I'm developing this networking boardgame that can support multiplayers. Right now, in order to communication between the server and client, I have predefined commands (or communication protocol) that the server and the client can understand. For example, if a new player gets connected, the client appends 'Conn' before the msg sent to the server, or if a player sends a chat msg, the client appends 'Chat' before the msg. All this is controlled by a method in the MainServerControl class called ProcessClientCmd. It has a series of switch statements for each predefined commands.
Here's the problem area:
I have another class GameObject which keeps track of each set of games being played. It keeps track of the two players involved in the game and also the other players who are 'watching' this particular set of game. The logic of the boardgame is also contained in this class. I'm looking for a more effective way of communication between players in particular set of game.
Currently what i plan to do is, in the MainServerControl, i have kept an arraylist of GameObject instances. Whenever a player makes a move, the msg from the client (containing the move that player made) will first go through ProcessClientCmd. From here it will go through the arraylist of GameObject and search of the particular game set this player is involved in. Once found it verifies the move. And then it echos the move to the other players involved in that set of game. So in short, arraylist is used to control each game set.
Would that be an effective way of doing things? I'm not sure if any threading problems will come up or not too. Can anyone give me some ideas on how to go about it? The players' turn to move is also not controlled by the server. Instead i have put a variable - myMove of type boolean which is set to true everytime the opponent makes a move (that is everytime the clientApp receives the opponent's move echoed by the server) and set to false after his move. Is that correct?
I'm developing this networking boardgame that can support multiplayers. Right now, in order to communication between the server and client, I have predefined commands (or communication protocol) that the server and the client can understand. For example, if a new player gets connected, the client appends 'Conn' before the msg sent to the server, or if a player sends a chat msg, the client appends 'Chat' before the msg. All this is controlled by a method in the MainServerControl class called ProcessClientCmd. It has a series of switch statements for each predefined commands.
Here's the problem area:
I have another class GameObject which keeps track of each set of games being played. It keeps track of the two players involved in the game and also the other players who are 'watching' this particular set of game. The logic of the boardgame is also contained in this class. I'm looking for a more effective way of communication between players in particular set of game.
Currently what i plan to do is, in the MainServerControl, i have kept an arraylist of GameObject instances. Whenever a player makes a move, the msg from the client (containing the move that player made) will first go through ProcessClientCmd. From here it will go through the arraylist of GameObject and search of the particular game set this player is involved in. Once found it verifies the move. And then it echos the move to the other players involved in that set of game. So in short, arraylist is used to control each game set.
Would that be an effective way of doing things? I'm not sure if any threading problems will come up or not too. Can anyone give me some ideas on how to go about it? The players' turn to move is also not controlled by the server. Instead i have put a variable - myMove of type boolean which is set to true everytime the opponent makes a move (that is everytime the clientApp receives the opponent's move echoed by the server) and set to false after his move. Is that correct?