Change Encyclo button name and macros icon
[ryzomcore.git] / nelns / admin_service / connection_web.cpp
blob23214958441f73ffbf43ba20017ede2a382bcefb
1 // NeLNS - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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"
19 #include <stdio.h>
20 #include <ctype.h>
21 #include <math.h>
23 #include <vector>
24 #include <map>
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"
37 // Namespaces
40 using namespace std;
41 using namespace NLMISC;
42 using namespace NLNET;
46 // Variables
49 CBufServer *WebServer = 0;
53 // Callbacks
56 void cbGetRequest (CMemStream &msgin, TSockId host)
58 string rawvarpath;
59 msgin.serial (rawvarpath);
60 addRequest (rawvarpath, host);
63 typedef void (*WebCallback)(CMemStream &msgin, TSockId host);
65 WebCallback WebCallbackArray[] =
67 cbGetRequest,
71 // Functions
74 void sendString (TSockId from, const string &str)
76 nlinfo ("REQUEST: Send '%s' to php '%s'", str.c_str (), from->asString ().c_str());
78 if(from == 0)
79 return;
81 CMemStream msgout;
82 uint32 fake = 0;
83 msgout.serial(fake);
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);
113 TSockId host;
114 sint8 messageType = 0;
118 WebServer->receive (msgin, &host);
119 uint32 fake = 0;
120 msgin.serial(fake);
122 msgin.serial (messageType);
124 catch (Exception &e)
126 nlwarning ("Error during receive: '%s'", e.what ());
129 if(messageType>=0 && messageType<(sint8)(sizeof(WebCallbackArray)/sizeof(WebCallbackArray[0])))
131 WebCallbackArray[messageType](msgin, host);
133 else
135 nlwarning ("Received an unknown message type %d from web server", messageType);
139 catch (Exception &e)
141 nlwarning ("Error during update: '%s'", e.what ());
145 void connectionWebRelease ()
147 nlassert(WebServer != 0);
149 delete WebServer;
150 WebServer = 0;