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

Changes the password of a Room at runtime. More...

#include <ChangeRoomPasswordStateRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 ChangeRoomPasswordStateRequest (boost::shared_ptr< Room > room, string newPass)
 Constructor More...
 

Detailed Description

Changes the password of a Room at runtime.

The request not only changes the password of a Room but also its "password state", which indicates if a Room is password protected or not.
This request might fail if the Room was configured to deny password runtime changes or if the User sending the request is not the owner of the Room.

Moderators and Administrator can override this last constraint.

Constructor & Destructor Documentation

◆ ChangeRoomPasswordStateRequest()

Sfs2X::Requests::ChangeRoomPasswordStateRequest::ChangeRoomPasswordStateRequest ( boost::shared_ptr< Room >  room,
string  newPass 
)

Constructor

Parameters
roomthe Room
newPassthe new password (null or empty string means no password)
ptrSmartFox->AddEventListener(SFSEvent::ROOM_PASSWORD_STATE_CHANGE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnRoomPasswordStateChange, (unsigned long long)this));
ptrSmartFox->AddEventListener(SFSEvent::ROOM_PASSWORD_STATE_CHANGE_ERROR, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnRoomPasswordStateChangeError, (unsigned long long)this));
boost::shared_ptr<Room> theRoom = ptrSmartFox->GetRoomByName("DeveloperChatRoom");
// Change room password
boost::shared_ptr<IRequest> request (new ChangeRoomPasswordStateRequest(theRoom, "forloop"));
ptrSmartFox->Send(request);
static void OnRoomPasswordStateChange(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
static void OnRoomPasswordStateChangeError(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnRoomPasswordStateChange(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
{
CMyClass* ptrMyClass = (CMyClass*)ptrContext;
// Room password change success
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::OnRoomPasswordStateChangeError(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
{
CMyClass* ptrMyClass = (CMyClass*)ptrContext;
// Room password 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_PASSWORD_STATE_CHANGE, Core.SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR, ChangeRoomNameRequest, ChangeRoomPasswordStateRequest