Page 1 of 1

buddyList

Posted: 12 Mar 2008, 21:58
by asflash
Hi Lapo I am having troubles with the event onBuddyPermissionRequest the event don´t fire at all my this is the zone I am using please explain what can be happening any clue why this is not working I am using this code is the same code of the example just with a little modifications please take a look to the code .

thanks in advanced


Code: Select all

package
{
   import flash.display.MovieClip
   import it.gotoandplay.smartfoxserver.SmartFoxClient
   import it.gotoandplay.smartfoxserver.SFSEvent
   import flash.events.*
   import fl.events.ListEvent
   import fl.data.DataProvider
   import flash.text.TextField
   import flash.utils.*
   
   public class Main extends MovieClip
   {
      private var sfs:SmartFoxClient
      
      init()
      
      function Main() : void
      {
         mc_alert.visible = false
         init()
      }
      
      function init() : void
      {
         setTimeout(toggleUI, 50, false)
         
         sfs = new SmartFoxClient()

         // Register for SFS events
         sfs.addEventListener( SFSEvent.onConnection, onConnection )
         sfs.addEventListener( SFSEvent.onConnectionLost, onConnectionLost )
         
         sfs.addEventListener( SFSEvent.onBuddyList, onBuddyList )
         sfs.addEventListener( SFSEvent.onBuddyListUpdate, onBuddyListUpdate )
         sfs.addEventListener( SFSEvent.onBuddyPermissionRequest, onBuddyPermissionRequest )
         
         sfs.addEventListener( SFSEvent.onPrivateMessage, onPrivateMessage )
         
         
         // Register for generic errors
         sfs.addEventListener( SecurityErrorEvent.SECURITY_ERROR, onSecurityError )
         sfs.addEventListener( IOErrorEvent.IO_ERROR, onIOError )

         bt_connect.addEventListener( MouseEvent.CLICK, bt_connect_click )
         bt_addBuddy.addEventListener( MouseEvent.CLICK, bt_addBuddy_click )
         bt_removeBuddy.addEventListener( MouseEvent.CLICK, bt_removeBuddy_click )
         bt_blockBuddy.addEventListener( MouseEvent.CLICK, bt_blockBuddy_click )
         bt_unblockBuddy.addEventListener( MouseEvent.CLICK, bt_unblockBuddy_click )
         bt_setVariable.addEventListener( MouseEvent.CLICK, bt_setVariable_click )
         bt_disconnect.addEventListener( MouseEvent.CLICK, bt_disconnect_click )
         bt_send.addEventListener( MouseEvent.CLICK, bt_send_click )
         
         mc_alert.bt_grant.addEventListener ( MouseEvent.CLICK, bt_grant_click )
         mc_alert.bt_refuse.addEventListener ( MouseEvent.CLICK, bt_refuse_click )
         
         // Initialize datagrids components
         dg_buddies.columns = ["name", "online", "X"]
         dg_vars.columns = ["key", "value"]
         
         dg_buddies.getColumnAt(0).width = 80
         dg_buddies.getColumnAt(2).width = 25
         
         dg_buddies.addEventListener(ListEvent.ITEM_CLICK, dg_buddies_click)
         
         debugTrace( "API Version: " + sfs.getVersion() )
         debugTrace( "Click the CONNECT button to start" )
      }
      
   
      
      /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       *   Button Handlers
       * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       */
      function bt_connect_click(evt:Event):void
      {
         if ( !sfs.isConnected && tf_connect.text != "" )
            sfs.connect("127.0.0.1",9339);
            
         else
            debugTrace("You are already connected!")
      }
      
      function bt_addBuddy_click(evt:Event):void
      {
         if ( tf_buddyName.text != "" )
         {
            sfs.addBuddy( tf_buddyName.text )
            tf_buddyName.text = ""
         }
            
      }
      
      function bt_removeBuddy_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null )
         {
            sfs.removeBuddy( dg_buddies.selectedItem.name )
         }
            
      }
      
      function bt_blockBuddy_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null )
            sfs.setBuddyBlockStatus( dg_buddies.selectedItem.name, true )
      }
      
      function bt_unblockBuddy_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null )
            sfs.setBuddyBlockStatus( dg_buddies.selectedItem.name, false )
      }
      
      function bt_setVariable_click(evt:Event):void
      {
         if ( tf_varKey.text != "" && tf_varValue.text != "" )
         {
            var vars:Array = []
            vars[tf_varKey.text] = tf_varValue.text
            
            sfs.setBuddyVariables( vars )
         }
      }
      
      function bt_grant_click(evt:Event):void
      {
         sendBuddyPermissionResponse( true )
      }
      
      function bt_refuse_click(evt:Event):void
      {
         sendBuddyPermissionResponse( false )
      }
      
      function bt_disconnect_click(evt:Event):void
      {
         sfs.disconnect()
      }
      
      function bt_send_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null && tf_chat.text != "" )
         {
            var buddy = sfs.getBuddyByName( dg_buddies.selectedItem.name )
            
            if ( buddy.isOnline)
            {
               sfs.sendPrivateMessage( tf_chat.text, buddy.id )
               tf_chat.text = ""
            }
         }
      }
      
      function sendBuddyPermissionResponse( b:Boolean ):void
      {
         sfs.sendBuddyPermissionResponse( b, mc_alert.lb_name.text )
         mc_alert.lb_name.text = ""
         mc_alert.visible = false
      }
      
      /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       *   Datagrid Handlers
       * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       */
      
      function dg_buddies_click( evt:ListEvent ) : void
      {
         var buddy:Object = sfs.getBuddyByName( evt.item.name )
         refreshBuddyVariables( buddy )
      }
      
      function toggleUI(b:Boolean):void
      {
         tf_connect.enabled = !b
         bt_connect.enabled = !b
         
         tf_buddyName.enabled = b
         tf_varKey.enabled = b
         tf_varValue.enabled = b
         tf_chat.enabled = b
         ta_chat.enabled = b
         
         bt_disconnect.enabled = b
         bt_removeBuddy.enabled = b
         bt_blockBuddy.enabled = b
         bt_unblockBuddy.enabled = b
         bt_setVariable.enabled = b
         bt_addBuddy.enabled = b
         
         dg_vars.enabled = b
         dg_buddies.enabled = b
      }
      
      
      function onConnection(evt:SFSEvent):void
      {
         var success:Boolean = evt.params.success
         trace(success);
         if (success)
         {
            debugTrace("Connection successfull!")
            tf_conn.text = "Connected"
            mc_conn.gotoAndStop(2)
            
            toggleUI( true )
            
            sfs.login("ACA", "a", "a")
         }
         else
         {
            debugTrace("Connection failed!")   
         }
      }
      
      
      function onConnectionLost(evt:SFSEvent):void
      {
         debugTrace("Connection lost!")
         
         tf_conn.text = "Not Connected"
         mc_conn.gotoAndStop(1)

         ta_chat.text = ""
         tf_connect.text = ""
         
         dg_buddies.dataProvider = new DataProvider([])
         dg_vars.dataProvider = new DataProvider([])
         
         toggleUI( false )
      }

      
      function onBuddyList(evt:SFSEvent):void
      {
         refreshBuddyList()
         for (var i:String in sfs.myBuddyVars )
         {
            trace(i + " >> " + sfs.myBuddyVars[i])
         }
      }
      
      function onBuddyListUpdate(evt:SFSEvent):void
      {
         trace("list update");
         var isSameItem:Boolean = dg_buddies.selectedItem != null && dg_buddies.selectedItem.name == evt.params.buddy.name
         refreshBuddyList()
         
         if ( isSameItem )
            refreshBuddyVariables( evt.params.buddy )
      }
      
      function onBuddyPermissionRequest(evt:SFSEvent):void
      {
         trace("request permision");
         mc_alert.lb_name.text = evt.params.sender
         mc_alert.visible = true
      }
      
      
   }

   

   
   
   
}




Code: Select all

<Zone name="ACA" uCountUpdate="true" buddyList="20" maxUsers="4000" customLogin="true">
      <BuddyList active="true">
            <size>50</size>
            <maxBuddyVariables>6</maxBuddyVariables>
            <mode>advanced</mode>
            <addBuddyPermission>true</addBuddyPermission>
            <offLineBuddyVariables>true</offLineBuddyVariables>
            <mutualAddBuddy>true</mutualAddBuddy>
            <mutualRemoveBuddy>true</mutualRemoveBuddy>
          </BuddyList>
         <Rooms>
             <Room name="enter" maxUsers="1000" limbo="true" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="false" />
         </Rooms>
         <AutoReloadExtensions>true</AutoReloadExtensions>
         <Extensions>
            <extension name="SapiDB"  className="SapiDB.as" type="script" />
            <extension name="SapiFastData"  className="SapiFastData.as" type="script" />
            <extension name="SapiLogin"  className="SapiLogin.as" type="script" />
            <extension name="SapiMU"  className="SapiMU.as" type="script" />
            <extension name="SapiAvatar"  className="SapiAvatar.as" type="script" />
            <extension name="SapiTrivia"  className="SapiTrivia.as" type="script" />
            <extension name="SapiMessage"  className="SapiMessage.as" type="script" />
            <extension name="SapiClue"  className="SapiClue.as" type="script" />
            <extension name="SapiPassport"  className="SapiPassport.as" type="script" />

         </Extensions>
         
         <DatabaseManager active="true">
            
            <Driver>org.gjt.mm.mysql.Driver</Driver>
            <ConnectionString>jdbc:mysql://127.0.0.1:3306/vWorld</ConnectionString>
      
            <UserName>root</UserName>
            <Password>root</Password>
            
            <TestSQL><![CDATA[SELECT COUNT(*) FROM user]]></TestSQL>
            
            <MaxActive>10</MaxActive>
            <MaxIdle>10</MaxIdle>
            
            <OnExhaustedPool>fail</OnExhaustedPool>
            <BlockTime>5000</BlockTime>
               
         </DatabaseManager>
   </Zone>   

Posted: 12 Mar 2008, 22:34
by mistermind
I had some problems with buddy list not long ago. You can check all my progress here:
viewtopic.php?t=2639

I narrowed down the problem by catching every event fired by both the command prompt on SFS service and the file logs.
Could you post the warning or severe events fired on your file logs the moment you click on permission request from your client app? There may be an error there and it can be similar to mine.

Posted: 14 Mar 2008, 09:08
by Lapo
I have two requests:
1. what version of the client API are you using? use sfs.getVersion() to check
2. please copy/paste here the debug info of your client app while running, this will help more than the code

Thanks

Posted: 14 Mar 2008, 15:07
by eldervaz
Lapo wrote:I have two requests:
1. what version of the client API are you using? use sfs.getVersion() to check
2. please copy/paste here the debug info of your client app while running, this will help more than the code

Thanks


API Version: 1.5.3

hey man well the big problem is that I can´t get the permission request working I dunno exactly maybe is the version about the second request I don´t understand exactly what you waqnt if you mean traces I don´t have too much traces on my app I hope yoy can help me something with the version maybe that can give you some conclusions about what is happening if not please explain me what else you need to help yourself to get a conclusion
we are close to finish the project and also the end day is close too haha so please please help me with this man also thank you so much for all the help you have gave me really man is really appreciated :)

PD man is ok that the folder installation says "SmartFoxServerPRO_1.6.0" and the api version 1.5.3? , thanks again man :)

Posted: 15 Mar 2008, 16:31
by Lapo
We need the debug output of the SmartFoxClient object, which is shown in the Flash output window (F2)
To activate add this line:

Code: Select all

sfs.debug = true

right after creating the SmartFoxClient instance ("sfs" is should be your instance name)

p.s. = API version doesn't follow Server version, so it's ok

Posted: 17 Mar 2008, 13:16
by eldervaz
Thank Lapo

Code: Select all

[Sending]: <msg t='sys'><body action='verChk' r='0'><ver v='153' /></body></msg>

[ RECEIVED ]: <cross-domain-policy><allow-access-from domain='*' to-ports='9339' /></cross-domain-policy>, (len: 91)
[ RECEIVED ]: <msg t='sys'><body action='apiOK' r='0'></body></msg>, (len: 53)
true
[Sending]: <msg t='sys'><body action='login' r='0'><login z='ACA'><nick><![CDATA[b]]></nick><pword><![CDATA[b]]></pword></login></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='rmList' r='0'><rmList><rm id='222' priv='0' temp='0' game='0' ucnt='0' lmb='1' maxu='1000' maxs='0'><n><![CDATA[enter]]></n></rm></rmList></body></msg>, (len: 178)
[Sending]: <msg t='sys'><body action='autoJoin' r='-1'></body></msg>

[ RECEIVED ]: <msg t='xt'><body action='xtRes' r='-1'><![CDATA[<dataObj><var n='_avatar' t='s'>0</var><var n='dbId' t='s'>2017</var><var n='_registrationDate' t='s'>2008-03-03</var><var n='_userId' t='s'>2017</var><var n='_username' t='s'>b</var><var n='myClothes' t='s'>3,4,1,2</var><var n='colors' t='s'>0x87B200,0xCB000F,0xE17E00,0xF9EA00,0xCB0067,0x318BDA,0x000000,0xFFFFFF</var><var n='_playtime' t='s'>0</var><var n='ids' t='s'>1,2,3,4,5,6,7,8</var><var n='myUserName' t='s'>b</var><var n='_name' t='s'>b</var><var n='_hotelRoomStar' t='s'>2</var><var n='_hasPassport' t='s'>1</var><var n='_coins' t='s'>12</var><var n='_state' t='s'>0</var><var n='_age' t='s'>4</var><obj o='_rowLabel' t='a'><var n='19' t='s'>TIME SELECTION</var><var n='17' t='s'>AIR ROCKET</var><var n='18' t='s'>NUCLEAR ROCKET</var><var n='15' t='s'>SOLAR ROCKET</var><var n='16' t='s'>H2O ROCKET</var><var n='13' t='s'>ROCKET TYPE</var><var n='14' t='s'>ROCKET CASUAL</var><var n='11' t='s'>PLAY TIME</var><var n='12' t='s'>ENERGY</var><var n='21' t='s'>FUTURE</var><var n='20' t='s'>HISTORY</var><var n='22' t='s'>TIME</var><var n='23' t='s'>PERIOD</var><var n='24' t='s'>TIMEGUIDE</var><var n='25' t='s'>ACTIVITIES</var><var n='26' t='s'>ACTIVIDADES</var><var n='27' t='s'>ACCESS</var><var n='28' t='s'>MESSAGES</var><var n='3' t='s'>MEMBER SINCE</var><var n='2' t='s'>AGE</var><var n='10' t='s'>HOTEL ROOM</var><var n='1' t='s'>NAME</var><var n='0' t='s'>PROFILE</var><var n='7' t='s'>TIMELEVELS</var><var n='6' t='s'>COINS</var><var n='5' t='s'>ENERGY LEVEL</var><var n='4' t='s'>ROCKET</var><var n='9' t='s'>FRIENDS</var><var n='8' t='s'>SOUVENIRS</var></obj><var n='_accepted' t='b'>1</var><var n='myUserId' t='n'>5</var><var n='_language' t='n'>1</var><var n='_cmd' t='s'>loginRequest</var><var n='myColor' t='s'>0xFFFFFF,0xCB000F,0xFFFFFF,0xFFFFFF</var><var n='user' t='s'>it.gotoandplay.smartfoxserver.data.User@17f085a</var></dataObj>]]></body></msg>, (len: 1924)
[ RECEIVED ]: <msg t='sys'><body action='joinOK' r='222'><pid id='0'/><vars /><uLs r='222'></uLs></body></msg>, (len: 96)
[Sending]: <msg t='sys'><body action='loadB' r='-1'></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='bList' r='-1'><bList><b s='0' i='-1' x='0'><n><![CDATA[a]]></n></b></bList></body></msg>, (len: 115)
[Sending]: <msg t='sys'><body action='remB' r='-1'><n>a</n></body></msg>

[Sending]: <msg t='sys'><body action='addB' r='-1'><n>a</n></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='bAdd' r='-1'><b s='1' i='6'><n><![CDATA[a]]></n></b></body></msg>, (len: 92)
[Sending]: <msg t='sys'><body action='prvMsg' r='222'><txt rcp='6'><![CDATA[123]]></txt></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='prvMsg' r='222'><user id='5' /><txt><![CDATA[123]]></txt></body></msg>, (len: 97)


my Main.as

Code: Select all

package
{
   import flash.display.MovieClip
   import it.gotoandplay.smartfoxserver.SmartFoxClient
   import it.gotoandplay.smartfoxserver.SFSEvent
   import flash.events.*
   import fl.events.ListEvent
   import fl.data.DataProvider
   import flash.text.TextField
   import flash.utils.*
   
   public class Main extends MovieClip
   {
      private var sfs:SmartFoxClient
      
      init()
      
      function Main() : void
      {
         mc_alert.visible = false
         init()
      }
      
      function init() : void
      {
         setTimeout(toggleUI, 50, false)
         
         sfs = new SmartFoxClient()

         // Register for SFS events
          sfs.debug = true
         sfs.addEventListener( SFSEvent.onConnection, onConnection )
         sfs.addEventListener( SFSEvent.onConnectionLost, onConnectionLost )
         sfs.addEventListener( SFSEvent.onLogin, onLogin )
         sfs.addEventListener( SFSEvent.onRoomListUpdate, onRoomListUpdate )
         sfs.addEventListener( SFSEvent.onJoinRoom, onJoinRoom )
         sfs.addEventListener( SFSEvent.onJoinRoomError, onJoinRoomError )
         sfs.addEventListener( SFSEvent.onConfigLoadFailure, onConfigLoadFailure )
         
         sfs.addEventListener( SFSEvent.onBuddyList, onBuddyList )
         sfs.addEventListener( SFSEvent.onBuddyListUpdate, onBuddyListUpdate )
         sfs.addEventListener( SFSEvent.onBuddyPermissionRequest, onBuddyPermissionRequest )
         
         sfs.addEventListener( SFSEvent.onPrivateMessage, onPrivateMessage )
         
         
         // Register for generic errors
         sfs.addEventListener( SecurityErrorEvent.SECURITY_ERROR, onSecurityError )
         sfs.addEventListener( IOErrorEvent.IO_ERROR, onIOError )

         bt_connect.addEventListener( MouseEvent.CLICK, bt_connect_click )
         bt_addBuddy.addEventListener( MouseEvent.CLICK, bt_addBuddy_click )
         bt_removeBuddy.addEventListener( MouseEvent.CLICK, bt_removeBuddy_click )
         bt_blockBuddy.addEventListener( MouseEvent.CLICK, bt_blockBuddy_click )
         bt_unblockBuddy.addEventListener( MouseEvent.CLICK, bt_unblockBuddy_click )
         bt_setVariable.addEventListener( MouseEvent.CLICK, bt_setVariable_click )
         bt_disconnect.addEventListener( MouseEvent.CLICK, bt_disconnect_click )
         bt_send.addEventListener( MouseEvent.CLICK, bt_send_click )
         
         mc_alert.bt_grant.addEventListener ( MouseEvent.CLICK, bt_grant_click )
         mc_alert.bt_refuse.addEventListener ( MouseEvent.CLICK, bt_refuse_click )
         
         // Initialize datagrids components
         dg_buddies.columns = ["name", "online", "X"]
         dg_vars.columns = ["key", "value"]
         
         dg_buddies.getColumnAt(0).width = 80
         dg_buddies.getColumnAt(2).width = 25
         
         dg_buddies.addEventListener(ListEvent.ITEM_CLICK, dg_buddies_click)
         
         debugTrace( "API Version: " + sfs.getVersion() )
         debugTrace( "Click the CONNECT button to start" )
      }
      
   
      
      /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       *   Button Handlers
       * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       */
      function bt_connect_click(evt:Event):void
      {
         if ( !sfs.isConnected && tf_connect.text != "" )
            sfs.connect("192.168.2.175",9339);
            
         else
            debugTrace("You are already connected!")
      }
      
      function bt_addBuddy_click(evt:Event):void
      {
         if ( tf_buddyName.text != "" )
         {
            sfs.addBuddy( tf_buddyName.text )
            tf_buddyName.text = ""
         }
            
      }
      
      function bt_removeBuddy_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null )
         {
            sfs.removeBuddy( dg_buddies.selectedItem.name )
         }
            
      }
      
      function bt_blockBuddy_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null )
            sfs.setBuddyBlockStatus( dg_buddies.selectedItem.name, true )
      }
      
      function bt_unblockBuddy_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null )
            sfs.setBuddyBlockStatus( dg_buddies.selectedItem.name, false )
      }
      
      function bt_setVariable_click(evt:Event):void
      {
         if ( tf_varKey.text != "" && tf_varValue.text != "" )
         {
            var vars:Array = []
            vars[tf_varKey.text] = tf_varValue.text
            
            sfs.setBuddyVariables( vars )
         }
      }
      
      function bt_grant_click(evt:Event):void
      {
         sendBuddyPermissionResponse( true )
      }
      
      function bt_refuse_click(evt:Event):void
      {
         sendBuddyPermissionResponse( false )
      }
      
      function bt_disconnect_click(evt:Event):void
      {
         sfs.disconnect()
      }
      
      function bt_send_click(evt:Event):void
      {
         if ( dg_buddies.selectedItem != null && tf_chat.text != "" )
         {
            var buddy = sfs.getBuddyByName( dg_buddies.selectedItem.name )
            
            if ( buddy.isOnline)
            {
               sfs.sendPrivateMessage( tf_chat.text, buddy.id )
               tf_chat.text = ""
            }
         }
      }
      
      function sendBuddyPermissionResponse( b:Boolean ):void
      {
         sfs.sendBuddyPermissionResponse( b, mc_alert.lb_name.text )
         mc_alert.lb_name.text = ""
         mc_alert.visible = false
      }
      
      /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       *   Datagrid Handlers
       * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       */
      
      function dg_buddies_click( evt:ListEvent ) : void
      {
         var buddy:Object = sfs.getBuddyByName( evt.item.name )
         refreshBuddyVariables( buddy )
      }
      
      function toggleUI(b:Boolean):void
      {
         tf_connect.enabled = !b
         bt_connect.enabled = !b
         
         tf_buddyName.enabled = b
         tf_varKey.enabled = b
         tf_varValue.enabled = b
         tf_chat.enabled = b
         ta_chat.enabled = b
         
         bt_disconnect.enabled = b
         bt_removeBuddy.enabled = b
         bt_blockBuddy.enabled = b
         bt_unblockBuddy.enabled = b
         bt_setVariable.enabled = b
         bt_addBuddy.enabled = b
         
         dg_vars.enabled = b
         dg_buddies.enabled = b
      }
      
      /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       *   SmartFoxServer Handlers
       * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       */
      
      /**
       * Handle connection
       */
      function onConnection(evt:SFSEvent):void
      {
         var success:Boolean = evt.params.success
         trace(success);
         if (success)
         {
            debugTrace("Connection successfull!")
            tf_conn.text = "Connected"
            mc_conn.gotoAndStop(2)
            
            toggleUI( true )
            
            sfs.login("ACA", "b", "b")
         }
         else
         {
            debugTrace("Connection failed!")   
         }
      }
      
      /**
      * Handle configuration load failure
      */
      function onConfigLoadFailure(evt:SFSEvent):void
      {
         debugTrace("Failed loading config file: " + evt.params.message)
      }

      /**
       * Handle connection lost
       */
      function onConnectionLost(evt:SFSEvent):void
      {
         debugTrace("Connection lost!")
         
         tf_conn.text = "Not Connected"
         mc_conn.gotoAndStop(1)

         ta_chat.text = ""
         tf_connect.text = ""
         
         dg_buddies.dataProvider = new DataProvider([])
         dg_vars.dataProvider = new DataProvider([])
         
         toggleUI( false )
      }

      /**
       * Handle login response
       */
      function onLogin(evt:SFSEvent):void
      {
         if (evt.params.success)
         {
            debugTrace("Successfully logged in -> " + evt.params.name)
         }
         else
         {
            debugTrace("Login failed. Reason: " + evt.params.error)
         }
      }

      /**
       * Handle room list
       */
      function onRoomListUpdate(evt:SFSEvent):void
      {
         debugTrace("Room list received")

         // Tell the server to auto-join us in the default room for this Zone
         sfs.autoJoin()
      }

      /**
       * Handle successfull join
       */
      function onJoinRoom(evt:SFSEvent):void
      {
         debugTrace("Successfully joined room: " + evt.params.room.getName())
         sfs.loadBuddyList()
      }

      /**
       * Handle problems with join
       */
      function onJoinRoomError(evt:SFSEvent):void
      {
         debugTrace("Problems joining default room. Reason: " + evt.params.error)   
      }
      
      /**
      * Handle buddy list
      */
      function onBuddyList(evt:SFSEvent):void
      {
         refreshBuddyList()
         for (var i:String in sfs.myBuddyVars )
         {
            trace(i + " >> " + sfs.myBuddyVars[i])
         }
      }
      
      function onBuddyListUpdate(evt:SFSEvent):void
      {
         trace("list update");
         var isSameItem:Boolean = dg_buddies.selectedItem != null && dg_buddies.selectedItem.name == evt.params.buddy.name
         refreshBuddyList()
         
         if ( isSameItem )
            refreshBuddyVariables( evt.params.buddy )
      }
      
      function onBuddyPermissionRequest(evt:SFSEvent):void
      {
         trace("request permision");
         mc_alert.lb_name.text = evt.params.sender
         mc_alert.visible = true
      }
      
      function onPrivateMessage(evt:SFSEvent):void
      {
         var userName:String
         
         if ( evt.params.userId == sfs.myUserId )
            userName = "me"
         else
         {
             var buddy:Object = sfs.getBuddyById( int(evt.params.userId) )
            
            if ( buddy != null )
               userName = buddy.name
            else
               userName = "Unknown"
         }
         
         debugTrace("[ " + userName + " ] " + evt.params.message)
      }
      
      private function refreshBuddyList()
      {
         var dp:Array = []
         
         for each ( var buddy:Object in sfs.buddyList )
         {
            dp.push(
                     {
                        name:buddy.name,
                        online: buddy.isOnline ? "Y" : "N",
                        X:buddy.isBlocked ? "Y" : "N"
                     }
                  )
         }
         
         dg_buddies.dataProvider = new DataProvider( dp )
      }
      
      
      function refreshBuddyVariables( buddy:Object ) : void
      {
         if ( buddy != null )
         {
            var dp:Array = []
         
            for ( var key:String in buddy.variables )
            {
               dp.push( { key:key, value:buddy.variables[key] } )
            }
         
            dg_vars.dataProvider = new DataProvider( dp )
         }
      }

      /**
       * Handle a Security Error
       */
      function onSecurityError(evt:SecurityErrorEvent):void
      {
         debugTrace("Security error: " + evt.text)
      }

      /**
       * Handle an I/O Error
       */
      function onIOError(evt:IOErrorEvent):void
      {
         debugTrace("I/O Error: " + evt.text)
      }

      /**
       * Trace messages to the debug text area
       */
      function debugTrace(msg:String):void
      {
         ta_chat.text += "{ LOG } " + msg + "\n"
      }
      
   }

   

   
   
   
}

Posted: 17 Mar 2008, 16:59
by eldervaz
Lapo wrote:We need the debug output of the SmartFoxClient object, which is shown in the Flash output window (F2)
To activate add this line:

Code: Select all

sfs.debug = true

right after creating the SmartFoxClient instance ("sfs" is should be your instance name)

p.s. = API version doesn't follow Server version, so it's ok



Hi Lapo:

I have made a simple example of using of advanced buddy list and still not working , I am using onBuddyPermissionRequest please man take a look to the code the buddy is added to the list the only problem is the request if you have some time please takae a look to the source the link is this:

http://www.eldervaz.com/sfs/Escritorio.zip


package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextField;
import it.gotoandplay.smartfoxserver.SmartFoxClient
import it.gotoandplay.smartfoxserver.SFSEvent
import it.gotoandplay.smartfoxserver.data.*


public class MyTest extends MovieClip
{
private var smartFox:SmartFoxClient
private const serverZone:String = "simpleChat"
private var yo:Cursor;

public function MyTest()
{
campo.text = "init\n";
// Create instance
smartFox = new SmartFoxClient( );
smartFox.debug = true;
trace(smartFox.getVersion() );

// Add event handler for connection
smartFox.addEventListener(SFSEvent.onConnection, onConnectionHandler)

// Connect to server
smartFox.connect("127.0.0.1", 9339)
//me logueo
smartFox.addEventListener(SFSEvent.onLogin, onLogin);
//ingreso al room
//veo a usuarios
smartFox.addEventListener(SFSEvent.onJoinRoom, onJoinRoom)
//muestro los room
smartFox.addEventListener(SFSEvent.onRoomListUpdate, onRoomListUpdate)
//actualiza nuevos usuarios
smartFox.addEventListener(SFSEvent.onUserEnterRoom, onUserEnterRoom)
//si abandona la sala
smartFox.addEventListener(SFSEvent.onUserLeaveRoom, onUserLeaveRoom)
smartFox.addEventListener(SFSEvent.onJoinRoomError, onJoinRoomError)

//actualiza variables
smartFox.addEventListener(SFSEvent.onUserVariablesUpdate, onUserVariablesUpdateHandler);


//permisos
smartFox.addEventListener(SFSEvent.onBuddyPermissionRequest, onBuddyPermissionRequestHandler)
smartFox.addEventListener(SFSEvent.onBuddyList, onBuddyListHandler)
smartFox.loadBuddyList()
smartFox.addEventListener(SFSEvent.onBuddyListUpdate, onBuddyListUpdateHandler)

}

private function ingresar(event:MouseEvent):void {
smartFox.login(serverZone, user_txt.text, "")
}

private function addBuddy(event:MouseEvent):void {
smartFox.addBuddy(nombre.text)
trace("\nagregando a ", nombre.text)
}

function onBuddyPermissionRequestHandler(evt:SFSEvent):void
{

trace( evt.params.sender, evt.params.message);
campo.appendText( "\nonBuddyPermissionRequestHandler" );
campo.appendText( "\n"+evt.params.sender+" - "+ evt.params.message+"\n" );
}


function onBuddyListHandler(evt:SFSEvent):void {
campo.appendText( "\nonBuddyListHandler" );
for (var b:String in evt.params.list)
{
var buddy:Object = evt.params.list[b]

campo.appendText("\nBuddy id: " + buddy.id)
campo.appendText("\nBuddy name: " + buddy.name)
campo.appendText("\nIs buddy online? " + buddy.isOnline ? "Yes" : "No")
campo.appendText("\nIs buddy blocked? " + buddy.isBlocked ? "Yes" : "No")
campo.appendText("\n--------------------------\n")

//campo.appendText("Buddy Variables:")
//for (var v:String in buddy.variables)
//campo.appendText("\n" + v + " --> " + buddy.variables[v])
}
}

function onBuddyListUpdateHandler(evt:SFSEvent):void
{
campo.appendText( "\nonBuddyListUpdateHandler" );
var buddy:Object = evt.params.buddy

var name:String = buddy.name
var status:String = (buddy.isOnline) ? "online" : "offline"

campo.appendText("\nBuddy " + name + " is currently " + status)
}

function onUserVariablesUpdateHandler(evt:SFSEvent):void
{
var changedVars:Array = evt.params.changedVars
//trace(changedVars["px"], true)
if (changedVars["px"] != null || changedVars["py"] != null)
{
//trace("User " + evt.params.user.getName() + " moved to new coordinates:")
yo.x = evt.params.user.getVariable("px")
yo.y = evt.params.user.getVariable("py")
yo.campo.text = evt.params.user.getName()
}

}
private function mover(evt:MouseEvent):void {

var vars:Object = new Object()
vars.px = stage.mouseX
vars.py = stage.mouseY
smartFox.setUserVariables(vars)
moverCaja(stage.mouseX, stage.mouseY );
}
private function moverCaja(X:Number, Y:Number):void {
yo.x = X
yo.y = Y
//trace(X, Y)
}


// Handle connection event
public function onConnectionHandler(evt:SFSEvent):void
{
if (evt.params.success){
trace("Great, successfully connected!\n")
//me logueo
//smartFox.login(serverZone, "eldervaz", "")
btn_login.addEventListener(MouseEvent.CLICK, ingresar);
btn_add.addEventListener(MouseEvent.CLICK, addBuddy);
//
}else{
trace("Ouch, connection failed!\n")
}
}



function onLogin(evt:SFSEvent):void
{
campo.appendText("ya toy logueado >>" + evt.params.success + "\n");
smartFox.loadBuddyList();

}
public function onJoinRoomError(evt:SFSEvent):void {
trace("ERROR LUSER");
}
public function onRoomListUpdate(evt:SFSEvent):void {
//trace("oki", evt.params.roomList);
var misSalas:Array = evt.params.roomList as Array;

for each(var r:Room in misSalas)
{
campo.appendText(r.getName() + " (" + r.getUserCount() + "/" + r.getMaxUsers() + ")"+"\n")
}


smartFox.autoJoin()

}
public function onJoinRoom(evt: SFSEvent):void {


var room:Room = evt.params.room as Room

trace("ME CONECTE!!!!!!!!!!");
campo.appendText( "Room " + room.getName() + " joined successfully" + "\n");

for each(var u:User in room.getUserList())
{
campo.appendText (u.getName()+" "+ u.getId() +"\n")
}

}
public function onUserEnterRoom(evt:SFSEvent):void {
//var room:Room = evt.params.room as Room
var u:User = evt.params.user as User
campo.appendText ("new user: " + u.getName() + " " + u.getId() + "\n" )


}
public function onUserLeaveRoom(evt:SFSEvent):void {
var userName :String = evt.params.userName as String;
campo.appendText("el usuario "+ userName + " abandono la sala XD"+"\n")
}
}
}



<Zone name="simpleChat" uCountUpdate="true" buddyList="4000" maxUsers="4000" customLogin="false">

<BuddyList active="true">
<size>500000000</size>
<maxBuddyVariables>6</maxBuddyVariables>
<mode>advanced</mode>
<addBuddyPermission>true</addBuddyPermission>
<offLineBuddyVariables>true</offLineBuddyVariables>
<mutualAddBuddy>true</mutualAddBuddy>
<mutualRemoveBuddy>true</mutualRemoveBuddy>
<permissionTimeOut>30</permissionTimeOut>
</BuddyList>



<Rooms>
<Room name="The Hall" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true" />
<Room name="The Kitchen" maxUsers="50" isPrivate="false" isGame="false" isTemp="false" />
<Room name="The Garden" maxUsers="50" isPrivate="false" isTemp="false" />
<Room name="The Bathroom" maxUsers="50" isPrivate="false" isTemp="false" />
<Room name="The Garage" maxUsers="50" isPrivate="false" isTemp="false" />
<Room name="The Living Room" maxUsers="50" isPrivate="true" isTemp="false" pwd="test" />
</Rooms>

<Extensions>
<extension name="json" className="jsonSample.as" type="script" />
</Extensions>

<Moderators status="on">
<Mod name="modName" pwd="modPass" />
</Moderators>
</Zone>


and debug

Code: Select all

1.5.3
[Sending]: <msg t='sys'><body action='loadB' r='-1'></body></msg>

[Sending]: <msg t='sys'><body action='verChk' r='0'><ver v='153' /></body></msg>

[ RECEIVED ]: <cross-domain-policy><allow-access-from domain='*' to-ports='9339' /></cross-domain-policy>, (len: 91)
[ RECEIVED ]: <msg t='sys'><body action='apiOK' r='0'></body></msg>, (len: 53)
Great, successfully connected!

[Sending]: <msg t='sys'><body action='login' r='0'><login z='simpleChat'><nick><![CDATA[marco]]></nick><pword><![CDATA[]]></pword></login></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='logOK' r='0'><login n='marco' id='3' mod='0'/></body></msg>, (len: 86)
[Sending]: <msg t='sys'><body action='loadB' r='-1'></body></msg>

[Sending]: <msg t='sys'><body action='getRmList' r='-1'></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='bList' r='-1'><bList><b s='1' i='2' x='0'><n><![CDATA[eldervaz]]></n></b></bList></body></msg>, (len: 121)
[ RECEIVED ]: <msg t='sys'><body action='rmList' r='0'><rmList><rm id='34' priv='0' temp='0' game='0' ucnt='0' maxu='50' maxs='0'><n><![CDATA[The Kitchen]]></n></rm><rm id='35' priv='0' temp='0' game='0' ucnt='0' maxu='50' maxs='0'><n><![CDATA[The Garden]]></n></rm><rm id='33' priv='0' temp='0' game='0' ucnt='1' maxu='50' maxs='0'><n><![CDATA[The Hall]]></n></rm><rm id='38' priv='1' temp='0' game='0' ucnt='0' maxu='50' maxs='0'><n><![CDATA[The Living Room]]></n></rm><rm id='36' priv='0' temp='0' game='0' ucnt='0' maxu='50' maxs='0'><n><![CDATA[The Bathroom]]></n></rm><rm id='37' priv='0' temp='0' game='0' ucnt='0' maxu='50' maxs='0'><n><![CDATA[The Garage]]></n></rm></rmList></body></msg>, (len: 683)
[Sending]: <msg t='sys'><body action='autoJoin' r='-1'></body></msg>

[ RECEIVED ]: <msg t='sys'><body action='joinOK' r='33'><pid id='0'/><vars /><uLs r='33'><u i='2' m='0'><n><![CDATA[eldervaz]]></n><vars></vars></u><u i='3' m='0'><n><![CDATA[marco]]></n><vars></vars></u></uLs></body></msg>, (len: 209)
ME CONECTE!!!!!!!!!!
[ RECEIVED ]: <msg t='sys'><body action='uCount' r='33' u='2'></body></msg>, (len: 61)
[ RECEIVED ]: <msg t='sys'><body action='userGone' r='33'><user id='2' /></body></msg>, (len: 72)
[ RECEIVED ]: <msg t='sys'><body action='uCount' r='33' u='1'></body></msg>, (len: 61)
[ RECEIVED ]: <msg t='sys'><body action='bUpd' r='-1'><b s='0' i='-1'><n><![CDATA[eldervaz]]></n></b></body></msg>, (len: 100)
[ RECEIVED ]: <msg t='sys'><body action='uER' r='33'><u i ='4' m='0'><n><![CDATA[q1]]></n><vars></vars></u></body></msg>, (len: 106)
[ RECEIVED ]: <msg t='sys'><body action='uCount' r='33' u='2'></body></msg>, (len: 61)
[Sending]: <msg t='sys'><body action='addB' r='-1'><n>q1</n></body></msg>


agregando a  q1
[ RECEIVED ]: <msg t='sys'><body action='bAdd' r='-1'><b s='1' i='4'><n><![CDATA[q1]]></n></b></body></msg>, (len: 93)

Posted: 17 Mar 2008, 17:15
by Lapo
Thanks for the zip, we'll look into it as soon as possible
stay tuned :)

Posted: 18 Mar 2008, 08:25
by Lapo
I've checked the example and it works for me.
I think you have an error in the Zone declaration:

Code: Select all

<Zone name="simpleChat" uCountUpdate="true" buddyList="4000" maxUsers="4000" customLogin="false">
         
         <BuddyList active="true">
            <size>500000000</size>
            <maxBuddyVariables>6</maxBuddyVariables>
            <mode>advanced</mode>
            <addBuddyPermission>true</addBuddyPermission>
            <offLineBuddyVariables>true</offLineBuddyVariables>
            <mutualAddBuddy>true</mutualAddBuddy>
            <mutualRemoveBuddy>true</mutualRemoveBuddy>
            <permissionTimeOut>30</permissionTimeOut>
         </BuddyList>


You are declaring the buddy-list twice using both the old way (buddy-list 1.0) and the new way (buddy-list 2.0)

Please remove the buddyList="4000" attribute from the Zone definition and everything should be running fine.

Hope it helps