+ Reply to Thread
Results 1 to 4 of 4

Thread: room level plugin for creating user variables

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    room level plugin for creating user variables

    Hi, is there any way to get a room level plugin to create user variables?
    I've been using the userEnter method from basePlugin to see when users connect to the room. Now I need to add a user variable to the user that enters the room, is it possible to do this directly from within the room level plugin?

    Thanks

  2. #2
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    Yes, you can do this. I would strongly suggest not doing it completely inside the userEnter method, but you could call a method that then does a scheduledCallback for 1 ms later that does it. This puts it in a separate thread, which helps keep your plugin running smoothly.

    Your code for actually doing the user variable would look like this:
    Code:
    UserVariableResponse uvr = getApi().createOrUpdateUserVariable(userName, nameOfVariable, esob);
    These user variables will be seen by all users in the room, and a hacker could modify the client to change the user variable. For most games, it's better to store info that a hacker could ruin the game by changing on the server only, and have the plugin broadcast the info to the room when it changes. I normally create a Java object class called PlayerInfo, then have the game plugin maintain a ConcurrentHashMap<String, PlayerInfo> where the key is the username. Another alternative is to use UserPluginVariable or one of the other server-side-only variables that get attached to users.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    does the class UserVariableResponse mean that I have to actually make a request from the client for uvr to be assigned a value?

    If I were to use UserPluginVariable, how would I do this?

    What I'm trying to do is have every user that enters the room get a numeric value between 1 and 5 (my gamemanager is setup for max. 5 users). So I'm using a Stack, but I'm not sure how to assign these values, the UserPluginVariable seems like an interesting idea

  4. #4
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    The plugin gets the UserVariableResponse, and then you can look at that response to make sure it's successful.

    To use a user plugin variable, you create any Java Object you want to hold the data (or if it's just your numbers from 1 to 5 you could use Integer). Let's assume that you create a PlayerInfo object class. To set it you use something like this:
    Code:
    PlayerInfo pInfo = new PlayerInfo(... whatever the parameters are....);
    getApi().setUserPluginVariable(userName, varName, pInfo);
    Then to get it back again later:
    Code:
    PlayerInfo pInfo = (PlayerInfo) getApi().getUserPluginVariable(userName, varName);
    This is if you want to be able to look up a user's value. If your game needs to be able to look up who is the user with value of 3, then you would need a data structure instead, unless you wanted to iterate through all the users in the room until you found the right one.
    Last edited by tcarr; 07-23-2010 at 10:08 PM. Reason: typo
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  5. The Following User Says Thank You to tcarr For This Useful Post:

    danielrc (07-26-2010)

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts