mirror of
https://github.com/spiffcode/hostile-takeover.git
synced 2025-12-16 12:08:36 +00:00
Add null checks to fix server crashing
This commit is contained in:
parent
fc00f91f25
commit
b57f5a3a62
@ -25,6 +25,7 @@ Endpoint::Endpoint(Server& server, base::Socket *socket, dword id,
|
||||
admin_(false), muted_(false), sigvisible_(false), seechat_(false),
|
||||
roomlimiter_(2, 120), teamchat_(false) {
|
||||
did_[0] = 0;
|
||||
platform_[0] = 0;
|
||||
xpump_.Attach(socket, this, server.log());
|
||||
}
|
||||
|
||||
|
||||
@ -1190,13 +1190,15 @@ void Game::SetAllies(SideMask side, SideMask sidmAllies) {
|
||||
}
|
||||
|
||||
Player *Game::HumanPlayerFromEndpoint(Endpoint *endpoint) {
|
||||
Player *pplr;
|
||||
Player *pplr = NULL;
|
||||
for (int i = 0; i < kcPlayersMax; i++) {
|
||||
pplr = playerMgr_.GetPlayer(i);
|
||||
|
||||
if (pplr == NULL)
|
||||
continue;
|
||||
|
||||
if (pplr->endpoint() == endpoint) {
|
||||
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) {
|
||||
if (endpoint == NULL)
|
||||
return false;
|
||||
|
||||
// Game not started yet
|
||||
if (!playing()) {
|
||||
if (broadcast) {
|
||||
|
||||
@ -374,19 +374,25 @@ void Server::SetAnonsAllowed(bool anons_allowed) {
|
||||
}
|
||||
|
||||
bool Server::SharedAccountExists(Endpoint *endpointAsker, const char *name) {
|
||||
if (endpointAsker == NULL)
|
||||
return false;
|
||||
|
||||
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 (strcmp(name, it->second->name()) == 0) {
|
||||
if (it->second->name() == NULL)
|
||||
continue;
|
||||
|
||||
// Don't count endpointAsker
|
||||
if (endpointAsker->id() != it->second->id()) {
|
||||
// Do the names match?
|
||||
if (strcmp(name, it->second->name()) == 0) {
|
||||
|
||||
// We found a shared account
|
||||
return true;
|
||||
}
|
||||
// Don't count endpointAsker
|
||||
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) {
|
||||
if (endpointAsker == NULL)
|
||||
return;
|
||||
|
||||
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 (strcmp(name, it->second->name()) == 0) {
|
||||
if (it->second->name() == NULL)
|
||||
continue;
|
||||
|
||||
// Son't disconnect the asker, only other endpoints
|
||||
if (endpointAsker->id() != it->second->id()) {
|
||||
// Do the names match?
|
||||
if (strcmp(name, it->second->name()) == 0) {
|
||||
|
||||
// We found a shared account, dispose of it
|
||||
it->second->Dispose();
|
||||
}
|
||||
// Son't disconnect the asker, only other endpoints
|
||||
if (endpointAsker->id() != it->second->id()) {
|
||||
|
||||
// We found a shared account, dispose of it
|
||||
it->second->Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user