internal void AddListeners(SmartFox smartFox) { smartFox.AddEventListener(SFSEvent.SOCKET_ERROR, onSocketError); smartFox.AddEventListener(SFSEvent.CONNECTION, onConnection); smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost); smartFox.AddEventListener(SFSEvent.CRYPTO_INIT, onCryptoInit); smartFox.AddEventListener(SFSEvent.CONNECTION_RETRY, onConnectionRetry); smartFox.AddEventListener(SFSEvent.CONNECTION_RESUME, onConnectionResume); smartFox.AddEventListener(SFSEvent.LOGIN, onLogin); smartFox.AddEventListener(SFSEvent.UDP_INIT, onUdpInit); smartFox.AddEventListener(SFSEvent.LOGIN_ERROR, onLoginError); smartFox.AddEventListener(SFSEvent.LOGOUT, onLogout); smartFox.AddEventListener(SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError); smartFox.AddEventListener(SFSEvent.ROOM_JOIN, onRoomJoin); smartFox.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError); smartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, onExtensionResponse); smartFox.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, onUserVariableUpdate); smartFox.AddEventListener(SFSEvent.PROXIMITY_LIST_UPDATE, onProximityListUpdate); smartFox.AddEventListener(SFSEvent.MMOITEM_VARIABLES_UPDATE, onServerObjectUpdate); smartFox.AddEventListener(SFSEvent.PING_PONG, onPingPong); if (smartFox.Debug) { smartFox.AddLogListener(LogLevel.DEBUG, onDebugMessage); smartFox.AddLogListener(LogLevel.INFO, onInfoMessage); smartFox.AddLogListener(LogLevel.WARN, onWarnMessage); smartFox.AddLogListener(LogLevel.ERROR, onErrorMessage); } }
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); } }
//---------------------------------------------------------- // 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(); } }
//---------------------------------------------------------- // Called when program starts //---------------------------------------------------------- void Start() { smartFox = new SmartFox(); smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection); smartFox.AddLogListener(LogLevel.DEBUG, OnDebugMessage); smartFox.Connect(ip, port); }
//---------------------------------------------------------- // 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 InitSmartfox() { if (Application.isWebPlayer || Application.isEditor) { bool flag = Security.PrefetchSocketPolicy(serverName, serverPort); Logger.trace("[NetworkManager::InitSmartfox] securityPolicyPassed: " + flag); } if (SmartFoxConnection.IsInitialized) { Debug.Log("<< is initialized"); smartFox = SmartFoxConnection.Connection; } else { bool debug = true; Debug.Log("<< initializing smartfox"); smartFox = new SmartFox(debug); } GameObject x = GameObject.Find("Game"); if (x != null) { } smartFox.AddLogListener(LogLevel.INFO, OnDebugMessage); m_state = null; }
/// <summary> /// Método que recria a instância do SmartFox. É necessário ser chamado sempre que o cliente perde a conexão com o servidor. Em modo de /// debug essa instância também redireciona as mensagens do log para o console da Unity. /// </summary> /// <returns>A instância do SmartFox.</returns> public SmartFox Reset() { if (sfs != null) sfs.RemoveAllEventListeners(); #if DEBUG sfs = new SmartFox(true); sfs.Logger.LoggingLevel = LogLevel.INFO; sfs.AddLogListener(LogLevel.INFO, OnInfoMessage); sfs.AddLogListener(LogLevel.WARN, OnWarnMessage); sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage); #else sfs = new SmartFox(false); #endif return sfs; }
private SFSClient( ) { SFSInstance = new SmartFox ( debug ); Application.runInBackground = true; RegisterCallbacks (); SFSInstance.AddLogListener ( logLevel, OnDebugMessage ); }
public static void Connect(string uname) { if (sfs == null || !sfs.IsConnected) { username = uname; // CONNECT Debug.Log("Now connecting..."); // Add listeners 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.AddLogListener(LogLevel.INFO, OnInfoMessage); sfs.AddLogListener(LogLevel.WARN, OnWarnMessage); sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage); //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); // Set connection parameters ConfigData cfg = new ConfigData(); cfg.Host = defaultHost; cfg.Port = Convert.ToInt32(defaultTcpPort.ToString()); cfg.Zone = zone; //cfg.Debug = true; // Connect to SFS2X sfs.Connect(cfg); } else { // Disconnect from SFS2X sfs.Disconnect(); trace("Disconnected"); } }
/// <summary> /// Método que recria a instância do SmartFox. É necessário ser chamado sempre que o cliente perde a conexão com o servidor. Em modo de /// debug essa instância também redireciona as mensagens do log para o console da Unity. /// </summary> /// <returns>A instância do SmartFox.</returns> public SmartFox Reset() { if (sfs != null) { sfs.RemoveAllEventListeners(); } #if DEBUG sfs = new SmartFox(true); sfs.Logger.LoggingLevel = LogLevel.INFO; sfs.AddLogListener(LogLevel.INFO, OnInfoMessage); sfs.AddLogListener(LogLevel.WARN, OnWarnMessage); sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage); #else sfs = new SmartFox(false); #endif return(sfs); }
void AddSfsListeners() { 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.USER_ENTER_ROOM, OnUserEnterRoom); sfs.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom); sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage); sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); sfs.AddLogListener(LogLevel.INFO, OnInfoMessage); sfs.AddLogListener(LogLevel.WARN, OnWarnMessage); sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage); print("added event listeners"); }
public void RegistSmartFoxEvents() { //Connect smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection); smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); //System Message smartFox.AddLogListener(LogLevel.INFO, OnInfoMessage); smartFox.AddLogListener(LogLevel.WARN, OnWarnMessage); smartFox.AddLogListener(LogLevel.ERROR, OnErrorMessage); //Lobby smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin); smartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError); smartFox.AddEventListener(SFSEvent.ROOM_ADD, OnRoomAdd); smartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin); smartFox.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError); smartFox.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVariablesUpate); smartFox.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage); smartFox.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom); smartFox.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom); smartFox.AddEventListener(SFSEvent.USER_COUNT_CHANGE, OnUserCountChange); smartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); }
void Start() { if (sfs == null || !sfs.IsConnected) { Debug.Log("Client Connecting..."); sfs = new SmartFox(); 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.PING_PONG, OnPingPong); sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom); sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError); sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage); sfs.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVariableUpdated); 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(); cfg.Host = defaultHost; cfg.Port = Convert.ToInt32(defaultTcpPort); cfg.HttpPort = httpPort; cfg.HttpsPort = httpsPort; cfg.Zone = "BasicExamples"; cfg.Debug = debugMode; // Connect to SFS2X sfs.Connect(cfg); } }
public void InitSmarfoxServer() { UnityEngine.Debug.Log("Initializing the SmartFox"); sfs = new SmartFox(true); UnityEngine.Debug.Log("Adding events"); sfs.AddEventListener(SFSEvent.CONNECTION, OnSmarfoxConnection); sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnSmarfoxConnectionLost); sfs.AddEventListener(SFSEvent.LOGIN, OnLogin); sfs.AddEventListener(SFSEvent.LOGIN, OnLogout); sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError); sfs.AddLogListener(logLevel, OnDebugLogMessage); }
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 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 ConnectToSmartFox(string n, string r, string l = "") { if (smartFox != null && (smartFox.IsConnecting || smartFox.IsConnected)) { return; } #if UNITY_WEBPLAYER Debug.LogError("WebPlayer setup: " + serverName + ":" + serverPort); if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500)) { Debug.LogError("Security Exception. Policy file load failed!"); } #endif username = n; roomNumToLoad = int.Parse(r); LevelToLoad = ConsoleInterpreter.GetLevel((l != "") ? l : defaultLevel); //string[] cmdLnArgs = System.Environment.GetCommandLineArgs(); //BotManager.Inst.SetBotOptions(cmdLnArgs); // Register SFS callbacks smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection); smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); smartFox.AddEventListener(SFSEvent.CONNECTION_RETRY, OnConnectionRetry); smartFox.AddEventListener(SFSEvent.CONNECTION_ATTEMPT_HTTP, OnConnectionAttemptHttp); smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin); smartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError); smartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin); smartFox.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError); smartFox.AddEventListener(SFSEvent.ROOM_CREATION_ERROR, OnRoomCreationError); smartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); // Data messages AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, DataMessageManager.Inst.OnRoomVariablesUpdate); AddEventListener(SFSEvent.PUBLIC_MESSAGE, DataMessageManager.Inst.OnPublicMessage); AddEventListener(SFSEvent.PRIVATE_MESSAGE, DataMessageManager.Inst.OnPrivateMessage); AddEventListener(SFSEvent.OBJECT_MESSAGE, DataMessageManager.Inst.OnObjectMessage); AddEventListener(SFSEvent.ADMIN_MESSAGE, DataMessageManager.Inst.OnAdminMessage); AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, DataMessageManager.Inst.OnUserVariableUpdate); AddEventListener(SFSEvent.USER_ENTER_ROOM, DataMessageManager.Inst.OnUserEnterRoom); AddEventListener(SFSEvent.USER_EXIT_ROOM, DataMessageManager.Inst.OnUserExitRoom); // Callbacks for buddy events smartFox.AddEventListener(SFSBuddyEvent.BUDDY_LIST_INIT, OnBuddyListInit); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_ERROR, OnBuddyError); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_ONLINE_STATE_UPDATE, OnBuddyListUpdate); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, OnBuddyListUpdate); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_ADD, OnBuddyAdded); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_REMOVE, OnBuddyRemoved); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_BLOCK, OnBuddyBlocked); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_MESSAGE, OnBuddyMessage); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, OnBuddyVarsUpdate); Debug.LogError("Connecting to " + serverName + ":" + serverPort); smartFox.AddLogListener(logLevel, OnDebugMessage); smartFox.Connect(serverName, serverPort); serverConnectionStatusMessage = "Establishing Connection"; DontDestroyOnLoad(this); // keep persistent when loading new levels }
void Start() { Debug.Log("start game lobby"); smartFox = SmartFoxConnection.Connection; currentActiveRoom = smartFox.LastJoinedRoom; smartFox.AddLogListener(LogLevel.INFO, OnDebugMessage); screenW = Screen.width; AddEventListeners(); username = smartFox.MySelf.Name; lobbyGameInfo = (SFSObject)currentActiveRoom.GetVariable("gameInfo").GetSFSObjectValue(); maxPlayers = currentActiveRoom.MaxUsers; host = lobbyGameInfo.GetUtfString("host"); numberOfTeams = lobbyGameInfo.GetInt("numTeams"); Debug.Log("start number of teams: " + numberOfTeams); if (GameValues.isHost) currentTeams = new int[8]; teams = (SFSArray)lobbyGameInfo.GetSFSArray("teams"); playerPerTeam = numberOfPlayers / numberOfTeams; gameLength = (int)lobbyGameInfo.GetInt("gameLength"); //Make Contents for the popup gameLength list gameLengthList[0] = (new GUIContent("60")); gameLengthList[1] = (new GUIContent("120")); gameLengthList[2] = (new GUIContent("300")); gameLengthList[3] = (new GUIContent("600")); //Make Contents for the popup number of teams list teamNumberList[0] = (new GUIContent("2")); teamNumberList[1] = (new GUIContent("3")); teamNumberList[2] = (new GUIContent("4")); teamNumberList[3] = (new GUIContent("5")); teamNumberList[4] = (new GUIContent("6")); teamNumberList[5] = (new GUIContent("7")); teamNumberList[6] = (new GUIContent("8")); //Set team scroll positions to zero for(int i = 0; i < 8; i++) { teamScrollPositions.Add(Vector2.zero); } //Make a gui style for the lists listStyle.normal.textColor = Color.white; Texture2D tex = new Texture2D(2, 2); Color[] colors = new Color[4]; for (int i = 0; i < 4; i++) { colors[i] = Color.white; } tex.SetPixels(colors); tex.Apply(); listStyle.hover.background = tex; listStyle.onHover.background = tex; listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4; if (GameValues.isHost) { currentIDs.AddInt(0); GameValues.playerID = 0; GameValues.teamNum = 0; currentTeams[0]++; List<UserVariable> uData = new List<UserVariable>(); uData.Add(new SFSUserVariable("playerID", GameValues.playerID)); uData.Add(new SFSUserVariable("playerTeam", GameValues.teamNum)); smartFox.Send(new SetUserVariablesRequest(uData)); SFSObject gameInfo = (SFSObject)currentActiveRoom.GetVariable("gameInfo").GetSFSObjectValue(); //send back to store on server List<RoomVariable> rData = new List<RoomVariable>(); gameInfo.PutSFSArray("playerIDs", currentIDs); rData.Add(new SFSRoomVariable("gameInfo", gameInfo)); smartFox.Send(new SetRoomVariablesRequest(rData)); } if (currentActiveRoom.ContainsVariable("lastGameScores")) { Debug.Log("scores from last game are present, adding to the message window..."); //write out the last games scores to the chat window //format: //scores: int array //winner: string SFSObject lastGameData = (SFSObject)currentActiveRoom.GetVariable("lastGameScores").GetSFSObjectValue(); int[] scoresArray = lastGameData.GetIntArray("scores"); string[] teamColors = lastGameData.GetUtfStringArray("teamColors"); messages.Add("Previous Game's Scores"); messages.Add("The Winner is... " + lastGameData.GetUtfString("winner").ToString()); for (int i = 0; i < scoresArray.Length; i++) { string teamName = teamColors[i] + " Team"; messages.Add(teamName + "\tscored " + scoresArray[i].ToString() + " points."); } } tryJoiningRoom = false; }
// 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); }
//---------------------------------------------------------- // 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(useEncryption ? UseWebSocket.WSS_BIN : UseWebSocket.WS_BIN); #endif 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.PING_PONG, OnPingPong); sfs.AddEventListener(SFSEvent.CONNECTION_RETRY, OnConnectionRetry); sfs.AddEventListener(SFSEvent.CONNECTION_RESUME, OnConnectionResume); 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(); cfg.Host = hostInput.text; cfg.Port = Convert.ToInt32(portInput.text); cfg.HttpPort = httpPort; cfg.HttpsPort = httpsPort; cfg.Zone = "BasicExamples"; cfg.Debug = debugToggle.isOn; cfg.BlueBox.IsActive = true; cfg.BlueBox.UseHttps = false; // Connect to SFS2X sfs.Connect(cfg); } else { // DISCONNECT // Disable button button.interactable = false; // Disconnect from SFS2X sfs.Disconnect(); } }
void Start() { smartFox = SmartFoxConnection.Connection; currentActiveRoom = smartFox.LastJoinedRoom; if (!currentActiveRoom.IsGame) { DontDestroyOnLoad(gameObject); } else { Debug.Log("whoops :()"); Destroy(gameObject); } smartFox.AddLogListener(LogLevel.INFO, OnDebugMessage); screenW = Screen.width; AddEventListeners(); }
void Start() { #if !UNITY_WEBGL port = defaultTcpPort.ToString(); #else port = defaultWsPort.ToString(); #endif 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(defaultHost, Convert.ToInt32(port), 500)) { Debug.LogError("Security Exception. Policy file loading failed!"); } #endif // Enable interface // 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; 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); } else { sfs.Disconnect(); } }
void Start() { if (sfs == null || !sfs.IsConnected) { Debug.Log("Teacher connecting..."); sfs = new SmartFox(); 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.PING_PONG, OnPingPong); sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom); sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError); sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage); sfs.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVariableUpdated); 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(); cfg.Host = defaultHost; cfg.Port = Convert.ToInt32(defaultTcpPort); cfg.HttpPort = httpPort; cfg.HttpsPort = httpsPort; cfg.Zone = "BasicExamples"; cfg.Debug = debugMode; TextAsset textAsset = (TextAsset)Resources.Load("community_challenge"); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(textAsset.text); //Read XmlNode root = xmldoc.LastChild.FirstChild; Debug.Log("name is" + root.Name); foreach (XmlNode node in root.ChildNodes) { Debug.Log("Children: " + node.ChildNodes); //Debug.Log("Outisde if"+node.FirstChild.NodeType); if (node.Name.CompareTo("question") == 0) { int id = 1; foreach (XmlNode node1 in node.ChildNodes) { //Debug.Log("answer count+ "+node1.ChildNodes.Count); var newquestion = new Question(); newquestion.value = node1.Attributes["value"].Value; newquestion.answers = new List <string>(); newquestion.id = id; id++; foreach (XmlNode node2 in node1.ChildNodes) { newquestion.answers.Add(node2.Attributes["type"].Value); } if (questionsContent != null && questionMold != null) { var newQuestionButton = Instantiate(questionMold, questionsContent); var buttonScript = newQuestionButton.GetComponent <Button>(); var buttonText = buttonScript.transform.GetComponentInChildren <Text>(); if (buttonText != null) { buttonText.text = newquestion.value; } buttonScript.gameObject.SetActive(true); buttonScript.name = newquestion.id.ToString(); buttonScript.onClick.AddListener(delegate { SelectQuestion(newquestion.id); }); } _questions.Add(newquestion); } } } sfs.Connect(cfg); } }
public void Init() { SFInstance = new SmartFox(); SFInstance.ThreadSafeMode = true; SFInstance.AddEventListener(SFSEvent.CONNECTION, OnConnection); SFInstance.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); SFInstance.AddEventListener(SFSEvent.LOGIN, OnLoginToSF); SFInstance.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginToSFError); SFInstance.AddEventListener(SFSEvent.ROOM_JOIN, OnSFRoomJoin); SFInstance.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnSFRoomJoinError); SFInstance.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnSFRoomLeave); SFInstance.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnSFExtensionResponse); SFInstance.AddLogListener(LogLevel.INFO, OnLogMessageInfo); SFInstance.AddLogListener(LogLevel.WARN, OnLogMessageWarn); SFInstance.AddLogListener(LogLevel.ERROR, OnLogMessageError); DoConnect(); }
//---------------------------------------------------------- // Unity callbacks //---------------------------------------------------------- void Start() { if (!SmartFoxConnection.IsInitialized) { Application.LoadLevel("Connection"); return; } smartFox = SmartFoxConnection.Connection; // Register callback delegates smartFox.AddEventListener(SFSEvent.OBJECT_MESSAGE, OnObjectMessage); smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); smartFox.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, OnUserVariableUpdate); smartFox.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom); smartFox.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom); smartFox.AddLogListener(logLevel, OnDebugMessage); // Start this clients avatar and get cracking! int numModel = UnityEngine.Random.Range(0, playerModels.Length); int numMaterial = UnityEngine.Random.Range(0, playerMaterials.Length); SpawnLocalPlayer(numModel, numMaterial); }
//---------------------------------------------------------- // 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(); } }
//---------------------------------------------------------- // Public interface methods for UI //---------------------------------------------------------- public void OnButtonClick() { if (sfs == null || !sfs.IsConnected) { // CONNECT #if UNITY_WEBPLAYER if (!useEncryption) { // 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 // 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(useEncryption ? UseWebSocket.WSS_BIN : 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.AddEventListener(SFSEvent.CRYPTO_INIT, OnCryptoInit); sfs.AddEventListener(SFSEvent.LOGIN, OnLogin); sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError); sfs.AddEventListener(SFSEvent.PING_PONG, OnPingPong); sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom); sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError); sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage); sfs.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVariableUpdated); 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(); cfg.Host = hostInput.text; cfg.Port = Convert.ToInt32(portInput.text); cfg.HttpPort = httpPort; cfg.HttpsPort = httpsPort; 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(); } }
//---------------------------------------------------------- // 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); }