aboutsummaryrefslogtreecommitdiffstats
path: root/src/ClientTools.hx
blob: 5da23c4dadd254577d496876fde2b247ab359a91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package;

class ClientTools {
	public static function setLeader(clients:Array<Client>, name:String):Void {
		for (client in clients) {
			if (client.name == name) client.isLeader = true;
			else if (client.isLeader) client.isLeader = false;
		}
	}

	public static function hasLeader(clients:Array<Client>):Bool {
		return getLeader(clients) != null;
	}

	public static function getLeader(clients:Array<Client>):Null<Client> {
		for (client in clients) {
			if (client.isLeader) return client;
		}
		return null;
	}

	public static function getByName(
		clients:Array<Client>, name:String, ?def:Client
	):Null<Client> {
		for (client in clients) {
			if (client.name == name) return client;
		}
		return def;
	}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage