Skip to content

Commit d6b4703

Browse files
committed
Properly send new clients all user info
1 parent 8cf2a10 commit d6b4703

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

mmo/Server.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ void Server::addNewUser(SOCKET socket){
156156
sendUserLocation(socket);
157157

158158
// Send new user everybody else's location
159-
std::ostringstream oss;
160-
oss << '[' << MSG_OTHER_LOCATION << ',' << socket << ',' << _userLocations[socket].first << ',' << _userLocations[socket].second << ']';
161-
for (std::set<SOCKET>::iterator it = _clientSockets.begin(); it != _clientSockets.end(); ++it)
162-
if (*it != socket)
163-
Socket::sendMessage(*it, oss.str());
159+
for (std::set<SOCKET>::iterator it = _clientSockets.begin(); it != _clientSockets.end(); ++it){
160+
if (*it != socket && _userLocations.find(*it) != _userLocations.end()) {
161+
std::ostringstream oss;
162+
oss << '[' << MSG_OTHER_LOCATION << ',' << *it << ',' << _userLocations[*it].first << ',' << _userLocations[*it].second << ']';
163+
Socket::sendMessage(socket, oss.str());
164+
}
165+
}
164166
}
165167

166168
void Server::handleMessage(SOCKET user, std::string msg){

0 commit comments

Comments
 (0)