Buddy list: empty list on client.

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

Moderators: Lapo, Bax

User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Buddy list: empty list on client.

Postby Real McCoy » 07 Dec 2008, 20:32

Hello All!

I'm created buddy list persister extending AbstractBuddyPersister. loadList() method implemented similarly as in Anber's example in this thread: http://www.smartfoxserver.com/forums/viewtopic.php?t=3230&start=0&postdays=0&postorder=asc&highlight=.
And it occurs when User log in to SFS. When client runs SmartFoxClient.loadBuddyList() no any debug strings from loadList() come to SFS console but OnDebug event fires on client with following message:

Code: Select all

[ RECEIVED ]: <msg t='sys'><body action='bList' r='-1'><bList><b s='0' i='-1' x='0'><n><![CDATA[Newbie]]></n><vs><v n='dbid'><![CDATA[8]]></v></vs></b><b s='0' i='-1' x='0'><n><![CDATA[Uzer]]></n><vs><v n='dbid'><![CDATA[9]]></v></vs></b><b s='0' i='-1' x='0'><n><![CDATA[User2]]></n><vs><v n='dbid'><![CDATA[10]]></v></vs></b><b s='0' i='-1' x='0'><n><![CDATA[User3]]></n><vs><v n='dbid'><![CDATA[11]]></v></vs></b></bList></body></msg>, (len: 423)

and OnBuddyList event also fired but buddyList in it comes empty.

Why? And what I doing wrong?

Thanks in advance!
User avatar
Anber
Posts: 14
Joined: 27 Jun 2008, 09:43
Location: South Africa
Contact:

Postby Anber » 08 Dec 2008, 15:47

Hi Real McCoy

Except for OnBuddyList, that should be onBuddyList, it looks like you are on the right track.

Could you please post some code on how you handle the SmartFoxClient.onBuddyList event. It might help us solve your problem a bit faster.
Lord BABDEn rulez!

Xbox gamertag: LordBaden
User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Postby Real McCoy » 09 Dec 2008, 05:31

Thank you for response!

Here is almost full of my buddy persister implementation:

Code: Select all

public class BuddyListPersister extends AbstractBuddyPersister
{
  private DbManager dbManager;
  private ExtensionHelper helper;

  @Override
  public void init(Object param)
  {
    helper = ExtensionHelper.instance();

    dbManager = SmartFoxServer.getInstance().getZone("testZone").dbManager;
  }

  @Override
  public StorableBuddyList loadList(String userName)
  {
      StorableBuddyList buddyList = new StorableBuddyList();

      String query = "select users.userid, users.nick from users, friends " +
            "where users.userid = friends.friendid " +
            "and friends.userid = (select userid from users where nick='" +
            userName + "')";

      ArrayList<DataRow> resultSet = dbManager.executeQuery(query);

      for (int i = 0; i < resultSet.size(); i++)
      {
          DataRow row = resultSet.get(i);

          StorableBuddyItem buddyItem = new StorableBuddyItem(row.getItem("nick"), false);

          User user = this.getCurrentZone().getUserByName(buddyItem.name);

          Map<String,String> vars = new HashMap<String,String>();
          vars.put("dbid",row.getItem("friendid"));

          helper.setBuddyVariables(user,vars);

          buddyList.buddies.add(buddyItem);
      }

      return buddyList;
  }

  @Override
  public boolean saveList(String userName, StorableBuddyList buddyList)
  {
      System.out.println("BuddyListPersister: saveList started...");
      return true;
  }

  @Override
  public Map getOfflineVariables(String userName)
  {
      Map<String, String> offlineVars = new HashMap<String, String>();

      String query = "SELECT userid FROM users WHERE nick='" + userName + "'";

      ArrayList<DataRow> resultSet = dbManager.executeQuery(query);

      for (int i = 0; i < resultSet.size(); i++)
      {
          DataRow row = resultSet.get(i);
          offlineVars.put("dbid", row.getItem("userid"));
      }

      return offlineVars;
  }

  @Override
  public void destroy(Object param)
  {
      System.out.println("VD-MSG: BuddyListPersister: destroy started...");
  }
}


I am sorry for not full information: Java-client works properly
Here is client code fragment:

Code: Select all

btnLoadBuddyList.addActionListener(new java.awt.event.ActionListener()
{
  public void actionPerformed(java.awt.event.ActionEvent evt)
  {
    sfs.loadBuddyList();
  }
});

// ....

public void handleEvent(final SFSEvent event)
{
  java.awt.EventQueue.invokeLater(new Runnable()
  {
    public void run()
    {
      if(event.getName().equals(SFSEvent.onBuddyList))
      {
        int size = ((List<Buddy>)event.getParams().get("list")).size();
        System.out.println("Buddy list size = " + size);
      }
    }
  }
}


But .NET-client don't works.

Code: Select all

private void Form1_Load(object sender, EventArgs e)
{
  SFSEvent.onBuddyList += OnBuddyList;
}

// ...

public void OnBuddyList(ArrayList buddyList)                                     
{
  if (chbShowEventsEntrance.Checked)
    lock (this) { txtLog.Text = txtLog.Text + "On_Buddy_List\r\n"; }         

    foreach (Buddy buddy in buddyList)
    {
      lock (this)
      {
        txtLog.Text = txtLog.Text + "Buddy name: " + buddy.GetName() + "\r\n";
    }
  }                                                                             
}


Thank you for help!
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Dec 2008, 08:04

To better understand... the problem shows up in a .Net client using C# API?
If so I will move the post in the BETA API section so that our .Net guy can check it out.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Postby Real McCoy » 09 Dec 2008, 08:48

Yes, the problem is in .Net-client using C# API.
Thank you for support!
I will keep my eyes on BETA API forum and here.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Dec 2008, 09:50

ok, moved in the proper section.
We'll get back to you asap.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 09 Dec 2008, 11:19

I will try to look at this tonight and see if the buddylist XML node is correctly matched with the data that comes in.

To help me a bit - what version of the C# API do you use? There has been a beta 1, beta 2 and one or two code drops in between.
User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Postby Real McCoy » 09 Dec 2008, 18:00

There is beta 2 C# uses. SmartFoxClient.dll has 72192 byte size Nov 10 2008 date.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 09 Dec 2008, 20:56

Definitely a bug - working on a fix. Hold on 10-15 mins :-)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 09 Dec 2008, 21:10

OK - give it a try with this one. It seems to pull out the data correctly now from your XML example.

http://www.fullcontrol.dk/downloads/Sma ... 081209.zip

The entire buddy part is the last thing that is not tested very well. If you run into anything else on the buddy part, then start by blaming me and buzz me. And please send your XML like you did. It makes it a breeze to fix the bugs.

And very much pretty please report back if this works for you or not!

/Thomas
User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Postby Real McCoy » 10 Dec 2008, 15:12

Hello Tohmas! Sorry for delay.

Here is result of testing.

When I trying to get buddy list for user after user connect/login/join as

Code: Select all

list = SmartFoxClient.buddyList;

I get nothing.

If I calling for

Code: Select all

SmartFoxClient.LoadBuddyList();

then in OnBuddyList event handler reaches null instead buddy list.

But if i try to obtain list = SmartFoxClient.buddyList; after SmartFoxClient.LoadBuddyList() method called then I get expected buddy list with -1 as each buddy id.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 10 Dec 2008, 18:15

Hi again

Thanks for the feedback, and I did find yet another "feature" in there. Sorry I didnt get that fixed properly. New build in a few minutes once I made sure that the buddy list is properly sent back to the client.

Regarding initial load - as far as I know, then the buddy list will always be empty on startup until you requested to load it. So it will be empty until you call LoadBuddyList()

Regarding your -1 as buddy id - that is actually what your XML contains! You have i='-1' as id for each one in the XML you posted earlier on. So here the API does as expected/requested.

But gimme a few more minutes, and I should have at least the onBuddyList event working.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 10 Dec 2008, 18:38

User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Postby Real McCoy » 11 Dec 2008, 06:09

Thanks!
More better now but...

SmartFoxClient.LoadBuddyList() sends to OnBuddyList event handler right list at first time, but doubled list at second time, then tripled at third, etc. At the same time SmartFoxClient.buddyList keeps list as it saved after LoadBuddyList method and don't increase it.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 11 Dec 2008, 06:30

Ahhhh damn - yes. Sorry. I am forgetting to clear the list prior to each load.

Doing that now - so please try this one:
http://www.fullcontrol.dk/downloads/Sma ... 081211.zip

/Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 31 guests