C# Class WebSocketServer.CardServer

Implements a single Poker Server instance, with various game functions / game data storage.
Mostra file Open project: qJake/planning-poker Class Usage Examples

Public Methods

Method Description
BeginNewRound ( string title ) : bool

Begins a new round.

BroadcastClientList ( ) : void

Sends the most recent client list to all of the clients.

BroadcastError ( Client origin, string source, string message, bool sendBack = false ) : void

Broadcasts an error message to all clients. If an origin is specified, the message is not re-broadcast back to the origin.

BroadcastGameState ( ) : void

Broadcasts the current game state to each of the connected clients.

BroadcastMessage ( Client origin, string message ) : void

Broadcasts a JSON message to all clients. If an origin is specified, the message is not re-broadcast back to the origin.

CardServer ( string adminPass ) : System.Collections.Generic

Initializes a new instance of the CardServer class, with the specified admin password.

DiscardActiveRound ( ) : void

Discards the active round and all of its associted data.

GetRoundState ( ) : Newtonsoft.Json.Linq.JObject

Compiles the state of the current round and serializes it as a JObject.

GetSetting ( string key, string defaultValue ) : string

Retrieves a setting, or returns the default value if the setting doesn't exist.

NewClient ( WebSocketConnection conn ) : void

Accepts a new WebSocketConnection object and creates a new game Client based on it.

RegisterAdmin ( Client c, string pass ) : bool

Attempts to register the specified client as an admin using the specified password. This checks against the server password, and will return true if the password was correct (and the client was elevated to an admin), otherwise it returns false.

RegisterVote ( Client c, string vote ) : bool

Registers a new vote for the specified client, with the specified vote value.

RemoveClient ( Client c ) : void

Removes the specified client from the game, usually due to a disconnect. This also cleans up their votes and other game data.

SortCards ( ) : bool

Sorts the cards from lowest to highest using the VoteComparer class.

UndoVote ( Client c ) : bool

Removes a vote that the client previously registered.

UpdateSetting ( string name, string value ) : void

Helper method to update a setting with a value, or add it if it doesn't exist yet.

Private Methods

Method Description
AutoSortOnFlip ( ) : void

Helper method; when called, if the "AutoSort" setting is on, this will flip the cards.

CheckVoteCount ( ) : void

Checks if everyone who is logged in, and is playing, has voted. If so, after a 1s delay, the cards are flipped.

Method Details

BeginNewRound() public method

Begins a new round.
public BeginNewRound ( string title ) : bool
title string The title of the new round.
return bool

BroadcastClientList() public method

Sends the most recent client list to all of the clients.
public BroadcastClientList ( ) : void
return void

BroadcastError() public method

Broadcasts an error message to all clients. If an origin is specified, the message is not re-broadcast back to the origin.
public BroadcastError ( Client origin, string source, string message, bool sendBack = false ) : void
origin Client Optionally, a client origin which the error will not be broadcast back to. Set to null to broadcast to every client.
source string The source of the error.
message string The error message to broadcast.
sendBack bool Whether or not to send the error back to the origin client or not.
return void

BroadcastGameState() public method

Broadcasts the current game state to each of the connected clients.
public BroadcastGameState ( ) : void
return void

BroadcastMessage() public method

Broadcasts a JSON message to all clients. If an origin is specified, the message is not re-broadcast back to the origin.
public BroadcastMessage ( Client origin, string message ) : void
origin Client Optionally, a client origin which the message will not be broadcast back to. Set to null to broadcast to every client.
message string The message to broadcast.
return void

CardServer() public method

Initializes a new instance of the CardServer class, with the specified admin password.
public CardServer ( string adminPass ) : System.Collections.Generic
adminPass string The admin password for this game.
return System.Collections.Generic

DiscardActiveRound() public method

Discards the active round and all of its associted data.
public DiscardActiveRound ( ) : void
return void

GetRoundState() public method

Compiles the state of the current round and serializes it as a JObject.
public GetRoundState ( ) : Newtonsoft.Json.Linq.JObject
return Newtonsoft.Json.Linq.JObject

GetSetting() public method

Retrieves a setting, or returns the default value if the setting doesn't exist.
public GetSetting ( string key, string defaultValue ) : string
key string The key of the setting to retrieve.
defaultValue string The default value, if the setting was not found in the store.
return string

NewClient() public method

Accepts a new WebSocketConnection object and creates a new game Client based on it.
public NewClient ( WebSocketConnection conn ) : void
conn WebSocketConnection The connection to use for the new client.
return void

RegisterAdmin() public method

Attempts to register the specified client as an admin using the specified password. This checks against the server password, and will return true if the password was correct (and the client was elevated to an admin), otherwise it returns false.
public RegisterAdmin ( Client c, string pass ) : bool
c Client The client requesting administrative priveleges.
pass string The password that the client provided, to be checked against the actual password for the server.
return bool

RegisterVote() public method

Registers a new vote for the specified client, with the specified vote value.
public RegisterVote ( Client c, string vote ) : bool
c Client The client who voted.
vote string The value of the vote.
return bool

RemoveClient() public method

Removes the specified client from the game, usually due to a disconnect. This also cleans up their votes and other game data.
public RemoveClient ( Client c ) : void
c Client The client to remove.
return void

SortCards() public method

Sorts the cards from lowest to highest using the VoteComparer class.
public SortCards ( ) : bool
return bool

UndoVote() public method

Removes a vote that the client previously registered.
public UndoVote ( Client c ) : bool
c Client The client whose vote to remove.
return bool

UpdateSetting() public method

Helper method to update a setting with a value, or add it if it doesn't exist yet.
public UpdateSetting ( string name, string value ) : void
name string The name (or key) of the setting.
value string The value of the setting.
return void