SFS2X Objective-C API  1.7.13
iOS / macOS / tvOS
<ISFSEvents> Protocol Reference

Inherits <IConfigLoader>.

Instance Methods

(void) - onConnection:
 
(void) - onConnectionLost:
 
(void) - onConnectionRetry:
 
(void) - onConectionAttempHTTP:
 
(void) - onConnectionResume:
 
(void) - onUDPSocketConnect:
 
(void) - onConfigLoadSuccess:
 
(void) - onConfigLoadFailure:
 
(void) - onLogin:
 
(void) - onLoginError:
 
(void) - onLogout:
 
(void) - onRoomAdd:
 
(void) - onRoomRemove:
 
(void) - onRoomCreationError:
 
(void) - onRoomJoin:
 
(void) - onRoomJoinError:
 
(void) - onUserEnterRoom:
 
(void) - onUserExitRoom:
 
(void) - onUserCountChange:
 
(void) - onPublicMessage:
 
(void) - onPrivateMessage:
 
(void) - onModeratorMessage:
 
(void) - onAdminMessage:
 
(void) - onObjectMessage:
 
(void) - onExtensionResponse:
 
(void) - onRoomVariablesUpdate:
 
(void) - onUserVariablesUpdate:
 
(void) - onSubscribeRoomGroup:
 
(void) - onSubscribeRoomGroupError:
 
(void) - onUnsubscribeRoomGroup:
 
(void) - onUnsubscribeRoomGroupError:
 
(void) - onSpectatorToPlayer:
 
(void) - onSpectatorToPlayerError:
 
(void) - onPlayerToSpectator:
 
(void) - onPlayerToSpectatorError:
 
(void) - onRoomNameChange:
 
(void) - onRoomNameChangeError:
 
(void) - onRoomPasswordStateChange:
 
(void) - onRoomPasswordStateChangeError:
 
(void) - onRoomCapacityChange:
 
(void) - onRoomCapacityChangeError:
 
(void) - onRoomFindResult:
 
(void) - onUserFindResult:
 
(void) - onInvitation:
 
(void) - onInvitationReply:
 
(void) - onInvitationReplyError:
 
(void) - onBuddyMessage:
 
(void) - onBuddyListInit:
 
(void) - onBuddyAdd:
 
(void) - onBuddyRemove:
 
(void) - onBuddyBlock:
 
(void) - onBuddyOnlineStateUpdate:
 
(void) - onBuddyVariablesUpdate:
 
(void) - onBuddyError:
 
(void) - onDebugMessage:
 
(void) - onPingPong:
 
(void) - onProximityListUpdate:
 
(void) - onMMOItemVariablesUpdate:
 
(void) - onCryptoInit:
 

Method Documentation

◆ onAdminMessage:

- (void) onAdminMessage: (SFSEvent *)  evt
optional

This event is fired when a User receives an Admin message.

-(void)onAdminMessage:(SFSEvent *)evt
{
NSLog(@"Admin says: %@", [evt.params objectForKey:@"message"]);
}
Parameters
sender(SFSUser *) the sender of the message
message(NSString *) the message
data(SFSObject *) an object with custom data
See also
AdminMessageRequest

◆ onBuddyAdd:

- (void) onBuddyAdd: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a AddBuddyRequest.

Parameters
buddy(SFSBuddy *) the Buddy that was added
See also
SFSBuddy
AddBuddyRequest

◆ onBuddyBlock:

- (void) onBuddyBlock: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a BlockBuddyRequest.

Parameters
buddy(SFSBuddy *) the Buddy that was blocked/unblocked
See also
SFSBuddy
BlockBuddyRequest

◆ onBuddyError:

- (void) onBuddyError: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a failed Buddy request, such as AddBuddy, RemoveBuddy etc...

Parameters
errorMessage(NSString *) the error message

◆ onBuddyListInit:

- (void) onBuddyListInit: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a InitBuddyListRequest.

After the Buddy List initialization the User will return to his previous Buddy state. His online/offline status, the Buddy state and his persistent Buddy Variables will all be loaded and broadcast in the system. In particular the online status determines if the User will appear online or not to other Users that have added him/her to their lists.

At this stage the custom Buddy states are also loaded and populated locally by the API.

NSLog(@"Buddy States: " + [smartFox.buddyManager buddyStates]);
Parameters
buddyList(NSArray *) a list of Buddy objects
myVariables(NSArray *) a list of the User's BuddyVariable(s)
See also
SFSBuddy
SFSBuddyVariable
InitBuddyListRequest

◆ onBuddyMessage:

- (void) onBuddyMessage: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a BuddyMessageRequest.

Parameters
buddy(SFSBuddy *) the Buddy that updated the BuddyVariables
isItMe(NSNumber *) true if the Buddy is actually the current User
message(NSString *) a list with the names of the Variables that where changed/set
data(SFSObject *) optional custom parameters
See also
SFSBuddy
BuddyMessageRequest

◆ onBuddyOnlineStateUpdate:

- (void) onBuddyOnlineStateUpdate: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a GoOnlineRequest.

Parameters
buddy(SFSBuddy *) the Buddy that was has changed his online status
isItMe(NSNumber *) (contains a BOOL value) true if the Buddy is actually the current User
See also
SFSBuddy
GoOnlineRequest

◆ onBuddyRemove:

- (void) onBuddyRemove: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a RemoveBuddyRequest.

Parameters
buddy(SFSBuddy *) the Buddy that was removed
See also
SFSBuddy
RemoveBuddyRequest

◆ onBuddyVariablesUpdate:

- (void) onBuddyVariablesUpdate: (SFSBuddyEvent *)  evt
optional

This event is fired in response to a SetBuddyVariablesRequest.

Parameters
buddy(SFSBuddy *) the Buddy that updated the BuddyVariables
changedVars(NSArray *) a list with the names of the Variables that where changed/set
isItMe(NSNumber *) true if the Buddy is actually the current User
See also
SFSBuddy
SetBuddyVariablesRequest

◆ onConectionAttempHTTP:

- (void) onConectionAttempHTTP: (SFSEvent *)  evt
optional

This event notifies an attempt to establish an HTTP tunnel connection with SmartFoxServer 2X.

The following example shows how to handle a reconnection

-(void)onConectionAttempHTTP:(SFSEvent *)evt
{
// Provide feedback to client on BlueBox(HTTP) connection attempt.
}
See also
- onConnectionRetry:evt
- onConnection:evt

◆ onConfigLoadFailure:

- (void) onConfigLoadFailure: (SFSEvent *)  evt
optional

Dispatched when an error occurs while loading the external SmartFox configuration file.

Parameters
message(NSString *) the error message.

The following example shows how to handle a potential error in configuration loading.

[smartFox loadConfig:@"testEnvironmentConfig.xml" connectOnSuccess:YES];
function onConfigLoadFailure:(SFSEvent *)evt
{
NSLog(@"Failed loading config file: %@", [evt.params objectForKey:@"message"]);
}
See also
- onConfigLoadSuccess:evt
- loadConfig:connectOnSuccess: (SmartFox2XClient)

◆ onConfigLoadSuccess:

- (void) onConfigLoadSuccess: (SFSEvent *)  evt
optional

Dispatched when the external SmartFox configuration file has been loaded successfully.

This event is dispatched only if the connectOnSuccess parameter of the loadConfig:connectOnSuccess: (SmartFox2XClient) method is set to NO; otherwise the connection is made and the related onConnection: event is fired.

No parameters are provided.

The following example shows how to handle a successful configuration loading.

[smartFox loadConfig:@"testEnvironmentConfig.xml" connectOnSuccess:NO];
function onConfigLoadSuccess(evt:SFSEvent):void
{
NSLog(@"Config file loaded, now connecting...");
[smartFox connect:smartFox.currentIp port:smartFox.currentPort];
}
See also
- onConfigLoadFailure:evt
loadConfig:connectOnSuccess

◆ onConnection:

- (void) onConnection: (SFSEvent *)  evt
optional

This event notifies the result of a connection attempt.

Parameters
success(contains an NSNumber with BOOL in it) true if a connection was established, false otherwise.

The following example shows how to start a connection

smartFox = [SmartFox2XClient smartFoxWithDebugMode:NO delegate:self];
[smartFox loadConfig:@"config.xml" connectOnSuccess:YES];
-(void)onConnection:(SFSEvent *)evt
{
if ([[evt.params objectForKey:@"success"] boolValue])
{
NSLog(@"Connection was established");
}
else
{
NSLog(@"Connection failed");
}
}
See also
- onConnectionRetry:evt
- onConnectionResume:evt
- onConnectionLost:evt

◆ onConnectionLost:

- (void) onConnectionLost: (SFSEvent *)  evt
optional

This event notifies of a disconnection from the Server.

When possible the API will also provide a reason for the disconnection:

  • Idle: the connection was dropped because the User was inactive for too long
  • Manual: the User requested the disconnection
  • Kick: the connection was dropped because the User was kicked
  • Ban: the connection was dropped because the User was banned
  • Unknown: the connection was lost for reasons outside of the API (slow or bad connection, network problems etc...)
Parameters
reason(contains NSString) the reason of the disconnection.

The following example shows how to handle a disconnection

-(void)onConnectionLost:(SFSEvent *)evt
{
NSLog(@"Connection was lost, Reason: %@", [evt.params objectForKey:@"reason"]);
}
See also
- onConnectionRetry:evt
- onConnectionResume:evt
- onConnection:evt

◆ onConnectionResume:

- (void) onConnectionResume: (SFSEvent *)  evt
optional

This event is dispatched after a temporary disconnection, when the connection to the Server has been re-establisehd.

SmartFoxServer 2X provides a powerful new feature that allows a broken connection to be re-established transparently without loosing any of the current application state. This allows any player to get back in the game without fear of loosing the match because of a sloppy internet connection or a sudden disconnection.

In case the re-connection attempts fail onConnectionLost: event will be fired.

The following example shows how to handle a reconnection

-(void)onConnectionRetry:(SFSEvent *)evt
{
// Freeze your GUI and provide some feedback to the Player
}
-(void)onConnectionResume:(SFSEvent *)evt
{
// Unfreeze the GUI and let the player continue with the game...
}
-(void)onConnectionLost:(SFSEvent *)evt
{
NSLog(@"Ouch, connection was lost. Reason: %@", [evt.params objectForKey:@"reason"]);
}
See also
- onConnectionLost:evt
- onConnectionResume:evt
- onConnection:evt

◆ onConnectionRetry:

- (void) onConnectionRetry: (SFSEvent *)  evt
optional

This event notifies a temporary disconnection from the Server followed by an immediate attempt to reconnect.

SmartFoxServer 2X provides a powerful new feature that allows a broken connection to be re-established transparently without loosing any of the current application state. This allows any player to get back in the game without fear of loosing the match because of a sloppy internet connection.

When this event is dispatched the API enter a "freeze" mode where no new requests can be sent until the reconnection is successfully performed. It is highly recommended to handle this event and freeze your application interface accordingly until the onConnectionResume: event is fired.

The following example shows how to handle a reconnection

-(void)onConnectionRetry:(SFSEvent *)evt
{
// Freeze your GUI and provide some feedback to the Player
}
-(void)onConnectionResume:(SFSEvent *)evt
{
// Unfreeze the GUI and let the player continue with the game...
}
See also
- onConnectionLost:evt
- onConnectionResume:evt
- onConnection:evt

◆ onCryptoInit:

- (void) onCryptoInit: (SFSEvent *)  evt
optional

This event is fired in response to a server side InitCrypto request.

NOTE: It is necessary to send this request right after a successful connection event, before login.

Example:
The code below allows to easily toggle the use of encryption for local vs production testing.

BOOL useEncryption = YES;
smartFox = [[SmartFox2XClient alloc] initSmartFoxWithDebugMode:YES delegate:self];
ConfigData *cfg = [[ConfigData alloc] init];
cfg.host = @"127.0.0.1";
cfg.port = 9933;
cfg.zone = @"BasicExamples";
// Start connection
[smartFox connectWithConfig:cfg];
-(void) onConnection:(SFSEvent *)evt
{
NSNumber *success = [evt.params objectForKey:@"success"];
if (success)
{
if (useEncryption)
[smartFox initCrypto];
else
[self sendLogin];
}
else
NSLog(@"Connection failed");
}
- (void)onCryptoInit:(SFSEvent *)evt
{
NSNumber* success = [evt.params objectForKey:@"success"];
if (success)
{
NSLog(@"Crypto Init Success!");
[self sendLogin];
}
else
NSLog(@"Crypto Init Failure!");
}
-(void) sendLogin
{
[smartFox send:[LoginRequest requestWithUserName:@"" password:@"" zoneName:smartFox.config.zone params:nil]];
}
-(void) onLogin:(SFSEvent *)evt
{
NSLog("Logged in as: %@", smartFox.mySelf.name];
}

◆ onDebugMessage:

- (void) onDebugMessage: (LoggerEvent *)  evt
optional

This event is fired in response to a console message from the logger

Parameters
message(String) the debug message.

◆ onExtensionResponse:

- (void) onExtensionResponse: (SFSEvent *)  evt
optional

This event is fired every time a server-side Extension sends a message, usually in response to an ExtensionRequest.

(A server Extension can send messages at any moment, not just in response to a specific client request)

-(void)onExtensionResponse:(SFSEvent *)evt
{
NSArray *keys = [evt.params allKeys];
for (NSString *key in keys)
{
NSLog(@"%@: %@", key, [evt.params objectForKey:key]);
}
}
Parameters
cmd(NSString *) the name of the "command" (or "action id") associated with the message
params(SFSObject *) custom parameters
room(id<Room>) the Room which the Extension is attached to (for Room Extensions only)
See also
ExtensionRequest
SFSObject

◆ onInvitation:

- (void) onInvitation: (SFSEvent *)  evt
optional

This event is fired when another User has sent you an Invitation

Parameters
invitation(SFSInvitation *) the invitation object
See also
InviteUsersRequest
SFSInvitation

◆ onInvitationReply:

- (void) onInvitationReply: (SFSEvent *)  evt
optional

This event is fired when a User sends a reply to your Invitation

Parameters
invitee(SFSUser) the User that was invited
reply(NSNumber *) the reply code. It can be either InvitationReply.ACCEPT or InvitationReply.REFUSE
data(SFSObject *) additional custom paramters (e.g. a reason for the refusal, a message etc...)
See also
InvitationReply
InviteUsersRequest

◆ onInvitationReplyError:

- (void) onInvitationReplyError: (SFSEvent *)  evt
optional

This event is fired in response to a failed InvitationReplyRequest The failure is usually caused by a late reply which doesn't make it to the server within the expected time

Parameters
errorMessage(NSString *) the error message
See also
InvitationReplyRequest
InviteUsersRequest

◆ onLogin:

- (void) onLogin: (SFSEvent *)  evt
optional

This event is dispatched in response to a login request.

The params object may contain the following keys.

Parameters
user(SFSUser *) the User object
zone(NSString *) the zone
data(SFSObject *) a custom object with extra params (if you have added custom server side logic)

The following example shows how to handle a login event

-(void)onLogin:(SFSEvent *)evt
{
NSLog(@"Hi, I have just logged in as: %@" + [[evt.params objectForKey:@"user"] name]);
}
See also
- onLoginError:
LoginRequest

◆ onLoginError:

- (void) onLoginError: (SFSEvent *)  evt
optional

This event is dispatched in response to a failed login request.

Parameters
errorMessage(NSString *) the error message
-(void)onLoginError:(SFSEvent *)evt
{
NSLog(@"Login Failed. Reason: %@" ,[evt.params objectForKey:@"errorMessage"]);
}
See also
- onLogin:evt
LoginRequest

◆ onLogout:

- (void) onLogout: (SFSEvent *)  evt
optional

This event is dispatched in response to a logout request.

Usually this event needs to be handled when you want to logout from the current Zone and join another one. In order to perform the operation correctly you need to do as follows:

  • Send a LogoutRequest to the Server
  • Handle the onLogout event on the client
  • Perform a new login in the new Zone

No parameters are passed for this event

-(void)onLogout:(SFSEvent *)evt
{
NSLog(@"Logout was successful");
// Proceed with more logic here...
}
See also
LogoutRequest
LoginRequest

◆ onMMOItemVariablesUpdate:

- (void) onMMOItemVariablesUpdate: (SFSEvent *)  evt
optional

This event is fired in response to a server side SetMMOItemVariables.

Parameters
room(SFSRoom*) the room in which the event occurred
mmoItem(MMOItem*) the item whose variables where changed
changedVars(NSArray*) an array of variable names that were changed

The following example shows how handle the event:

-(void)onMMOItemVariablesUpdate:(SFSEvent *)evt
{
IMMOItem* mmoItem = [evt.params objectForKey:@"mmoItem"];
NSArray* changedVars = [evt.params objectForKey:@"changedVars"];
for (NSString* varName in changedVars)
{
MMOItemVariable* itemVar = [mmoItem getVariable: varName];
// Handle the new value
}
}
See also
MMOItemVariable
MMOItem

◆ onModeratorMessage:

- (void) onModeratorMessage: (SFSEvent *)  evt
optional

This event is fired when a User receives a Moderator message.

-(void)onModeratorMessage:(SFSEvent *)evt
{
SFSUser *sender = [evt.params objectForKey:@"sender"];
NSLog(@"Moderator says: %@, from: %@", [evt.params objectForKey:@"message"], sender.name);
}
Parameters
sender(SFSUser *) the sender of the message
message(NSString *) the message
data(SFSObject *) an object with custom data
See also
ModeratorMessageRequest

◆ onObjectMessage:

- (void) onObjectMessage: (SFSEvent *)  evt
optional

This event is received when a User has sent an ObjectMessage request

The object sent by the sender can contain custom data, such as a game move etc...

-(void)onObjectMessage:(SFSEvent *)evt
{
SFSObject *obj = [evt.params objectForKey:@"message"];
NSLog(@"Received data: %@", [obj getDump]);
}
Parameters
sender(SFSUser *) the sender of the message
message(SFSObject *) the object data
See also
ObjectMessageRequest

◆ onPingPong:

- (void) onPingPong: (SFSEvent *)  evt
optional

This event is fired at regular intervals when the LagMonitor is active

Parameters
lagValue(NSNumber) the average of the last measured lag values, expressed in milliseconds.

◆ onPlayerToSpectator:

- (void) onPlayerToSpectator: (SFSEvent *)  evt
optional

This event is fired in response to a successful PlayerToSpectatorRequest

Parameters
room(SFSRoom *) the Room where the player became a spectator
user(SFSUser *) the User who became a spectator
//This is how to dispatch the event
-(void)switchPlayerToSpectator
{
[client send:[PlayerToSpectatorRequest requestWithTargetRoom:nil]];
}
//This is how to handle the event
-(void)onPlayerToSpectator:(SFSEvent *)evt
{
NSLog(@"Hi, I'm handling an onPlayerToSpectator event. My params are %@",evt.params);
}
See also
PlayerToSpectatorRequest

◆ onPlayerToSpectatorError:

- (void) onPlayerToSpectatorError: (SFSEvent *)  evt
optional

This event is fired in response to a failed PlayerToSpectatorRequest

Parameters
errorMessage(NSString *) the error message
//This is how to handle the event
-(void)onSpectatorToPlayerError:(SFSEvent *)evt
{
NSLog(@"Hi, I'm handling an onPlayerToSpectatorError event. My params are %@",evt.params);
}
See also
PlayerToSpectatorRequest

◆ onPrivateMessage:

- (void) onPrivateMessage: (SFSEvent *)  evt
optional

This event is fired when a User receives a private message.

-(void)onPrivateMessage:(SFSEvent *)evt
{
SFSUser *sender = [evt.params objectForKey:@"sender"];
NSLog(@"PM: %@, from: %@", [evt.params objectForKey:@"message"], sender.name);
}
Parameters
sender(SFSUser *) the sender of the message
message(NSString *) the message
data(SFSObject *) an object with custom data
See also
PrivateMessageRequest

◆ onProximityListUpdate:

- (void) onProximityListUpdate: (SFSEvent *)  evt
optional

This event is fired in response to a SetUserPositionRequest.

Parameters
addedUsers(NSArray *) A list of User objects representing the users who entered the current user's Area of Interest.
removedUsers(NSArray *) A list of User objects representing the users who left the current user's Area of Interest.
addedItems(NSArray *) A list of MMOItem objects which entered the current user's Area of Interest.
removedItems(NSArray *) A list of MMOItem objects which left the current user's Area of Interest.
room(SFSRoom*) The room where the event occurred

The following example shows how to set the position in virtual world and handle the proximity list event:

[smartFox send:[SetUserPositionRequest requestWithPosition:[[Vec3D alloc] initWithX:@10 Y:@20 Z:@10] mmoRoom: [smartFox lastJoinedRoom]]];
-(void)onProximityListUpdate:(SFSEvent *)evt
{
NSArray* addedUsers = [evt.params objectForKey:@"addedUsers"];
NSArray* removedUsers = [evt.params objectForKey:@"removedUsers"];
NSArray* addedItems = [evt.params objectForKey:@"addedItems"];
NSArray* removedItems = [evt.params objectForKey:@"removedItems"];
//Trace the number of changes for each list
NSLog(@"ProxyUpdate: %d, %d, %d, %d", addedUsers.count, removedUsers.count, addedItems.count, removedItems.count);
//Proceed with rendering the users and items on screen
//...
//...
}
See also
MMORoom
MMOItem
SetUserPositionRequest

◆ onPublicMessage:

- (void) onPublicMessage: (SFSEvent *)  evt
optional

This event is fired when a User sends a public message.

Also the User receives this event every time he sends a public message.

-(void)onPublicMessage:(SFSEvent *)evt
{
SFSUser *sender = [evt.params objectForKey:@"sender"];
NSLog(@"%@: %@", sender.name, [evt.params objectForKey:@"message"]);
}
Parameters
room(SFSRoom *) the target Room
sender(SFSUser *) the sender
message(NSString *) the message
data(SFSObject *) an object with custom data
See also
PublicMessageRequest

◆ onRoomAdd:

- (void) onRoomAdd: (SFSEvent *)  evt
optional

This event is dispatched when a new Room was created inside the Zone under any of the Room Groups that the User is listening for.

The params object contains the following keys.

Parameters
room(SFSRoom *) the room object
-(void)onRoomAdd:(SFSEvent *)evt
{
NSLog(@"A new Room was added: %@", [evt.params objectForKey:@"room"]);
}
See also
- onRoomRemove:evt
CreateRoomRequest

◆ onRoomCapacityChange:

- (void) onRoomCapacityChange: (SFSEvent *)  evt
optional

This event is fired in response to a ChangeRoomCapacityRequest

Parameters
room(SFSRoom *) the Room where the change occurred
See also
ChangeRoomCapacityRequest

◆ onRoomCapacityChangeError:

- (void) onRoomCapacityChangeError: (SFSEvent *)  evt
optional

This event is fired in response to a failed ChangeRoomCapacityRequest

Parameters
errorMessage(NSString *) the error message
See also
ChangeRoomCapacityRequest

◆ onRoomCreationError:

- (void) onRoomCreationError: (SFSEvent *)  evt
optional

This event is dispatched in response to a failed create room request.

Parameters
errorMessage(NSString *) the error message
-(void)onRoomCreationError:(SFSEvent *)evt
{
NSLog(@"Room Creation Error: %@", [evt.params objectForKey:@"errorMessage"]);
}
See also
- onRoomAdd:evt
CreateRoomRequest

◆ onRoomFindResult:

- (void) onRoomFindResult: (SFSEvent *)  evt
optional

This event is fired in response to a FindRoomsRequest

Parameters
rooms(NSArray *) a list of Rooms matching the request criteria. If no Room was found the list will be empty.
See also
FindRoomsRequest

◆ onRoomJoin:

- (void) onRoomJoin: (SFSEvent *)  evt
optional

This event is dispatched in response to a JoinRoomRequest.

Parameters
room(SFSRoom *) the joined Room
-(void)onRoomJoin:(SFSEvent *)evt
{
SFSRoom *room = [evt.params objectForKey:@"room"];
NSLog(@"The Room %@ was successfully joined!", room.name);
}
See also
- onRoomJoinError:evt
JoinRoomRequest

◆ onRoomJoinError:

- (void) onRoomJoinError: (SFSEvent *)  evt
optional

This event is dispatched in response to a failed JoinRoomRequest.

The params object contains the following parameters.

Parameters
errorMessage(NSString *) the error message
-(void)onRoomJoinError:(SFSEvent *)evt
{
NSLog(@"Join Room Failure: %@", [evt.params objectForKey:@"errorMessage"]);
}
See also
- onRoomJoinError:evt
JoinRoomRequest

◆ onRoomNameChange:

- (void) onRoomNameChange: (SFSEvent *)  evt
optional

This event is fired in response to a ChangeRoomNameRequest

Parameters
room(SFSRoom *) the Room where the change occurred
oldName(NSString *) the old Room name
-(void)onRoomNameChange:(SFSEvent *)evt
{
NSLog(@"Hi, I'm handling an onRoomNameChange event. My params are %@",evt.params);
}
See also
ChangeRoomNameRequest

◆ onRoomNameChangeError:

- (void) onRoomNameChangeError: (SFSEvent *)  evt
optional

This event is fired in response to a failed ChangeRoomNameRequest

Parameters
errorMessage(NSString *) the error message
See also
ChangeRoomNameRequest

◆ onRoomPasswordStateChange:

- (void) onRoomPasswordStateChange: (SFSEvent *)  evt
optional

This event is fired in response to a ChangeRoomPasswordStateRequest.

In particular this event when the password state is changed. For example when a non-password protected Room is assigned a password, or vice-versa

Parameters
room(SFSRoom *) the Room where the change occurred
See also
ChangeRoomPasswordStateRequest

◆ onRoomPasswordStateChangeError:

- (void) onRoomPasswordStateChangeError: (SFSEvent *)  evt
optional

This event is fired in response to a failed ChangeRoomPasswordStateRequest

Parameters
errorMessage(NSString *) the error message
See also
ChangeRoomPasswordStateRequest

◆ onRoomRemove:

- (void) onRoomRemove: (SFSEvent *)  evt
optional

This event is dispatched whenever a Room is removed from the Zone, under any of the Room Groups that the User is listening for.

Parameters
room(SFSRoom *) the room object
-(void)onRoomRemove:(SFSEvent *)evt
{
NSLog(@"A new Room was removed: %@", [evt.params objectForKey:@"room"]);
}
See also
- onRoomAdd:evt

◆ onRoomVariablesUpdate:

- (void) onRoomVariablesUpdate: (SFSEvent *)  evt
optional

This event is fired in response to a SetRoomVariablesRequest

Parameters
room(SFSRoom *) the Room in which the event occurred (Since API 1.7.x)
changedVars(NSArray *) the list of variable names that where modified or created
sourceRoom(NSNumber *) The id of the Room which the Extension is attached to (for Room Extensions only),
See also
SetRoomVariablesRequest
SFSRoomVariable

◆ onSpectatorToPlayer:

- (void) onSpectatorToPlayer: (SFSEvent *)  evt
optional

This event is fired in response to a successful SpectatorToPlayerRequest

Parameters
room(SFSRoom *) the Room where the spectator became a player
user(SFSUser *) the User who became a player
playerId(NSNumber *) the new playerId of the User
//This is how to dispatch the event
-(void)switchSpectatorToPlayer
{
[client send:[SpectatorToPlayerRequest requestWithTargetRoom:nil]];
}
//This is how to handle the event
-(void)onSpectatorToPlayer:(SFSEvent *)evt
{
NSLog(@"Hi, I'm handling an onSpectatorToPlayer event. My params are %@",evt.params);
}
See also
SpectatorToPlayerRequest

◆ onSpectatorToPlayerError:

- (void) onSpectatorToPlayerError: (SFSEvent *)  evt
optional

This event is fired in response to a failed SpectatorToPlayerRequest

Parameters
errorMessage(NSString *) the error message
//This is how to handle the event
-(void)onSpectatorToPlayerError:(SFSEvent *)evt
{
NSLog(@"Hi, I'm handling an onSpectatorToPlayerError event. My params are %@",evt.params);
}
See also
SpectatorToPlayerRequest

◆ onSubscribeRoomGroup:

- (void) onSubscribeRoomGroup: (SFSEvent *)  evt
optional

This event is fired in response to a SubscribeRoomGroupRequest

Parameters
groupId(NSString *) the name of thr group that was subscribed
newRooms(NSArray *) the list of rooms contained in the new group
See also
SubscribeRoomGroupRequest

◆ onSubscribeRoomGroupError:

- (void) onSubscribeRoomGroupError: (SFSEvent *)  evt
optional

This event is fired in response to a failed SubscribeRoomGroupRequest

The params object contains the following parameters.

Parameters
errorMessage(NSString *) the error message
See also
SubscribeRoomGroupRequest

◆ onUDPSocketConnect:

- (void) onUDPSocketConnect: (SFSEvent *)  evt
optional

The onUDPSocketConnect event is dispatched after a UDP connection has been attempted and either failed (0) or succedded (1) to establish a connection.

The client will attempt to connect three (3) time before dispatching a failed event.

The following example shows how to handle the event

-(void)onUDPSocketConnect:(SFSEvent *)evt
{
if ([[evt.params objectForKey:@"success"] boolValue])
{
NSLog(@"UDP connected");
}
else
{
NSLog(@"UDP not connected");
}
}
See also
- onConnectionLost:evt
- onConnectionResume:evt
- onConnection:evt
UDPManager

◆ onUnsubscribeRoomGroup:

- (void) onUnsubscribeRoomGroup: (SFSEvent *)  evt
optional

This event is fired in response to an UnsubscribeRoomGroupRequest

Parameters
groupId(NSString *) the name of the group that was unsubscribed.
See also
UnsubscribeRoomGroupRequest

◆ onUnsubscribeRoomGroupError:

- (void) onUnsubscribeRoomGroupError: (SFSEvent *)  evt
optional

This event is fired in response to a failed UnsubscribeRoomGroupRequest

The params object contains the following parameters.

Parameters
errorMessage(NSString *) the error message
See also
UnsubscribeRoomGroupRequest

◆ onUserCountChange:

- (void) onUserCountChange: (SFSEvent *)  evt
optional

This event is fired whenever the number of users/spectators in a Room changes.

The client receives updates for all Rooms inside the Room Groups that he is listening to.

-(void)onUserCountChange:(SFSEvent *)evt
{
SFSRoom *room = [evt.params objectForKey:@"room"];
int uCount = [[evt.params objectForKey:@"uCount"] intValue];
int sCount = [[evt.params objectForKey:@"sCount"] intValue];
NSLog(@"Room: %@ contains %d users and %d spectators", room.name, uCount, sCount);
}
Parameters
room(Room) the Room
uCount(NSNumber *) the new user count
sCount(NSNumber *) the new spectator count

◆ onUserEnterRoom:

- (void) onUserEnterRoom: (SFSEvent *)  evt
optional

This event is fired whenever a User enters one of the Rooms where the current User is joined.

Parameters
user(SFSUser *) the User object
room(SFSRoom *) the Room object
-(void)onUserEnterRoom:(SFSEvent *)evt
{
SFSRoom *room = [evt.params objectForKey:@"room"];
SFSUser *user = [evt.params objectForKey:@"user"];
NSLog(@"User: %@ has just joined Room: %@", user.name, room.name);
}
See also
- onUserExitRoom:evt
- onRoomJoin:evt
JoinRoomRequest

◆ onUserExitRoom:

- (void) onUserExitRoom: (SFSEvent *)  evt
optional

This event is fired whenever a User leaves one of the Rooms where the current User is joined.

Parameters
user(SFSUser *) the User object
room(SFSRoom *) the Room object
-(void)onUserExitRoom:(SFSEvent *)evt
{
SFSRoom *room = [evt.params objectForKey:@"room"];
SFSUser *user = [evt.params objectForKey:@"user"];
NSLog(@"User: %@ has just left Room: %@", user.name, room.name);
}
See also
- onUserEnterRoom:evt
- onRoomJoin:evt
LeaveRoomRequest

◆ onUserFindResult:

- (void) onUserFindResult: (SFSEvent *)  evt
optional

This event is fired in response to a FindUsersRequest

Parameters
users(NSArray *) a list of Users matching the request criteria. If no User was found the list will be empty.
See also
FindUsersRequest

◆ onUserVariablesUpdate:

- (void) onUserVariablesUpdate: (SFSEvent *)  evt
optional

This event is fired in response to a SetUserVariablesRequest

Parameters
user(SFSUser *) the User that created or modified the Variables
changedVars(NSArray *) the list of variable names that where modified or created
See also
SetUserVariablesRequest
SFSUserVariable
SFSUser
Definition: SFSUser.h:20
ConfigData
Definition: ConfigData.h:15
SFSRoom
Definition: SFSRoom.h:35
LoginRequest
Definition: LoginRequest.h:30
SFSObject
Definition: SFSObject.h:29
Vec3D
Definition: Vec3D.h:26
SmartFox2XClient
Definition: SmartFox2XClient.h:113
PlayerToSpectatorRequest
Definition: PlayerToSpectatorRequest.h:22
SFSRoom::name
NSString * name
Definition: SFSRoom.h:66
SFSEvent
Definition: SFSEvent.h:65
SetUserPositionRequest
Definition: SetUserPositionRequest.h:30
SFSUser::name
NSString * name
Definition: SFSUser.h:54
MMOItemVariable
Definition: MMOItemVariable.h:27
SpectatorToPlayerRequest
Definition: SpectatorToPlayerRequest.h:23