/* (non-Javadoc) * @see org.promasi.playmode.multiplayer.IClientState#onReceive(org.promasi.playmode.multiplayer.ProMaSiClient, java.lang.String) */ @Override public void onReceive(ProMaSiClient client, String recData) { try { Object object = new XMLDecoder(new ByteArrayInputStream(recData.getBytes())).readObject(); if (object instanceof GameStartedResponse) { } else if (object instanceof MessageRequest) { MessageRequest request = (MessageRequest) object; if (request.getMessage() == null) { client.sendMessage(new WrongProtocolResponse().serialize()); client.disconnect(); } else { _game.sendMessage(_clientId, request.getMessage()); } } else if (object instanceof GameCanceledResponse) { changeClientState(client, new ChooseGameClientState(_server, _clientId)); } else if (object instanceof LeaveGameRequest) { _server.leaveGame(_gameId, _clientId); changeClientState(client, new ChooseGameClientState(_server, _clientId)); } else { client.sendMessage(new WrongProtocolResponse().serialize()); } } catch (NullArgumentException e) { client.sendMessage(new InternalErrorResponse().serialize()); client.disconnect(); } catch (IllegalArgumentException e) { client.sendMessage(new InternalErrorResponse().serialize()); client.disconnect(); } }
@Override public void messageSent(String playerId, IMultiPlayerGame game, String message) { MessageRequest request = new MessageRequest(playerId, message); _client.sendMessage(request.serialize()); }