package com.group.controller;

import com.group.Protocol;
import com.group.WebInterceptor;
import com.group.service.GroupRoomService;
import com.taurus.core.entity.ITObject;
import com.taurus.core.plugin.redis.Redis;
import com.taurus.core.routes.ActionKey;
import com.taurus.web.Controller;
import com.taurus.web.WebException;
import jdk.nashorn.internal.objects.Global;
import redis.clients.jedis.Jedis;

public class GroupRoomController extends Controller{

	/**
	 * 获取玩家列表
	 * 
	 * @throws Exception
	 */
	@ActionKey(value = Protocol.GROUP_MATCH_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP)
	public final void matchRoom() throws Exception {
		String session = this.getSession();
		ITObject reqData = this.getParams();
		int groupId = reqData.getInt("id");
		int pid = reqData.getInt("pid");
		String platform = reqData.getString("platform");
		boolean is_null = reqData.containsKey("is_null")? reqData.getBoolean("is_null"):false;

		logger.info("matchRoom() ==> pid = "+pid);

		ITObject resData = GroupRoomService.matchRoom(groupId, pid, session,platform,is_null);
		this.sendResponse(0, resData);
	}
	
	/**
	 * 获取玩家列表
	 * 
	 * @throws Exception
	 */
	@ActionKey(value = Protocol.GROUP_JOIN_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP)
	public final void joinRoom() throws Exception {
		String session = this.getSession();
		ITObject reqData = this.getParams();
		int groupId = reqData.getInt("id");
		String roomid = reqData.getString("room_id");
		String platform = reqData.getString("platform");

		ITObject resData = GroupRoomService.joinRoom(groupId, roomid, session,platform);
		this.sendResponse(0, resData);
	}
	
	/**
	 * 获取玩家列表
	 * 
	 * @throws Exception
	 */
	@ActionKey(value = Protocol.GROUP_DEL_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_OWNER)
	public final void delRoom() throws Exception {
		ITObject reqData = this.getParams();
		int groupId = reqData.getInt("id");
		String roomId = reqData.getString("roomId");
		ITObject obj = GroupRoomService.delRoom(groupId, roomId);
		this.sendResponse(0, obj);
	}
}
