aboutsummaryrefslogtreecommitdiffstats
path: root/src/Client.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client.hx')
-rw-r--r--src/Client.hx49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/Client.hx b/src/Client.hx
index e44417a..7aa14c5 100644
--- a/src/Client.hx
+++ b/src/Client.hx
@@ -5,33 +5,70 @@ import js.npm.ws.WebSocket;
#elseif js
import js.html.WebSocket;
#end
+import haxe.EnumFlags;
+
+enum ClientGroup {
+ User;
+ Leader;
+ Admin;
+}
typedef ClientData = {
name:String,
- isLeader:Bool
+ group:Int
}
class Client {
+ #if nodejs
public final ws:WebSocket;
+ public final id:Int;
+ #end
public var name:String;
- public var isLeader:Bool;
+ public var group:EnumFlags<ClientGroup>;
+ public var isLeader(get, set):Bool;
+ public var isAdmin(get, set):Bool;
- public function new(?ws:WebSocket, name:String, isLeader = false) {
+ public function new(?ws:WebSocket, ?id:Int, name:String, group:Int) {
+ #if nodejs
this.ws = ws;
+ this.id = id;
+ #end
this.name = name;
- this.isLeader = isLeader;
+ this.group = new EnumFlags(group);
+ }
+
+ inline function get_isLeader():Bool {
+ return group.has(Leader);
+ }
+
+ inline function set_isLeader(flag:Bool):Bool {
+ return setGroupFlag(Leader, flag);
+ }
+
+ inline function get_isAdmin():Bool {
+ return group.has(Admin);
+ }
+
+ inline function set_isAdmin(flag:Bool):Bool {
+ return setGroupFlag(Admin, flag);
+ }
+
+ function setGroupFlag(type:ClientGroup, flag:Bool):Bool {
+ if (flag) group.set(type);
+ else group.unset(type);
+ return flag;
}
public function getData():ClientData {
return {
name: name,
- isLeader: isLeader
+ group: group.toInt()
}
}
public static function fromData(data:ClientData):Client {
- return new Client(data.name, data.isLeader);
+ return new Client(data.name, data.group);
}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage