1 |
pcg |
1.1 |
package room; |
2 |
|
|
|
3 |
pcg |
1.11 |
use KGS::Constants; |
4 |
|
|
|
5 |
pcg |
1.1 |
use base KGS::Listener::Room; |
6 |
pcg |
1.17 |
|
7 |
|
|
use Glib::Object::Subclass |
8 |
pcg |
1.19 |
Gtk2::Frame; |
9 |
pcg |
1.1 |
|
10 |
|
|
sub new { |
11 |
pcg |
1.17 |
my ($self, %arg) = @_; |
12 |
root |
1.27 |
|
13 |
pcg |
1.17 |
$self = $self->Glib::Object::new; |
14 |
|
|
$self->{$_} = delete $arg{$_} for keys %arg; |
15 |
|
|
|
16 |
pcg |
1.18 |
$self->signal_connect (destroy => sub { |
17 |
|
|
delete $::config->{rooms}{$self->{channel}}; |
18 |
|
|
delete $self->{app}{room}{$self->{channel}}; |
19 |
|
|
(remove Glib::Source delete $self->{gameupdate}) if $self->{gameupdate}; |
20 |
|
|
$self->unlisten; |
21 |
|
|
%{$_[0]} = (); |
22 |
|
|
}); |
23 |
pcg |
1.1 |
|
24 |
pcg |
1.17 |
$self->listen ($self->{conn}, qw(msg_room:)); |
25 |
pcg |
1.1 |
|
26 |
pcg |
1.17 |
$self->signal_connect (delete_event => sub { $self->part; 1 }); |
27 |
pcg |
1.1 |
|
28 |
pcg |
1.19 |
$self->add (my $hbox = new Gtk2::HBox); |
29 |
pcg |
1.1 |
|
30 |
pcg |
1.19 |
$hbox->pack_start ((my $vbox = new Gtk2::VBox), 1, 1, 0); |
31 |
pcg |
1.1 |
|
32 |
root |
1.31 |
$vbox->add ($self->{chat} = new chat app => $self->{app}); |
33 |
pcg |
1.1 |
|
34 |
root |
1.28 |
$self->{chat}->signal_connect (command => sub { |
35 |
pcg |
1.15 |
my ($chat, $cmd, $arg) = @_; |
36 |
pcg |
1.16 |
$self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self); |
37 |
pcg |
1.1 |
}); |
38 |
|
|
|
39 |
pcg |
1.19 |
$hbox->pack_start ((my $vbox = new Gtk2::VBox), 0, 1, 0); |
40 |
|
|
|
41 |
root |
1.24 |
$vbox->pack_start ((my $button = new_with_label Gtk2::Button "Leave"), 0, 1, 0); |
42 |
pcg |
1.19 |
$button->signal_connect (clicked => sub { $self->part }); |
43 |
|
|
|
44 |
|
|
$vbox->pack_start ((my $button = new_with_label Gtk2::Button "New Game"), 0, 1, 0); |
45 |
|
|
$button->signal_connect (clicked => sub { $self->new_game }); |
46 |
|
|
|
47 |
|
|
$vbox->pack_start ((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0); |
48 |
root |
1.27 |
$sw->set_policy ("automatic", "always"); |
49 |
pcg |
1.1 |
|
50 |
pcg |
1.17 |
$sw->add ($self->{userlist} = new userlist); |
51 |
pcg |
1.1 |
|
52 |
|
|
$self; |
53 |
|
|
} |
54 |
|
|
|
55 |
pcg |
1.17 |
sub FINALIZE_INSTANCE { print "FIN room\n" } # never called MEMLEAK #d#TODO# |
56 |
pcg |
1.1 |
|
57 |
|
|
sub part { |
58 |
|
|
my ($self) = @_; |
59 |
root |
1.30 |
|
60 |
|
|
$self->hide; |
61 |
pcg |
1.1 |
$self->SUPER::part; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
sub inject_msg_room { |
65 |
|
|
my ($self, $msg) = @_; |
66 |
|
|
|
67 |
pcg |
1.7 |
# secret typoe ;-) |
68 |
root |
1.29 |
$self->{chat}->append_text ("\n<user>" . (util::toxml $msg->{name}) |
69 |
|
|
. "</user>: " . (util::toxml $msg->{message})); |
70 |
pcg |
1.1 |
} |
71 |
|
|
|
72 |
|
|
sub event_update_users { |
73 |
pcg |
1.5 |
my ($self, $add, $update, $remove) = @_; |
74 |
pcg |
1.1 |
|
75 |
pcg |
1.5 |
$self->{userlist}->update ($add, $update, $remove); |
76 |
pcg |
1.1 |
} |
77 |
|
|
|
78 |
|
|
sub event_update_games { |
79 |
pcg |
1.5 |
my ($self, $add, $update, $remove) = @_; |
80 |
pcg |
1.1 |
|
81 |
pcg |
1.14 |
$self->{app}{gamelist}->update ($self, $add, $update, $remove); |
82 |
pcg |
1.20 |
|
83 |
|
|
# try to identify any new games assigned to us. stupid protocol |
84 |
|
|
# first updates the game, joins you and THEN tells you that |
85 |
|
|
# which of the games you asked for this is. |
86 |
|
|
|
87 |
|
|
for (@$add) { |
88 |
pcg |
1.23 |
if (($_->{black}{name} eq $self->{conn}{name} |
89 |
|
|
|| $_->{white}{name} eq $self->{conn}{name} |
90 |
|
|
|| $_->{owner}{name} eq $self->{conn}{name}) |
91 |
|
|
&& (my $game = shift @{$self->{new_game}})) { |
92 |
pcg |
1.20 |
$game->inject_upd_game ({ game => $_ }); |
93 |
|
|
$game->set_channel ($game->{channel}); |
94 |
|
|
} |
95 |
|
|
} |
96 |
pcg |
1.1 |
} |
97 |
|
|
|
98 |
|
|
sub event_join { |
99 |
|
|
my ($self) = @_; |
100 |
|
|
$self->SUPER::event_join; |
101 |
|
|
|
102 |
pcg |
1.4 |
$::config->{rooms}{$self->{channel}} = { channel => $self->{channel}, name => $self->{name} }; |
103 |
pcg |
1.11 |
|
104 |
|
|
# mysteriously enough, we have to request game updates manually |
105 |
|
|
$self->{gameupdate} ||= add Glib::Timeout INTERVAL_GAMEUPDATES * 1000, sub { |
106 |
|
|
$self->req_games; |
107 |
|
|
1; |
108 |
|
|
}; |
109 |
pcg |
1.17 |
|
110 |
|
|
$self->show_all; |
111 |
pcg |
1.11 |
} |
112 |
|
|
|
113 |
|
|
sub event_part { |
114 |
|
|
my ($self) = @_; |
115 |
pcg |
1.13 |
|
116 |
pcg |
1.11 |
$self->SUPER::event_part; |
117 |
pcg |
1.17 |
$self->destroy; |
118 |
pcg |
1.1 |
} |
119 |
|
|
|
120 |
root |
1.26 |
sub event_quit { |
121 |
|
|
my ($self) = @_; |
122 |
|
|
|
123 |
|
|
$self->SUPER::event_quit; |
124 |
|
|
$self->destroy; |
125 |
|
|
} |
126 |
|
|
|
127 |
pcg |
1.1 |
sub event_update_roominfo { |
128 |
|
|
my ($self) = @_; |
129 |
|
|
|
130 |
pcg |
1.15 |
$self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n" |
131 |
pcg |
1.10 |
. "<description>" . (util::toxml $self->{description}) . "</description>\n"); |
132 |
pcg |
1.11 |
} |
133 |
|
|
|
134 |
pcg |
1.19 |
sub new_game { |
135 |
|
|
my ($self) = @_; |
136 |
|
|
|
137 |
pcg |
1.20 |
my $game = new game conn => $self->{conn}, app => $self->{app}, roomid => $self->{channel}; |
138 |
root |
1.25 |
$game->new_game_challenge; |
139 |
pcg |
1.20 |
$game->show_all; |
140 |
|
|
|
141 |
|
|
push @{$self->{new_game}}, $game; |
142 |
pcg |
1.19 |
} |
143 |
|
|
|
144 |
pcg |
1.1 |
1; |
145 |
|
|
|