-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameManager.cpp
74 lines (56 loc) · 1.52 KB
/
GameManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "constants.h"
#include "GameManager.h"
#include "game.h"
#include <packet.h>
using namespace FTS;
using namespace FTSSrv2;
int FTSSrv2::GameManager::addGame( FTSSrv2::Game *in_pGame )
{
std::lock_guard<std::recursive_mutex> l(m_mutex);
m_lpGames.push_back(in_pGame);
return ERR_OK;
}
int FTSSrv2::GameManager::remGame(FTSSrv2::Game *in_pGame)
{
// If the game has been canceled, remove it from the list.
std::lock_guard<std::recursive_mutex> l(m_mutex);
m_lpGames.remove(in_pGame);
delete in_pGame;
return ERR_OK;
}
int FTSSrv2::GameManager::startGame(FTSSrv2::Game *in_pGame)
{
// If the game has been started, keep it in the list and set it to started state.
in_pGame->start();
return ERR_OK;
}
FTSSrv2::Game *FTSSrv2::GameManager::findGame( const std::string &in_sName )
{
std::lock_guard<std::recursive_mutex> l(m_mutex);
for( auto i : m_lpGames ) {
if(i->getName() == in_sName) {
return i;
}
}
return nullptr;
}
FTSSrv2::Game *FTSSrv2::GameManager::findGameByHost(const std::string &in_sHost)
{
std::lock_guard<std::recursive_mutex> l(m_mutex);
for( auto i : m_lpGames ) {
if(i->getHost() == in_sHost) {
return i;
}
}
return nullptr;
}
int FTSSrv2::GameManager::writeListToPacket(Packet *in_pPacket)
{
if(!in_pPacket)
return -1;
std::lock_guard<std::recursive_mutex> l(m_mutex);
for( auto i : m_lpGames) {
i->addToLstPacket(in_pPacket);
}
return ERR_OK;
}