63 lines
1.7 KiB
Java
63 lines
1.7 KiB
Java
package uulm.teamname.marvelous.server.lobbymanager;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage;
|
|
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
|
import uulm.teamname.marvelous.server.netconnector.Client;
|
|
import uulm.teamname.marvelous.server.netconnector.SUID;
|
|
|
|
public class Participant {
|
|
private Client client;
|
|
public final SUID id;
|
|
public final String lobby;
|
|
public ParticipantState state = ParticipantState.Assigned;
|
|
public final ParticipantType type;
|
|
public boolean disconnected = false;
|
|
public final boolean isAI;
|
|
|
|
public Participant(Client client, String lobby, ParticipantType type, boolean ai) {
|
|
this.client = client;
|
|
this.id = client.getId();
|
|
this.lobby = lobby;
|
|
this.type = type;
|
|
this.isAI = ai;
|
|
}
|
|
|
|
public void setClient(Client client) {
|
|
this.client = client;
|
|
}
|
|
|
|
public Client getClient() {
|
|
return client;
|
|
}
|
|
|
|
public boolean sendError(String error) {
|
|
if(disconnected) {
|
|
return false;
|
|
}
|
|
return client.sendError(error);
|
|
}
|
|
|
|
public boolean sendMessage(BasicMessage message) {
|
|
if(disconnected) {
|
|
return false;
|
|
}
|
|
return client.sendMessage(message);
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
Participant other = (Participant) o;
|
|
return other.id.equals(id);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode(){
|
|
final int prime = 31;
|
|
int result = 1;
|
|
result = prime * result + ((client == null) ? 0 : client.hashCode()) + ((id == null) ? 0 : id.hashCode());
|
|
return result;
|
|
}
|
|
}
|