author | koda |
Tue, 15 Oct 2013 01:15:39 +0200 | |
changeset 9543 | 1826b5315369 |
parent 7691 | 55c0a856ecd0 |
child 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 { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
public static final char FLAG_ADMIN = 'a'; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
public static final char FLAG_CHIEF = 'h'; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
public static final char FLAG_READY = 'r'; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
public static final char FLAG_REGISTERED = 'u'; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
public final String nick, flags; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
public final boolean newFlagState; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
public ClientFlagsUpdate(String nick, String flags, boolean newFlagState) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
this.nick = nick; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
this.flags = flags; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
this.newFlagState = newFlagState; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
public Player applyTo(Player p) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
return new Player( |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
p.name, |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
updatedFlag(FLAG_REGISTERED, p.registered), |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
updatedFlag(FLAG_ADMIN, p.admin)); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
public PlayerInRoom applyTo(PlayerInRoom p) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
return new PlayerInRoom( |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
this.applyTo(p.player), |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
updatedFlag(FLAG_READY, p.ready), |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
updatedFlag(FLAG_CHIEF, p.roomChief)); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
public boolean appliesTo(char flag) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
return flags.indexOf(flag) != -1; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
private boolean updatedFlag(char flag, boolean oldValue) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
return appliesTo(flag) ? newFlagState : oldValue; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
|
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
@Override |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
public String toString() { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
return "ClientFlagsUpdate [nick=" + nick + ", flags=" + flags |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
+ ", newFlagState=" + newFlagState + "]"; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
} |