Forum C# Broadcast for not a specific player

Broadcast for not a specific player

Postby prsolucoes » March 23rd, 2010, 3:42 am

Hi,

I have seen in other librarys that they have a nice method that we can call Broadcast too, but with more one parameter, so can be a overload method for playerio, that send a message for all player but not for a specific player passed by parameter. Example:

The method can be:

Code: Select all
public void Broadcast(int playerId, string type, params object[] parameters)
{
    foreach (Player p in Players)
    {
        if (player.Id != playerId)
        {
            //send the message
        }
    }
}


and/or

Code: Select all
public void Broadcast(int playerId, Message m)
{
    foreach (Player p in Players)
    {
        if (player.Id != playerId)
        {
            //send the message
            player.send(m);
        }
    }
}



This will help when i need send some information for other players and not for a player that send a message for the server.
Example:

1 - We have Player A, B, C, D, E
2 - Player A is GM and he send the command: "/killall"
3 - The method "killall" is received by the server and execute:
Code: Select all
Broadcast("DISCONNECT_FROM_SERVER");

4 - All the clients will receive the message, and the GM too :)
5 - If i have the command that i suggest, i can use:
Code: Select all
Broadcast(player.id, "DISCONNECT_FROM_SERVER");

6 - And only the GM not receive the message

This is simple example, it can help my life and the others developers too, because we dont need player a loop and after send the message to a specific player, i need use much more code to make it and more process.

What playerio team think about?
prsolucoes
 
Posts: 47
Joined: March 18th, 2010, 3:20 pm

Re: Broadcast for not a specific player

Postby Toby » March 23rd, 2010, 12:32 pm

I'd rather the broadcast call had an extra (optional) parameter for an array of players which it would ignore than have a single user ID.

I've had a similar function on most of my C# solutions. It would be nice if it was actually built into the IO API though.
User avatar
Toby
 
Posts: 86
Joined: January 14th, 2010, 4:01 pm

Re: Broadcast for not a specific player

Postby Oliver » March 23rd, 2010, 7:51 pm

Not a bad idea. I'll put it in the suggested features list.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Broadcast for not a specific player

Postby default0 » March 29th, 2010, 11:01 pm

Maybe even being able to exclude players which dont meet a condition.

f.e.:
Broadcast("somemsg", {level==1, ...});

so it would broadcast the message to everyone who isn't on level 1 or doesnt meet the other expectations ;)

Best regards
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany

Re: Broadcast for not a specific player

Postby prsolucoes » March 30th, 2010, 7:16 am

Hi...

This is something that i need now too.

I need broadcast the message for only players that is in the same map of me.

Can be (default0):
Code: Select all
Broadcast("MOVE_PLAYER", {map:"map1", ...});


Or:

like this: conditions.add({"player_attribute", "condition", "value"});


Code: Select all
ArrayList conditions = new ArrayList();
conditions.add({"map", "=", "map1"});
conditions.add({"level", ">=", "5"});

Broadcast("MOVE_PLAYER", conditions);


Thx.
prsolucoes
 
Posts: 47
Joined: March 18th, 2010, 3:20 pm


Return to C#



cron