-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMatchServer.cpp
More file actions
175 lines (143 loc) · 3.77 KB
/
MatchServer.cpp
File metadata and controls
175 lines (143 loc) · 3.77 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "MatchServer.h"
#include "MatchServantImp.h"
#include "LogComm.h"
//
using namespace std;
//
MatchServer g_app;
/////////////////////////////////////////////////////////////////
void
MatchServer::initialize()
{
//initialize application here:
//...
///
addServant<MatchServantImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".MatchServantObj");
//初始化外部接口对象
initOuterFactory();
// 注册动态加载命令
TARS_ADD_ADMIN_CMD_NORMAL("reload", MatchServer::reloadSvrConfig);
// 加载比赛配置
TARS_ADD_ADMIN_CMD_NORMAL("matchconfig", MatchServer::reloadMatchConfig);
// 清理比赛场
TARS_ADD_ADMIN_CMD_NORMAL("cleanmatchgame", MatchServer::cleanMatchGame);
}
/////////////////////////////////////////////////////////////////
void
MatchServer::destroyApp()
{
//destroy application here:
//...
}
/*
* 配置变更,重新加载配置
*/
bool MatchServer::reloadSvrConfig(const string &command, const string ¶ms, string &result)
{
try
{
//加载配置
getOuterFactoryPtr()->load();
result = "reload server config success.";
LOG_DEBUG << "reloadSvrConfig: " << result << endl;
return true;
}
catch (TC_Exception const &e)
{
result = string("catch tc exception: ") + e.what();
}
catch (std::exception const &e)
{
result = string("catch std exception: ") + e.what();
}
catch (...)
{
result = "catch unknown exception.";
}
result += "\n fail, please check it.";
LOG_DEBUG << "reloadSvrConfig: " << result << endl;
return true;
}
/**
* 加载比赛场配置
*/
bool MatchServer::reloadMatchConfig(const string &command, const string ¶ms, string &result)
{
try
{
getOuterFactoryPtr()->loadMatchConfig();
result = "reload match config success.";
LOG_DEBUG << "reloadMatchConfig: " << result << endl;
return true;
}
catch (TC_Exception const &e)
{
result = string("catch tc exception: ") + e.what();
}
catch (std::exception const &e)
{
result = string("catch std exception: ") + e.what();
}
catch (...)
{
result = "catch unknown exception.";
}
result += "\n fail, please check it.";
LOG_DEBUG << "reloadMatchConfig: " << result << endl;
return true;
}
/**
* 清理某比赛场
*/
bool MatchServer::cleanMatchGame(const string &command, const string ¶ms, string &result)
{
try
{
result = "clean match game success.";
LOG_DEBUG << "cleanMatchGame: " << result << endl;
return true;
}
catch (TC_Exception const &e)
{
result = string("catch tc exception: ") + e.what();
}
catch (std::exception const &e)
{
result = string("catch std exception: ") + e.what();
}
catch (...)
{
result = "catch unknown exception.";
}
result += "\n fail, please check it.";
LOG_DEBUG << "cleanMatchGame: " << result << endl;
return true;
}
/**
* 初始化外部接口对象
**/
int MatchServer::initOuterFactory()
{
_pOuter = new OuterFactoryImp();
return 0;
}
/////////////////////////////////////////////////////////////////
int
main(int argc, char *argv[])
{
try
{
g_app.main(argc, argv);
g_app.waitForShutdown();
}
catch (std::exception &e)
{
cerr << "std::exception:" << e.what() << std::endl;
}
catch (...)
{
cerr << "unknown exception." << std::endl;
}
return -1;
}
/////////////////////////////////////////////////////////////////