Update al users with UserManager plugin

Questions and answers on developing, deploying and using plugins and JavaBeans

Update al users with UserManager plugin

Postby irene.meyer » Wed Jan 14, 2015 3:55 pm

Hello,

I'm developing a game.app that shows the state of some objects by color (e.g state 1 = green, 2 = yellow etc...). The users are asked to make some choices on some objects and when they are finished they have to check a field. As soon as the last user finish the round a global method is fired to update the objects in the game. After that I try to fire another method to update the colors for every user and sends a message that they can begin with the second round.

I tried to do the last with the UserManager plugin, but when we tested the game the interface was updated only in the last user (the one who fires the method) and he got also 4 times the message instead of one.

Code: Select all
//if all players are finished
      if (datasetarrayU.getMaxRowIndex() == 4)
      {   
         var serverName = databaseManager.getDataSourceServerName(forms.game_objects1.controller.getDataSource());
         var noyears = forms.game_settings.set_no_years;
         //updates the objects
         globals.markovCode(serverName,noyears);
         
         //updates the game and send a message to every user
         // Returns all clients an execute the script
         var vClients = plugins.UserManager.getClients()
         var len = vClients.length
         for (var i = 1; i<=len; i++)
         {
            var clientID = vClients[0].clientId
            application.output(clientID);
            var client = plugins.UserManager.getClientByUID(clientID)
            client.executeMethod(globals.updateClients);
            client.sendMessage('please start a new round.')            
         }
         }
      
         else
         {
            var title = "";
            var message = i18n.getI18NMessage('i18n:ssg.not.all.players.finished');
            var btn1 = i18n.getI18NMessage('i18n:ssg.ok');
            plugins.dialogs.showInfoDialog(title, message, btn1);
            
         }


Do I miss something in my code or is this not the right way?
irene.meyer
 
Posts: 5
Joined: Tue Feb 11, 2014 3:38 pm

Re: Update al users with UserManager plugin

Postby patrick » Wed Jan 14, 2015 4:15 pm

First of all, your loop is completely wrong. You are always getting the first client (you always request vClients[0]!). Second you ask for the clients twice. First when you ask getClients(), then in your loop when you call getClientByUID(clientID). That's unnecessary. getClients() already gives you all the clients. Change it to:

Code: Select all
var vClients = plugins.UserManager.getClients()
for (var i = 0; i < vClients .length; i++)
{
    var client = vClients [i];
    client.executeMethod(globals.updateClients);
    client.sendMessage('please start a new round.')           
}


Note that this will only work in smart clients!
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Update al users with UserManager plugin

Postby irene.meyer » Wed Jan 14, 2015 4:31 pm

Ok, now I feel like an idiot :oops: ! I shouldn't work so late at night.

But thank you Patrik
irene.meyer
 
Posts: 5
Joined: Tue Feb 11, 2014 3:38 pm

Re: Update al users with UserManager plugin

Postby amcgilly » Thu Aug 25, 2016 11:02 am

Patrick,

You mention above that executeMethod() only works for smart clients. Is there any way to make client.executeMethod() work when the client is a headless client (batch processor)?
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Update al users with UserManager plugin

Postby patrick » Tue Aug 30, 2016 4:19 pm

The last time I checked on this the API was only implemented for smart clients, so I suppose the answer is no.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Update al users with UserManager plugin

Postby rafig » Tue Sep 27, 2016 10:04 pm

Hi Patrick,
patrick wrote:The last time I checked on this the API was only implemented for smart clients, so I suppose the answer is no.

I want to be able to use 'executeMethod' on web clients, is there any way to do that, or do you have another way of doing that? (I have a server side batch process running that I want to fire a method for each active web client)

Thanks

Rafi
Servoy Certified Developer
Image
rafig
 
Posts: 704
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 12 guests