HELP! uCount, AutoJoin, questions everywhere!

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

HELP! uCount, AutoJoin, questions everywhere!

Postby Fishypants » 03 Mar 2011, 10:36

Ok, so I have uCount update set to true for a zone. Is it normal behavior if I were to log in, lot out, log in, and log out again for the uCount to constantly be increasing? I am signing into a zone, with no name or password and letting the server generate one for me ("guest_#"), and the number keeps going up and up and up. This seems wrong . . . Would anyone know what causes that? Or is it normal behavior for it to not reset and always increase?

Next is the AutoJoin feature in the server config. If I setup a zone, and have a room set to AutoJoin (no custom login), I would like to sign into that zone and have the client autoJoin the room set as "autojoin". This seems to be the way it should happen, but mine does not do this. I have to tell the client to .AutoJoin(), which to me, kinda defeats the purpose of having an autojoin. If I have to manually tell it to AutoJoin, then with the same amount of effort I could just say Join("level"). Either I'm doing something wrong or it doesn't work the way I am expecting it to.

I'm using Unity by the way, and I updated my server to version 1.6.9 . . . I know I should most likely post my code, but I was more curious if anyone has run into this and knows a quick solution, if not ill post both the client and server config. Thanks!
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 03 Mar 2011, 13:48

userCount: seem you are doing something wrong on the client side. If you check the messages received from the server (turning on the client-side debug) you should see the event data and read the number you receive, which the real one. In your interface you are probably keeping adding.

autojoin: that is the expected behavior.
Paolo Bax
The SmartFoxServer Team
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 03 Mar 2011, 21:01

Hey Bax, could you elaborate a bit on 'keep adding'? Is there something I should be doing to make sure the user leaves the room?

One thing I am wondering, instead of logging out, I am just quitting the application. On applicationQuit I am unregistering all the smartfox delegates and doing a smartFox.Disconnect(). Is this the correct method of terminating a connection to the server?

Also here is my client side code:

Code: Select all

using UnityEngine;
using System;
using System.Collections;

using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;

// Displays the login screen
public class Login : MonoBehaviour {
   // SmartFox Variables
   private SmartFoxClient smartFox;
   private string status = "none";

   // GUI Variables
   private bool fadeIn = true;
   private bool fadeOut = false;
   private float guiOpacity = 0.0f;

   // Login Variables
   private bool emailFocus = true;
   private string loginEmail = "";
   private string loginPass = "";

   private void Awake(){
      // Check that we have a connection
      smartFox = SmartFox.Connection;
      if(smartFox == null){
         // If not, go to connecting screen
         Application.LoadLevel("Connecting");
         return;
      }
      else{
         SubscribeEvents();
      }

      // Set GUI to be disabled at start
      GUI.enabled = false;
   }

   private void FixedUpdate(){
      // Manually process the event queue (for thread safety)
      smartFox.ProcessEventQueue();
   }

   private void Update(){
      // If we want to fade out
      if(fadeIn){
         guiOpacity += Time.deltaTime * 2;

         // If we have faded out
         if(guiOpacity >= 1){
            fadeIn = false;

            // Enable the GUI
            GUI.enabled = true;
         }
      }

      // If user presses Enter, attempt to log them in
      if(Input.GetKeyDown(KeyCode.Return)){
         LogUserIn();
      }
   }

   private void OnGUI(){
      // Set GUI Opacity
      GUI.color = new Color(1, 1, 1, guiOpacity);

      DrawLoginGui();
   }


   private void DrawLoginGui(){
      GUI.Box(new Rect(Screen.width / 2 - 150,Screen.height - 220,300,210), "Log In");
      GUI.Label (new Rect(Screen.width / 2 - 100, Screen.height - 190, 200, 20), "Email Address:");

      // Set a focus control point
      GUI.SetNextControlName ("emailFocus");
      loginEmail = GUI.TextField (new Rect(Screen.width / 2 - 100, Screen.height - 170, 200, 20), loginEmail, 40);

      GUI.Label (new Rect (Screen.width / 2 - 100, Screen.height - 150, 200, 20), "Password:");
      loginPass = GUI.PasswordField(new Rect(Screen.width / 2 - 100, Screen.height - 130, 200, 20), loginPass, "*"[0], 12);

      if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height - 100, 200, 25), "Login")){
         LogUserIn();
      }

      if(GUI.Button(new Rect (Screen.width / 2 - 100, Screen.height - 50, 200, 25), "Create New Account")){
         CreateNewAccount();
      }

      //  Set focus to login email, only once on load so we can tab between email and password
      if(emailFocus){
         GUI.FocusControl ("emailFocus");
         emailFocus = false;
      }
   }

   private void LogUserIn(){
      Debug.Log("ATTEMPTING TO LOG USER IN ... ");
      status = "log in";
      smartFox.Login("Game", loginEmail, loginPass);
   }

   private void CreateNewAccount(){
      Debug.Log("ATTEMPTING TO CREATE NEW ACCOUNT ... ");
      status = "create account";
      smartFox.Login("Guests", "", "");
   }

   private void SubscribeEvents(){
      SFSEvent.onConnectionLost += OnConnectionLost;
      SFSEvent.onLogin += OnLogin;
      SFSEvent.onLogout += OnLogout;
      SFSEvent.onRoomListUpdate += OnRoomList;
      SFSEvent.onJoinRoom += OnJoinRoom;
      SFSEvent.onExtensionResponse += OnExtensionResponse;
      SFSEvent.onDebugMessage += OnDebugMessage;
    }

   private void UnsubscribeEvents(){
      SFSEvent.onConnectionLost -= OnConnectionLost;
      SFSEvent.onLogin -= OnLogin;
      SFSEvent.onLogout -= OnLogout;
      SFSEvent.onRoomListUpdate -= OnRoomList;
      SFSEvent.onJoinRoom -= OnJoinRoom;
      SFSEvent.onExtensionResponse -= OnExtensionResponse;
      SFSEvent.onDebugMessage -= OnDebugMessage;
   }

   private void OnConnectionLost(){
      UnsubscribeEvents();
      Application.LoadLevel("Connecting");
   }

   private void OnLogin(bool success, string name, string error){
      if(success){
         Debug.Log("USER LOGGED IN");
         // When using a custom login, you have to update the room list manually.
         if(status == "log in") smartFox.GetRoomList();
      }
      else{
      }
   }

   private void OnLogout(){
      Debug.Log("Logged out successfully");
   }

   private void OnRoomList(Hashtable roomList){
      Debug.Log("Room List Recieved, status is: " + status);

      if(status == "log in"){
         smartFox.JoinRoom("Login");
      }
      if(status == "create account"){
         smartFox.AutoJoin();
      }
   }

   private void OnJoinRoom(Room room){
      Debug.Log("IM IN A ROOM NOW!!!");
   }

   private void OnExtensionResponse(object data, string type){

   }

   private void OnDebugMessage(string message){
      Debug.Log("[DEBUG] " + message);
   }

   private void OnApplicationQuit(){
      // If the game is closed, release connection to server
      smartFox.Disconnect();
      UnsubscribeEvents();
   }
}


And here is part of my server config for the zone and room:

Code: Select all

<Zone name="Guests" uCountUpdate="true" buddyList="20" maxUsers="4000" emptyNames="true" customLogin="false">
         <Rooms>
            <Room name="GuestRoom" maxUsers="1000" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true" />      
         </Rooms>


I am only concerned with the guest room at the moment. Since you have to be signed into a room in order to use extensions, I create a "guestroom" that lets anybody in so they can talk to the server and create a new account, then it auto logs them out when they go back to sign in screen and then they can sign in (using custom login).

I would really like to figure out why the user count keeps increasing. On a somewhat related note, I have been getting error messages on the server that "User is already in room!" so I am trying to rip apart the code and double check everything to make sure its working like its supposed to.

Any information will be much appreciated. Thanks!
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 04 Mar 2011, 09:29

I think the first thing you should do is check the client side debug messages logged by the SFS api. Look for the data sent in the uCount event.
If the right number of users is received, then the problem is in your application.
Paolo Bax
The SmartFoxServer Team
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 04 Mar 2011, 16:11

uCount reads normally, i think the problem is I wasn't understanding how SmartFox handled guest users. From what I can tell, anytime you log in without a custom login and you do not supply a user name / password SmartFox will create a "guest_#" name. I thought the # would change to each active user that joins.

So person A would join, they get guest_0. Person B would join, then they get guest_1, etc. Then I thought that if both person A and B leave, then join again, it would be guest_0 and guest_1, but apprently the counter keeps counting up each time a new user joins? Weird, but I guess it makes sense.

All the debug info sent back by the server reads ok, and the uCount does reflect the accurate user count, so I am just going to believe the guest counter counts up into infinity.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 04 Mar 2011, 18:03

Yes, that number in the "guest" name has nothing to do with the user count, which tells how many users are inside a room. That # is just the internal id assigned to the user by SFS.
Paolo Bax
The SmartFoxServer Team

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 36 guests