1
0

Compilation fixes

This commit is contained in:
Tiger Wang 2014-11-23 14:22:05 +00:00
parent e8e03e5df2
commit 6382989ba0
5 changed files with 11 additions and 15 deletions

View File

@ -189,7 +189,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
m_Server(a_Server), m_Server(a_Server),
m_ClientSocket(a_ClientSocket), m_ClientSocket(a_ClientSocket),
m_ServerSocket(-1), m_ServerSocket(-1),
m_BeginTick(m_Timer.GetNowTime()), m_BeginTick(std::chrono::steady_clock::now()),
m_ClientState(csUnencrypted), m_ClientState(csUnencrypted),
m_ServerState(csUnencrypted), m_ServerState(csUnencrypted),
m_Nonce(0), m_Nonce(0),
@ -436,7 +436,7 @@ bool cConnection::RelayFromClient(void)
double cConnection::GetRelativeTime(void) double cConnection::GetRelativeTime(void)
{ {
return (double)(m_Timer.GetNowTime() - m_BeginTick) / 1000; return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_BeginTick).count() / 1000;
} }

View File

@ -10,7 +10,6 @@
#pragma once #pragma once
#include "ByteBuffer.h" #include "ByteBuffer.h"
#include "OSSupport/Timer.h"
#include "PolarSSL++/AesCfb128Decryptor.h" #include "PolarSSL++/AesCfb128Decryptor.h"
#include "PolarSSL++/AesCfb128Encryptor.h" #include "PolarSSL++/AesCfb128Encryptor.h"
@ -37,8 +36,7 @@ class cConnection
SOCKET m_ClientSocket; SOCKET m_ClientSocket;
SOCKET m_ServerSocket; SOCKET m_ServerSocket;
cTimer m_Timer; std::chrono::steady_clock::time_point m_BeginTick; // Tick when the relative time was first retrieved (used for GetRelativeTime())
long long m_BeginTick; // Tick when the relative time was first retrieved (used for GetRelativeTime())
enum eConnectionState enum eConnectionState
{ {

View File

@ -354,7 +354,7 @@ float cPlayer::GetXpPercentage()
bool cPlayer::SetCurrentExperience(short int a_CurrentXp) bool cPlayer::SetCurrentExperience(short int a_CurrentXp)
{ {
if (!(a_CurrentXp >= 0) || (a_CurrentXp > (SHRT_MAX - m_LifetimeTotalXp))) if (!(a_CurrentXp >= 0) || (a_CurrentXp > (std::numeric_limits<short>().max() - m_LifetimeTotalXp)))
{ {
LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp); LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp);
return false; // oops, they gave us a dodgey number return false; // oops, they gave us a dodgey number
@ -374,18 +374,17 @@ bool cPlayer::SetCurrentExperience(short int a_CurrentXp)
short cPlayer::DeltaExperience(short a_Xp_delta) short cPlayer::DeltaExperience(short a_Xp_delta)
{ {
if (a_Xp_delta > (SHRT_MAX - m_CurrentXp)) if (a_Xp_delta > (std::numeric_limits<short>().max() - m_CurrentXp))
{ {
// Value was bad, abort and report // Value was bad, abort and report
LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the short datatype. Ignoring.", LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the short datatype. Ignoring.", a_Xp_delta);
a_Xp_delta);
return -1; // Should we instead just return the current Xp? return -1; // Should we instead just return the current Xp?
} }
m_CurrentXp += a_Xp_delta; m_CurrentXp += a_Xp_delta;
// Make sure they didn't subtract too much // Make sure they didn't subtract too much
m_CurrentXp = std::max<short int>(m_CurrentXp, 0); m_CurrentXp = std::max<short>(m_CurrentXp, 0);
// Update total for score calculation // Update total for score calculation
if (a_Xp_delta > 0) if (a_Xp_delta > 0)
@ -393,8 +392,7 @@ short cPlayer::DeltaExperience(short a_Xp_delta)
m_LifetimeTotalXp += a_Xp_delta; m_LifetimeTotalXp += a_Xp_delta;
} }
LOGD("Player \"%s\" gained/lost %d experience, total is now: %d", LOGD("Player \"%s\" gained/lost %d experience, total is now: %d", GetName().c_str(), a_Xp_delta, m_CurrentXp);
GetName().c_str(), a_Xp_delta, m_CurrentXp);
// Set experience to be updated // Set experience to be updated
m_bDirtyExperience = true; m_bDirtyExperience = true;

View File

@ -45,7 +45,7 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
AString Line; AString Line;
#ifdef _DEBUG #ifdef _DEBUG
Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", std::this_thread::get_id().hash(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str()); Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", std::hash<std::thread::id>()(std::this_thread::get_id()), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
#else #else
Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str()); Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
#endif #endif

View File

@ -85,7 +85,7 @@ bool cIsThread::Start(void)
} }
catch (std::system_error & a_Exception) catch (std::system_error & a_Exception)
{ {
LOGERROR("cIsThread::Wait (std::thread) error %i: could not construct thread %s; %s", m_ThreadName.c_str(), a_Exception.code().value(), a_Exception.what()); LOGERROR("cIsThread::Wait (std::thread) error %i: could not construct thread %s; %s", a_Exception.code().value(), m_ThreadName.c_str(), a_Exception.what());
return false; return false;
} }
} }
@ -119,7 +119,7 @@ bool cIsThread::Wait(void)
} }
catch (std::system_error & a_Exception) catch (std::system_error & a_Exception)
{ {
LOGERROR("cIsThread::Wait (std::thread) error %i: could not join thread %s; %s", m_ThreadName.c_str(), a_Exception.code().value(), a_Exception.what()); LOGERROR("cIsThread::Wait (std::thread) error %i: could not join thread %s; %s", a_Exception.code().value(), m_ThreadName.c_str(), a_Exception.what());
return false; return false;
} }
} }