author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 07 Mar 2018 18:23:21 +0100 | |
changeset 13092 | 422e20b577e2 |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7691
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
package org.hedgewars.hedgeroid.netplay; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
import org.hedgewars.hedgeroid.Datastructures.Player; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
final class ClientFlagsUpdate { |
10017 | 7 |
public static final char FLAG_ADMIN = 'a'; |
8 |
public static final char FLAG_CHIEF = 'h'; |
|
9 |
public static final char FLAG_READY = 'r'; |
|
10 |
public static final char FLAG_REGISTERED = 'u'; |
|
11 |
||
12 |
public final String nick, flags; |
|
13 |
public final boolean newFlagState; |
|
14 |
||
15 |
public ClientFlagsUpdate(String nick, String flags, boolean newFlagState) { |
|
16 |
this.nick = nick; |
|
17 |
this.flags = flags; |
|
18 |
this.newFlagState = newFlagState; |
|
19 |
} |
|
20 |
||
21 |
public Player applyTo(Player p) { |
|
22 |
return new Player( |
|
23 |
p.name, |
|
24 |
updatedFlag(FLAG_REGISTERED, p.registered), |
|
25 |
updatedFlag(FLAG_ADMIN, p.admin)); |
|
26 |
} |
|
7691
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
|
10017 | 28 |
public PlayerInRoom applyTo(PlayerInRoom p) { |
29 |
return new PlayerInRoom( |
|
30 |
this.applyTo(p.player), |
|
31 |
updatedFlag(FLAG_READY, p.ready), |
|
32 |
updatedFlag(FLAG_CHIEF, p.roomChief)); |
|
33 |
} |
|
34 |
||
35 |
public boolean appliesTo(char flag) { |
|
36 |
return flags.indexOf(flag) != -1; |
|
37 |
} |
|
38 |
||
39 |
private boolean updatedFlag(char flag, boolean oldValue) { |
|
40 |
return appliesTo(flag) ? newFlagState : oldValue; |
|
41 |
} |
|
42 |
||
43 |
@Override |
|
44 |
public String toString() { |
|
45 |
return "ClientFlagsUpdate [nick=" + nick + ", flags=" + flags |
|
46 |
+ ", newFlagState=" + newFlagState + "]"; |
|
47 |
} |
|
7691
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
} |