/*******************************************************************************************
 * 
 * TITLE: 		SFS2X Space Race
 * VERSION:		1.0
 * RELEASE:		2011-03-15
 * COPYRIGHT:	2011 gotoAndPlay() - http://www.smartfoxserver.com
 * DEVELOPER:	A51 Integrated - http://a51integrated.com
 * 
 * This file is part of SFS2X Space Race.
 * 
 * Contributers: Wayne Helman, Fabricio Medeiros, David Irons,
 * 				 Steve Schoger, Ryan Albrecht, Andy Rohan
 * 
 * SFS2X Space Race is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * included license for more details.
 *
 * You are not allowed to rent, lend, lease, license or distribute SFS2X Space Race or a
 * modified version of SFS2X Space Race to any other person or organization in any way.
 * 
 * For commercial licensing information, please contact gotoAndPlay().
 * 
 *******************************************************************************************/

package sfs2x.extensions.games.spacerace;

import java.util.Collection;

import sfs2x.extensions.games.spacerace.handlers.ConnectedUsers;
import sfs2x.extensions.games.spacerace.handlers.OnUserDisconnect;
import sfs2x.extensions.games.spacerace.handlers.OnUserExitGame;
import sfs2x.extensions.games.spacerace.handlers.OnUserVarChange;

import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.extensions.SFSExtension;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.Zone;


/**
 * SFS2x Space Race demo - Zone Extension
 * 
 * @author A51 Integrated
 * 
 */
public class SpaceRaceZoneExtension extends SFSExtension
{
	public static final String VERSION 			= "1.0";
	
	public static final String LOBBY_ROOM 		= "lobby";
	
	public static final String USER_LIST		= "ul";
	public static final String PLAYER_NAME		= "pn";
	public static final String PLAYER_ID		= "id";
	public static final String PLAYER_STATUS	= "s";
	public static final String PLAYER_READY		= "r";
	public static final String PLAYER_POSITION	= "pos";
	public static final String NUMBER_PLAYERS	= "n";
	public static final String COUNTDOWN		= "C";
	public static final String USER_DISCONNECT	= "D";
	
	
	@Override
	public void init()
	{
		trace("SFS2XSpaceRaceZone Extension init. Version: " + VERSION);
		
		// Register Request handlers
		this.addRequestHandler(USER_LIST, ConnectedUsers.class);
		
		// Register Event handlers
		this.addEventHandler(SFSEventType.USER_VARIABLES_UPDATE, OnUserVarChange.class);
		this.addEventHandler(SFSEventType.USER_LEAVE_ROOM, OnUserExitGame.class);
		this.addEventHandler(SFSEventType.USER_DISCONNECT, OnUserDisconnect.class);
	}
	
	public Zone getZone()
	{
		return this.getParentZone();
	}
	
	public Collection<User> getConnectedUsers()
	{
		return this.getParentZone().getUserList();
	}
	
	@Override
	public void destroy() 
	{
		super.destroy();
		trace("SFS2XSpaceRaceZone destroyed.");
	}
	
}
