Add null checks to fix server crashing

This commit is contained in:
Nathan Fulton 2016-05-04 22:42:02 -04:00
parent fc00f91f25
commit b57f5a3a62
3 changed files with 39 additions and 21 deletions

View File

@ -25,6 +25,7 @@ Endpoint::Endpoint(Server& server, base::Socket *socket, dword id,
admin_(false), muted_(false), sigvisible_(false), seechat_(false), admin_(false), muted_(false), sigvisible_(false), seechat_(false),
roomlimiter_(2, 120), teamchat_(false) { roomlimiter_(2, 120), teamchat_(false) {
did_[0] = 0; did_[0] = 0;
platform_[0] = 0;
xpump_.Attach(socket, this, server.log()); xpump_.Attach(socket, this, server.log());
} }

View File

@ -1190,13 +1190,15 @@ void Game::SetAllies(SideMask side, SideMask sidmAllies) {
} }
Player *Game::HumanPlayerFromEndpoint(Endpoint *endpoint) { Player *Game::HumanPlayerFromEndpoint(Endpoint *endpoint) {
Player *pplr; Player *pplr = NULL;
for (int i = 0; i < kcPlayersMax; i++) { for (int i = 0; i < kcPlayersMax; i++) {
pplr = playerMgr_.GetPlayer(i); pplr = playerMgr_.GetPlayer(i);
if (pplr == NULL)
continue;
if (pplr->endpoint() == endpoint) { if (pplr->endpoint() == endpoint) {
break; break;
} else {
pplr = NULL;
} }
} }
@ -1301,6 +1303,9 @@ void Game::SendTeamChat(Endpoint *endpoint, const char *chat, const char *unfilt
} }
bool Game::CanSendTeamChat(Endpoint *endpoint, bool broadcast) { bool Game::CanSendTeamChat(Endpoint *endpoint, bool broadcast) {
if (endpoint == NULL)
return false;
// Game not started yet // Game not started yet
if (!playing()) { if (!playing()) {
if (broadcast) { if (broadcast) {

View File

@ -374,19 +374,25 @@ void Server::SetAnonsAllowed(bool anons_allowed) {
} }
bool Server::SharedAccountExists(Endpoint *endpointAsker, const char *name) { bool Server::SharedAccountExists(Endpoint *endpointAsker, const char *name) {
if (endpointAsker == NULL)
return false;
EndpointMap::iterator it = endpointmap_.begin(); EndpointMap::iterator it = endpointmap_.begin();
if (it->second->name() != NULL) { for (; it != endpointmap_.end(); it++) {
for (; it != endpointmap_.end(); it++) { if (it->second == NULL)
continue;
// Do the names match? if (it->second->name() == NULL)
if (strcmp(name, it->second->name()) == 0) { continue;
// Don't count endpointAsker // Do the names match?
if (endpointAsker->id() != it->second->id()) { if (strcmp(name, it->second->name()) == 0) {
// We found a shared account // Don't count endpointAsker
return true; if (endpointAsker->id() != it->second->id()) {
}
// We found a shared account
return true;
} }
} }
} }
@ -394,19 +400,25 @@ bool Server::SharedAccountExists(Endpoint *endpointAsker, const char *name) {
} }
void Server::DisconnectSharedAccounts(Endpoint *endpointAsker, const char *name) { void Server::DisconnectSharedAccounts(Endpoint *endpointAsker, const char *name) {
if (endpointAsker == NULL)
return;
EndpointMap::iterator it = endpointmap_.begin(); EndpointMap::iterator it = endpointmap_.begin();
if (it->second->name() != NULL) { for (; it != endpointmap_.end(); it++) {
for (; it != endpointmap_.end(); it++) { if (it->second == NULL)
continue;
// Do the names match? if (it->second->name() == NULL)
if (strcmp(name, it->second->name()) == 0) { continue;
// Son't disconnect the asker, only other endpoints // Do the names match?
if (endpointAsker->id() != it->second->id()) { if (strcmp(name, it->second->name()) == 0) {
// We found a shared account, dispose of it // Son't disconnect the asker, only other endpoints
it->second->Dispose(); if (endpointAsker->id() != it->second->id()) {
}
// We found a shared account, dispose of it
it->second->Dispose();
} }
} }
} }