mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
added startMatch and joinGame
This commit is contained in:
parent
19ad01ced8
commit
58e85df735
17 changed files with 220 additions and 46 deletions
|
|
@ -362,15 +362,20 @@ public class Client {
|
|||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public UUID getGameChatId(UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// public UUID getGameChatId(UUID gameId) {
|
||||
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// }
|
||||
|
||||
public UUID joinGame(UUID gameId) {
|
||||
try {
|
||||
return clientMessageHandler.joinGame(gameId);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error joining game", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean joinGame(UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public boolean watchGame(UUID gameId) {
|
||||
public UUID watchGame(UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.mage.network.handlers.server.ServerRequestHandler;
|
|||
//import org.mage.network.handlers.server.TableMessageHandler;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
import org.mage.network.model.ChatMessageMessage;
|
||||
import org.mage.network.model.GameStartedMessage;
|
||||
import org.mage.network.model.InformClientMessage;
|
||||
import org.mage.network.model.JoinedTableMessage;
|
||||
import org.mage.network.model.MessageType;
|
||||
|
|
@ -179,5 +180,11 @@ public class Server {
|
|||
ch.writeAndFlush(new JoinedTableMessage(roomId, tableId, chatId, owner, tournament)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public void gameStarted(String sessionId, UUID gameId, UUID playerId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
ch.writeAndFlush(new GameStartedMessage(gameId, playerId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import org.mage.network.model.ClientMessage;
|
|||
import org.mage.network.model.CreateTableRequest;
|
||||
import org.mage.network.model.GetRoomRequest;
|
||||
import org.mage.network.model.JoinChatRequest;
|
||||
import org.mage.network.model.JoinGameRequest;
|
||||
import org.mage.network.model.JoinTableRequest;
|
||||
import org.mage.network.model.LeaveChatRequest;
|
||||
import org.mage.network.model.LeaveTableRequest;
|
||||
|
|
@ -104,6 +105,12 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
return booleanQueue.take();
|
||||
}
|
||||
|
||||
public UUID joinGame(UUID gameId) throws Exception {
|
||||
uuidQueue.clear();
|
||||
ctx.writeAndFlush(new JoinGameRequest(gameId)).addListener(WriteListener.getInstance());
|
||||
return uuidQueue.take();
|
||||
}
|
||||
|
||||
public void joinChat(UUID chatId) {
|
||||
ctx.writeAndFlush(new JoinChatRequest(chatId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,6 @@ public interface MageClient {
|
|||
ServerState getServerState();
|
||||
|
||||
void joinedTable(UUID roomId, UUID tableId, UUID chatId, boolean owner, boolean tournament);
|
||||
void gameStarted(UUID gameId, UUID playerId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public interface MageServer {
|
|||
void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2);
|
||||
|
||||
boolean startMatch(String sessionId, UUID roomId, UUID tableId);
|
||||
UUID joinGame(final UUID gameId, final String sessionId);
|
||||
|
||||
void pingTime(long milliSeconds, String sessionId);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.mage.network.handlers.client.ClientMessageHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class GameStartedMessage extends ClientMessage {
|
||||
|
||||
private UUID gameId;
|
||||
private UUID playerId;
|
||||
|
||||
public GameStartedMessage(UUID gameId, UUID playerId) {
|
||||
this.gameId = gameId;
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.getClient().gameStarted(gameId, playerId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.mage.network.handlers.client.ClientMessageHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class JoinGameMessage extends ClientMessage {
|
||||
|
||||
private UUID chatId;
|
||||
|
||||
public JoinGameMessage(UUID chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.receiveId(chatId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.UUID;
|
||||
import org.mage.network.handlers.WriteListener;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class JoinGameRequest extends ServerRequest {
|
||||
|
||||
private UUID gameId;
|
||||
|
||||
public JoinGameRequest(UUID gameId) {
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
ctx.writeAndFlush(new JoinGameMessage(server.joinGame(gameId, ctx.channel().id().asLongText()))).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import org.mage.network.handlers.client.ClientMessageHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class StartMatchMessage extends ClientMessage {
|
||||
|
||||
private boolean success;
|
||||
|
||||
public StartMatchMessage(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.receiveBoolean(success);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.UUID;
|
||||
import org.mage.network.handlers.WriteListener;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class StartMatchRequest extends ServerRequest {
|
||||
|
||||
private UUID roomId;
|
||||
private UUID tableId;
|
||||
|
||||
public StartMatchRequest(UUID roomId, UUID tableId) {
|
||||
this.roomId = roomId;
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
ctx.writeAndFlush(new StartMatchMessage(server.startMatch(ctx.channel().id().asLongText(), roomId, tableId))).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue