SmartFoxServer 2X C++ API
Sfs2X::Requests::ChangeRoomCapacityRequest Class Reference

Change the capacity of a Room (maxUsers and maxSpectators) at runtime. More...

#include <ChangeRoomCapacityRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 ChangeRoomCapacityRequest (boost::shared_ptr< Room > room, long int newMaxUsers, long int newMaxSpect)
 Constructor More...
 

Detailed Description

Change the capacity of a Room (maxUsers and maxSpectators) at runtime.

This request might fail if the Room was configured not be re-sizable or if the User sending the request is not the owner of the Room. Moderators and Administrator can override this last constraint.

It is possible to "shrink" the Room capacity so that maxUsers < userCount.
In this case nothing will happen to the "extra" users.
As soon as clients will leave the Room the userCount will get down to the new maxUsers value.

Constructor & Destructor Documentation

◆ ChangeRoomCapacityRequest()

Sfs2X::Requests::ChangeRoomCapacityRequest::ChangeRoomCapacityRequest ( boost::shared_ptr< Room >  room,
long int  newMaxUsers,
long int  newMaxSpect 
)

Constructor

Parameters
roomthe Room to resize
newMaxUsersthe new maxUsers value (use -1 if don't want to change the current value)
newMaxSpectthe new maxSpect value (use -1 if don't want to change the current value)
ptrSmartFox->AddEventListener(SFSEvent::ROOM_CAPACITY_CHANGE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnRoomCapacityChange, (unsigned long long)this));
ptrSmartFox->AddEventListener(SFSEvent::ROOM_CAPACITY_CHANGE_ERROR, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnRoomCapacityChangeError, (unsigned long long)this));
boost::shared_ptr<Room> theRoom = ptrSmartFox->GetRoomByName("DeveloperChatRoom");
// Resize the room to have 100 users and zero spectators
boost::shared_ptr<IRequest> request (new ChangeRoomCapacityRequest(theRoom, 100, 0));
ptrSmartFox->Send(request);
static void OnRoomCapacityChange(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
static void OnRoomCapacityChangeError(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnRoomCapacityChange(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
{
CMyClass* ptrMyClass = (CMyClass*)ptrContext;
// Room capacity was changed successfully
boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
boost::shared_ptr<void> ptrEventParamValueRoom = (*ptrEventParams)["room"];
boost::shared_ptr<Room> ptrNotifiedRoom = ((boost::static_pointer_cast<Room>)(ptrEventParamValueRoom));
}
void CMyClass::OnRoomCapacityChangeError(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
{
CMyClass* ptrMyClass = (CMyClass*)ptrContext;
// Room capacity change failed
boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
boost::shared_ptr<void> ptrEventParamValueErrorMessage = (*ptrEventParams)["errorMessage"];
boost::shared_ptr<string> ptrErrorMessage = ((boost::static_pointer_cast<string>)(ptrEventParamValueErrorMessage));
}
See also
Core.SFSEvent.ROOM_CAPACITY_CHANGE, Core.SFSEvent.ROOM_CAPACITY_CHANGE_ERROR, ChangeRoomNameRequest, ChangeRoomPasswordStateRequest