Skip to content

Commit

Permalink
Added player flags to support invisibility.
Browse files Browse the repository at this point in the history
Suppressed connection messages if player connects as invisible.

Added in an option to check if client wishes to connect as invisible
(leaves an unused variable in /client/Client.java).
  • Loading branch information
njs11009 committed Dec 9, 2015
1 parent ca106f0 commit 723e1de
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
24 changes: 23 additions & 1 deletion MegaMek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public class Client implements IClientCommandHandler {

// we need these to communicate with the server
private String name;

private boolean conAsInvis;

private IConnection connection;

// the hash table of client commands
Expand Down Expand Up @@ -250,6 +251,27 @@ public Client(String name, String host, int port) {
rsg = new RandomSkillsGenerator();
}

public Client(String name, String host, int port, boolean invisible) {
// construct new client
this.name = name;
this.host = host;
this.port = port;
this.conAsInvis = invisible;

registerCommand(new HelpCommand(this));
registerCommand(new MoveCommand(this));
registerCommand(new RulerCommand(this));
registerCommand(new ShowEntityCommand(this));
registerCommand(new FireCommand(this));
registerCommand(new DeployCommand(this));
registerCommand(new ShowTileCommand(this));
registerCommand(new AddBotCommand(this));
registerCommand(new AssignNovaNetworkCommand(this));

rsg = new RandomSkillsGenerator();
}


public int getLocalPlayerNumber() {
return localPlayerNumber;
}
Expand Down
12 changes: 10 additions & 2 deletions MegaMek/src/megamek/client/ui/swing/MegaMekGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,17 @@ void connect() {
Messages.getString("MegaMek.ConnectAlert.message"), Messages.getString("MegaMek.ConnectAlert.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
return;
}

boolean conAsInvis = false;
if (cd.spectateValue.equalsIgnoreCase("Yes")) {
conAsInvis = true;
}
// initialize game
client = new Client(cd.playerName, cd.serverAddr, cd.port);
if(!conAsInvis){
client = new Client(cd.playerName, cd.serverAddr, cd.port);
}
else {
client = new Client(cd.playerName, cd.serverAddr, cd.port, true);
}
ClientGUI gui = new ClientGUI(client,controller);
controller.clientgui = gui;
frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
Expand Down
5 changes: 5 additions & 0 deletions MegaMek/src/megamek/common/IPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public interface IPlayer extends ITurnOrdered {
Vector<Coords> getArtyAutoHitHexes();

void addArtyAutoHitHex(Coords c);

boolean isInvisible();

void setInvisible(boolean invisible);

boolean hasTAG();

Expand Down Expand Up @@ -192,4 +196,5 @@ public interface IPlayer extends ITurnOrdered {
* @return a vector of relevant entity ids
*/
Vector<Integer> getAirborneVTOL();

}
13 changes: 12 additions & 1 deletion MegaMek/src/megamek/common/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class Player extends TurnOrdered implements IPlayer {

private String name = "unnamed";
private int id;

private boolean invisible = false;
private int team = TEAM_NONE;

private boolean done = false; // done with phase
Expand Down Expand Up @@ -228,6 +228,11 @@ public void setTeam(int team) {
this.team = team;
}

@Override
public boolean isInvisible() {
return this.invisible;
}

@Override
public boolean isDone() {
return done;
Expand Down Expand Up @@ -282,6 +287,11 @@ public void setObserver(boolean observer) {
setSeeAll(false);
}
}

@Override
public void setInvisible(boolean invisible) {
this.invisible = invisible;
}

@Override
public int getColorIndex() {
Expand Down Expand Up @@ -554,4 +564,5 @@ public Vector<Integer> getAirborneVTOL() {
public String toString() {
return "Player " + getId() + " (" + getName() + ")";
}

}
5 changes: 4 additions & 1 deletion MegaMek/src/megamek/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,8 @@ private void receivePlayerName(Packet packet, int connId) {
&& (game.getEntitiesOwnedBy(player) < 1)) {
player.setObserver(true);
}


if (player.isInvisible() == false) {
// send the player the motd
sendServerChat(connId, motd);

Expand Down Expand Up @@ -1015,6 +1016,8 @@ private void receivePlayerName(Packet packet, int connId) {
sendServerChat(who);

} // Found the player

}

}

Expand Down

0 comments on commit 723e1de

Please sign in to comment.