Skip to content

Commit d8d1eb0

Browse files
committed
Add NaCl availability cvar and block remote server joins on non-NaCl platforms
- Add vm.nacl.available ROM cvar (true on amd64/i686/armhf, false otherwise) so the UI can detect NaCl availability at runtime - Default vm.cgame.type and vm.sgame.type to native DLL (3) on platforms without NaCl runtime, instead of NaCl (0) which would fail - Block joining remote servers on non-NaCl platforms in CL_InitCGame() since loading local (unsandboxed) game code instead of the server's NaCl modules is considered cheating - Move Sys::Error guard from early in VMBase::Create() to just before the CreateNaClVM dispatch as a secondary safety net
1 parent 5d7424a commit d8d1eb0

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

src/engine/client/cl_cgame.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,18 @@ Should only by called by CL_StartHunkUsers
593593
*/
594594
void CL_InitCGame()
595595
{
596+
#ifndef DAEMON_NACL_RUNTIME_ENABLED
597+
// NaCl sandbox is not available on this platform. Joining a remote server
598+
// would load local (unsandboxed) game code instead of the server's NaCl
599+
// modules, which is considered cheating. Only local games (via devmap,
600+
// which enables cheats) are allowed.
601+
if ( !NET_IsLocalAddress( clc.serverAddress ) )
602+
{
603+
Sys::Error( "Cannot join remote servers: NaCl sandbox is not available on this platform.\n"
604+
"You can host a local game using devmap (the server creation menu does this automatically)." );
605+
}
606+
#endif
607+
596608
const char *info;
597609
const char *mapname;
598610
int t1, t2;

src/engine/framework/VirtualMachine.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ static Cvar::Cvar<int> vm_timeout(
8888
"Receive timeout in seconds",
8989
Cvar::NONE, 2);
9090

91+
#ifdef DAEMON_NACL_RUNTIME_ENABLED
92+
static Cvar::Cvar<bool> vm_nacl_available(
93+
"vm.nacl.available",
94+
"Whether NaCl runtime is available on this platform",
95+
Cvar::ROM, true);
96+
#else
97+
static Cvar::Cvar<bool> vm_nacl_available(
98+
"vm.nacl.available",
99+
"Whether NaCl runtime is available on this platform",
100+
Cvar::ROM, false);
101+
#endif
102+
91103
namespace VM {
92104

93105
// https://github.com/Unvanquished/Unvanquished/issues/944#issuecomment-744454772
@@ -479,14 +491,6 @@ void VMBase::Create()
479491
if (type < TYPE_BEGIN || type >= TYPE_END)
480492
Sys::Drop("VM: Invalid type %d", type);
481493

482-
#ifndef DAEMON_NACL_RUNTIME_ENABLED
483-
if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) {
484-
Sys::Error("VM: NaCl is not available on this platform. "
485-
"NaCl is required for online games. "
486-
"To play offline with native DLLs, set vm.cgame.type, vm.sgame.type to 3");
487-
}
488-
#endif
489-
490494
int loadStartTime = Sys::Milliseconds();
491495

492496
// Free the VM if it exists
@@ -505,6 +509,13 @@ void VMBase::Create()
505509
std::pair<IPC::Socket, IPC::Socket> pair = IPC::Socket::CreatePair();
506510

507511
IPC::Socket rootSocket;
512+
#ifndef DAEMON_NACL_RUNTIME_ENABLED
513+
if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) {
514+
Sys::Error("NaCl VM is not supported on this platform. "
515+
"Set vm.cgame.type and vm.sgame.type to 3 (native DLL) "
516+
"and use devmap instead of map.");
517+
}
518+
#endif
508519
if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) {
509520
std::tie(processHandle, rootSocket) = CreateNaClVM(std::move(pair), name, params.debug.Get(), type == TYPE_NACL, params.debugLoader.Get());
510521
} else if (type == TYPE_NATIVE_EXE) {

src/engine/framework/VirtualMachine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ enum vmType_t {
9595
struct VMParams {
9696
VMParams(std::string name, int vmTypeFlags)
9797
: logSyscalls("vm." + name + ".logSyscalls", "dump all the syscalls in the " + name + ".syscallLog file", Cvar::NONE, false),
98+
#ifdef DAEMON_NACL_RUNTIME_ENABLED
9899
vmType("vm." + name + ".type", "how the vm should be loaded for " + name, vmTypeFlags,
99100
Util::ordinal(vmType_t::TYPE_NACL), 0, Util::ordinal(vmType_t::TYPE_END) - 1),
101+
#else
102+
vmType("vm." + name + ".type", "how the vm should be loaded for " + name, vmTypeFlags,
103+
Util::ordinal(vmType_t::TYPE_NATIVE_DLL), 0, Util::ordinal(vmType_t::TYPE_END) - 1),
104+
#endif
100105
debug("vm." + name + ".debug", "run a gdbserver on localhost:4014 to debug the VM", Cvar::NONE, false),
101106
debugLoader("vm." + name + ".debugLoader", "make nacl_loader dump information to " + name + "-nacl_loader.log", Cvar::NONE, 1, 0, 5) {
102107
}
@@ -111,7 +116,11 @@ struct VMParams {
111116
class VMBase {
112117
public:
113118
VMBase(std::string name_, int vmTypeCvarFlags)
119+
#ifdef DAEMON_NACL_RUNTIME_ENABLED
114120
: processHandle(Sys::INVALID_HANDLE), name(name_), type(TYPE_NACL), params(name_, vmTypeCvarFlags) {}
121+
#else
122+
: processHandle(Sys::INVALID_HANDLE), name(name_), type(TYPE_NATIVE_DLL), params(name_, vmTypeCvarFlags) {}
123+
#endif
115124

116125
// Create the VM for the named module. This will automatically free any existing VM.
117126
void Create();

0 commit comments

Comments
 (0)