Package be.demmel.jgws.actions

Source Code of be.demmel.jgws.actions.ChatMessageAction

package be.demmel.jgws.actions;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import be.demmel.jgws.CharacterData;
import be.demmel.jgws.GameServerSession;
import be.demmel.jgws.SessionKey;
import be.demmel.jgws.QueueAction;
import be.demmel.jgws.packets.gameserver.outbound.P081_GeneralChatMessage;
import be.demmel.jgws.packets.gameserver.outbound.P085_GeneralChatOwner;

public class ChatMessageAction implements QueueAction {

  private static final Logger LOGGER = LoggerFactory.getLogger(ChatMessageAction.class);
  private CharacterData character;
  private String message;
  private ChannelGroup channels;

  public ChatMessageAction(CharacterData character, String message, ChannelGroup channels) {
    this.character = character;
    this.message = message;
    this.channels = channels;
  }

  @Override
  public void execute() {
    char messageType = this.message.toCharArray()[0];
    String realMessage = this.message.substring(1);
    LOGGER.debug("Message Type: {}. Real Message: {}", new Object[] { messageType, realMessage });

    switch (messageType) {
    // send to all players of the map
    case '!':
      String prefix = character.getChatPrefix();
      byte chatColor = character.getChatColor();
      // MapData map = GameServer.getMap((int) character.getMapID()); //FIXME: only players on the same map should qualify

      for (Channel channel : channels) {
        P081_GeneralChatMessage generalChatMessage = new P081_GeneralChatMessage();
        generalChatMessage.setMessage("Ĉć" + prefix + realMessage + '\u0001');
        try {
          channel.write(generalChatMessage);
        } catch (Exception e) {
          // TODO: what to do in this case? review the exceptions possible?
        }

        GameServerSession playerData = channel.attr(SessionKey.SESSION_KEY).get();
        // Retrieve the Character the player is currently playing
        CharacterData character = playerData.getCurrentCharacter();

        P085_GeneralChatOwner generalChatOwner = new P085_GeneralChatOwner();
        generalChatOwner.setUnknown1((int) character.getLocalID());
        generalChatOwner.setUnknown2(chatColor);
        try {
          channel.write(generalChatOwner);
        } catch (Exception e) {
          // TODO: idem
        }
      }
      // TODO: other type of chat messages
      break;
    case '#':
      break;
    case '$':
      break;
    case '@':
      break;
    case '%':
      break;
    case '"':
      break;
    case '/':
      break;
    }
  }
}
TOP

Related Classes of be.demmel.jgws.actions.ChatMessageAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.