Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetSession.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "NetSession.h" | #include "NetSession.h" | ||||
#include "NetClient.h" | #include "NetClient.h" | ||||
#include "NetEnet.h" | |||||
#include "NetMessage.h" | #include "NetMessage.h" | ||||
#include "NetServer.h" | #include "NetServer.h" | ||||
#include "NetStats.h" | #include "NetStats.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
constexpr int NETCLIENT_POLL_TIMEOUT = 50; | constexpr int NETCLIENT_POLL_TIMEOUT = 50; | ||||
Show All 24 Lines | |||||
} | } | ||||
bool CNetClientSession::Connect(const CStr& server, const u16 port, ENetHost* enetClient) | bool CNetClientSession::Connect(const CStr& server, const u16 port, ENetHost* enetClient) | ||||
{ | { | ||||
ENSURE(!m_LoopRunning); | ENSURE(!m_LoopRunning); | ||||
ENSURE(!m_Host); | ENSURE(!m_Host); | ||||
ENSURE(!m_Server); | ENSURE(!m_Server); | ||||
// Create ENet host | // Create ENet host if necessary. | ||||
ENetHost* host; | ENetHost* host = enetClient != nullptr ? enetClient : PS::Enet::CreateHost(nullptr, 1, CHANNEL_COUNT); | ||||
if (enetClient != nullptr) | |||||
host = enetClient; | |||||
else | |||||
host = enet_host_create(NULL, 1, CHANNEL_COUNT, 0, 0); | |||||
if (!host) | if (!host) | ||||
return false; | return false; | ||||
// Bind to specified host | // Bind to specified host | ||||
ENetAddress addr; | ENetAddress addr; | ||||
addr.port = port; | addr.port = port; | ||||
if (enet_address_set_host(&addr, server.c_str()) < 0) | if (enet_address_set_host(&addr, server.c_str()) < 0) | ||||
▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator