1 // NeLNS - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "nel/misc/types_nl.h"
26 #include "nel/misc/debug.h"
27 #include "nel/misc/config_file.h"
28 #include "nel/misc/displayer.h"
29 #include "nel/misc/log.h"
31 #include "nel/net/buf_server.h"
32 #include "nel/net/service.h"
34 #include "admin_service.h"
41 using namespace NLMISC
;
42 using namespace NLNET
;
49 CBufServer
*WebServer
= 0;
56 void cbGetRequest (CMemStream
&msgin
, TSockId host
)
59 msgin
.serial (rawvarpath
);
60 addRequest (rawvarpath
, host
);
63 typedef void (*WebCallback
)(CMemStream
&msgin
, TSockId host
);
65 WebCallback WebCallbackArray
[] =
74 void sendString (TSockId from
, const string
&str
)
76 nlinfo ("REQUEST: Send '%s' to php '%s'", str
.c_str (), from
->asString ().c_str());
84 msgout
.serial (const_cast<string
&>(str
));
85 WebServer
->send (msgout
, from
);
88 void connectionWebInit ()
90 nlassert(WebServer
== 0);
92 WebServer
= new CBufServer ();
93 nlassert(WebServer
!= 0);
95 uint16 port
= (uint16
) IService::getInstance ()->ConfigFile
.getVar ("WebPort").asInt();
96 WebServer
->init (port
);
98 nlinfo ("Set the server connection for web to port %hu", port
);
101 void connectionWebUpdate ()
103 nlassert(WebServer
!= 0);
107 WebServer
->update ();
109 while (WebServer
->dataAvailable ())
111 // create a string mem stream to easily communicate with web server
112 NLMISC::CMemStream
msgin (true);
114 sint8 messageType
= 0;
118 WebServer
->receive (msgin
, &host
);
122 msgin
.serial (messageType
);
126 nlwarning ("Error during receive: '%s'", e
.what ());
129 if(messageType
>=0 && messageType
<(sint8
)(sizeof(WebCallbackArray
)/sizeof(WebCallbackArray
[0])))
131 WebCallbackArray
[messageType
](msgin
, host
);
135 nlwarning ("Received an unknown message type %d from web server", messageType
);
141 nlwarning ("Error during update: '%s'", e
.what ());
145 void connectionWebRelease ()
147 nlassert(WebServer
!= 0);