muc.vala
author Stiletto <blasux@blasux.ru>
Tue, 23 Oct 2012 18:33:49 +0400
changeset 2 4e050075fab9
parent 1 76caf6a3f413
child 3 dd7a02c6d476
permissions -rw-r--r--
Level of stubbornness skyrocketed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     1
abstract class Module : Object {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     2
    protected weak Config cfg;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     3
    protected weak Connection conn;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     4
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     5
    public Module(Config cfg, Connection conn) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     6
        this.cfg = cfg;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     7
        this.conn = conn;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     8
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     9
    public abstract string name();
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    10
}
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    11
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    12
class ModuleMuc : Module {
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
    13
    public static const string NS_MUC_USER = "http://jabber.org/protocol/muc#user";
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
    14
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    15
    public enum Affiliation {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    16
        NONE,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    17
        OUTCAST,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    18
        MEMBER,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    19
        ADMIN,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    20
        OWNER
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    21
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    22
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    23
    public enum Role {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    24
        NONE,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    25
        VISITOR,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    26
        PARTICIPANT,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    27
        MODERATOR
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    28
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    29
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    30
    static Role role_from_string(string role) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    31
        switch (role) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    32
            case "moderator": return Role.MODERATOR; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    33
            case "participant": return Role.PARTICIPANT; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    34
            case "visitor": return Role.VISITOR; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    35
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    36
        return Role.NONE;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    37
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    38
    static Affiliation affil_from_string(string affil) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    39
        switch (affil) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    40
            case "owner": return Affiliation.OWNER; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    41
            case "admin": return Affiliation.ADMIN; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    42
            case "member": return Affiliation.MEMBER; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    43
            case "outcast": return Affiliation.OUTCAST; break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    44
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    45
        return Affiliation.NONE;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    46
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    47
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    48
    public class Occupant : Object {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    49
        public weak Conference conference;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    50
        public string nick;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    51
        public string real_jid;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    52
        public Affiliation affil;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    53
        public Role role;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    54
        public bool isme;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    55
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    56
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    57
    public enum State {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    58
        CONNECTED,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    59
        DISCOVERING,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    60
        CONNECTING,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    61
        DISCONNECTING,
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    62
        DISCONNECTED
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    63
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    64
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    65
    public signal void state_changed(Conference conf, State old_state, State new_state, string description);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    66
    public signal void on_join(Conference conf, Occupant occupant);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    67
    public signal void on_part(Conference conf, Occupant occupant);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    68
    public signal void on_role(Conference conf, Occupant occupant, Role prev);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    69
    public signal void on_affil(Conference conf, Occupant occupant, Affiliation prev);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    70
    public signal void on_nick(Conference conf, Occupant occupant, string prev);
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
    71
    public signal void on_message(Conference conf, Occupant occupant, Lm.MessageNode message, string body);
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    72
    public signal void on_subject(Conference conf);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    73
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    74
    public class Conference : Object {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    75
        public string jid;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    76
        public string nick;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    77
        public string desired_nick;
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
    78
        public bool enabled;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    79
        public string subject;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    80
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    81
        protected State _state;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    82
        public Time time;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    83
        public State state { get { return _state; } }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    84
        public Gee.HashMap<string,Occupant> occupants;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    85
        protected string presence_join_id;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    86
        protected weak ModuleMuc module;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    87
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    88
        protected void _change_state(State new_state, string description) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    89
            var old_state = this._state;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    90
            if (old_state != new_state) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    91
                this._state = new_state;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    92
                stderr.printf("MUC State changed %s -> %s : %s\n",old_state.to_string(), new_state.to_string(), description);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    93
                module.state_changed(this, old_state, new_state, description);
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
    94
                if (new_state == State.DISCONNECTED)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
    95
                    occupants.clear();
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    96
            } else
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    97
                stderr.printf("MUC State not changed %s : %s\n",old_state.to_string(), description);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    98
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    99
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   100
        public Conference(ModuleMuc module, string jid) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   101
            this.module = module;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   102
            var section = "muc "+jid;
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   103
            this.desired_nick = module.cfg.get_default(section,"nick",module.cfg.get_default("muc","nick",Random.next_int().to_string()));
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   104
            this.nick = this.desired_nick;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   105
            this.jid = jid;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   106
            this._state = State.DISCONNECTED;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   107
            this.occupants = new Gee.HashMap<string,Occupant>();
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   108
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   109
        public void join(string desc) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   110
            if (_state == State.DISCONNECTED) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   111
                var prs = new Lm.Message(jid+"/"+desired_nick, Lm.MessageType.PRESENCE);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   112
                presence_join_id = jid+"_"+Random.next_int().to_string();
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   113
                prs.node.set_attribute("id",presence_join_id);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   114
                prs.node.add_child("x",null).set_attribute("xmlns","http://jabber.org/protocol/muc");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   115
                module.conn.cn.send(prs);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   116
                nick = desired_nick;
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   117
                _change_state(State.CONNECTING, "requested to join: "+desc);
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   118
            }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   119
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   120
        
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   121
        public Lm.HandlerResult muc_handler(Lm.MessageHandler handler, Lm.Connection connection, Lm.Message message) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   122
            var node = message.node;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   123
            var from = node.get_attribute("from").split("/",2);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   124
            stdout.printf("MUC<%s>: %s\n",this.jid,node.to_string());
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   125
            var type = node.get_attribute("type");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   126
            if (message.get_type()==Lm.MessageType.PRESENCE) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   127
                switch (type) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   128
                    case null:
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   129
                    case "unavailable":
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   130
                        if (from.length==2) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   131
                            var statuses = new Gee.HashSet<int>();
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   132
                            var occupant = occupants[from[1]];
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   133
                            var affil = Affiliation.NONE;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   134
                            var role = Role.NONE;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   135
                            string prs_nick = null;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   136
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   137
                            var chn = node.children;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   138
                            while (chn != null) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   139
                                switch (chn.name) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   140
                                    
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   141
                                    case "x":
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   142
                                        switch (chn.get_attribute("xmlns")) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   143
                                            case NS_MUC_USER:
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   144
                                                var child = chn.children;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   145
                                                while (child != null) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   146
                                                    stdout.printf("Child %s %s\n", child.name, child.get_attribute("code"));
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   147
                                                    if (child.name == "status") {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   148
                                                        var code = child.get_attribute("code");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   149
                                                        if (code!=null)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   150
                                                            statuses.add(code.to_int());
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   151
                                                    }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   152
                                                    child = child.next;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   153
                                                }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   154
                                                var item = chn.get_child("item");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   155
                                                if (item == null)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   156
                                                    log("Muc", LogLevelFlags.LEVEL_ERROR, "Your MUC server is shit. No role and affiliation info in presences: %s", node.to_string());
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   157
                                                affil = affil_from_string(item.get_attribute("affiliation"));
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   158
                                                role = role_from_string(item.get_attribute("role")); 
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   159
                                                prs_nick = item.get_attribute("nick");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   160
                                                break;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   161
                                        }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   162
                                        break;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   163
                                }
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   164
                                chn = chn.next;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   165
                            }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   166
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   167
                            if (statuses.contains(110) && (_state == State.CONNECTED))
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   168
                                log("Muc", LogLevelFlags.LEVEL_INFO, "Joined a room which I was already in: %s", from[0]);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   169
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   170
                            if (occupant != null) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   171
                                if (role == Role.NONE) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   172
                                    occupants.unset(from[1]);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   173
                                    log("Muc", LogLevelFlags.LEVEL_INFO, "MUC<%s> %s has parted.", this.jid, from[1]);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   174
                                    module.on_part(this, occupant);
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   175
                                    if (occupant.isme) {
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   176
                                        _change_state(State.DISCONNECTED, "we became unavailable");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   177
                                    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   178
                                } else {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   179
                                    if (affil != occupant.affil) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   180
                                        var prev = occupant.affil;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   181
                                        occupant.affil = affil;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   182
                                        module.on_affil(this, occupant, prev);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   183
                                    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   184
                                    if (role != occupant.role) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   185
                                        var prev = occupant.role;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   186
                                        occupant.role = role;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   187
                                        module.on_role(this, occupant, prev);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   188
                                    }
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   189
                                    if (statuses.contains(303) && (prs_nick!=null)) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   190
                                        occupants[prs_nick] = occupant;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   191
                                        occupants.unset(from[1]);
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   192
                                        occupant.nick = prs_nick;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   193
                                        module.on_nick(this, occupant, from[1]);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   194
                                    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   195
                                }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   196
                            } else {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   197
                                assert( role!= Role.NONE);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   198
                                occupant = new Occupant();
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   199
                                occupant.role = role;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   200
                                occupant.affil = affil;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   201
                                occupant.nick = from[1];
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   202
                                occupants[from[1]] = occupant;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   203
                                occupant.isme = statuses.contains(110);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   204
                                log("Muc", LogLevelFlags.LEVEL_INFO, "MUC<%s> %s has joined as %s/%s.", this.jid, from[1], affil.to_string(), role.to_string());
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   205
                                if (statuses.contains(110)) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   206
                                    this.nick = from[1];
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   207
                                    _change_state(State.CONNECTED, "got own presence. we are "+this.nick);
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   208
                                }
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   209
                                module.on_join(this, occupant);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   210
                            }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   211
                            
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   212
                            stdout.printf("User list: ");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   213
                            foreach (var a in occupants.keys)
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   214
                                stdout.printf("%s <%s,%s>, ", a, occupants[a].affil.to_string(), occupants[a].role.to_string());
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   215
                            stdout.printf("\n");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   216
                        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   217
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   218
                        break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   219
                    case "error":
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   220
                        if ((from.length==1)||(node.get_attribute("id")==presence_join_id)) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   221
                            _change_state(State.DISCONNECTED, node.get_child("error").to_string());
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   222
                            return Lm.HandlerResult.ALLOW_MORE_HANDLERS;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   223
                        } else if (from.length==2) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   224
                            //if (from[1]==this.nick) 
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   225
                        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   226
                        break;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   227
                }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   228
            } else if ((message.get_type()==Lm.MessageType.MESSAGE)&&(type=="groupchat")) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   229
                var subj = node.get_attribute("subject");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   230
                if (subj != null) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   231
                    if (subj != this.subject) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   232
                        this.subject = subj;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   233
                        module.on_subject(this);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   234
                    }
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   235
                } else {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   236
                    var occupant = (from.length > 1) ? occupants[from[1]] : null;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   237
                    var body = node.find_child("body");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   238
                    module.on_message(this, occupant, node, (body!=null) ? body.get_value() : null);
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   239
                }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   240
            }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   241
            return Lm.HandlerResult.ALLOW_MORE_HANDLERS;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   242
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   243
        public void part(string desc) {
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   244
            if (_state != State.DISCONNECTED) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   245
                var prs = new Lm.Message(jid+"/"+desired_nick, Lm.MessageType.PRESENCE);
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   246
                presence_join_id = jid+"_"+Random.next_int().to_string();
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   247
                prs.node.set_attribute("type","unavailable");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   248
                prs.node.add_child("x",null).set_attribute("xmlns","http://jabber.org/protocol/muc");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   249
                module.conn.cn.send(prs);
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   250
                nick = desired_nick;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   251
            }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   252
        }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   253
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   254
        public void connection_lost() {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   255
            _change_state(State.DISCONNECTED, "connection lost");
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   256
        }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   257
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   258
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   259
    public override string name() { return "muc"; }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   260
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   261
    public Gee.HashMap<string,Conference> rooms;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   262
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   263
    public ModuleMuc(Config cfg, Connection conn) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   264
        base(cfg,conn);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   265
        this.rooms = new Gee.HashMap<string,Conference>();
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   266
        
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   267
        var muc_handler = new Lm.MessageHandler((handler, connection, message) => {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   268
            var node = message.node;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   269
            var from = node.get_attribute("from");
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   270
            if (from != null) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   271
                var froms = from.split("/",2);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   272
                if (rooms.has_key(froms[0])) {
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   273
                    return rooms[froms[0]].muc_handler(handler, connection, message);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   274
                }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   275
            }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   276
            return Lm.HandlerResult.ALLOW_MORE_HANDLERS;
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   277
        }, null);
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   278
        var names = cfg.get_default("muc","mucs","").split(" ");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   279
        foreach (var name in names) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   280
            var room = new Conference(this, name); //, "Ζαλυπα");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   281
            //room.join("Oh hai");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   282
            room.enabled = true;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   283
            this.rooms[room.jid] = room;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   284
        }
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   285
        conn.cn.register_message_handler(muc_handler, Lm.MessageType.MESSAGE, Lm.HandlerPriority.NORMAL);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   286
        conn.cn.register_message_handler(muc_handler, Lm.MessageType.PRESENCE, Lm.HandlerPriority.NORMAL);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   287
        conn.cn.register_message_handler(muc_handler, Lm.MessageType.IQ, Lm.HandlerPriority.NORMAL);
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   288
        conn.state_changed.connect( (olds, news, desc) => {
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   289
            switch (news) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   290
                case Connection.State.CONNECTED:
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   291
                    break;
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   292
                case Connection.State.DISCONNECTED:
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   293
                    foreach(var room in rooms.values)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   294
                        room.connection_lost();
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   295
                    break;
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   296
            }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   297
        });
2
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   298
        conn.check_time.connect( () => {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   299
            if (conn.state == Connection.State.CONNECTED)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   300
                foreach (var room in rooms.values) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   301
                    if (room.enabled) {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   302
                        if (room.state == State.DISCONNECTED)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   303
                            room.join("Reconnect");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   304
                    } else {
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   305
                        if (room.state == State.CONNECTED)
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   306
                            room.part("Disabled");
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   307
                    }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   308
                }
4e050075fab9 Level of stubbornness skyrocketed
Stiletto <blasux@blasux.ru>
parents: 1
diff changeset
   309
        });
1
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   310
    }
76caf6a3f413 Somehow compiles and even joins a conference
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   311
}