Пример #1
0
        public void OnConnect()
        {
            if (_sfs != null)
            {
                return;
            }

            var cfg = new ConfigData
            {
                Host = _config.Host,
                Port = _config.Port,
                Zone = _config.ZoneName
            };

            GD.Print("Connecting...");

            _sfs = new SmartFox {
                ThreadSafeMode = false, Debug = true
            };
            _sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            _sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
            _sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
            _sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
            _sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
            _sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);
            _sfs.AddEventListener(SFSEvent.LOGOUT, OnLogout);

            _sfs.Connect(cfg);
        }
Пример #2
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------

    public void OnLoginButtonClick()
    {
        enableLoginUI(false);

        // Set connection parameters
        ConfigData cfg = new ConfigData();

        cfg.Host    = Host;
        cfg.Port    = TcpPort;
        cfg.Zone    = Zone;
        cfg.UdpHost = Host;
        cfg.UdpPort = UdpPort;

        // Initialize SFS2X client and add listeners
        sfs = new SmartFox();

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.UDP_INIT, OnUdpInit);

        // Connect to SFS2X
        sfs.Connect(cfg);
    }
Пример #3
0
 //----------------------------------------------------------
 // Called when program starts
 //----------------------------------------------------------
 void Start()
 {
     smartFox = new SmartFox();
     smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection);
     smartFox.AddLogListener(LogLevel.DEBUG, OnDebugMessage);
     smartFox.Connect(ip, port);
 }
Пример #4
0
    public void startSmartfox()
    {
        sfs = new SmartFox();

        // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        sfs.ThreadSafeMode = true;

        // SmartFox Event listeners
        sfs.AddEventListener(SFSEvent.CONNECTION, connectionHandler);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, connectionLostHandler);
        sfs.AddEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, configLoadHandler);
        sfs.AddEventListener(SFSEvent.CONFIG_LOAD_FAILURE, configLoadFailHandler);
        sfs.AddEventListener(SFSEvent.LOGIN, loginHandler);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, loginErrorHandler);
        sfs.AddEventListener(SFSEvent.ROOM_ADD, roomAddHandler);
        sfs.AddEventListener(SFSEvent.ROOM_CREATION_ERROR, roomCreationErrorHandler);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN, roomJoinHandler);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, roomJoinErrorHandler);

        serverIP = inputField.text;
        if (UseConfigFile)
        {
            sfs.LoadConfig(Application.dataPath + "/Resources/sfs-config.xml", true);
        }
        else
        {
            sfs.Connect(serverIP, serverPort);
        }

        popUp.SetActive(false);
    }
Пример #5
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------

    public void OnLoginButtonClick()
    {
        enableLoginUI(false);

        // Set connection parameters
        ConfigData cfg = new ConfigData();

        cfg.Host = Host;
                #if !UNITY_WEBGL
        cfg.Port = TcpPort;
                #else
        cfg.Port = WSPort;
                #endif
        cfg.Zone = Zone;

        // Initialize SFS2X client and add listeners
                #if !UNITY_WEBGL
        sfs = new SmartFox();
                #else
        sfs = new SmartFox(UseWebSocket.WS_BIN);
                #endif

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);

        // Connect to SFS2X
        sfs.Connect(cfg);
    }
Пример #6
0
    //----------------------------------------------------------
    // Called when program starts
    //----------------------------------------------------------
    void Start()
    {
        // In a webplayer (or editor in webplayer mode) we need to setup security policy negotiation with the server first
        if (Application.isWebPlayer || Application.isEditor)
        {
            if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500))
            {
                Debug.LogError("Security Exception. Policy file loading failed!");
            }
        }

        // Lets connect
        smartFox = new SmartFox(true);

        // Register callback delegate
        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.LOGOUT, OnLogout);
        smartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
        smartFox.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);

        smartFox.AddLogListener(LogLevel.DEBUG, OnDebugMessage);

        smartFox.Connect(serverName, serverPort);

        //		var ipaddress = Network.player.ipAddress;
        //		Debug.Log (ipaddress);
    }
Пример #7
0
        public void Connect()
        {
            Debug.Log("Connect");

            if (smartFox == null || !smartFox.IsConnected)
            {
                // Set connection parameters
                ConfigData cfg = new ConfigData();

                cfg.Host = SCG_Host;

#if !UNITY_WEBGL
                cfg.Port = Convert.ToInt32(SCG_TcpPort);
#else
                cfg.Port = Convert.ToInt32(SCG_WsPort);
#endif

                cfg.Zone = SCG_Zone;

                cfg.Debug = true;

                // Connect to SFS2X
                smartFox.Connect(cfg);
            }
            else
            {
                // DISCONNECT

                // Disconnect from SFS2X
                smartFox.Disconnect();
            }
        }
Пример #8
0
    public void RegisButtonClick()
    {
        enableLoginUI(false);

        // Set connection parameters
        Sfs2X.Util.ConfigData cfg = new ConfigData();
        cfg.Host    = Host;
        cfg.Port    = TcpPort;
        cfg.Zone    = Zone;
        cfg.UdpHost = Host;
        cfg.UdpPort = UdpPort;

        // Initialize SFS2X client and add listeners
        sfs = new SmartFox();

        // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.UDP_INIT, OnUdpInit);
        sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

        // Connect to SFS2X
        sfs.Connect(cfg);
    }
Пример #9
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------


    public void OnOKButtonClicked()
    {
        if (AdminUserName.text != "")
        {
            username = AdminUserName.text;
            email    = AdminEmail.text;
        }
        else
        {
            username = Transverser.MemberUsername; // MemberUserName.text;
            email    = Transverser.MemberEmail;    // MemberEmail.text;
        }

#if UNITY_WEBGL
        {
            sfs        = new SmartFox(UseWebSocket.WS);
            ServerPort = defaultWsPort;
        }
#else
        {
            sfs        = new SmartFox();
            ServerPort = defaultTcpPort;
        }
#endif
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

        sfs.Connect(ServerIP, ServerPort);
    }
Пример #10
0
        public ShinyFinder()
        {
            InitSteam();
            if (DefaultSFSDataSerializer.RunningAssembly == null)
            {
                DefaultSFSDataSerializer.RunningAssembly = Assembly.Load("Assembly-CSharp");
            }

            SFClient = new SmartFox();
            SFClient.Log.LoggingLevel = Sfs2X.Logging.LogLevel.INFO;
            SFClient.ThreadSafeMode   = false;
            //SFClient.RemoveAllEventListeners();
            SFClient.AddEventListener(SFSEvent.EXTENSION_RESPONSE, new EventListenerDelegate(OnResponse));
            SFClient.AddEventListener(SFSEvent.PING_PONG, new EventListenerDelegate(OnPing));
            SFClient.AddEventListener(SFSEvent.CONNECTION_LOST, new EventListenerDelegate(OnDisconnect));

            SFClient.AddEventListener(SFSEvent.CONNECTION, new EventListenerDelegate(OnConnect));
            SFClient.AddEventListener(SFSEvent.LOGIN, new EventListenerDelegate(OnLogin));
            SFClient.AddEventListener(SFSEvent.LOGOUT, new EventListenerDelegate(OnLogout));
            SFClient.AddEventListener(SFSEvent.LOGIN_ERROR, new EventListenerDelegate(OnLoginError));

            SFClient.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, new EventListenerDelegate(OnUserVarUpdate));
            SFClient.AddEventListener(SFSEvent.PUBLIC_MESSAGE, new EventListenerDelegate(OnPublicMessage));

            SFClient.AddEventListener(SFSEvent.USER_ENTER_ROOM, new EventListenerDelegate(Dummy));
            SFClient.AddEventListener(SFSEvent.USER_EXIT_ROOM, new EventListenerDelegate(Dummy));
            SFClient.AddEventListener(SFSEvent.ROOM_JOIN, new EventListenerDelegate(Dummy));
            SFClient.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, new EventListenerDelegate(Dummy));
            SFClient.Connect(ConfigData);
        }
Пример #11
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------
    public void JoinZone()
    {
        // Set connection parameters
        ConfigData cfg = new ConfigData();
        cfg.Host = Host;
        #if !UNITY_WEBGL
        cfg.Port = TcpPort;
        #else
        cfg.Port = WSPort;
        #endif
        cfg.Zone = Zone;

        // Initialize SFS2X client and add listeners
        #if !UNITY_WEBGL
        sfs = new SmartFox();
        #else
        sfs = new SmartFox(UseWebSocket.WS);
        #endif
        cfg.Debug = true;

        // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);

        // Connect to SFS2X
        sfs.Connect(cfg);
    }
Пример #12
0
    void ClickConnect()
    {
        _connectButton.interactable = true;

        ConfigData cfg = new ConfigData();

        cfg.Host = HostIp;
#if !UNITY_WEBGL
        cfg.Port = TcpPort;
#else
        cfg.Port = WsPort;
#endif
        cfg.Zone = ZoneName;

#if !UNITY_WEBGL
        _smartFoxServer = new SmartFox();
#else
        _smartFoxServer = new SmartFox(UseWebSocket.WS);
#endif

        _smartFoxServer.ThreadSafeMode = true;

        _smartFoxServer.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        _smartFoxServer.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        _smartFoxServer.AddEventListener(SFSEvent.LOGIN, OnLogin);
        _smartFoxServer.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);

        _smartFoxServer.Connect(cfg);

        DebugConsole.Log("Connecting...");
    }
Пример #13
0
    void Start()
    {
        SpawnLocalPlayer();
        username = "******" + UnityEngine.Random.Range(0, 1000).ToString();
        sfs      = new SmartFox();
        //sfs.Debug = true;
        sfs.AddEventListener(SFSEvent.CONNECTION, onConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
        sfs.AddEventListener(SFSEvent.OBJECT_MESSAGE, OnObjectMessage);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, OnUserVariableUpdate);
        sfs.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
        sfs.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError);
        ConfigData cfg = new ConfigData();

        cfg.Host  = defaultHost;
        cfg.Port  = defaultTcpPort;
        cfg.Zone  = "BasicExamples";
        cfg.Debug = true;
        sfs.Connect(cfg);
    }
Пример #14
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------

    public void OnActivateAccountButtonClicked()
    {
        activation = Activation.text;
        if (activation == "" || activation == " ")
        {
            TextMessage.text = "Missing to fill required value";
        }
        else
        {  // Enable interface
            enableInterface(false);

#if UNITY_WEBGL
            {
                sfs        = new SmartFox(UseWebSocket.WS);
                ServerPort = defaultWsPort;
            }
#else
            {
                sfs        = new SmartFox();
                ServerPort = defaultTcpPort;
            }
#endif

            sfs.ThreadSafeMode = true;

            sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
            sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
            sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
            sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

            sfs.Connect(ServerIP, ServerPort);
        }
    }
Пример #15
0
    // Use this for initialization
    void Start()
    {
        LoginPanel    = GameObject.Find("LoginBox");
        RegisterPanel = GameObject.Find("RegisterBox");
        RegisterPanel.SetActive(false);
        MessageText = GameObject.Find("MessageText");
        MessageText.SetActive(false);

        UsernameTB = GameObject.Find("UsernameTB").GetComponent <InputField>();
        PasswordTB = GameObject.Find("PasswordTB").GetComponent <InputField>();
        UsernameTB.Select();

        SFServer = new SmartFox();

        //Set our basic default connection parameters
        this.OurConfigData.Host = "biele.us";
        this.OurConfigData.Port = 9933;
        this.OurConfigData.Zone = GAME_ZONE;

        // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        SFServer.ThreadSafeMode = true;

        SFServer.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        SFServer.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        SFServer.AddEventListener(SFSEvent.LOGIN, OnLogin);
        SFServer.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        SFServer.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

        SFServer.Connect(this.OurConfigData);
    }
Пример #16
0
 public void Connect()
 {
     if (!isLoadConfig)
     {
         ConfigData data = new ConfigData();
         data.Port  = PORT;
         data.Zone  = ZONE;
         data.Host  = HOST;
         data.Debug = false;
         sfs.Connect(data);
     }
     else
     {
         string path = Consts.SMARTFOX_CONFIG;
         sfs.LoadConfig(path);
     }
 }
Пример #17
0
    public void Connect()
    {
        if (sfs == null || !sfs.IsConnected)
        {
            // CONNECT

                #if UNITY_WEBPLAYER
            // Socket policy prefetch can be done if the client-server communication is not encrypted only (read link provided in the note above)
            if (!Security.PrefetchSocketPolicy(hostInput.text, Convert.ToInt32(portInput.text), 500))
            {
                Debug.LogError("Security Exception. Policy file loading failed!");
            }
                #endif

            Debug.Log("Now connecting...");

            // Initialize SFS2X client and add listeners
            // WebGL build uses a different constructor
                #if !UNITY_WEBGL
            sfs = new SmartFox();
                #else
            sfs = new SmartFox(UseWebSocket.WS_BIN);
                #endif

            // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
            sfs.ThreadSafeMode = true;

            sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

            sfs.AddLogListener(LogLevel.INFO, OnInfoMessage);
            sfs.AddLogListener(LogLevel.WARN, OnWarnMessage);
            sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage);

            sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
            sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
            sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
            sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);
            sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
            sfs.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
            sfs.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
            sfs.AddEventListener(SFSEvent.ROOM_ADD, OnRoomAdd);

            sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);



            // Set connection parameters
            ConfigData cfg = new ConfigData();
            cfg.Host  = IpAddress;
            cfg.Port  = Convert.ToInt32(Port);
            cfg.Zone  = "slotZ";
            cfg.Debug = DebugMode;

            // Connect to SFS2X
            sfs.Connect(cfg);
        }
    }
Пример #18
0
    void Start()
    {
        sfs = new SmartFox();
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);

        sfs.Connect(ServerIP, ServerPort);
    }
 internal void connect(string serverIP, int serverTcpPort, int serverHttpsPort)
 {
     lock (smartFoxLock)
     {
         setup();
         ConnectionAttempts = 0;
         ConfigData configData = new ConfigData();
         configData.Host       = serverIP;
         configData.Port       = serverTcpPort;
         configData.HttpsPort  = serverHttpsPort;
         configData.Zone       = zone;
         configData.Debug      = sfsDebugLogging;
         configData.UseBlueBox = false;
         configData.UdpHost    = serverIP;
         configData.UdpPort    = serverTcpPort;
         smartFox.Connect(configData);
     }
 }
Пример #20
0
    public void Connect()
    {
        ConfigData cfg = new ConfigData();

        cfg.Host = GameUtil.HOST;
        cfg.Port = GameUtil.PORT;
        cfg.Zone = GameUtil.ZONE;
        _smartFox.Connect(cfg);
        Debug.Log("CONNECT");
    }
Пример #21
0
 public void Connect()
 {
     if (smartFox == null)
     {
         Debug.Log("Smartfox is null so i'm reiniting");
         InitSmartfox();
     }
     else if (!smartFox.IsConnected)
     {
         Logger.trace("<< adding event listeners -- server: " + serverName + " port: " + serverPort);
         AddEventListeners();
         smartFox.Connect(serverName, serverPort);
         Logger.trace("<< connecting to " + serverName + " port: " + serverPort);
         running = true;
     }
     else
     {
         running = true;
         Debug.Log("Smartfox is already connected");
     }
 }
Пример #22
0
 public void Connect(Sfs2X.Util.ConfigData config)
 {
     if (!sfs.IsConnected)
     {
         sfsConfig = config;
         UnityEngine.Debug.Log("Starting the connection request");
         sfs.Connect(config);
     }
     else
     {
         UnityEngine.Debug.LogWarning("The Smartfox already connected");
     }
 }
Пример #23
0
 // send request
 public void SendConnectRequest(string zoneName = "BattleTank")
 {
     try
     {
         ZONE         = zoneName;
         _config.Zone = ZONE;
         _sfs.Connect(_config);
     }
     catch (Exception exp)
     {
         Debug.WriteLine("config error: " + exp.Message);
     }
 }
Пример #24
0
    // public interface method for ui
    public void OnLoginButtonClick()
    {
        sfs = new SmartFox();
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);

        sfs.Connect(serverIP, serverPort);
    }
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------

    public void OnButtonClick()
    {
        if (sfs == null || !sfs.IsConnected)
        {
            // CONNECT

            // Enable interface
            enableInterface(false);

            // Clear console
            debugText.text = "";
            debugScrollRect.verticalNormalizedPosition = 1;

            trace("Now connecting...");

            // Initialize SFS2X client and add listeners
            // WebGL build uses a different constructor
                        #if !UNITY_WEBGL
            sfs = new SmartFox();
                        #else
            sfs = new SmartFox(UseWebSocket.WS_BIN);
                        #endif

            sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

            sfs.AddLogListener(LogLevel.INFO, OnInfoMessage);
            sfs.AddLogListener(LogLevel.WARN, OnWarnMessage);
            sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage);

            // Set connection parameters
            ConfigData cfg = new ConfigData();
            cfg.Host  = hostInput.text;
            cfg.Port  = Convert.ToInt32(portInput.text);
            cfg.Zone  = "BasicExamples";
            cfg.Debug = debugToggle.isOn;

            // Connect to SFS2X
            sfs.Connect(cfg);
        }
        else
        {
            // DISCONNECT

            // Disable button
            button.interactable = false;

            // Disconnect from SFS2X
            sfs.Disconnect();
        }
    }
Пример #26
0
    public bool Connect(string hostInput, string portInput, int maxPlayers)
    {
        if (!SfsReady || !sfs.IsConnected)         // CONNECT
        {
                        #if UNITY_WEBPLAYER
            // Socket policy prefetch can be done if the client-server communication is not encrypted only (read link provided in the note above)
            if (!Security.PrefetchSocketPolicy(hostInput.text, Convert.ToInt32(portInput.text), 500))
            {
                Debug.LogError("Security Exception. Policy file loading failed!");
            }
                        #endif

            print("Now connecting...");

            // Initialize SFS2X client and add listeners
            // WebGL build uses a different constructor
                        #if !UNITY_WEBGL
            sfs = new SmartFox();
                        #else
            sfs = new SmartFox(UseWebSocket.WS);
                        #endif

            // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
            sfs.ThreadSafeMode = true;

            AddSfsListeners();

            // Set connection parameters
            ConfigData cfg = new ConfigData();
            cfg.Host = hostInput;
            cfg.Port = Convert.ToInt32(portInput);
            cfg.Zone = ZONE;

            if (this.maxPlayers == null)
            {
                this.maxPlayers = maxPlayers;
            }

            // Connect to SFS2X
            sfs.Connect(cfg);

            return(true);
        }
        else         // DISCONNECT
        {
            // Disconnect from SFS2X
            sfs.Disconnect();

            return(false);
        }
    }
Пример #27
0
    // Start is called before the first frame update
    void Start()
    {
        sfs = new SmartFox();
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        // sfs.AddEventListener(SFSEvent.ROOM_JOIN,OnJoinRoom);
        // sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR,OnJoinRoomError);
        // sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE,OnPublicMessage);

        sfs.Connect(ServerIp, ServerPort);
    }
Пример #28
0
    public void OnSignUpButtonClick()
    {
        //initialize SmartFox and EventListeners
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        //connect, then login as guest, then send signup request
        ConfigData cfg = new ConfigData();

        cfg.Host = "127.0.0.1";
        cfg.Port = 9933;
        cfg.Zone = "SignUpZone";
        sfs.Connect(cfg);
    }
Пример #29
0
    public void OnLoginButtonClick()
    {
        ConfigData cfg = new ConfigData();

        cfg.Host = Host;
        cfg.Port = TcpPort;
        cfg.Zone = Zone;
        sfs      = new SmartFox();
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);

        // Connect to SFS2X
        sfs.Connect(cfg);
    }
Пример #30
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------

    public void OnDeleteButtonClocked()
    {
        int    index;
        string admin;

        username = UserName.text;
        index    = username.IndexOf("n");
        admin    = username.Substring(0, index + 1);
        Debug.Log("delete account");
        if (username == "" || username == " ")
        {
            TextMessage.text = "Missing to fill required value";
        }
        else
        if (admin.Equals("Admin"))
        {
            TextMessage.text = "You are not allow to delete admin";
        }
        else
        {  // Enable interface
            enableInterface(false);

#if UNITY_WEBGL
            {
                sfs        = new SmartFox(UseWebSocket.WS);
                ServerPort = defaultWsPort;
            }
#else
            {
                sfs        = new SmartFox();
                ServerPort = defaultTcpPort;
            }
#endif

            sfs.ThreadSafeMode = true;

            sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
            sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
            sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
            sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

            sfs.Connect(ServerIP, ServerPort);
            UserName.text = "";
            enableInterface(true);
        }
    }//end
Пример #31
0
 // connection methods
 public void Connect(string host, int port)
 {
     try
     {
         ConfigData data = new ConfigData();
         data.Port       = port;
         data.Zone       = ZONE;
         data.Host       = host;
         data.Debug      = false;
         data.UseBlueBox = true;
         _sfs.Connect(data);
     }
     catch (NullReferenceException e)
     {
         Debug.WriteLine(e.Message);
     }
 }
Пример #32
0
    //----------------------------------------------------------
    // Public interface methods for UI
    //----------------------------------------------------------

    public void OnLoginButtonClick()
    {
        enableLoginUI(false);

        // Set connection parameters
        ConfigData cfg = new ConfigData();

        cfg.Host = Host;
                #if !UNITY_WEBGL
        cfg.Port = TcpPort;
                #else
        cfg.Port = WSPort;
                #endif
        cfg.Zone = zoneInput.text;

        // Initialize SFS2X client and add listeners
                #if !UNITY_WEBGL
        sfs = new SmartFox();
                #else
        sfs = new SmartFox(UseWebSocket.WS_BIN);
                #endif

        // Add SFS2X event listeners
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);

        // Add SFS2X buddy-related event listeners
        // NOTE: for simplicity, most buddy-related events cause the whole
        // buddylist in the interface to be recreated from scratch, also if those
        // events are caused by the current user himself. A more refined approach should
        // update the specific items to which the event refers.
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_LIST_INIT, OnBuddyListInit);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_ERROR, OnBuddyError);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_ONLINE_STATE_UPDATE, OnBuddyListUpdate);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, OnBuddyListUpdate);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_ADD, OnBuddyListUpdate);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_REMOVE, OnBuddyListUpdate);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_BLOCK, OnBuddyListUpdate);
        sfs.AddEventListener(SFSBuddyEvent.BUDDY_MESSAGE, OnBuddyMessage);

        // Connect to SFS2X
        sfs.Connect(cfg);
    }
Пример #33
0
	// Use this for initialization
	void Awake() {
		
		Application.runInBackground = true; // so unity doesn't timeout when switching focus
		
		// initialize smartfox with debug flag
		smartFox = new SmartFox(debug);
		
		// Register callback delegate
		smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection);
		smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
		smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin);
		smartFox.AddEventListener(SFSEvent.UDP_INIT, OnUdpInit);
		smartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
		smartFox.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);
		smartFox.AddEventListener(SFSEvent.ROOM_ADD, OnRoomAdded);

		smartFox.AddLogListener(LogLevel.DEBUG, OnDebugMessage);

		smartFox.Connect(serverName, serverPort);
	}
Пример #34
0
    public void BottoneLogin()
    {
        ManagerScenaZero.AttivaDisattivaCanvasGroupLogin(false);
        erroreText.text = "";

        ConfigData cfg = new ConfigData();
        cfg.Host = host;
        cfg.Port = port;
        cfg.Zone = zona;

        sfs = new SmartFox();

        sfs.ThreadSafeMode = true;
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);

        sfs.Connect(cfg);
    }
Пример #35
0
 void Start()
 {
     SetMessage ("Loading..");
             server = new SmartFox (true);
             server.AddEventListener (SFSEvent.CONNECTION, OnConnection);
             server.AddEventListener (SFSEvent.CONNECTION_LOST, OnConnectionLost);
             server.AddEventListener (SFSEvent.LOGIN, OnLogin);
             server.AddEventListener (SFSEvent.LOGIN_ERROR, OnLoginError);
             SetMessage ("Connecting..");
             if (Security.PrefetchSocketPolicy (serverName, serverPort, 200)) {
                     server.Connect (serverName, serverPort);
             } else {
                     SetError ("Failed to prefetch the webplayer socket security policy.");
             }
 }
Пример #36
0
    //----------------------------------------------------------
    // Called when program starts
    //----------------------------------------------------------
    void Start()
    {
        // In a webplayer (or editor in webplayer mode) we need to setup security policy negotiation with the server first
        if (Application.isWebPlayer) {
            if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500)) {
                Debug.LogError("Security Exception. Policy file load failed!");
            }
        }

        // Lets connect
        smartFox = new SmartFox(true);

        // Register callback delegate
        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.ROOM_JOIN, OnRoomJoin);
        smartFox.AddEventListener(SFSEvent.LOGOUT, OnLogout);

        smartFox.AddLogListener(logLevel, OnDebugMessage);

        smartFox.Connect(serverName, serverPort);
    }
Пример #37
0
    // Use this for initialization
    void Start()
    {
        PlayerPrefs.SetInt("playerNumber", 1);
        smartFox = new SmartFox(true);

        smartFox.AddLogListener(LogLevel.INFO, OnDebugMessage);

        username = "******";
        password = "******";
        AddEventListeners();
        smartFox.Connect(serverName, serverPort);
    }
Пример #38
0
 // Use this for initialization
 void Start()
 {
     _sfs = new SmartFox();
     _sfs.ThreadSafeMode = true;
     _sfs.AddEventListener(SFSEvent.CONNECTION , OnConnection);
     _sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
     _sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
     _sfs.AddEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, OnConfigLoad);
     _sfs.AddEventListener(SFSEvent.CONFIG_LOAD_FAILURE, OnConfigFail);
     _sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
     _sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError);
     _sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
     _sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnSumResponse);
     Security.PrefetchSocketPolicy(serverIp,serverPort);
     if(useConfigFile)
         _sfs.LoadConfig(Application.dataPath + "/" + configFile);
     else
         _sfs.Connect(serverIp,serverPort);
 }
Пример #39
0
	//----------------------------------------------------------
	// Public interface methods for UI
	//----------------------------------------------------------

	public void doConnectToServer() {
		if (sfs == null || !sfs.IsConnected) {
			
			// Initialize SFS2X client and add listeners
			// WebGL build uses a different constructor
			#if !UNITY_WEBGL
				sfs = new SmartFox();
				label = "Connecting via Standard Sockets";
			#else
				sfs = new SmartFox(UseWebSocket.WS);
				label = "Connecting via Websocket";
			#endif
			 
			// Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
			sfs.ThreadSafeMode = true;
			
			sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
			sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
			sfs.AddEventListener(SFSEvent.CRYPTO_INIT, OnCryptoInit);
			sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
			sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
			sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
			sfs.AddEventListener(SFSEvent.ROOM_JOIN,OnRoomJoined);
			sfs.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE,onRoomVariableUpdate);
			sfs.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE,onUserVariablesUpdate);
		/*	sfs.AddLogListener(LogLevel.DEBUG, OnDebugMessage);
			sfs.AddLogListener(LogLevel.INFO, OnInfoMessage);
			sfs.AddLogListener(LogLevel.WARN, OnWarnMessage);*/
			sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage);
			// Set connection parameters
			ConfigData cfg = new ConfigData();
			
			
			#if !UNITY_WEBGL
				cfg.Host = "64.91.226.4";
				cfg.Port = 9933;
			#endif
			#if UNITY_WEBGL
				cfg.Port = 8888;
				cfg.Host = "64.91.226.4";
			#endif
			cfg.Zone = "HA3D";
			cfg.Debug = false;
			
			// Connect to SFS2X

			// Debug.Log("Client Version: "+sfs.Version);
			sfs.Connect(cfg);
		} else {
			
			// DISCONNECT
			
			// Disable button
			
			// Disconnect from SFS2X
			sfs.Disconnect();
		}
	}
Пример #40
0
    // Update is called once per frame
    void Update()
    {
        if (StartConnection) {
            sfs = new SmartFox ();
            sfs.ThreadSafeMode = true;

            sfs.AddEventListener (SFSEvent.CONNECTION, OnConnection);
            sfs.AddEventListener (SFSEvent.LOGIN, OnLogin);
            sfs.AddEventListener (SFSEvent.LOGIN_ERROR, OnLoginError);
            sfs.AddEventListener (SFSEvent.ROOM_JOIN, OnJoinRoom);
            sfs.AddEventListener (SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError);
            sfs.AddEventListener (SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
            sfs.AddEventListener (SFSEvent.OBJECT_MESSAGE, OnObjectMessage);
            sfs.AddEventListener (SFSEvent.USER_VARIABLES_UPDATE, OnUserVariableUpdate);

            sfs.Connect (ServerIP, ServerPort);
            StartConnection = false;
            ConnectionRunning = true;
        }

        if(ConnectionRunning)
            sfs.ProcessEvents ();
    }
Пример #41
0
    private void connect()
    {
        Debug.Log("Going to connect!");
        _board.setInputAllowed(false);

        //Set connection parameters
        ConfigData cfg = new ConfigData();
        cfg.Host = host;
        #if !UNITY_WEBGL
            cfg.Port = tcpPort;
        #else
            cfg.Port = WSPort;
        #endif
        cfg.Zone = zone;

        //Initialize SFS2X client
        #if !UNITY_WEBGL
            _sfs = new SmartFox();
        #else
            _sfs = new SmartFox(UseWebSocket.WS);
        #endif

        //Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        _sfs.ThreadSafeMode = true;

        //Add listeners then connect
        addConnectionListeners();
        setWorkingAnimationActive(true);
        _sfs.Connect(cfg);
    }
Пример #42
0
    private void Start()
    {
        // Create the instance to the smarfox object
        _sfs = new SmartFox(true);

        _sfs.AddLogListener(logLevel, OnDebugMessage);

        _sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        _sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

        _sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        _sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        _sfs.AddEventListener(SFSEvent.LOGOUT, OnLogout);

        OnStart();

        // Connect to the server. It need to be running first !
        _sfs.Connect(serverIP, serverPort);
    }
Пример #43
0
    // Use this for initialization
    void Start()
    {
        LoginPanel = GameObject.Find("LoginBox");
        RegisterPanel = GameObject.Find("RegisterBox");
        RegisterPanel.SetActive(false);
        MessageText = GameObject.Find("MessageText");
        MessageText.SetActive(false);

        UsernameTB = GameObject.Find("UsernameTB").GetComponent<InputField>();
        PasswordTB = GameObject.Find("PasswordTB").GetComponent<InputField>();
        UsernameTB.Select();

        SFServer = new SmartFox();

        //Set our basic default connection parameters
        this.OurConfigData.Host = "biele.us";
        this.OurConfigData.Port = 9933;
        this.OurConfigData.Zone = GAME_ZONE;

        // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        SFServer.ThreadSafeMode = true;

        SFServer.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        SFServer.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        SFServer.AddEventListener(SFSEvent.LOGIN, OnLogin);
        SFServer.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        SFServer.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

        SFServer.Connect(this.OurConfigData);
    }