-
Notifications
You must be signed in to change notification settings - Fork 0
/
RequestFactory.cpp
68 lines (62 loc) · 2.29 KB
/
RequestFactory.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
/*
* RequestFactory.cpp
*
* Created on: 16 déc. 2012
* Author: root
*/
#include "RequestFactory.h"
#include "WSServer.h"
RequestFactory::RequestFactory(WSServer* server){
this->server=server;
}
Request* RequestFactory::createRequest(const websocketpp::server::handler::connection_ptr& con,const std::string& source){
//parsing json
JsonParser* parser = new JsonParser(source);
if(parser->getCurrentValue()){
if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(MESSAGE)) == 0){
if(parser->nextValue()){
return new RequestMessage(parser,con,this->server);
}
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(SEND_SELF_DATA)) == 0){
if(parser->nextValue()){
return new RequestSendSelfData(parser,con,this->server);
}
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(LAUNCH_GAME)) == 0){
if(parser->nextValue()){
return new RequestLaunchGame(parser,con,this->server);
}
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(REFRESH_OUT_GAME_DATA)) == 0){
delete parser;
return new RequestRefreshOutGameData(con,this->server);
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(CREATE_GAME)) == 0){
delete parser;
return new RequestCreateGame(con,this->server);
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(JOIN_GAME)) == 0){
if(parser->nextValue()){
return new RequestJoinGame(parser,con,this->server);
}
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(SELECT_SERVER_MAP)) == 0){
return new RequestSelectMap(parser,con,this->server);
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(CHOOSE_COLOR)) == 0){
return new RequestChooseColor(parser,con,this->server);
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(MOVE)) == 0){
if(parser->nextValue()){
return new RequestMove(parser,con,this->server);
}
}
else if(std::string((parser->getCurrentValue()->string_value)).compare(stringify(DROP_BOMB)) == 0){
if(parser->nextValue()){
return new RequestDropBomb(parser,con,this->server);
}
}
}
return new Request(con);
}