Some more network stuff. We almost have a working lobby!

This commit is contained in:
elcnesh
2015-02-27 13:02:20 +00:00
parent 7ff89bd6b2
commit ca82a3b0d9
25 changed files with 462 additions and 106 deletions

View File

@@ -3,9 +3,11 @@ package forge.net.game;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import forge.net.game.server.RemoteClient;
import forge.trackable.TrackableObject;
public final class GuiGameEvent implements NetEvent {
private static final long serialVersionUID = 6223690008522514574L;
private final String method;
private final Iterable<? extends TrackableObject> objects;
@@ -15,6 +17,10 @@ public final class GuiGameEvent implements NetEvent {
this.objects = objects == null ? ImmutableSet.<TrackableObject>of() : objects;
}
@Override
public void updateForClient(final RemoteClient client) {
}
public String getMethod() {
return method;
}

View File

@@ -0,0 +1,8 @@
package forge.net.game;
public enum LobbySlotType {
LOCAL,
AI,
OPEN,
REMOTE;
}

View File

@@ -0,0 +1,51 @@
package forge.net.game;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
public class LobbyState implements Serializable {
private static final long serialVersionUID = 3899410700896996173L;
private final List<LobbyPlayerData> players = Lists.newArrayList();
private int localPlayer = -1;
public int getLocalPlayer() {
return localPlayer;
}
public void setLocalPlayer(final int localPlayer) {
this.localPlayer = localPlayer;
}
public void addPlayer(final LobbyPlayerData data) {
players.add(data);
}
public List<LobbyPlayerData> getPlayers() {
return Collections.unmodifiableList(players);
}
public final static class LobbyPlayerData implements Serializable {
private static final long serialVersionUID = 8642923786206592216L;
private final String name;
private final int avatarIndex;
private final LobbySlotType type;
public LobbyPlayerData(final String name, final int avatarIndex, final LobbySlotType type) {
this.name = name;
this.avatarIndex = avatarIndex;
this.type = type;
}
public String getName() {
return name;
}
public int getAvatarIndex() {
return avatarIndex;
}
public LobbySlotType getType() {
return type;
}
}
}

View File

@@ -0,0 +1,21 @@
package forge.net.game;
import forge.net.game.server.RemoteClient;
public class LobbyUpdateEvent implements NetEvent {
private static final long serialVersionUID = -3176971304173703949L;
private final LobbyState state;
public LobbyUpdateEvent(final LobbyState state) {
this.state = state;
}
@Override
public void updateForClient(final RemoteClient client) {
state.setLocalPlayer(client.getIndex());
}
public LobbyState getState() {
return state;
}
}

View File

@@ -1,5 +1,7 @@
package forge.net.game;
import forge.net.game.server.RemoteClient;
public class LoginEvent implements NetEvent {
private static final long serialVersionUID = -8865183377417377938L;
@@ -8,6 +10,10 @@ public class LoginEvent implements NetEvent {
this.username = username;
}
@Override
public void updateForClient(final RemoteClient client) {
}
public String getUsername() {
return username;
}

View File

@@ -1,5 +1,7 @@
package forge.net.game;
import forge.net.game.server.RemoteClient;
public class LogoutEvent implements NetEvent {
private static final long serialVersionUID = -8262613254026625787L;
@@ -8,6 +10,9 @@ public class LogoutEvent implements NetEvent {
this.username = username;
}
public void updateForClient(final RemoteClient client) {
}
public String getUsername() {
return username;
}

View File

@@ -1,5 +1,7 @@
package forge.net.game;
import forge.net.game.server.RemoteClient;
public class MessageEvent implements NetEvent {
private static final long serialVersionUID = 1700060210647684186L;
@@ -8,6 +10,8 @@ public class MessageEvent implements NetEvent {
this.source = source;
this.message = message;
}
public void updateForClient(final RemoteClient client) {
}
public String getSource() {
return source;

View File

@@ -2,5 +2,8 @@ package forge.net.game;
import java.io.Serializable;
import forge.net.game.server.RemoteClient;
public interface NetEvent extends Serializable {
void updateForClient(RemoteClient client);
}

View File

@@ -1,6 +1,7 @@
package forge.net.game;
import forge.deck.Deck;
import forge.net.game.server.RemoteClient;
public class RegisterDeckEvent implements NetEvent {
private static final long serialVersionUID = -6553476654530937343L;
@@ -9,6 +10,8 @@ public class RegisterDeckEvent implements NetEvent {
public RegisterDeckEvent(final Deck deck) {
this.deck = deck;
}
public void updateForClient(final RemoteClient client) {
}
public final Deck getDeck() {
return deck;

View File

@@ -1,9 +1,8 @@
package forge.net.game.client;
import forge.net.game.server.RemoteClient;
import forge.net.game.LobbyState;
public interface ILobbyListener {
void login(RemoteClient client);
void logout(RemoteClient client);
void message(String source, String message);
void update(LobbyState state);
}

View File

@@ -7,6 +7,7 @@ public final class RemoteClient implements IToClient {
private final Channel channel;
private String username;
private int index;
public RemoteClient(final Channel channel) {
this.channel = channel;
}
@@ -22,4 +23,11 @@ public final class RemoteClient implements IToClient {
public void setUsername(final String username) {
this.username = username;
}
public int getIndex() {
return index;
}
public void setIndex(final int index) {
this.index = index;
}
}