… | |
… | |
23 | $app::self = $self; # singleton |
23 | $app::self = $self; # singleton |
24 | Scalar::Util::weaken $app::self; |
24 | Scalar::Util::weaken $app::self; |
25 | |
25 | |
26 | $self->{conn} = new KGS::Protocol::Client; |
26 | $self->{conn} = new KGS::Protocol::Client; |
27 | |
27 | |
28 | KGS::Listener::Debug->new->listen($self->{conn}, "any"); #d# debug only :) |
28 | #KGS::Listener::Debug->new->listen($self->{conn}, "any"); #d# debug only :) |
29 | |
29 | |
30 | $self->listen($self->{conn}, qw(login userpic idle_warn)); |
30 | $self->listen($self->{conn}, qw(login userpic idle_warn msg_chat)); |
31 | |
31 | |
32 | $self->{roomlist} = new roomlist conn => $self->{conn}, app => $self; |
32 | $self->{roomlist} = new roomlist conn => $self->{conn}, app => $self; |
33 | |
33 | |
34 | $self->{window} = new Gtk2::Window 'toplevel'; |
34 | $self->{window} = new Gtk2::Window 'toplevel'; |
35 | $self->{window}->set_title('kgsueme'); |
35 | $self->{window}->set_title('kgsueme'); |
… | |
… | |
55 | |
55 | |
56 | $hbox->add(new Gtk2::Label "Login"); |
56 | $hbox->add(new Gtk2::Label "Login"); |
57 | |
57 | |
58 | $hbox->add($self->{login} = new_with_max_length Gtk2::Entry 12); |
58 | $hbox->add($self->{login} = new_with_max_length Gtk2::Entry 12); |
59 | $self->{login}->set_text($::config->{login}); |
59 | $self->{login}->set_text($::config->{login}); |
60 | |
|
|
61 | if ($::HACK) { |
|
|
62 | $self->{login}->signal_connect(activate => sub { |
|
|
63 | $self->{conn}{name} = $self->{login}->get_text; |
|
|
64 | }); |
|
|
65 | } |
|
|
66 | |
60 | |
67 | $hbox->add(new Gtk2::Label "Password"); |
61 | $hbox->add(new Gtk2::Label "Password"); |
68 | $hbox->add($self->{password} = new Gtk2::Entry); |
62 | $hbox->add($self->{password} = new Gtk2::Entry); |
69 | $self->{password}->set_visibility(0); |
63 | $self->{password}->set_visibility(0); |
70 | |
64 | |
… | |
… | |
111 | $self->{conn}->login($ENV{KGSUEME_CLIENTVER} || "kgsueme $VERSION $^O", # allow users to overwrite |
105 | $self->{conn}->login($ENV{KGSUEME_CLIENTVER} || "kgsueme $VERSION $^O", # allow users to overwrite |
112 | $self->{login}->get_text, |
106 | $self->{login}->get_text, |
113 | $self->{password}->get_text); |
107 | $self->{password}->get_text); |
114 | } |
108 | } |
115 | |
109 | |
116 | sub inject_idle_warn { |
|
|
117 | my ($self, $msg) = @_; |
|
|
118 | |
|
|
119 | $self->send ("idle_reset"); |
|
|
120 | } |
|
|
121 | |
|
|
122 | sub inject_login { |
110 | sub inject_login { |
123 | my ($self, $msg) = @_; |
111 | my ($self, $msg) = @_; |
124 | |
112 | |
|
|
113 | $self->{name} = $self->{conn}{name}; |
|
|
114 | |
|
|
115 | $::config->{login} = $self->{name}; |
|
|
116 | |
125 | app::status("login", "logged in as '$self->{conn}{name}' with status '$msg->{result}' ('$msg->{reason}')"); |
117 | app::status("login", "logged in as '$self->{name}' with status '$msg->{result}' ('$msg->{reason}')"); |
126 | $::config->{login} = $self->{conn}{name}; |
|
|
127 | |
118 | |
128 | if ($msg->{success}) { |
119 | if ($msg->{success}) { |
129 | # auto-join |
120 | # auto-join |
130 | $self->open_room (%$_) for values %{$::config->{rooms}}; |
121 | $self->open_room (%$_) for values %{$::config->{rooms}}; |
131 | |
122 | |
132 | sound::play 3, "connect"; |
123 | sound::play 3, "connect"; |
133 | } elsif ($msg->{result} eq "user unknown") { |
124 | } elsif ($msg->{result} eq "user unknown") { |
134 | sound::play 2, "user_unknown"; |
125 | sound::play 2, "user_unknown"; |
135 | } else { |
126 | } else { |
136 | sound::play 2, "warning"; |
127 | sound::play 2, "warning"; |
|
|
128 | } |
|
|
129 | } |
|
|
130 | |
|
|
131 | sub inject_idle_warn { |
|
|
132 | my ($self, $msg) = @_; |
|
|
133 | |
|
|
134 | $self->send ("idle_reset"); |
|
|
135 | } |
|
|
136 | |
|
|
137 | sub inject_msg_chat { |
|
|
138 | my ($self, $msg) = @_; |
|
|
139 | |
|
|
140 | if ((lc $msg->{name2}) eq (lc $self->{name})) { |
|
|
141 | unless ($self->{user}{lc $msg->{name}}) { |
|
|
142 | $self->open_user (name => $msg->{name})->inject ($msg); |
|
|
143 | } |
137 | } |
144 | } |
138 | } |
145 | } |
139 | |
146 | |
140 | my %userpic; |
147 | my %userpic; |
141 | my %userpic_cb; |
148 | my %userpic_cb; |
… | |
… | |
201 | } |
208 | } |
202 | |
209 | |
203 | sub do_command { |
210 | sub do_command { |
204 | my ($self, $chat, $cmd, $arg, %arg) = @_; |
211 | my ($self, $chat, $cmd, $arg, %arg) = @_; |
205 | |
212 | |
206 | if ($cmd eq "msg") { |
213 | if ($cmd eq "say") { |
207 | if (my $context = $arg{game} || $arg{room}) { |
214 | if (my $context = $arg{game} || $arg{room} || $arg{user}) { |
208 | $context->say ($arg); |
215 | $context->say ($arg); |
209 | } else { |
216 | } else { |
210 | $chat->append_text ("\n<error>no context for message</error>"); |
217 | $chat->append_text ("\n<error>no context for message</error>"); |
211 | } |
218 | } |
212 | } elsif ($cmd eq "whois" or $cmd eq "w") { |
219 | } elsif ($cmd eq "whois" or $cmd eq "w") { |