package com.backfire.socket;

import com.backfire.room.Room;
import com.backfire.utils.Log;

public class SocketDataReceiveProcessor {
	private Room mRoom;

	public SocketDataReceiveProcessor(Room room) {
		mRoom = room;
	}

	public void close() {
		Log.v(this, "close");
		mRoom = null;
	}

	public void process(final DataPacket packet, final int cmd) {
		if (mRoom == null)
			return;
		byte[] body = packet.readBody();
		Log.w(this, SocketCommand.toString(cmd));
		switch (cmd) {
		case SocketCommand.SVR_REBIND_RPY:
			if (mRoom != null) {
				mRoom.userProtoManager.rebindRpy(body);
			}
			break;
		case SocketCommand.SVR_AUTH_RPY:
			if (mRoom != null) {
				mRoom.userProtoManager.authRpy(body);
			}
			break;
		case SocketCommand.SVR_USER_SIT_RPY:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.sitRpy(body);
			}
			break;
		case SocketCommand.BROAD_PLAYERINFO_RPY:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.playerInfoRpy(body);
			}
			break;

		case SocketCommand.SVR_PLAYER_READY_RPY:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.readyRpy(body);
			}
			break;
		case SocketCommand.BROAD_HAND_CARD:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.handCard(body,false);
			}
			break;
		case SocketCommand.SVR_QIANGDIZHU_RPY:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.qiangDizhuRpy(body);
			}
			break;
		case SocketCommand.BROAD_GAME_START:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.gameStart(body,false);
			}
			break;
		case SocketCommand.SVR_USER_PLAY_ACTION_RPY:
			if (mRoom != null) {
				mRoom.userProtoManager.playerActionRpy(body);
			}
			break;
		case SocketCommand.BROAD_USER_PLAYER_ACTION:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.userAction(body,false);
			}
			break;
		case SocketCommand.SVR_CHAT_RPY:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.chatRpy(body);
			}
		case SocketCommand.BROAD_GAME_OVER:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.gameOver(body);
			}
			break;
		case SocketCommand.SVR_PLAYER_DEPOSIT_RPY:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.depositRpy(body);
			}
			break;
		case SocketCommand.BROAD_CAST_LAIZI:
			if (mRoom != null) {
				mRoom.broadcastProtoManager.addLaiZi(body,false);
			}
			break;
		}
	}

}