ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/room.pl
(Generate patch)

Comparing kgsueme/kgsueme/room.pl (file contents):
Revision 1.22 by pcg, Sun May 30 05:04:09 2004 UTC vs.
Revision 1.30 by root, Wed Jun 2 09:32:32 2004 UTC

7use Glib::Object::Subclass 7use Glib::Object::Subclass
8 Gtk2::Frame; 8 Gtk2::Frame;
9 9
10sub new { 10sub new {
11 my ($self, %arg) = @_; 11 my ($self, %arg) = @_;
12
12 $self = $self->Glib::Object::new; 13 $self = $self->Glib::Object::new;
13 $self->{$_} = delete $arg{$_} for keys %arg; 14 $self->{$_} = delete $arg{$_} for keys %arg;
14 15
15 $self->signal_connect (destroy => sub { 16 $self->signal_connect (destroy => sub {
16 delete $::config->{rooms}{$self->{channel}}; 17 delete $::config->{rooms}{$self->{channel}};
28 29
29 $hbox->pack_start ((my $vbox = new Gtk2::VBox), 1, 1, 0); 30 $hbox->pack_start ((my $vbox = new Gtk2::VBox), 1, 1, 0);
30 31
31 $vbox->add ($self->{chat} = new chat); 32 $vbox->add ($self->{chat} = new chat);
32 33
33 $self->{chat}->signal_connect(command => sub { 34 $self->{chat}->signal_connect (command => sub {
34 my ($chat, $cmd, $arg) = @_; 35 my ($chat, $cmd, $arg) = @_;
35 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self); 36 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self);
36 }); 37 });
37 38
38 $hbox->pack_start ((my $vbox = new Gtk2::VBox), 0, 1, 0); 39 $hbox->pack_start ((my $vbox = new Gtk2::VBox), 0, 1, 0);
39 40
40 $vbox->pack_start ((my $button = new_with_label Gtk2::Button "Close"), 0, 1, 0); 41 $vbox->pack_start ((my $button = new_with_label Gtk2::Button "Leave"), 0, 1, 0);
41 $button->signal_connect (clicked => sub { $self->part }); 42 $button->signal_connect (clicked => sub { $self->part });
42 43
43 $vbox->pack_start ((my $button = new_with_label Gtk2::Button "New Game"), 0, 1, 0); 44 $vbox->pack_start ((my $button = new_with_label Gtk2::Button "New Game"), 0, 1, 0);
44 $button->signal_connect (clicked => sub { $self->new_game }); 45 $button->signal_connect (clicked => sub { $self->new_game });
45 46
46 $vbox->pack_start ((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0); 47 $vbox->pack_start ((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0);
47 $sw->set_policy("automatic", "always"); 48 $sw->set_policy ("automatic", "always");
48 49
49 $sw->add ($self->{userlist} = new userlist); 50 $sw->add ($self->{userlist} = new userlist);
50 51
51 $self; 52 $self;
52} 53}
53 54
54sub FINALIZE_INSTANCE { print "FIN room\n" } # never called MEMLEAK #d#TODO# 55sub FINALIZE_INSTANCE { print "FIN room\n" } # never called MEMLEAK #d#TODO#
55 56
56sub part { 57sub part {
57 my ($self) = @_; 58 my ($self) = @_;
59
60 $self->hide;
58 $self->SUPER::part; 61 $self->SUPER::part;
59
60 $self->hide_all;
61} 62}
62 63
63sub inject_msg_room { 64sub inject_msg_room {
64 my ($self, $msg) = @_; 65 my ($self, $msg) = @_;
65 66
66 # secret typoe ;-) 67 # secret typoe ;-)
67 $self->{chat}->append_text ("\n<header><user>" . (util::toxml $msg->{name}) 68 $self->{chat}->append_text ("\n<user>" . (util::toxml $msg->{name})
68 . "</user>: </header>" . (util::toxml $msg->{message})); 69 . "</user>: " . (util::toxml $msg->{message}));
69} 70}
70 71
71sub event_update_users { 72sub event_update_users {
72 my ($self, $add, $update, $remove) = @_; 73 my ($self, $add, $update, $remove) = @_;
73 74
82 # try to identify any new games assigned to us. stupid protocol 83 # try to identify any new games assigned to us. stupid protocol
83 # first updates the game, joins you and THEN tells you that 84 # first updates the game, joins you and THEN tells you that
84 # which of the games you asked for this is. 85 # which of the games you asked for this is.
85 86
86 for (@$add) { 87 for (@$add) {
87 if ($_->player_colour ($self->{conn}{name}) 88 if (($_->{black}{name} eq $self->{conn}{name}
89 || $_->{white}{name} eq $self->{conn}{name}
90 || $_->{owner}{name} eq $self->{conn}{name})
88 and my $game = shift @{$self->{new_game}}) { 91 && (my $game = shift @{$self->{new_game}})) {
89 $game->inject_upd_game ({ game => $_ }); 92 $game->inject_upd_game ({ game => $_ });
90 $game->set_channel ($game->{channel}); 93 $game->set_channel ($game->{channel});
91 } 94 }
92 } 95 }
93} 96}
112 115
113 $self->SUPER::event_part; 116 $self->SUPER::event_part;
114 $self->destroy; 117 $self->destroy;
115} 118}
116 119
120sub event_quit {
121 my ($self) = @_;
122
123 $self->SUPER::event_quit;
124 $self->destroy;
125}
126
117sub event_update_roominfo { 127sub event_update_roominfo {
118 my ($self) = @_; 128 my ($self) = @_;
119 129
120 $self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n" 130 $self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n"
121 . "<description>" . (util::toxml $self->{description}) . "</description>\n"); 131 . "<description>" . (util::toxml $self->{description}) . "</description>\n");
122} 132}
123 133
124sub new_game { 134sub new_game {
125 my ($self) = @_; 135 my ($self) = @_;
126 136
127 my $d = $self->{app}{defaults};
128
129 my $game = new game conn => $self->{conn}, app => $self->{app}, roomid => $self->{channel}; 137 my $game = new game conn => $self->{conn}, app => $self->{app}, roomid => $self->{channel};
130 $game->{challenge}{""} = { 138 $game->new_game_challenge;
131 gametype => $d->{gametype},
132 flags => 0,
133 notes => $d->{stones},
134 rules => {
135 ruleset => $d->{ruleset},
136 size => $d->{size},
137 timesys => $d->{timesys},
138 time => $d->{time},
139 interval => $d->{timesys} == TIMESYS_BYO_YOMI ? $d->{byo_time} : $d->{can_time},
140 count => $d->{timesys} == TIMESYS_BYO_YOMI ? $d->{byo_periods} : $d->{can_stones},
141 },
142
143 inlay => $game->{chat}->new_inlay,
144 };
145 $game->draw_challenge ("");
146 $game->show_all; 139 $game->show_all;
147 140
148 push @{$self->{new_game}}, $game; 141 push @{$self->{new_game}}, $game;
149} 142}
150 143

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines