Player.IO is the next version of the Nonoba Developer Tools.
More Features, No Branding, Integrates with Everything. Read more »
Class NonobaGameUser
Namespace: Nonoba.GameLibrary
Language: C# / (.NET)
NonobaGameUser is the base class for a player connected to a game instance.
For example, here is a simple, bare bones player implementation that doesn't contain anything.
using System;
using Nonoba.GameLibrary;
namespace MyGame {
// This class represents a user connected to our game
public class MyPlayer : NonobaGameUser {
}
}
Public Virtual Methods
Methods you can override if you want.
Dictionary<string,string> GetDebugValues()
Called by the development server in order to display debug data about the user.
Public Properties
int UserId
An unique id for this connected player for the entire lifetime of the game. Useful for
identifying one player from another in messages sent between the clients and the server.
bool IsGuest
Whether the connected player is a guest or a registered Nonoba user.
string Username
The username of the player. Guest-[guestname] is returned for guests.
Gender Gender
The Gender of the connected player. Gender.Unknown is returned for guests.
string ProfileUrl
A url to the player's profile. An empty string is returned for guests.
string SmallAvatar
A url to the player's small avatar image (width:20px, height:20px). An empty string is returned for guests.
string Avatar
A url to the players avatar image (width:60px, height:72px). An empty string is returned for guests.
string LargeAvatar
A url to the player's large avatar image (width:100px, height:120px). An empty string is returned for guests.
uint PlayerLevel
The Nonoba player level of the player. 0 is returned for guests.
uint? DeveloperLevel
The Nonoba developer level of the player. null is returned for guests and non developers.
Public Methods
void Send(params Message[] messages)
Send one or more messages to the player.
void Send(string type, params object[] parameters)
Sends one message to the player.
string GetData(string key, string nullFallback)
Gets the persistant user data stored under the given key, falling back to nullFallback if no value has been saved.
void SetData(string key, string value)
Sets the persistant user data stored under the key to the specified value.
uint AwardAchievement(string key)
Awards the user the achievement identified by the given key.
void SubmitHighscore(string key, int score)
Submits a score to the highscore list identified by the key.
void SubmitRankingDelta(string key, int delta)
Adds a ranking delta value to the ranking list identified by the key.
void SetRankingScore(string key, int score)
Sets the ranking value of the player in the ranking list identified by the key to the specified score.
void GetRankingScore(string key)
Gets the current ranking score of the player in the ranking list identified by the key
Send method
void Send(params Message[] messages)
Sends one or more messages to the player. The params keyword indicates that you can send any number of messages in one call.
Example// send one message to everybody player.Send(new Message("hi",1,2,3)) // send two messages to everybody player.Send(new Message("hello"), new Message("world"))
Send method
void Send(string type, params object[] paramters)
Sends one message to the player with an arbitrary number of arguments. The params keyword indicates that you can send any number of messages in one call.
Example
public override void UserJoined(Player player) {
// send one message to the player upon joining the game
player.Send("hi",1,"strings are okay also",true)
}
GetData method
string GetData(string key, string nullFallback)
Loads data specific to the player from the persistent data storage for the game. If the player is registered on Nonoba, the data will be persisted between games, and available whenever the player is logged into Nonoba.
Example
public override void UserJoined(Player player) {
// load whether the user has played the game before or not.
string hasPlayedGameBefore = player.GetData("hasplayedbefore","no")
if( hasPlayedGameBefore == "no"){
// user hasn't played the game before.
}
// save that the user has played the game.
player.SetData("hasplayedbefore","yes")
}
SetData method
void SetData(string key, string value)
Saves data specific to the player in the persistent data storage for the game. If the player is registered on Nonoba, the data will be persisted between games, and available whenever the player is logged into Nonoba.
For each user and game you can store several different key/value pairs on the server.
If you call this method with a key that already exists, the existing value will be overwritten.
Example
public override void UserJoined(Player player) {
// load whether the user has played the game before or not.
string hasPlayedGameBefore = player.GetData("hasplayedbefore","no")
if( hasPlayedGameBefore == "no"){
// user hasn't played the game before.
}
// save that the user has played the game.
player.SetData("hasplayedbefore","yes")
}
AwardAchievement method
uint AwardAchievement(string key)
Award an achievement to the user. Before you can award an achievement in your game, you must have set up one or more achievements on the game management page.
Returns the amount of times the user has received the achievement.
Example
public override void GetMessage(Player player, Message m) {
if( m.Type=="givemeachievement" ){
// award the player the achievement "easyachievement"
player.AwardAchievement("easyachievement");
}
}
SubmitHighscore method
void SubmitHighscore(string key, int score)
Submits a score to the Nonoba score system.
Before you can submit a highscore, you must have set up one or more highscore lists on the game management page.
player.SubmitHighscore("score",12345);
SubmitRankingDelta method
void SubmitRankingDelta(string key, int delta)
Adds a ranking delta value to the ranking list identified by the key
When submitting to a ranking list, the score will be added to the user's current score and thereby possibly change the rank. If you submit a negative value, you will lower the user's current score.
Before you can submit a ranking delta, you must have set up one or more ranking lists on the game management page.
player.SubmitRankingDelta("kills",3); // give the user 3 more points
player.SubmitRankingDelta("money",-3); // take 3 of the users money
SetRankingScore method
void SetRankingScore(string key, int score)
Sets the ranking value of the player in the ranking list identified by the key to the specified score.
Before you can set a ranking value, you must have set up one or more ranking lists on the game management page.
player.SetRankingScore("speed",100);
GetRankingScore method
int GetRankingScore(string key)
Gets the players current value on a ranking list. If the player has never received a score on the ranking list, the default value for the ranking list is returned.
int kills = player.GetRankingScore("kills"); // gets the amount of kills the user has
Enum Gender
Gender is an enum that is defined as follows:
public enum Gender {
Female = 0,
Male = 1,
Unknown = 2
}