-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredictCommand.cpp
More file actions
110 lines (95 loc) · 2.27 KB
/
PredictCommand.cpp
File metadata and controls
110 lines (95 loc) · 2.27 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Time : 2016/06/13
Author: Kay Yang (1025115216@qq.com)
*/
#include "PredictCommand.h"
#include "PredictPrint.h"
#include "PredictMessage.h"
#include "PredictCommandFactory.h"
#include "PredictSession.h"
#include "PredictGameThread.h"
PredictCommand::PredictCommand()
{
mCommandId = PMT_NULL;
}
PredictCommand::~PredictCommand()
{
}
void PredictCommand::Execute(PredictMessage* message, PredictSession* session)
{
this->ParseMessage(message);
this->ExecuteSession(session);
}
unsigned int PredictCommand::GetId()
{
return mCommandId;
}
void PredictCommand::SetCurrentThread(PredictGameThread* ownerThread)
{
mOwnerThread = ownerThread;
}
PredictCommandManager::~PredictCommandManager()
{
DataStructures::HashTable<DataStructures::HexString, PredictGameThread*>::SimpleIterator itr(&mGames);
PredictGameThread** command = itr.GetData();
while (command && *command)
{
// (*command)->Kill();
delete *command;
itr.FindNext();
command = itr.GetData();
}
mGames.Clear();
}
bool PredictCommandManager::InHashTable(const DataStructures::HexString& gameName)
{
return mGames.InHashTable(gameName);
}
__u32 PredictCommandManager::GetSessionId(const DataStructures::HexString& gameName)
{
// should exists
return mGames[gameName]->GeneratorSessionId();
}
PredictGameThread* PredictCommandManager::GetThreadByName(const DataStructures::HexString& gameName)
{
PredictGameThread* thread = 0;
if (mGames.InHashTable(gameName))
{
thread = mGames[gameName];
}
return thread;
}
void PredictCommandManager::AddGameThread(const DataStructures::HexString& gameName, PredictGameThread* gameThread)
{
mGames.Add(gameName, gameThread);
}
void PredictCommandManager::Execute(PredictMessage* message, PredictSession* session)
{
if (message->mId == PMT_SET_GAME_NAME)
{
PredictCommand* command = PredictCommandFactory::CreateCommand(message->mId);
if (command)
{
command->Execute(message, session);
delete command;
command = 0;
}
// print error
}
else
{
DataStructures::HexString gameName = session->GetGameName();
if (mGames.InHashTable(gameName))
{
mGames[gameName]->Submit(message, session);
}
}
}
PredictCommandManager* PredictCommandManager::Instance()
{
static PredictCommandManager manager;
return &manager;
}
PredictCommandManager::PredictCommandManager()
{
}