diff --git a/src/core/common/avatarmanager.cpp b/src/core/common/avatarmanager.cpp index 258a3f2e..a6e7669a 100644 --- a/src/core/common/avatarmanager.cpp +++ b/src/core/common/avatarmanager.cpp @@ -511,7 +511,7 @@ AvatarManager::InternalReadDirectory(const std::string &dir, AvatarMap &avatars) } } catch (...) { - LOG_ERROR("Exception caught when trying to scan cache directory."); + LOG_ERROR("Exception caught when trying to scan avatar directory."); retVal = false; } return retVal; diff --git a/src/core/loghelper.h b/src/core/loghelper.h index a5e6dcf4..b7f21a3d 100644 --- a/src/core/loghelper.h +++ b/src/core/loghelper.h @@ -34,6 +34,14 @@ syslog(LOG_ERR, "%s", outStream.str()); \ } \ while(false) + #define LOG_MSG(e) \ + do \ + { \ + std::ostringstream outStream; \ + outStream << e << std::endl; \ + syslog(LOG_INFO, "%s", outStream.str()); \ + } \ + while(false) #endif #endif @@ -41,6 +49,8 @@ #include #define LOG_ERROR(e) \ std::cout << e << std::endl + #define LOG_MSG(e) \ + std::cout << e << std::endl #endif #endif diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 79b32f12..5496480f 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -986,7 +986,6 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->getCurrentBeRo()->setCurrentPlayersTurnId(tmpPlayer->getMyID()); curGame->getCurrentHand()->getCurrentBeRo()->setMinimumRaise(turnData.minimumRaise); - // TODO: remove this curGame->getCurrentHand()->getCurrentBeRo()->setPlayersTurn(tmpPlayer->getMyID()); // Mark current player in GUI. diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 394ea296..be212348 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -122,8 +123,9 @@ ClientThread::SendStartEvent(bool fillUpWithCpuPlayers) static_cast(start.get())->SetData(startData); boost::mutex::scoped_lock lock(m_outPacketListMutex); m_outPacketList.push_back(start); - } catch (const NetException &) + } catch (const NetException &e) { + LOG_ERROR("ClientThread::SendStartEvent: " << e.what()); } } @@ -148,8 +150,9 @@ ClientThread::SendPlayerAction() // Just dump the packet. boost::mutex::scoped_lock lock(m_outPacketListMutex); m_outPacketList.push_back(action); - } catch (const NetException &) + } catch (const NetException &e) { + LOG_ERROR("ClientThread::SendPlayerAction: " << e.what()); } } @@ -167,8 +170,9 @@ ClientThread::SendChatMessage(const std::string &msg) // Just dump the packet. boost::mutex::scoped_lock lock(m_outPacketListMutex); m_outPacketList.push_back(chat); - } catch (const NetException &) + } catch (const NetException &e) { + LOG_ERROR("ClientThread::SendChatMessage: " << e.what()); } } @@ -186,9 +190,9 @@ ClientThread::SendJoinFirstGame(const std::string &password) static_cast(join.get())->SetData(joinData); boost::mutex::scoped_lock lock(m_outPacketListMutex); m_outPacketList.push_back(join); - } catch (const NetException &) + } catch (const NetException &e) { - // TODO + LOG_ERROR("ClientThread::SendJoinFirstGame: " << e.what()); } } @@ -206,9 +210,9 @@ ClientThread::SendJoinGame(unsigned gameId, const std::string &password) static_cast(join.get())->SetData(joinData); boost::mutex::scoped_lock lock(m_outPacketListMutex); m_outPacketList.push_back(join); - } catch (const NetException &) + } catch (const NetException &e) { - // TODO + LOG_ERROR("ClientThread::SendJoinGame: " << e.what()); } } @@ -227,9 +231,9 @@ ClientThread::SendCreateGame(const GameData &gameData, const std::string &name, static_cast(create.get())->SetData(createData); boost::mutex::scoped_lock lock(m_outPacketListMutex); m_outPacketList.push_back(create); - } catch (const NetException &) + } catch (const NetException &e) { - // TODO + LOG_ERROR("ClientThread::SendCreateGame: " << e.what()); } } @@ -431,7 +435,7 @@ ClientThread::SetUnknownPlayer(unsigned id) { // Just remove it from the request list. m_playerInfoRequestList.remove(id); - // TODO log error + LOG_ERROR("Server reported unknown player id: " << id); } void @@ -483,8 +487,9 @@ ClientThread::CompleteTempAvatarData(unsigned playerId) if (!GetCachedPlayerInfo(playerId, tmpPlayerInfo)) throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); - GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize); - // TODO log error + if (!GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize)) + LOG_ERROR("Failed to store avatar in cache directory."); + // Free memory. m_tempAvatarMap.erase(pos); @@ -496,7 +501,7 @@ void ClientThread::SetUnknownAvatar(unsigned playerId) { m_tempAvatarMap.erase(playerId); - // TODO log error + LOG_ERROR("Server reported unknown avatar for player: " << playerId); } const ClientContext & diff --git a/src/net/common/serveracceptthread.cpp b/src/net/common/serveracceptthread.cpp index 1000e756..93482ae7 100644 --- a/src/net/common/serveracceptthread.cpp +++ b/src/net/common/serveracceptthread.cpp @@ -47,7 +47,10 @@ void ServerAcceptThread::Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd) { if (IsRunning()) - return; // TODO: throw exception + { + assert(false); + return; + } ServerContext &context = GetContext(); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 433e69ab..90d3e1db 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -484,8 +484,9 @@ ServerLobbyThread::HandleNetPacketAvatarEnd(SessionWrapper session, const NetPac unsigned avatarSize = (unsigned)tmpAvatar->fileData.size(); if (avatarSize == tmpAvatar->reportedSize) { - GetAvatarManager().StoreAvatarInCache(avatarMD5, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize); - // TODO log error + if (!GetAvatarManager().StoreAvatarInCache(avatarMD5, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize)) + LOG_ERROR("Failed to store avatar in cache directory."); + // Free memory. session.playerData->SetNetAvatarData(boost::shared_ptr()); // Init finished - start session. @@ -551,12 +552,13 @@ ServerLobbyThread::HandleNetPacketRetrieveAvatar(SessionWrapper session, const N if (GetAvatarManager().GetAvatarFileName(request.avatar, tmpFile)) { NetPacketList tmpPackets; - if (GetAvatarManager().AvatarFileToNetPackets(tmpFile, request.requestId, tmpPackets)) + if (GetAvatarManager().AvatarFileToNetPackets(tmpFile, request.requestId, tmpPackets) == 0) { avatarFound = true; GetSender().SendLowPrio(session.sessionData->GetSocket(), tmpPackets); } - // TODO Log error + else + LOG_ERROR("Failed to read avatar file for network transmission."); } if (!avatarFound) @@ -865,9 +867,10 @@ ServerLobbyThread::BroadcastStatisticsUpdate() m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established); m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game); - } catch (const NetException &) + } catch (const NetException &e) { - // TODO log error. + // Ignore errors for now. + //LOG_ERROR("ServerLobbyThread::BroadcastStatisticsUpdate: " << e.what()); } } } diff --git a/src/pokerth_server.cpp b/src/pokerth_server.cpp index cc2bb131..7c8d9941 100644 --- a/src/pokerth_server.cpp +++ b/src/pokerth_server.cpp @@ -23,6 +23,7 @@ #include "configfile.h" #include #include +#include #include @@ -67,7 +68,7 @@ main(int argc, char *argv[]) { ENABLE_LEAK_CHECK(); - //_CrtSetBreakAlloc(164); +// _CrtSetBreakAlloc(4772); //create defaultconfig ConfigFile *myConfig = new ConfigFile(argc, argv); @@ -82,13 +83,15 @@ main(int argc, char *argv[]) socket_startup(); + LOG_MSG("Starting PokerTH dedicated server. Availability: IPv6 " + << socket_has_ipv6() << ", SCTP " << socket_has_sctp() << ", Dual Stack " << socket_has_dual_stack() << "."); + // Create pseudo Gui Wrapper for the server. boost::shared_ptr myServerGuiInterface(new ServerGuiWrapper(myConfig, NULL, NULL, NULL)); - { - boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig)); - session->init(); // TODO handle error - myServerGuiInterface->setSession(session); - } + boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig)); + if (!session->init()) + LOG_ERROR("Missing files - please check your directory settings!"); + myServerGuiInterface->setSession(session); myServerGuiInterface->getSession().startNetworkServer(); while (!g_pokerthTerminate) @@ -98,6 +101,7 @@ main(int argc, char *argv[]) } myServerGuiInterface->getSession().terminateNetworkServer(); + LOG_MSG("Terminating PokerTH dedicated server."); socket_cleanup(); return 0; }