sfs pro login example

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

Moderators: Lapo, Bax

Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

sfs pro login example

Postby Robbilie » 10 Sep 2010, 20:58

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
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 11 Sep 2010, 18:25

CameronB
Posts: 7
Joined: 11 Sep 2010, 17:47

Unity OnExtensionResponse C#

Postby CameronB » 12 Sep 2010, 01:04

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...

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#.
CameronB
Posts: 7
Joined: 11 Sep 2010, 17:47

Server side...

Postby CameronB » 12 Sep 2010, 01:11

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:

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
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 14 Sep 2010, 19:52

hey pls

Can anybody only translate the verry small javascript snippeet into c# for me?

Pls!

Thanks
Robert
Nanite
Posts: 7
Joined: 10 Aug 2010, 15:38

Postby Nanite » 15 Sep 2010, 00:52

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
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 15 Sep 2010, 04:17

yes i had the same idea bit it doesnt work....

Parse error

Come on guys pls that isnt much code only a few lines..

Thanks
Robert
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 15 Sep 2010, 07:49

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
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 15 Sep 2010, 12:27

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
CameronB
Posts: 7
Joined: 11 Sep 2010, 17:47

Postby CameronB » 16 Sep 2010, 17:14

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 21 Sep 2010, 15:15

Thanks CameronB, your post helped me create my custom login :)
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 21 Sep 2010, 20:00

i cheered to fast lol
my custom login is working but when i send a GetRoomList request, i don't get anything back.
is there anything else we need to add add in the extension for this ?
my OnRoomList function never gets called but i see i send the command in my logs.
Thanks.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 21 Sep 2010, 23:11

all good now, figured it out. still needed to login my user in the extension.
dr-mad
Posts: 22
Joined: 09 Aug 2010, 16:29
Location: Netherlands - rotterdam

Postby dr-mad » 29 Sep 2010, 13:45

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 30 Sep 2010, 03:40

I had 2 problems, i forgot to log the user into smartfox in the extension and on the client side I needed to call the roomlist. You need to call it yourself if you use a custom login.
My extension was pure as.

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 15 guests