x


Can't join SFS room, login works fine though

I've gotten my script to now connect to my server and login with a username. However, when I try to join a room (yes, the room exists), nothing happens. I get no errors, but OnJoinRoom doesn't run (I have a Debug.Log() inside it). I've been trying things for a few hours now and am completely stumped.

using UnityEngine;
using System;
using System.Collections;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;

public class NetworkController : MonoBehaviour {

    private static SmartFoxClient smartFoxClient;

    public static SmartFoxClient GetClient() {
        return SmartFox.Connection;
    }

    private void SubscribeEvents() {
        SFSEvent.onJoinRoom += OnJoinRoom;
        SFSEvent.onUserEnterRoom += OnUserEnterRoom;
        SFSEvent.onDebugMessage += OnJoinRoomError;
    }

    private void UnsubscribeEvents() {
        SFSEvent.onJoinRoom -= OnJoinRoom;
        SFSEvent.onUserEnterRoom -= OnUserEnterRoom;
    }

    // Use this for initialization
    void Start () {
        SubscribeEvents();
        smartFoxClient = GetClient();
        if (smartFoxClient==null) {
            Debug.Log("can't find connection");
            //Application.LoadLevel("Login");
            return;
        }
        smartFoxClient.JoinRoom("The Garden");
    }

    public void OnJoinRoomError(string error) {
        Debug.Log("room join error: " + error);
    }

    private void OnJoinRoom(Room room) {
        //SendMessage("SpawnPlayers");
        Debug.Log("Room " + room.GetName() + " joined successfully");
    }

    // This will be invoked when remote player enters our room
    private void OnUserEnterRoom(int roomId, User user)
    {
        //We assume here that we have only one room - so no need to check roomId
        SendMessage("UserEnterRoom", user);
    }
}
more ▼

asked Apr 13 '10 at 01:30 AM

James Simpson gravatar image

James Simpson
403 14 15 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You indicated that you successfully connected and logged in, but the code above does not show that. Assuming that is in another script, then the issue may be that you have not yet received a room list from the server. Typically the login will send one, but if you have created a custom login (e.g. with a server side extension), then you'll need to manually send it from the server.

more ▼

answered Apr 13 '10 at 01:54 AM

Molix gravatar image

Molix
4.8k 15 27 66

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x701
x681
x56

asked: Apr 13 '10 at 01:30 AM

Seen: 1122 times

Last Updated: Apr 13 '10 at 01:30 AM