ElectroServer 5 Client: Cocoa-Touch
EsLoginRequest Class Reference

This message is sent by the client to the server (after establishing a connection) to attempt to login. More...

Inheritance diagram for EsLoginRequest:
EsRequest EsMessage EsEventDispatcherEvent

Instance Methods

(id) - init
 
(id) - initWithThriftObject:
 
(void) - fromThrift:
 
(ThriftLoginRequest *) - toThrift
 
(id) - newThrift
 

Properties

NSString * userName
 The requested username. More...
 
NSString * password
 This is an optional property. More...
 
NSString * sharedSecret
 If a client already has a connection established and is logged in, and then would like to make a second connection and login, this property will be used. More...
 
EsObjectesObject
 
NSMutableDictionary * userVariables
 User variables are name (string) value (EsObject) pairs that are associated with a user. More...
 
int protocol
 
int32_t hashId
 
NSString * clientVersion
 
NSString * clientType
 

Additional Inherited Members

- Protected Attributes inherited from EsMessage
int messageType_
 

Detailed Description

This message is sent by the client to the server (after establishing a connection) to attempt to login.

With the default installation of the server the login attempt will be automatically accepted unless the username is already in use, or if the username fails the default language filter check. Listen for the LoginResponse class

Basic example.

 var r:LoginRequest = new LoginRequest;
 r.userName = "TestUser";
 send(r);
 

Full example. This code connects to the server, logs in, and captures the login response.

package {
        import flash.display.Sprite;
ElectroServer imports
        import com.electrotank.electroserver5.api.ConnectionResponse;
        import com.electrotank.electroserver5.api.LoginRequest;
        import com.electrotank.electroserver5.api.LoginResponse;
        import com.electrotank.electroserver5.api.MessageType;
        import com.electrotank.electroserver5.ElectroServer;
Logger imports
        import mx.logging.Log;
        import mx.logging.targets.TraceTarget;
        public class Main extends Sprite {

    private var _es:ElectroServer = new ElectroServer();

    public function Main():void {
add this so we can see the logs get traced
                        Log.addTarget(new TraceTarget());
                        load settings file and connect
                        _es.loadAndConnect("settings.xml");
listen to key events to know when a connection has succeeded (or failed), and when login has succeeded (or failed)
                        _es.engine.addEventListener(MessageType.ConnectionResponse.name, onConnectionResponse);
                        _es.engine.addEventListener(MessageType.LoginResponse.name, onLoginResponse);
                }
                private function onConnectionResponse(e:ConnectionResponse):void {
                        trace("Connection success: " + e.successful.toString());
                        if (e.successful) {
connection succeeded, so login. Use randomly generated name.
                                var lr:LoginRequest = new LoginRequest();
                                lr.userName = "guest" + Math.round(1000 * Math.random()).toString();
                                _es.engine.send(lr);
                        }
                }
                private function onLoginResponse(e:LoginResponse):void {
                        trace("Login accepted: " + e.successful.toString());
                        if (!e.successful) {
                                trace(e.error.name);
                        }
                }
        }
}
 

Method Documentation

- (void) fromThrift: (id)  thriftObject

Reimplemented from EsMessage.

- (id) init
- (id) initWithThriftObject: (id)  thriftObject
- (id) newThrift

Reimplemented from EsMessage.

- (ThriftLoginRequest *) toThrift

Reimplemented from EsMessage.

Property Documentation

- (NSString*) clientType
readwritenonatomicretain
- (NSString*) clientVersion
readwritenonatomicretain
- (EsObject*) esObject
readwritenonatomicretain
- (int32_t) hashId
readwritenonatomicassign
- (NSString*) password
readwritenonatomicretain

This is an optional property.

By default it isn't used. The only way for the server to use this property is if there is a LoginEventHandler registered with the server that looks for this property.

- (int) protocol
readwritenonatomicassign
- (NSString*) sharedSecret
readwritenonatomicretain

If a client already has a connection established and is logged in, and then would like to make a second connection and login, this property will be used.

Establish the second connection, and then in the LoginRequest make up some unique secret and send the LoginRequest. Just before the API sends the request it will pull out that secret and remember it. Before the server validates the login request it will send ValidateAdditionalLoginRequest to the client over the first connection. The API silently responds to this request with a ValidateAdditionalLoginResponse message and adds the secret word to it. The server then compares the secret received over the first and additional connections, and if they match then the login is accepted. A LoginResponse message will be received over the newly added connection.

- (NSString*) userName
readwritenonatomicretain

The requested username.

It will be accepted unless the name is already in use, it fails the language filter, or if there is a LoginEventHandler registered with the server that decides to fail this name.

- (NSMutableDictionary*) userVariables
readwritenonatomicretain

User variables are name (string) value (EsObject) pairs that are associated with a user.

They are publicly viewable by users in the same room. They can be modified by the user at any time and can be modified by the server at any time. This property can contain an unlimited number of user variables.

var lr:LoginRequest = new LoginRequest();
lr.userName = win.userName.text;
create an EsObject and populate with data
var uvEsob:EsObject = new EsObject();
uvEsob.setStringArray("pets", ["dogs", "cats", "rabbits"]);
uvEsob.setInteger("squareFootage", 3400);
add to the login request
lr.userVariables["myHouse"] = uvEsob;