Display Clients Connected...

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

lampshade
Posts: 18
Joined: 04 Dec 2010, 19:14

Display Clients Connected...

Postby lampshade » 15 Mar 2011, 22:21

How would I display the number of clients connected to the server? I think I have the jist of it but its not quite panning out..

Code: Select all

public class ClientCount : MonoBehaviour {

    private Room myRoom;
    private SmartFoxClient smartFox = null;

    public static int ClientCount = 0; //decremented when disconnected
    public GUIStyle s;
   
    // Use this for initialization
   private void Start ()
   {
        myRoom = new Room(ClientCount++, "Lobby", 100, 100, false, false, false, false, 10, 10);
        myRoom.SetUserCount(ClientCount++);
        smartFox = SmartFox.Connection;
   
        Debug.Log("ActiveRoom: " + smartFox.GetActiveRoom() + " name: " + smartFox.myUserName);
        Debug.Log("id: " + smartFox.myUserId);
        Debug.Log("userCount: " + myRoom.GetUserCount());
   }
   
    private void OnGUI()
    {
        if (myRoom.GetUserCount() == 1)
        {
            GUI.Label(new Rect(5, 100, 100, 100), smartFox.myUserName, s);
        }

        if (myRoom.GetUserCount() == 2)
        {
            GUI.Label(new Rect(5, 130, 100, 100), smartFox.myUserName, s);
        }
    }
}


I'd also like to know how to store multiple strings of information into an object for the client, for example:

smartFox.GetName("lampshade");
smartFox.GetLevel(1);
smartFox.GetProfession("programmer");

I have all of these set, but in playerprefs...I think I could just store it all in:

smartFox.myUserName;

and just parse the string? But is there an easier way? Thanks in advance.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 15 Mar 2011, 23:23

Users connected to a zone? Cant remember if you can in SFS1 without an extension

For saving properties on a user connection you use UserVariables. Each room can also have RoomVariables.

Check the API documentation for examples on using these!

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
lampshade
Posts: 18
Joined: 04 Dec 2010, 19:14

Postby lampshade » 15 Mar 2011, 23:49

Well, i know that i need to use the sfs2 LobbyGUI foreach statements for users connected into the lobby, but I don't quite understand how to implement that..

I can't seem to get it started by declaring:

private SmartFox smartFox;

without getting the error:

Assets/Networking/ClientCount.cs(17,29): error CS0723: 'ClientCount.smartFox': cannot declare variables of static types

This really leads me to believe that I did not include the proper dll's in my assets folder? Because I think that I did, the SFS2.dll is in the Assets/Plugins directory in my project..

When I try smartFox. I don't get the same members that are being used with version 2.....

To prevent the "cannot declare varaibles of static types" error, I just removed the 'static' from the SmartFox Class declaration...

Now that it compiles, I can't use the SFS2 members anyway! Especially the one that I need:

currentActiveRoom.UserList : Room
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 16 Mar 2011, 08:33

Cant tell you how to write your code - try to work off the examples.

Generally using Start for anything is really shit, as you dont know the order of when Start is fired. So how can you be sure that you even got a connection to the server at that point in time?

I'm also super confused here - are you using SFS1 or 2X?
Full Control - maker of Unity/C# and Java SFS API and indie games

Follow on twitter: http://twitter.com/thomas_h_lund

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 9 guests