project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ClientFlagsUpdate.java
author Wuzzy <Wuzzy2@mail.ru>
Sun, 07 Apr 2019 19:26:16 +0200
changeset 14755 ab7bf5036314
parent 10017 de822cd3df3a
permissions -rw-r--r--
Render mine timer if gear info is active
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     7
    public static final char FLAG_ADMIN = 'a';
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     8
    public static final char FLAG_CHIEF = 'h';
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     9
    public static final char FLAG_READY = 'r';
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    10
    public static final char FLAG_REGISTERED = 'u';
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    11
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    12
    public final String nick, flags;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    13
    public final boolean newFlagState;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    14
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    15
    public ClientFlagsUpdate(String nick, String flags, boolean newFlagState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    16
        this.nick = nick;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    17
        this.flags = flags;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    18
        this.newFlagState = newFlagState;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    19
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    20
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    21
    public Player applyTo(Player p) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    22
        return new Player(
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    23
                p.name,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    24
                updatedFlag(FLAG_REGISTERED, p.registered),
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    25
                updatedFlag(FLAG_ADMIN, p.admin));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    26
    }
7691
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    28
    public PlayerInRoom applyTo(PlayerInRoom p) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    29
        return new PlayerInRoom(
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    30
                this.applyTo(p.player),
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    31
                updatedFlag(FLAG_READY, p.ready),
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    32
                updatedFlag(FLAG_CHIEF, p.roomChief));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    33
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    34
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    35
    public boolean appliesTo(char flag) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    36
        return flags.indexOf(flag) != -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    37
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    38
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    39
    private boolean updatedFlag(char flag, boolean oldValue) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    40
        return appliesTo(flag) ? newFlagState : oldValue;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    41
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    42
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    43
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    44
    public String toString() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    45
        return "ClientFlagsUpdate [nick=" + nick + ", flags=" + flags
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    46
                + ", newFlagState=" + newFlagState + "]";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    47
    }
7691
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
}