- Home /
error keeps looping (smartfox connection) even after I stop testing my game
I'm having some major issues with my custom login script with smartfox telling me over and over that the password I'm sending it from Unity is incorrect, even though I know it is correct.. I know this because every once in a while it will take the password, but just once.
Right now, when I hit 'Play' in Unity and run my game, it connects to Smartfox and then attempts to login for me, which again works once but then never again. The odd thing I've noticed, which has me wondering if it's the cause of this problem, is that when I run the program after having stopped the smart fox server, it obviously doesn't connect.. but then when I click the 'Play' button again to stop Unity, my console continues to fill with the error messages telling me it cannot connect, even tho the program is stopped!
I can't imagine that this is supposed to happen, but then again I'm pretty new when it comes to Unity and SmartFox talking together... I'm honestly getting to the point where I am going to give up because I've spent way too much time on this and I simply (as a programmer with 10+ years experience) cannot stand unity telling me repeatedly that my password is incorrect when I know otherwise. I've checked all logs and there's no other information.. I've even traced the data that is being pulled from smartfox to ensure it's the correct record set.. and it is.
None of this makes sense to me, and not because I'm a n00b, I mean it doesn't make any sense programmatically. I've never experienced a system that allows me to login once, then if I click stop and play again immediately tells me that my password is now incorrect. I've checked my SFS admin to ensure that the user is not logged in anymore when I stop the program as well.
Perhaps I'm missing something completely amateur here, but this is all built from the Lobby example that comes with Smartfox and their tutorials... but I am leaning towards this is a Unity issue, not a SF one. I can post any requested code at any point if that helps anyone with assisting me, I just didn't want to dump a bunch of unnecessary code at this juncture, since I have no idea where the issue is.
Answer by geekedatbirth · Nov 06, 2011 at 07:52 PM
No, that's not found in my script at all, but that is definitely something I didn't even know about.. could be useful in the future. Here is my complete LobbyGUI script, modified from the one provided with SmartFox2X. There is a few lines that enable other scripts after a connection is made, but you'll see that my password variable is private, so they aren't affecting it at all.
using UnityEngine;
using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security.Permissions; using System.Text; using Sfs2X; using Sfs2X.Core; using Sfs2X.Entities; using Sfs2X.Requests; using Sfs2X.Logging;
public class LobbyGUI : MonoBehaviour { public string domain = "www.mydomain.com"; //this local address is set to my remote server in the project inspector public string serverName = "127.0.0.1"; public int serverPort = 9933;
public SmartFox smartFox;
private string zone = "myZone";
private string username = "geekedatbirth";
private string password = "ABC123";
string myUrl = "";
[HideInInspector] public string defaultRoom = "Lobby";
private string loginErrorMessage = "";
public bool isLoggingIn;
public bool isLoggedIn;
private bool isJoining = false;
private string newMessage = "";
public ArrayList messages = new ArrayList();
// Locker to use for messages collection to ensure its cross-thread safety
public System.Object messagesLocker = new System.Object();
private Vector2 chatScrollPosition, userScrollPosition;
private int roomSelection = 0;
public string [] roomStrings;
public GUISkin gSkin;
public Room currentActiveRoom;
public int user_id = 1;
public void sendChatMessage(string msg) {
smartFox.Send( new PublicMessageRequest(msg) );
}
void OnGUI() {
if (smartFox == null) return;
if (!smartFox.IsConnected) {
// if not connected, show connecting information...
//GUI.Label(new Rect(10, 90, 100, 100), "Connecting...");
}
// Login
else if (!isLoggedIn && !isLoggingIn) {
//here, I print the username and password so I can compare them to the username and password in the database... they both match exactly, to the point that I have copied the text directly from the database and used that... till keeps telling me my password is incorrect
print("sending login request - user = '"+username+"' & pass = '"+password+"'");
isLoggingIn = true;
smartFox.Send(new LoginRequest(username, password, zone));
}
//temporary labels to show some variables
GUI.Label(new Rect(40, 50, 200, 30), "pass = "+password);
GUI.Label(new Rect(40, 100, 400, 30), "url = "+myUrl);
GUI.Label(new Rect(40, 150, 200, 30), "id = "+user_id);
GUI.Label(new Rect(40, 200, 400, 30), "name = "+username);
}
public void joinChatRoom() {
//smartFox.Send(new JoinRoomRequest("7 Sins", "", -1, false));
}
void Start()
{
Security.PrefetchSocketPolicy(serverName, serverPort);
//the myUrl here is to create a 'fake' Application.srcValue when not running in a browser... my browser code passes a srcValue just like the one listed below when run in a browser
myUrl = ("WebPlayer.unity3d?id=2&key=ABC123");
if(Application.isWebPlayer || Application.isEditor) {
if(Application.isWebPlayer) {
myUrl = Application.srcValue;
}
}
// my code to split the srcValue string and pull out the values for id and key
string [] split = myUrl.Split(new Char [] {'='});
string [] id = split[1].Split(new Char [] {'&'});
user_id = System.Convert.ToInt32(id[0]);
// this was to set the password to the value pulled from the srcValue string, but I thought that it may not be working correctly, so I commented it out, which leaves the password to the same value as when I first created the variable
//password = split[2].ToString();
bool debug = true;
if (SmartFoxConnection.IsInitialized)
{
smartFox = SmartFoxConnection.Connection;
}
else
{
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.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);
Debug.Log(Application.platform.ToString());
}
void FixedUpdate() {
smartFox.ProcessEvents();
}
void OnApplicationQuit() {
Debug.Log("Quitting");
if (smartFox != null && smartFox.IsConnected)
{
smartFox.RemoveAllEventListeners();
smartFox.Disconnect();
}
}
private void UnregisterSFSSceneCallbacks() {
// This should be called when switching scenes, so callbacks from the backend do not trigger code in this scene
smartFox.RemoveAllEventListeners();
}
public void OnConnection(BaseEvent evt) {
bool success = (bool)evt.Params["success"];
string error = (string)evt.Params["errorMessage"];
Debug.Log("On Connection callback got: " + success + " (error : <" + error + ">)");
if (success) {
SmartFoxConnection.Connection = smartFox;
GetComponent<ChatGUI>().enabled = true;
GetComponent<PmGUI>().enabled = true;
GetComponent<ListGUI>().enabled = true;
}
}
public void OnConnectionLost(BaseEvent evt) {
Debug.Log("OnConnectionLost");
isLoggedIn = false;
isJoining = false;
currentActiveRoom = null;
UnregisterSFSSceneCallbacks();
}
// Various SFS callbacks
public void OnLogin(BaseEvent evt) {
try {
bool success = true;
if (evt.Params.ContainsKey("success") && !(bool)evt.Params["success"]) {
loginErrorMessage = (string)evt.Params["errorMessage"];
Debug.Log("Login error: "+loginErrorMessage);
}
else {
isLoggedIn = true;
Debug.Log("Logged in successfully");
ReadRoomListAndJoin();
}
}
catch (Exception ex) {
Debug.Log("Exception handling login request: "+ex.Message+" "+ex.StackTrace);
}
}
public void OnLoginError(BaseEvent evt) {
Debug.Log("Login error: "+(string)evt.Params["errorMessage"]);
}
void OnLogout(BaseEvent evt) {
Debug.Log("OnLogout");
isLoggedIn = false;
isJoining = false;
currentActiveRoom = null;
}
public void OnDebugMessage(BaseEvent evt) {
string message = (string)evt.Params["message"];
Debug.Log("[SFS DEBUG] " + message);
}
private void ReadRoomListAndJoin() {
Debug.Log("Room list: ");
List<Room> roomList = smartFox.RoomManager.GetRoomList();
List<string> roomNames = new List<string>();
foreach (Room room in roomList) {
if (room.IsHidden || room.IsPasswordProtected) {
continue;
}
roomNames.Add(room.Name);
Debug.Log("Room id: " + room.Id + " has name: " + room.Name);
}
roomStrings = roomNames.ToArray();
if (smartFox.LastJoinedRoom==null) {
GetComponent<ChatGUI>().roomsListed = true;
}
}
public void JoinRoom(string roomName) {
if (isJoining) return;
isJoining = true;
currentActiveRoom = null;
Debug.Log("Joining room: "+roomName);
//hide the room list
GetComponent<ChatGUI>().showHideRoomList();
// Need to leave current room, if we are joined one
if (smartFox.LastJoinedRoom==null)
smartFox.Send(new JoinRoomRequest(roomName));
else
smartFox.Send(new JoinRoomRequest(roomName, "", smartFox.LastJoinedRoom.Id));
}
void OnJoinRoom(BaseEvent evt) {
Room room = (Room)evt.Params["room"];
Debug.Log("Room " + room.Name + " joined successfully");
lock (messagesLocker) {
messages.Clear();
}
currentActiveRoom = room;
isJoining = false;
}
void OnPublicMessage(BaseEvent evt) {
try {
string message = (string)evt.Params["message"];
User sender = (User)evt.Params["sender"];
// We use lock here to ensure cross-thread safety on the messages collection
lock (messagesLocker) {
messages.Add(sender.Name + " said " + message);
}
chatScrollPosition.y = Mathf.Infinity;
Debug.Log("User " + sender.Name + " said: " + message);
}
catch (Exception ex) {
Debug.Log("Exception handling public message: "+ex.Message+ex.StackTrace);
}
}
// Finally draw all the lobby GUI
}
Luckily I was momentarily smart enough to backup all my source files when I had this working with the tutorials database (structure is quite a bit different than mine) but I never tested repeatedly like I did with this code.. it worked once and then I moved on. I think that unless someone has an idea as to why this is happening then I will revert back to that backup, which I hate to do because it means about 6 hours of frustration last night was for nothing.
It's annoying the script doesn't work, but as a program it is very worrisome to see Unity continue in what seems like a never-ending loop to connect to the SmartFox Server when I have the server shut off AND I stop the editor from playing. A few times while working on this Unity has crashed and the only error I got before the crash was "Too many threads", which leads me to believe that somehow the connection is always staying open even when I click the play button again to stop Unity. I definitely do not want that.
Just more bad news.. I reverted back to my backup and the same thing is happening... unity connects to the server every once in a great while, but most times returns the message 'wrong password', but I haven't changed the password...
I can't even begin to explain how frustrating this is. $$anonymous$$y entire project is on hold because I'm being told my password is incorrect when I know otherwise. Works great on my local server, works great on remote server without custom login, but as soon as I switch over to a custom login on the remote server I hit a wall.
Password string being sent by Unity (printed just before the login to SF is called) = "abc123"
Password being traced on SF server from the record it pulls for my database = "abc123"
And yet I get a wrong password error?
Your answer
Follow this Question
Related Questions
why can I not log in using my email and password? 2 Answers
A node in a childnode? 1 Answer
Unity3d + SmartFox dll + Windows 8 Store Build produces errors 0 Answers
Facebook Unity SDK login permission request pop up for authorized user 0 Answers
Post login script works but Unity doesn't knows it 2 Answers