void ClientInterface::UpdatePlayerList() { if (m_env != NULL) { std::vector<u16> clients = getClientIDs(); m_clients_names.clear(); if(!clients.empty()) infostream<<"Players:"<<std::endl; for(std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { Player *player = m_env->getPlayer(*i); if (player == NULL) continue; infostream << "* " << player->getName() << "\t"; { MutexAutoLock clientslock(m_clients_mutex); RemoteClient* client = lockedGetClientNoEx(*i); if(client != NULL) client->PrintInfo(infostream); } m_clients_names.push_back(player->getName()); } } }
void ClientInterface::UpdatePlayerList() { if (m_env) { std::vector<u16> clients = getClientIDs(); m_clients_names.clear(); if(!clients.empty()) infostream<<"Players:"<<std::endl; for (u16 i : clients) { RemotePlayer *player = m_env->getPlayer(i); if (player == NULL) continue; infostream << "* " << player->getName() << "\t"; { MutexAutoLock clientslock(m_clients_mutex); RemoteClient* client = lockedGetClientNoEx(i); if (client) client->PrintInfo(infostream); } m_clients_names.emplace_back(player->getName()); } } }
void ClientInterface::setPlayerName(u16 peer_id,std::string name) { MutexAutoLock clientslock(m_clients_mutex); RemoteClientMap::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. if (n != m_clients.end()) n->second->setName(name); }
ClientState ClientInterface::getClientState(u16 peer_id) { MutexAutoLock clientslock(m_clients_mutex); RemoteClientMap::const_iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. if (n == m_clients.end()) return CS_Invalid; return n->second->getState(); }
std::vector<u16> ClientInterface::getClientIDs(ClientState min_state) { std::vector<u16> reply; MutexAutoLock clientslock(m_clients_mutex); for (const auto &m_client : m_clients) { if (m_client.second->getState() >= min_state) reply.push_back(m_client.second->peer_id); } return reply; }
void ClientInterface::sendToAll(NetworkPacket *pkt) { MutexAutoLock clientslock(m_clients_mutex); for (auto &client_it : m_clients) { RemoteClient *client = client_it.second; if (client->net_proto_version != 0) { m_con->Send(client->peer_id, clientCommandFactoryTable[pkt->getCommand()].channel, pkt, clientCommandFactoryTable[pkt->getCommand()].reliable); } } }
void ClientInterface::sendToAll(u16 channelnum, NetworkPacket* pkt, bool reliable) { MutexAutoLock clientslock(m_clients_mutex); for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { RemoteClient *client = i->second; if (client->net_proto_version != 0) { m_con->Send(client->peer_id, channelnum, pkt, reliable); } } }
std::vector<u16> ClientInterface::getClientIDs(ClientState min_state) { std::vector<u16> reply; MutexAutoLock clientslock(m_clients_mutex); for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { if (i->second->getState() >= min_state) reply.push_back(i->second->peer_id); } return reply; }
ClientInterface::~ClientInterface() { /* Delete clients */ { MutexAutoLock clientslock(m_clients_mutex); for (auto &client_it : m_clients) { // Delete client delete client_it.second; } } }
RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min) { MutexAutoLock clientslock(m_clients_mutex); RemoteClientMap::const_iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. if (n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) return n->second; return NULL; }
void ClientInterface::sendToAll(NetworkPacket *pkt) { MutexAutoLock clientslock(m_clients_mutex); for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { RemoteClient *client = i->second; if (client->net_proto_version != 0) { m_con->Send(client->peer_id, clientCommandFactoryTable[pkt->getCommand()].channel, pkt, clientCommandFactoryTable[pkt->getCommand()].reliable); } } }
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) { JMutexAutoLock clientslock(m_clients_mutex); std::map<u16, RemoteClient*>::iterator n; n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. if(n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) return n->second; else return NULL; }
ClientInterface::~ClientInterface() { /* Delete clients */ { MutexAutoLock clientslock(m_clients_mutex); for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { // Delete client delete i->second; } } }
void ClientInterface::sendToAll(u16 channelnum, SharedBuffer<u8> data, bool reliable) { JMutexAutoLock clientslock(m_clients_mutex); for(std::map<u16, RemoteClient*>::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { RemoteClient *client = i->second; if (client->net_proto_version != 0) { m_con->Send(client->peer_id, channelnum, data, reliable); } } }
void ClientInterface::sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt, u16 min_proto_ver) { MutexAutoLock clientslock(m_clients_mutex); for (auto &client_it : m_clients) { RemoteClient *client = client_it.second; NetworkPacket *pkt_to_send = nullptr; if (client->net_proto_version >= min_proto_ver) { pkt_to_send = pkt; } else if (client->net_proto_version != 0) { pkt_to_send = legacypkt; } else { warningstream << "Client with unhandled version to handle: '" << client->net_proto_version << "'"; continue; } m_con->Send(client->peer_id, clientCommandFactoryTable[pkt_to_send->getCommand()].channel, pkt_to_send, clientCommandFactoryTable[pkt_to_send->getCommand()].reliable); } }