MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / MachineIdToPlayerId

Function MachineIdToPlayerId

engine/Poseidon/Network/MultiplayerAuth.cpp:23–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace Poseidon
22{
23uint64_t MachineIdToPlayerId(const char* rawMachineId)
24{
25 if (!rawMachineId)
26 return 0;
27
28 // Trim surrounding whitespace (the /etc/machine-id file carries a trailing
29 // newline; the id must be identical with or without it).
30 const char* begin = rawMachineId;
31 while (*begin != 0 && static_cast<unsigned char>(*begin) <= ' ')
32 ++begin;
33 const char* end = begin + strlen(begin);
34 while (end > begin && static_cast<unsigned char>(*(end - 1)) <= ' ')
35 --end;
36 if (end == begin)
37 return 0;
38
39 // FNV-1a 64-bit over the trimmed bytes.
40 uint64_t hash = 1469598103934665603ULL;
41 for (const char* p = begin; p < end; ++p)
42 {
43 hash ^= static_cast<unsigned char>(*p);
44 hash *= 1099511628211ULL;
45 }
46
47 // Mask to 63 bits so the value is a positive signed int64 (the _atoi64 /
48 // decimal ban.txt contract). Steer clear of the server's 0/999 sentinels.
49 hash &= 0x7FFFFFFFFFFFFFFFULL;
50 if (hash == 0 || hash == 999)
51 hash = 1;
52 return hash;
53}
54
55RString ReadOsMachineId()
56{

Callers 2

GetPublicKeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected