Class LoginController
Note this is in LlamaSoftware.Chat.Demo namespace so it works in the demo but may require modification to work in your game. Specifically, database management should be much more complex than this. This Controller is meant to provide the concept of what needs to be done, and can be utilized as a base, but does not handle all the nuances that need to be handled in a production application.
Inheritance
Inherited Members
Namespace: LlamaSoftware.Chat.Demo
Assembly: LlamaSoftware.Chat.Demo.dll
Syntax
public class LoginController : NetworkBehaviour
Fields
Connection
Declaration
protected SqliteConnection Connection
Field Value
Type | Description |
---|---|
Mono.Data.Sqlite.SqliteConnection |
InGameUICanvas
Declaration
[SerializeField]
protected Canvas InGameUICanvas
Field Value
Type | Description |
---|---|
UnityEngine.Canvas |
LOGIN_CHANNEL
Network channel to send Login messages on.
Declaration
public const short LOGIN_CHANNEL = 998
Field Value
Type | Description |
---|---|
System.Int16 |
LoginDemoUI
Declaration
[SerializeField]
protected GameObject LoginDemoUI
Field Value
Type | Description |
---|---|
UnityEngine.GameObject |
PathToDatabase
Path to the database file. If you update this, you will also probably want to update it in SQLitePlayerDatabase.cs.
Declaration
[SerializeField]
[Tooltip("Path to the database file.\nIf you update this, you will also probably want to update it in SQLitePlayerDatabase.cs.")]
protected string PathToDatabase
Field Value
Type | Description |
---|---|
System.String |
PlayerControllerId
Declaration
protected short PlayerControllerId
Field Value
Type | Description |
---|---|
System.Int16 |
REGISTER_USER_CHANNEL
Network channel to send Register User messages on.
Declaration
public const short REGISTER_USER_CHANNEL = 999
Field Value
Type | Description |
---|---|
System.Int16 |
Methods
ClientHandleRegisterUser(NetworkMessage)
Response processor for receiving RegisterUserResponseMessage messages. If Message is not SUCCESS it's assumed to be an error message.
Declaration
[Client]
protected virtual void ClientHandleRegisterUser(NetworkMessage message)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Networking.NetworkMessage | message |
ClientHandleUserLogin(NetworkMessage)
Response processor for LoginResponseMessage messages. If Message is not SUCCESS it's assumed to be an error message.
Declaration
[Client]
protected virtual void ClientHandleUserLogin(NetworkMessage message)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Networking.NetworkMessage | message |
CreatePlayerFromRow(SqliteDataReader, NetworkMessage, Boolean)
Note this assumes 1 character per account. If you would like to support multiple characters, then you'll need to:
- Create a new table mapping characters to login table in the database like: create table character( ID INTEGER PRIMARY KEY AUTOINCREMENT, ACCOUNT_ID INTEGER, CHARACTER_NAME TEXT NOT NULL, -- whatever else... FOREIGN KEY (ACCOUNT_ID) REFERENCES login(ID) );
- On successful login, do query the characters and display them somehow to allow the user to select which one they want to start playing as
- Send a new NetworkMessage(similar to LoginMessage, maybe just with the CharacterId)
- Add a Handler on Client and Server to handle that message, where this function is called to create the player, and Client does whatever they need on success.
Declaration
[Server]
protected virtual void CreatePlayerFromRow(SqliteDataReader reader, NetworkMessage message, bool isCreateAccount)
Parameters
Type | Name | Description |
---|---|---|
Mono.Data.Sqlite.SqliteDataReader | reader | |
UnityEngine.Networking.NetworkMessage | message | |
System.Boolean | isCreateAccount |
HandleRegisterUser(NetworkMessage)
Server request processor for RegisterPlayerMessages. Validates there's not already a user with the same email then sends a RegisterUserResponseMessage with SUCCESS if successful, otherwise Message is an error message.
Declaration
[Server]
protected virtual void HandleRegisterUser(NetworkMessage message)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Networking.NetworkMessage | message | Network Message |
HandleUserLogin(NetworkMessage)
Server request processor to handle existing users logging in. Checks email/password from the LoginMessage against the database and sends a LoginResponseMessage to the calling client.
Declaration
[Server]
protected virtual void HandleUserLogin(NetworkMessage message)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Networking.NetworkMessage | message | Network Message |
OnStartClient()
Registers client handlers for RegisterUserResponseMessage and LoginResponseMessage.
Declaration
public override void OnStartClient()
Overrides
OnStartServer()
Declaration
public override void OnStartServer()