Ejemplo n.º 1
0
    public void Initialize()
    {
        if (_isInitialized)
        {
            //Debug.Log("Initialized");
        }
        else
        {
            Debug.Log("Initialized " + SmartFox.Version);

            SmartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            SmartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
            SmartFox.AddEventListener(SFSEvent.LOGIN, OnLogin);
            SmartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
            SmartFox.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
            SmartFox.AddEventListener(SFSEvent.ROOM_ADD, OnRoomAdd);
            SmartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
            SmartFox.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);
            SmartFox.AddEventListener(SFSEvent.ROOM_REMOVE, OnRoomRemove);
            SmartFox.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
            SmartFox.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
            SmartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
            SmartFox.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVariableUpdate);
            SFSErrorCodes.SetErrorMessage(200, "Sorry {0}, you don't seem to be a human user. Nice try!");

            SmartFox.Connect(IP, PORT);
        }
        _isInitialized = true;
    }
Ejemplo n.º 2
0
        public void HandleHandShake(BaseEvent evt)
        {
            ISFSObject iSFSObject = evt.Params["message"] as ISFSObject;

            if (iSFSObject.IsNull(BaseRequest.KEY_ERROR_CODE))
            {
                sessionToken = iSFSObject.GetUtfString(HandshakeRequest.KEY_SESSION_TOKEN);
                socketClient.CompressionThreshold = iSFSObject.GetInt(HandshakeRequest.KEY_COMPRESSION_THRESHOLD);
                socketClient.MaxMessageSize       = iSFSObject.GetInt(HandshakeRequest.KEY_MAX_MESSAGE_SIZE);
                if (debug)
                {
                    log.Debug($"Handshake response: tk => {sessionToken}, ct => {socketClient.CompressionThreshold}");
                }
                if (socketClient.IsReconnecting)
                {
                    socketClient.IsReconnecting = false;
                    DispatchEvent(new SFSEvent(SFSEvent.CONNECTION_RESUME));
                    return;
                }
                isConnecting = false;
                Hashtable hashtable = new Hashtable();
                hashtable["success"] = true;
                DispatchEvent(new SFSEvent(SFSEvent.CONNECTION, hashtable));
            }
            else
            {
                short     @short       = iSFSObject.GetShort(BaseRequest.KEY_ERROR_CODE);
                string    errorMessage = SFSErrorCodes.GetErrorMessage(@short, log, iSFSObject.GetUtfStringArray(BaseRequest.KEY_ERROR_PARAMS));
                Hashtable hashtable2   = new Hashtable();
                hashtable2["success"]      = false;
                hashtable2["errorMessage"] = errorMessage;
                hashtable2["errorCode"]    = @short;
                DispatchEvent(new SFSEvent(SFSEvent.CONNECTION, hashtable2));
            }
        }