- Home /
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);
}
}
Answer by Molix · Apr 13, 2010 at 01:54 AM
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.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Using SmartFoxServer extension to detect collisions? 2 Answers
Multiplayer games with SmartFox very laggy/slow 1 Answer
UNET Health isn't syncing 1 Answer
Multiplayer|3dText PlayerName 1 Answer