+
+ # set up the basic channel info for "Normal" Users
+ # is there one already connected to me - locally?
+
+ $dxchan = DXChannel::get($call);
+ my $newcall = $call;
+ if ($dxchan) {
+ if ($user && $user->is_node) {
+ already_conn($conn, $call, DXM::msg($lang, 'conother', $call, $main::mycall));
+ return;
+ }
+ if ($allowmultiple && $user->is_user) {
+ # determine whether we are a candidate, have we flip-flopped frequently enough?
+ my @lastconns = @{$user->connlist} if $user->connlist;
+ my $allow = 0;
+ if (@lastconns >= $DXUser::maxconnlist) {
+ $allow = $lastconns[-1]->[0] - $lastconns[0]->[0] < $min_reconnection_rate;
+ }
+ # search for a spare ssid
+ L1: for (my $count = $call =~ /-\d+$/?0:1; $allow && $count < $allowmultiple; ) { # remember we have one call already
+ my $lastid = 1;
+ for (; $lastid < $max_ssid && $count < $allowmultiple; ++$lastid) {
+ my $chan = DXChannel::get("$basecall-$lastid");
+ if ($chan) {
+ ++$count;
+ next;
+ }
+ # we have a free call-ssid, save it
+ $newcall = "$basecall-$lastid";
+ last L1;
+ }
+ }
+ }
+
+ # handle "normal" (non-multiple) connections in the existing way
+ if ($call eq $newcall) {
+ if ($bumpexisting) {
+ my $ip = $dxchan->hostname;
+ $dxchan->send_now('D', DXM::msg($lang, 'conbump', $call, $ip));
+ LogDbg('', "$call bumped off by $ip, disconnected");
+ $dxchan->disconnect;
+ } else {
+ already_conn($conn, $call, DXM::msg($lang, 'conother', $call, $main::mycall));
+ return;
+ }
+ }
+
+ # make sure that the conn has the (possibly) new callsign
+ $conn->conns($newcall);
+ $msg =~ s/$call/$newcall/;
+ }
+
+
+ # (fairly) politely disconnect people that are connected to too many other places at once
+ my $r = Route::get($call);
+ if ($conn->{sort} && $conn->{sort} =~ /^I/ && $r && $user) {
+ my @n = $r->parents;
+ my $m = $r->isa('Route::Node') ? $maxconnect_node : $maxconnect_user;
+ my $c = $user->maxconnect;
+ my $v;
+ $v = defined $c ? $c : $m;
+ if ($v && @n >= $v+$allowmultiple) {
+ my $nodes = join ',', @n;
+ LogDbg('', "$call has too many connections ($v) at $nodes - disconnected");
+ already_conn($conn, $call, DXM::msg($lang, 'contomany', $call, $v, $nodes));
+ return;
+ }
+ }
+
+ if ($user) {
+ $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems
+ } else {
+ $user = DXUser->new($call);
+ }
+
+ # create the channel
+ # NOTE we are SHARING the same $user if $allowmultiple is > 1
+
+ $user->startt($systime); # mark the start time of this connection
+ if ($user->is_node) {
+ $dxchan = DXProt->new($call, $conn, $user);
+ } elsif ($user->is_user) {
+ $dxchan = DXCommandmode->new($newcall, $conn, $user);
+ } else {
+ die "Invalid sort of user on $call = $sort";
+ }