19 |
19 |
20 public State state { |
20 public State state { |
21 get { return _state; } |
21 get { return _state; } |
22 } |
22 } |
23 |
23 |
24 public Module[] modules; |
24 public Gee.ArrayList<Module> modules; |
25 |
25 |
26 public signal void state_changed(State old_state, State new_state, string description); |
26 public signal void state_changed(State old_state, State new_state, string description); |
27 public signal void check_time(); |
27 public signal void check_time(); |
28 protected void _change_state(State new_state, string description) { |
28 protected void _change_state(State new_state, string description) { |
29 var old_state = this._state; |
29 var old_state = this._state; |
34 } else |
34 } else |
35 stderr.printf("State not changed %s : %s\n",old_state.to_string(), description); |
35 stderr.printf("State not changed %s : %s\n",old_state.to_string(), description); |
36 } |
36 } |
37 |
37 |
38 public Connection(Config cfg) { |
38 public Connection(Config cfg) { |
39 this.modules = new Module[10]; |
39 this.modules = new Gee.ArrayList<Module>(); |
40 this.jid = cfg["server","jid"]; |
40 this.jid = cfg["server","jid"]; |
41 this.password = cfg["server","password"]; |
41 this.password = cfg["server","password"]; |
42 |
42 |
43 this.server = cfg.get_default("server", "server", this.jid.split("@",2)[1]); |
43 this.server = cfg.get_default("server", "server", this.jid.split("@",2)[1]); |
44 |
44 |
79 return Lm.HandlerResult.ALLOW_MORE_HANDLERS; |
79 return Lm.HandlerResult.ALLOW_MORE_HANDLERS; |
80 }, null); |
80 }, null); |
81 cn.register_message_handler(muc_handler, Lm.MessageType.MESSAGE, Lm.HandlerPriority.NORMAL); |
81 cn.register_message_handler(muc_handler, Lm.MessageType.MESSAGE, Lm.HandlerPriority.NORMAL); |
82 cn.register_message_handler(muc_handler, Lm.MessageType.PRESENCE, Lm.HandlerPriority.NORMAL); |
82 cn.register_message_handler(muc_handler, Lm.MessageType.PRESENCE, Lm.HandlerPriority.NORMAL); |
83 cn.register_message_handler(muc_handler, Lm.MessageType.IQ, Lm.HandlerPriority.NORMAL);*/ |
83 cn.register_message_handler(muc_handler, Lm.MessageType.IQ, Lm.HandlerPriority.NORMAL);*/ |
84 var module = new ModuleMuc(cfg, this); |
|
85 modules = {module}; |
|
86 state_changed.connect( (olds, news, desc) => { |
84 state_changed.connect( (olds, news, desc) => { |
87 if (news == Connection.State.CONNECTED) { |
85 if (news == Connection.State.CONNECTED) { |
88 cn.send_raw("<message to='stiletto@stiletto.name'><body>ТХБ</body></message>"); |
86 cn.send_raw("<message to='stiletto@stiletto.name'><body>ТХБ</body></message>"); |
89 /*var room = new Conference(this, "говнохост@conference.blasux.ru", "Ζαλυπα"); |
87 /*var room = new Conference(this, "говнохост@conference.blasux.ru", "Ζαλυπα"); |
90 room.join("Oh hai"); |
88 room.join("Oh hai"); |
124 } catch (Error e) { |
125 } catch (Error e) { |
125 stderr.printf("Error: %s\n", e.message); |
126 stderr.printf("Error: %s\n", e.message); |
126 _change_state(State.DISCONNECTED, e.message); |
127 _change_state(State.DISCONNECTED, e.message); |
127 } |
128 } |
128 } |
129 } |
129 |
130 public void close() { |
|
131 cn.close(); |
|
132 } |
130 } |
133 } |
131 |
134 |
|
135 |
|
136 static Connection account; |
|
137 static MainLoop loop; |
132 |
138 |
133 int main(string[] args) { |
139 int main(string[] args) { |
134 if (args.length<2) { |
140 if (args.length<2) { |
135 stderr.printf("Usage: %s <config file>\n",args[0]); |
141 stderr.printf("Usage: %s <config file>\n",args[0]); |
136 return 1; |
142 return 1; |
137 } |
143 } |
138 Log.set_handler("Muc", (LogLevelFlags)65535, (domain, levels, message) => { |
144 Log.set_handler("Muc", (LogLevelFlags)65535, (domain, levels, message) => { |
139 stderr.printf("--- %s\n", message); |
145 stderr.printf("--- %s\n", message); |
140 }); |
146 }); |
|
147 Log.set_handler("muc_log", (LogLevelFlags)65535, (domain, levels, message) => { |
|
148 stderr.printf("--- %s\n", message); |
|
149 }); |
141 log("LM", LogLevelFlags.LEVEL_DEBUG, "HATE HATE"); |
150 log("LM", LogLevelFlags.LEVEL_DEBUG, "HATE HATE"); |
142 var cfg = new Config.from_file(args[1]); |
151 var cfg = new Config.from_file(args[1]); |
143 var loop = new MainLoop(); |
152 loop = new MainLoop(); |
144 var account = new Connection(cfg); |
153 account = new Connection(cfg); |
145 //account.open(); |
154 //account.open(); |
146 stdout.printf("Fuck yeah\n"); |
155 stdout.printf("Fuck yeah\n"); |
147 var checktimer = new TimeoutSource(2000); |
156 var checktimer = new TimeoutSource(2000); |
148 checktimer.set_callback(() => { |
157 checktimer.set_callback(() => { |
149 account.check_time(); |
158 account.check_time(); |
150 //stderr.printf("TimeoutSource OLOLO\n"); |
159 //stderr.printf("TimeoutSource OLOLO\n"); |
151 return true; |
160 return true; |
152 }); |
161 }); |
153 checktimer.attach(loop.get_context()); |
162 checktimer.attach(loop.get_context()); |
|
163 |
|
164 account.add_module(new ModuleMuc(cfg, account)); |
|
165 account.add_module(new ModuleMucLog(cfg, account)); |
|
166 |
|
167 Posix.sigaction_t action = Posix.sigaction_t(); |
|
168 action.sa_handler = ((i) => { |
|
169 if (account.state != Connection.State.CONNECTED) |
|
170 loop.quit(); |
|
171 else { |
|
172 account.state_changed.connect( (olds, news, desc) => { |
|
173 if (news == Connection.State.DISCONNECTED) |
|
174 loop.quit(); |
|
175 }); |
|
176 account.close(); |
|
177 } |
|
178 }); |
|
179 Posix.sigaction(Posix.SIGINT, action, null); |
|
180 |
154 loop.run(); |
181 loop.run(); |
155 return 0; |
182 return 0; |
156 } |
183 } |