Skip to content

Commit 1aa024f

Browse files
committed
fixed problem where refreshing created blank users
Fixes #92
1 parent a2130a0 commit 1aa024f

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/login/controller.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,38 @@ function LoginController(CardshifterServerAPI, $scope, $location, $rootScope, $t
6666
$scope.refreshing = false;
6767
}, REFRESH_DELAY);
6868

69-
for(var i = 0, length = $scope.servers.length; i < length; i++) {
70-
if($scope.servers[i].name === "Other...") {
71-
continue;
69+
var i = 0;
70+
(function foo() {
71+
var thisServer = $scope.servers[i];
72+
73+
if(thisServer.name === "Other...") {
74+
return;
7275
}
7376

7477
var now = Date.now();
7578

76-
/**
77-
* The reason why there is all this anonymous function
78-
* returning anonymous function magic is because this
79-
* init method happens asynchronously, and that means
80-
* that the local thisServer variable is going to change
81-
* almost instantaneously to the very last server in the
82-
* list.
83-
*/
84-
(function(thisServer) {
85-
CardshifterServerAPI.init(thisServer.address, false, function() {
86-
thisServer.latency = Date.now() - now;
87-
thisServer.isOnline = true;
88-
}, function() {
89-
thisServer.latency = 0;
90-
thisServer.isOnline = false;
91-
thisServer.userCount = 0;
92-
})
93-
})($scope.servers[i]);
94-
}
79+
CardshifterServerAPI.init(thisServer.address, false, function() {
80+
thisServer.latency = Date.now() - now;
81+
thisServer.isOnline = true;
82+
83+
CardshifterServerAPI.socket.close();
84+
CardshifterServerAPI.socket = null;
85+
86+
i++;
87+
if($scope.servers[i]) {
88+
foo();
89+
}
90+
}, function() {
91+
thisServer.latency = 0;
92+
thisServer.isOnline = false;
93+
thisServer.userCount = 0;
94+
95+
i++;
96+
if($scope.servers[i]) {
97+
foo();
98+
}
99+
})
100+
})();
95101
};
96102

97103
/**

0 commit comments

Comments
 (0)