I followed a tutorial and had that working but I made a few changes to try and experiment to see how it works but I cant get it to work properly. Right now I tried to edit it so that it would send coordinates to the server and the server would send them back. But I get this error from the server.
if you comment to help or try to give a answer I well make sure to thumb it up
if you cant read it open the picture URL to get a larger image Piclair - Screenshot sharing
Here is the NetBeans project script
package PlayerPosExtension;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
public class PlayerPos extends BaseClientRequestHandler{
@Override
public void handleClientRequest(User user, ISFSObject objIn) {
int x = objIn.getInt("x");
int y = objIn.getInt("y");
int z = objIn.getInt("z");
ISFSObject objOut = new SFSObject();
objOut.putInt("PosX", x);
objOut.putInt("PosY", y);
objOut.putInt("PosZ", z);
send("PosX", objOut, user);
send("PosY", objOut, user);
send("PosZ", objOut, user);
}
}
Here is the script in unity
using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities;
using Sfs2X.Entities.Data;
public class SFS2X_Connect : MonoBehaviour
{
public string ConfigFile = "Network/sfs-config.xml";
public bool UseConfigFile = false;
public string ServerIP = "127.0.0.1";
public int ServerPort = 9933;
public string ZoneName ="BasicExamples";
public string UserName = "hi";
public string RoomName = "Lobby";
SmartFox sfs;
void Start()
{
sfs = new SmartFox();
sfs.ThreadSafeMode = true;
sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLogin);
sfs.AddEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, OnConfigLoad);
sfs.AddEventListener(SFSEvent.CONFIG_LOAD_FAILURE, OnConfigFail);
sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError);
sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
if(UseConfigFile)
{
sfs.LoadConfig(Application.dataPath + "/" + ConfigFile);
}
else
{
sfs.Connect(ServerIP, ServerPort);
}
sfs.Connect(ServerIP, ServerPort);
}
void OnConfigLoad(BaseEvent e)
{
Debug.Log("Config File Loaded");
sfs.Connect(sfs.Config.Host, sfs.Config.Port);
}
void OnJoinRoom(BaseEvent e)
{
Debug.Log("Joined Room: " + e.Params["room"]);
sfs.Send(new PublicMessageRequest("Hello world"));
}
void OnPublicMessage(BaseEvent e)
{
Room room = (Room)e.Params["room"];
User sender = (User)e.Params["sender"];
Debug.Log("[" + room.Name + "] " + sender.Name + ": " + e.Params["message"]);
}
void OnJoinRoomError(BaseEvent e)
{
Debug.Log("JoinRoom Error (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
}
void OnConfigFail(BaseEvent e)
{
Debug.Log("Failed to load Config File");
}
void OnLogin(BaseEvent e)
{
Debug.Log("Loggged in: " + e.Params["user"]);
sfs.Send(new JoinRoomRequest(RoomName));
ISFSObject objOut = new SFSObject();
objOut.PutInt("x", 2);
objOut.PutInt("y", 5);
objOut.PutInt("z", 1);
sfs.Send(new ExtensionRequest("PosX", objOut));
sfs.Send(new ExtensionRequest("PosY", objOut));
sfs.Send(new ExtensionRequest("PosZ", objOut));
}
void OnExtensionResponse(BaseEvent e)
{
string cmd = (string)e.Params["cmd"];
ISFSObject objIn = (SFSObject)e.Params["params"];
Debug.Log("x :" + objIn.GetInt("PosX"));
Debug.Log("y :" + objIn.GetInt("PosY"));
Debug.Log("z :" + objIn.GetInt("PosZ"));
}
void OnLoginError(BaseEvent e)
{
Debug.Log("Loggged error: (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
}
void OnConnection(BaseEvent e)
{
if((bool)e.Params["success"])
{
Debug.Log("Successfully Connected");
if(UseConfigFile)
{
ZoneName = sfs.Config.Zone;
}
sfs.Send(new LoginRequest(UserName, "",ZoneName));
}
else
{
Debug.Log("Connection Failed");
}
}
void Update()
{
sfs.ProcessEvents();
}
void OnApllicationQuit()
{
if(sfs.IsConnected)
sfs.Disconnect();
}
void OnGUI()
{
}
}