+ my $conn = shift;
+ $conn->{rproc} = \&new_channel;
+ $conn->{state} = 'WH';
+}
+
+#
+# happens next on receive
+#
+
+sub new_channel
+{
+ my ($conn, $msg) = @_;
+ my $call = $conn->{call} || $conn->{peerhost};
+
+ dbg("<- I $call $msg") if isdbg('chan');
+
+ my $thing = Aranea::input($msg);
+ unless ($thing) {
+ dbg("Invalid thingy: $msg from $conn->{peerhost}");
+ $conn->send_now("Sorry");
+ $conn->disconnect;
+ return;
+ }
+
+ $call = $thing->{origin};
+ unless (is_callsign($call)) {
+ main::already_conn($conn, $call, DXM::msg($main::lang, "illcall", $call));
+ return;
+ }
+
+ # set up the basic channel info
+ # is there one already connected to me - locally?
+ my $user = DXUser->get_current($call);
+ my $dxchan = DXChannel->get($call);
+ if ($dxchan) {
+ if ($main::bumpexisting && $call ne $main::mycall) {
+ my $ip = $conn->{peerhost} || 'unknown';
+ $dxchan->send_now('D', DXM::msg($main::lang, 'conbump', $call, $ip));
+ Log('DXCommand', "$call bumped off by $ip, disconnected");
+ dbg("$call bumped off by $ip, disconnected");
+ $dxchan->disconnect;
+ } else {
+ main::already_conn($conn, $call, DXM::msg($main::lang, 'conother', $call, $main::mycall));
+ return;
+ }
+ }
+
+ # is he locked out ?
+ my $basecall = $call;
+ $basecall =~ s/-\d+$//;
+ my $baseuser = DXUser->get_current($basecall);
+ my $lock = $user->lockout if $user;
+ if ($baseuser && $baseuser->lockout || $lock) {
+ if (!$user || !defined $lock || $lock) {
+ my $host = $conn->{peerhost} || "unknown";
+ Log('DXCommand', "$call on $host is locked out, disconnected");
+ $conn->disconnect;
+ return;
+ }
+ }
+
+ if ($user) {
+ $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems
+ } else {
+ $user = DXUser->new($call);
+ }
+
+ # create the channel
+ $dxchan = Aranea->new($call, $conn, $user);
+
+ # check that the conn has a callsign