-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two clients are able to connect and start a game, but crashes on startup
- Loading branch information
Showing
29 changed files
with
274 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...dshifter/server/incoming/CardMessage.java → ...cardshifter/server/abstr/CardMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ifter/server/incoming/RequestMessage.java → ...dshifter/server/abstr/RequestMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...dshifter/server/incoming/ChatMessage.java → ...dshifter/server/incoming/ChatMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
cardshifter-api/src/main/java/com/cardshifter/server/incoming/LoginMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
cardshifter-api/src/main/java/com/cardshifter/server/incoming/Message.java
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...fter/server/incoming/PlayCardMessage.java → ...fter/server/incoming/PlayCardMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
cardshifter-api/src/main/java/com/cardshifter/server/incoming/StartGameRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.cardshifter.server.incoming; | ||
|
||
import com.cardshifter.server.messages.Message; | ||
|
||
public class StartGameRequest extends Message { | ||
|
||
public StartGameRequest() { | ||
super("startgame"); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...er/server/incoming/UseAbilityMessage.java → ...er/server/incoming/UseAbilityMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
cardshifter-api/src/main/java/com/cardshifter/server/messages/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cardshifter.server.messages; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver; | ||
|
||
@JsonTypeInfo(use = Id.CUSTOM, property = "command", include = As.PROPERTY) | ||
@JsonTypeIdResolver(MessageTypeIdResolver.class) | ||
public abstract class Message { | ||
|
||
private final String command; | ||
|
||
public Message(String string) { | ||
this.command = string; | ||
} | ||
|
||
public final String getCommand() { | ||
return command; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
cardshifter-api/src/main/java/com/cardshifter/server/messages/MessageTypeIdResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.cardshifter.server.messages; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.cardshifter.server.incoming.ChatMessage; | ||
import com.cardshifter.server.incoming.LoginMessage; | ||
import com.cardshifter.server.incoming.PlayCardMessage; | ||
import com.cardshifter.server.incoming.StartGameRequest; | ||
import com.cardshifter.server.incoming.UseAbilityMessage; | ||
import com.cardshifter.server.outgoing.EndOfSequenceMessage; | ||
import com.cardshifter.server.outgoing.GameMessage; | ||
import com.cardshifter.server.outgoing.NewGameMessage; | ||
import com.cardshifter.server.outgoing.WaitMessage; | ||
import com.cardshifter.server.outgoing.WelcomeMessage; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
|
||
public class MessageTypeIdResolver implements TypeIdResolver { | ||
|
||
private static final Map<String, Class<? extends Message>> clazzes = new HashMap<>(); | ||
|
||
static { | ||
clazzes.put("chat", ChatMessage.class); | ||
clazzes.put("login", LoginMessage.class); | ||
clazzes.put("play", PlayCardMessage.class); | ||
clazzes.put("startgame", StartGameRequest.class); | ||
clazzes.put("use", UseAbilityMessage.class); | ||
|
||
clazzes.put("eosq", EndOfSequenceMessage.class); | ||
clazzes.put("game", GameMessage.class); | ||
clazzes.put("wait", WaitMessage.class); | ||
clazzes.put("loginresponse", WelcomeMessage.class); | ||
clazzes.put("newgame", NewGameMessage.class); | ||
} | ||
|
||
private JavaType mBaseType; | ||
|
||
@Override | ||
public void init(JavaType baseType) { | ||
mBaseType = baseType; | ||
} | ||
|
||
@Override | ||
public Id getMechanism() { | ||
return Id.CUSTOM; | ||
} | ||
|
||
@Override | ||
public String idFromValue(Object obj) { | ||
return idFromValueAndType(obj, obj.getClass()); | ||
} | ||
|
||
@Override | ||
public String idFromBaseType() { | ||
return idFromValueAndType(null, mBaseType.getRawClass()); | ||
} | ||
|
||
@Override | ||
public String idFromValueAndType(Object obj, Class<?> clazz) { | ||
// String name = clazz.getName(); | ||
// if (name.startsWith(COMMAND_PACKAGE)) { | ||
// return name.substring(COMMAND_PACKAGE.length() + 1); | ||
// } | ||
// throw new IllegalStateException("class " + clazz | ||
// + " is not in the package " + COMMAND_PACKAGE); | ||
Message mess = (Message) obj; | ||
return mess.getCommand(); | ||
} | ||
|
||
@Override | ||
public JavaType typeFromId(String type) { | ||
Class<?> clazz = clazzes.get(type); | ||
// String clazzName = COMMAND_PACKAGE + "." + type; | ||
// try { | ||
// clazz = ClassUtil.findClass(clazzName); | ||
// } catch (ClassNotFoundException e) { | ||
// throw new IllegalStateException("cannot find class '" + clazzName + "'"); | ||
// } | ||
if (clazz == null) { | ||
throw new UnsupportedOperationException("No such defined type: " + type); | ||
} | ||
return TypeFactory.defaultInstance().constructSpecializedType(mBaseType, clazz); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
cardshifter-api/src/main/java/com/cardshifter/server/outgoing/EndOfSequenceMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.cardshifter.server.outgoing; | ||
|
||
import com.cardshifter.server.messages.Message; | ||
|
||
public class EndOfSequenceMessage extends Message { | ||
|
||
public EndOfSequenceMessage() { | ||
super("eosq"); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
cardshifter-api/src/main/java/com/cardshifter/server/outgoing/GameMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cardshifter.server.outgoing; | ||
|
||
import com.cardshifter.server.messages.Message; | ||
|
||
public class GameMessage extends Message { | ||
|
||
public GameMessage() { | ||
super("game"); | ||
|
||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
cardshifter-api/src/main/java/com/cardshifter/server/outgoing/NewGameMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cardshifter.server.outgoing; | ||
|
||
import com.cardshifter.server.messages.Message; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
|
||
public class NewGameMessage extends Message { | ||
|
||
private final int gameId; | ||
private final int playerIndex; | ||
|
||
@JsonCreator | ||
NewGameMessage() { | ||
this(0, 0); | ||
} | ||
public NewGameMessage(int gameId, int playerIndex) { | ||
super("newgame"); | ||
this.gameId = gameId; | ||
this.playerIndex = playerIndex; | ||
} | ||
|
||
public int getGameId() { | ||
return gameId; | ||
} | ||
|
||
public int getPlayerIndex() { | ||
return playerIndex; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...dshifter/server/outgoing/WaitMessage.java → ...dshifter/server/outgoing/WaitMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.