WONStatus RoutingGroupInvitationOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingGroupInvitation)
		return WS_RoutingOp_DontWantReply;

	mGroupId = theMsg.ReadShort();
	mCaptainId = theMsg.ReadShort();
	mAmInvited = theMsg.ReadBool();
	theMsg.ReadWString(mComment);

	return WS_Success;
}
WONStatus RoutingYouWereBannedOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingYouWereBanned)
		return WS_RoutingOp_DontWantReply;

	mGroupId = theMsg.ReadShort();
	mAmBanned = theMsg.ReadBool();
	theMsg.ReadWString(mBanComment);
	mBanTime = theMsg.ReadLong();

	return WS_Success;
}
void StagingLogic::HandleClientKicked(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!theSender->IsCaptain(true))
		return;

	unsigned short aClientId = theMsg.ReadShort();
	bool isBan = theMsg.ReadBool();

	LobbyClient *aClient = mGame->GetClient(aClientId);
	if(aClient==NULL)
		return;

	NotifyClientKicked(aClient,isBan);
}
void StagingLogic::HandleReadyRequest(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!IAmCaptain() || !theSender->IsPlayer())
		return;

	bool isReady = theMsg.ReadBool();
	if(theSender->IsPlayerReady()==isReady) // no change needed
		return;

	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_PlayerReady);
	aMsg.AppendShort(theSender->GetClientId());
	aMsg.AppendBool(isReady);
	BroadcastGameMessage(aMsg.ToByteBuffer());
}
bool LobbyGame::ReadSummary(ReadBuffer &theMsg)
{
	try
	{
		if(mGameType==LobbyGameType_Internet)
			mIPAddr.SetSixByte(theMsg.ReadBytes(6));
		else
		{
			unsigned short aLanProductId = theMsg.ReadShort();
			if(aLanProductId!=LobbyMisc::GetLanProductId())
				return false;
		}
			
		mInProgress = theMsg.ReadBool();
		if(mGameType!=LobbyGameType_Internet)
		{
			std::wstring aName;
			theMsg.ReadWString(aName);
			mName = aName;
		}

		mSkillLevel = (LobbySkillLevel)theMsg.ReadByte();
		if(mSkillLevel<LobbySkillLevel_None || mSkillLevel>=LobbySkillLevel_Max)
			mSkillLevel = LobbySkillLevel_None;

		if(mGameType!=LobbyGameType_Internet)
		{
			unsigned char aProtectionFlags = theMsg.ReadByte();
			mHasPassword = (aProtectionFlags & 0x01)?true:false;
			mInviteOnly = (aProtectionFlags & 0x02)?true:false;
			mAskToJoin = (aProtectionFlags & 0x04)?true:false;
		}

		mNumPlayers = theMsg.ReadShort();
		mMaxPlayers = theMsg.ReadShort();

		return ReadSummaryHook(theMsg);
	}
	catch(ReadBufferException&)
	{
	}
	return false;
}
void StagingLogic::HandlePlayerReady(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!theSender->IsCaptain(true))
		return;


	unsigned short aClientId = theMsg.ReadShort();
	bool isReady = theMsg.ReadBool();
	
	LobbyClient *aClient = mGame->GetClient(aClientId);
	if(aClient==NULL)
		return;

	LobbyPlayer *aPlayer = aClient->GetPlayer();
	if(aPlayer==NULL)
		return;

	aPlayer->SetReady(isReady);

	CheckPlayReadySound();
	
	LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Modify));
}