sfs pro login example
sfs pro login example
hey guys i know its quite easy but I dont know the answer:
I used the example from the docs "sfs pro tutorial login example"
i integrated a password in the api c# script and i wrote the extension....
I get the debug that it is right but the last snippet from the tutorial is in javascript and i didnt integrated it yet cause i dont know how...
Would anybody be so kind to translate this snippet to c# for me?
Thanks
Robert
I used the example from the docs "sfs pro tutorial login example"
i integrated a password in the api c# script and i wrote the extension....
I get the debug that it is right but the last snippet from the tutorial is in javascript and i didnt integrated it yet cause i dont know how...
Would anybody be so kind to translate this snippet to c# for me?
Thanks
Robert
Unity OnExtensionResponse C#
I don't know if you are using unity, but here is an example of how I'm handling OnExtensionResponse. This is for an XML response, with two parameters (two strings) embedded
I in no way claim for this to be a good method, or even a right one, but it works for me. In your particular case, this may not be what you need, but it should give you enough of the syntax to work it out on your own...
Also...
This is all mildly modified from the Island demo. You should really check that out, as they handle most of the SFS stuff in C#.
I in no way claim for this to be a good method, or even a right one, but it works for me. In your particular case, this may not be what you need, but it should give you enough of the syntax to work it out on your own...
Code: Select all
public void OnExtensionResponse(object data, string type)
{
// Handle XML responses
if (type == SmartFoxClient.XTMSG_TYPE_XML)
{
print("XML Response Handler");
SFSObject responseData = (SFSObject)data;
// TODO: check command and perform required actions
print("Response Data: " + responseData.GetString("_cmd"));
switch ( responseData.GetString("_cmd") )
{
case "logOK":
OnLogin(true, responseData.GetString("name"), responseData.GetString("err"));
break;
case "logKO":
OnLogin(false, responseData.GetString("name"), responseData.GetString("err"));
break;
}
}
}
Also...
Code: Select all
public void OnLogin(bool success, string name, string error) {
if ( success ) {
// Lets wait for the room list
} else {
// Login failed - lets display the error message sent to us
loginErrorMessage = error;
}
}
void OnRoomList(Hashtable roomList) {
// When room list is updated we are ready to move on to the island
UnregisterSFSSceneCallbacks();
Application.LoadLevel("TheGame");
}
This is all mildly modified from the Island demo. You should really check that out, as they handle most of the SFS stuff in C#.
Server side...
Here is what I have on the server side. This was straight from a tutorial, but I took the time to understand it, hopefully it will help you with your Java extension and understanding how that reacts with the client:
The most important thing I think to look at is here:
response.put("_cmd", "logOK");
response.put("id", String.valueOf(newUser.getUserId()));
response.put("name", newUser.getName());
trace("Logged in user.");
ok = true;
You can see the server is stuffing that "logOK" message along with the ID, and the name of the logged in user, and sending it as an SFSObject to the client. The client then uses the code in my previous post to pull out those parameters and use them.
Hope this helps.
Code: Select all
@Override
public void handleInternalEvent(InternalEventObject ieo) {
// TODO Auto-generated method stub
String eventName = ieo.getEventName();
trace("Event Fired: " + eventName);
if (eventName.equals("loginRequest"))
{
boolean ok = false;
User newUser = null;
// Prepare a response object for the client
ActionscriptObject response = new ActionscriptObject();
// Get the user nickname and password
String user = ieo.getParam("nick");
String pass = ieo.getParam("pass");
SocketChannel chan = (SocketChannel) ieo.getObject("chan");
// validate the user name
if (validNames.contains(user))
{
ok = true;
}
if (ok)
{
try
{
// Attempt to login the user to the system
newUser = helper.canLogin(user, pass, chan, currentZone.getName());
response.put("_cmd", "logOK");
response.put("id", String.valueOf(newUser.getUserId()));
response.put("name", newUser.getName());
trace("Logged in user.");
ok = true;
}
catch (LoginException le)
{
this.trace("Could not login user: " + user);
response.put("_cmd", "logKO");
response.put("err", le.getMessage());
}
}
// The user name is not among the valid ones
else
{
response.put("_cmd", "logKO");
response.put("err", "Sorry, your user name was not accepted.");
trace("Failed");
}
// Prepare the list of recipients, in this case we only one.
LinkedList ll = new LinkedList();
ll.add(chan);
// Send login response
sendResponse(response, -1, null, ll);
// Send room list
if (ok)
helper.sendRoomList(chan);
}
The most important thing I think to look at is here:
response.put("_cmd", "logOK");
response.put("id", String.valueOf(newUser.getUserId()));
response.put("name", newUser.getName());
trace("Logged in user.");
ok = true;
You can see the server is stuffing that "logOK" message along with the ID, and the name of the logged in user, and sending it as an SFSObject to the client. The client then uses the code in my previous post to pull out those parameters and use them.
Hope this helps.
Robbilie wrote:hey pls
Can anybody only translate the verry small javascript snippeet into c# for me?
Pls!
Thanks
Robert
Hi,
Try to use this online converter http://www.m2h.nl/files/js_to_c.php
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
The client side javascript/AS3 in the bottom is totally unusable for you as its very Flash client dependent.
You need to hook in your game code there with how you want to present things in _your_ gui. So no one can write that code for you except yourself.
Also - if you have trouble with this part, then good luck making an MMO. I would definitely start with a muuuuuuuch smaller game idea.
Good read in that regards:
http://sol.gfxile.net/mmorpg.html
You need to hook in your game code there with how you want to present things in _your_ gui. So no one can write that code for you except yourself.
Also - if you have trouble with this part, then good luck making an MMO. I would definitely start with a muuuuuuuch smaller game idea.
Good read in that regards:
http://sol.gfxile.net/mmorpg.html
thomad i dont think that i have to read that cause im verry sure that i will get my mmorpg to work..
Now the problem:
Tha extension works fine and it sends back in the debug logOk
But i dont now how to get this response to use in the game
And that was the sense of the snippet i think
Thats why i want somebody to translate it for me...
It would be very kind
Thanks
Robert
Now the problem:
Tha extension works fine and it sends back in the debug logOk
But i dont now how to get this response to use in the game
And that was the sense of the snippet i think
Thats why i want somebody to translate it for me...
It would be very kind
Thanks
Robert
Robert,
I already basically translated it for you and showed you how I implemented the response catching in Unity. You need to take the time to read that and try it out and if you can't get that working, you might want to start with some java script tutorials.
If you learn Javascript as well as C#, you can translate things yourself and it will make your life a lot easier. Even if you can't 100% translate things, you will at least be able to get some idea of what's going on, so you can work it out yourself.
You also might be able to find a translator online.
Google Javascript to C# converter and do some research. There are a number of methods available.
-Cameron
I already basically translated it for you and showed you how I implemented the response catching in Unity. You need to take the time to read that and try it out and if you can't get that working, you might want to start with some java script tutorials.
If you learn Javascript as well as C#, you can translate things yourself and it will make your life a lot easier. Even if you can't 100% translate things, you will at least be able to get some idea of what's going on, so you can work it out yourself.
You also might be able to find a translator online.
Google Javascript to C# converter and do some research. There are a number of methods available.
-Cameron
hi thx cameronb
but i got a smal bug just like appels say
i cant get in my room but what function do i use in the extention i try alot but i cant go in my world how do i fix this because i cant join my game room but i wil get connected
appels how did you fix your problem
and i see that cameronB just post a extention but i think it is a C# script can that be inplemented in a .as extention???
before i mess things up i just ask this
thanks if someone reply to my message
but i got a smal bug just like appels say
i cant get in my room but what function do i use in the extention i try alot but i cant go in my world how do i fix this because i cant join my game room but i wil get connected
appels how did you fix your problem
and i see that cameronB just post a extention but i think it is a C# script can that be inplemented in a .as extention???
before i mess things up i just ask this
thanks if someone reply to my message
Return to “.Net / Unity3D API”
Who is online
Users browsing this forum: No registered users and 20 guests