这是indexloc提供的服务,不要输入任何密码
Skip to content
Benedikt Ringlein edited this page Jan 13, 2018 · 3 revisions

Welcome to the smartdice wiki!

You can jump right to one of the topics:

Models

The django built-in ORM is used for persisting objects. Four models are defined:

  • GameSession: SessionUser active_user
  • SessionUser: str name, GameSession session
  • RollResult: DateTime time, str mode, str value, SessionUser user, GameSession session
  • SmartDice: int dice_number, GameSession session, str mode

Everything is connected to the session. That is why the first step in using the application is to either create or join a session. The relevant users, results and devices can then be easily retrieved.

All the information present in an active game session is in the database. That means, at any time someone can join the session and get all information from the session, including all previous roll results.

All information about the session is removed, when a session is deleted by the users.

Views

Method based views are used. These views are available:

url description
/ Display main page with options to create or join a session
/session/newsession Create and join a new session
/session/<session_id> Display a session (sessionid is also accepted as POST parameter)
/session/<session_id>/endsession Exit and remove a session
/session/<session_id>/adduser Add a new user to a session. POST params: username
/session/<session_id>/removeuser/<user_id> Remove a user from the session (also removed their rolls)
/session/<session_id>/activateuser/<user_id> Make a user the 'active' user
/session/<session_id>/adddice Add a smartdice to the session. POST params: dice_number
/session/<session_id>/removedice/<dice_id> Remove a smartdice from the session
/session/<session_id>/selectdicemode/<dice_id> Change a smartdices mode

Communication

Communication with the smartdice devices happens trough a mqtt broker. Eclipse paho is used as a mqtt client. The following topic structure is used:

topic description
smartdice/<dice_number>/roll The smartdice publishes an (empty) event, when a roll should be executed
smartdice/<dice_number>/setmode A smartdice pushes mode changes to the application (so it can change its behavior)
smartdice/<dice_number>/getmode The application pushes mode changes to a smartdice (so it can adjust the LEDs)
smartdice/<dice_number>/battery The smartdice can push its battery status to the webapp

The two mode topics enable the mode to be set either on the device with a physical button or in the webapp. The hierarchical topic structure enables the webapp to easily listen to all smartdicerelated events and selectively listen to events from one device or all events of a certain type.

Websockets

Clients refresh automatically, when a change is made to a session (e.g. a user was added or a dice roll was made). To do so, each client is connected to the backend with a websocket. This websocket is used to send an update event to the clients which reload the page. Like this, the page always stays up to date without the need of constant polling. Note that this could be further improved by only loading changes in the client, instead of the whole page. Django channels is used for the websocket functionality.

Security

The security needs of this application are rather low. The dice rolls are executed by the webapplication and can not be manipulated in any meaningful way. The application is intendet to only be used for games. It is expected that no sensitive or personal data will be used. The risk of attacks is very low, since there is not much to gain when the application is used in its intended usecase.

Clone this wiki locally