- Implemented `setUsername(string username)`
- Implemented `getStatus()`
- Added status field

Status

- Added new enum
This commit is contained in:
Tristan B. Velloza Kildaire 2023-11-18 13:53:48 +02:00
parent b14f338695
commit dac50c74c6
1 changed files with 46 additions and 0 deletions

View File

@ -2,9 +2,18 @@ module renaissance.server.users;
import core.sync.mutex : Mutex;
public enum Status
{
ONLINE,
OFFLINE,
INVISIBLE,
AWAY
}
public struct User
{
private string username;
private Status status;
private Mutex lock;
@disable
@ -16,10 +25,47 @@ public struct User
}
// TODO: Disallow parameter less construction?
public bool setUsername(string username)
{
// Username cannot be empty (TODO: Have a regex check)
if(username.length == 0)
{
return false;
}
// Lock
this.lock.lock();
// Set the username
this.username = username;
// Unlock
this.lock.unlock();
return true;
}
public Status getStatus()
{
Status status;
// Lock
this.lock.lock();
// Get the status
status = this.status;
// Unlock
this.lock.unlock();
return status;
}
}
unittest
{
User u = User("deavmi");
}