Class AbstractPlayerDatabase<T>
Interface that defines all operations that are available on the database. Also provides singleton behavior. To swap databases you can create a new subclass of this class. Any subclasses must expose a PUBLIC constructor and subclass this class with your new class as a type parameter. This constructor will throw an exception if called. Always use the Instance property.
SQLitePlayerDatabase implements this for SQLite. Use it as a reference for your subclass.
Inherited Members
Namespace: LlamaSoftware.Chat
Assembly: LlamaSoftware.Chat.dll
Syntax
public abstract class AbstractPlayerDatabase<T>
where T : AbstractPlayerDatabase<T>, new()
Type Parameters
Name | Description |
---|---|
T |
Constructors
AbstractPlayerDatabase()
Throws an System.InvalidOperationException if constructing an instance and we have already initialized. Indicative of trying to create instances via a new SubClass() call instead of using Instance property.
Declaration
protected AbstractPlayerDatabase()
Properties
Instance
Instance of this singleton. Use this instead of trying to call new SubClass();
Declaration
public static T Instance { get; }
Property Value
Type | Description |
---|---|
T |
KnownPlayerSubscriptions
This is a map from player id -> player for only online players. Do not directly modify this - use the utility functions provided in this singleton
Declaration
public Dictionary<string, Player> KnownPlayerSubscriptions { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, Player> |
Methods
AddPlayer(Player)
Adds player to list of known online players. If player with existing ConnectionId is found, the old one will be removed and replaced with the new one.
Declaration
public virtual void AddPlayer(Player Player)
Parameters
Type | Name | Description |
---|---|---|
Player | Player | Player to add to KnownPlayerSubscriptions |
FindBlockedPlayersFor(String)
Retrieves all blocked players by a given PlayerId.
Declaration
public abstract List<Player> FindBlockedPlayersFor(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | PlayerId of the player whose block list you want to retrieve. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Player> | A List of count 0 or more of all blocked players for the provided PlayerId. |
FindFriendsFor(String)
Retrieves all friends of a given PlayerId.
Declaration
public abstract List<Player> FindFriendsFor(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | PlayerId of the player to find friends for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Player> | A List of count 0 or more of all friends for the provided PlayerId. |
FindPlayerByConnectionId(Int32)
Finds an Online player by
This is particularly useful for finding a player in response to a
Returns null if no online player exists with that id.
Declaration
public virtual Player FindPlayerByConnectionId(int ConnectionId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ConnectionId |
Returns
Type | Description |
---|---|
Player | Matching player, or null if they are not found. |
FindPlayersWhoAreBlockedBy(String)
Finds all players who are blocked by a given PlayerId.
Particularly useful to find out who should not receive messages.
Declaration
public abstract List<Player> FindPlayersWhoAreBlockedBy(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | PlayerId of the player to find blocked players of. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Player> |
FindPlayersWhoHaveFriend(String)
Searches the database for all players who have this player id listed as a friend.
This is particularly useful to notify players when a player goes offline / comes online
Declaration
public abstract List<Player> FindPlayersWhoHaveFriend(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | PlayerId to find friends of. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Player> | A List of count 0 or more of all players who have this person on their friends list. |
FindSubscribedChannelsFor(String)
Retrieves all ChatChannels a given PlayerId is subscribed to. Used on player creation to re-enter them into their previous channels. Global channels like World, General, Trade, or Guild, for example.
SavePlayerChatSettings(Player) will store this information.
Declaration
public abstract List<ChatChannel> FindSubscribedChannelsFor(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | PlayerId of the player to get ChatChannels for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<ChatChannel> | A list of count 0 or more Chat Channels the given player is subscribed to. |
LookupPlayer(String)
Retrieves an ONLINE player by id. Returns null if player is offline.
Declaration
public virtual Player LookupPlayer(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | Unique player id to retrieve |
Returns
Type | Description |
---|---|
Player | Fully instantiated Player |
RemovePlayer(Player)
Removes a player from the KnownPlayerSubscriptions dictionary. This is done by PlayerId.
Behaves the exact same as RemovePlayer(String).
Declaration
public virtual void RemovePlayer(Player Player)
Parameters
Type | Name | Description |
---|---|---|
Player | Player | Player to remove |
RemovePlayer(String)
Removes a player from the KnownPlayerSubscriptions dictionary.
Convenience method for RemovePlayer(Player) if you only have a PlayerId
Declaration
public virtual void RemovePlayer(string PlayerId)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerId | PlayerId to remove. |
SavePlayerChatSettings(Player)
Saves the player's friends list, block list, and subscribed channels to the database. Any data that needs to be persisted across sessions should be saved here.
Declaration
public abstract void SavePlayerChatSettings(Player Player)
Parameters
Type | Name | Description |
---|---|---|
Player | Player | Fully initialized player to save data for |