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); }
//---------------------------------------------------------- // 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); }
//---------------------------------------------------------- // Called when program starts //---------------------------------------------------------- void Start() { smartFox = new SmartFox(); smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection); smartFox.AddLogListener(LogLevel.DEBUG, OnDebugMessage); smartFox.Connect(ip, port); }
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); }
//---------------------------------------------------------- // 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); }
//---------------------------------------------------------- // 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); }
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(); } }
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); }
//---------------------------------------------------------- // 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); }
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); }
//---------------------------------------------------------- // 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); }
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..."); }
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); }
//---------------------------------------------------------- // 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); } }
// 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); }
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); } }
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); } }
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); } }
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"); }
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"); } }
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"); } }
// 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); } }
// 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(); } }
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); } }
// 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); }
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); }
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); }
//---------------------------------------------------------- // 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
// 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); } }
//---------------------------------------------------------- // 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); }
// 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); }
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); }
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."); } }
//---------------------------------------------------------- // 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); }
// 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); }
// 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); }
//---------------------------------------------------------- // 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(); } }
// 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 (); }
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); }
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); }
// 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); }