void WTemplate::setTemplateText(const WString& text, TextFormat textFormat) { text_ = text; if (textFormat == XHTMLText && text_.literal()) { if (!removeScript(text_)) text_ = escapeText(text_, true); } else if (textFormat == PlainText) text_ = escapeText(text_, true); if (!text_.literal() && !text_.isLanguage()) { WLocalizedStrings *ls = 0; WApplication *app = WApplication::instance(); if (app) ls = app->localizedStrings(); if (!ls) { WServer *server = WServer::instance(); if (server) ls = server->localizedStrings(); } ls->loadTemplateStyleSheet(text_.key(), text_.moduleAuthorId()); } changed_ = true; repaint(RepaintSizeAffected); }
/* create new instance based on template, or a saved instance */ Instance * ClusterMgr::CreateInstance(uint32 InstanceId, uint32 MapId) { /* pick a server for us :) */ WServer * server = GetWorkerServerForNewInstance(); if(!server) return 0; ASSERT(GetInstance(InstanceId) == NULL); /* bump up the max id if necessary */ if(m_maxInstanceId <= InstanceId) m_maxInstanceId = InstanceId + 1; Instance * pInstance = new Instance; pInstance->InstanceId = InstanceId; pInstance->MapId = MapId; pInstance->Server = server; Instances.insert( make_pair( InstanceId, pInstance ) ); /* tell the actual server to create the instance */ WorldPacket data(ISMSG_CREATE_INSTANCE, 8); data << MapId << InstanceId; server->SendPacket(&data); server->AddInstance(pInstance); Log.Debug("ClusterMgr", "Allocating instance %u on map %u to server %u", pInstance->InstanceId, pInstance->MapId, server->GetID()); return pInstance; }
int luawt_WServer_start(lua_State* L) { WServer* server = reinterpret_cast<WServer*>( luaL_checkudata(L, 1, "luawt_WServer") ); bool ok = server->start(); lua_pushboolean(L, ok); return 1; }
int luawt_WServer_stop(lua_State* L) { WServer* s = reinterpret_cast<WServer*>( luaL_checkudata(L, 1, "luawt_WServer") ); bool force = lua_toboolean(L, 2); if (force) { s->ioService().boost::asio::io_service::stop(); } s->stop(); return 0; }
WLogEntry log(const std::string& type) { WebSession *session = WebSession::instance(); if (session) return session->log(type); else { WServer *server = WServer::instance(); if (server) return server->log(type); else return defaultLogger.entry(type); } }
/** Creates the Wt application server Argument 1 is table of options Possible options: code, port, config. */ int luawt_WServer_make(lua_State* L) { luaL_checktype(L, 1, LUA_TTABLE); // get code lua_getfield(L, 1, "code"); size_t code_len; const char* code = luaL_checklstring(L, -1, &code_len); // get port lua_getfield(L, 1, "port"); const char* port = luaL_checkstring(L, -1); // get config lua_getfield(L, 1, "wt_config"); const char* config = luaL_checkstring(L, -1); // make argc, argv typedef std::vector<const char*> Options; Options opt; opt.push_back("luawt"); opt.push_back("--http-address=127.0.0.1"); opt.push_back("--http-port"); opt.push_back(port); opt.push_back("--docroot=/usr/share/Wt"); opt.push_back("--config"); opt.push_back(config); opt.push_back(0); WServer* server = reinterpret_cast<WServer*>( lua_newuserdata(L, sizeof(WServer)) ); int argc = opt.size() - 1; char** argv = const_cast<char**>(&opt[0]); new (server) WServer(); server->setServerConfiguration(argc, argv); server->addEntryPoint( Wt::Application, LuaAppCreator(std::string(code, code_len)) ); luaL_getmetatable(L, "luawt_WServer"); lua_setmetatable(L, -2); return 1; }
void *WServer::clientThread(void* param) #endif { WSClient *client = static_cast<WSClient*>(param); WServer *self = client->self; int recvBytes; char handshakeBuff[1024]; memset(handshakeBuff,0,sizeof(handshakeBuff)); int handshake = recv(client->sock,handshakeBuff,sizeof(handshakeBuff),0); if(!self->HandShakeClient(client,handshakeBuff)) { self->CloseClient(client); return NULL; } char buff[1024]; memset(buff,0,sizeof(buff)); do { recvBytes = recv(client->sock,buff,sizeof(buff),0); if(recvBytes > 0) { std::cout << "Received " << recvBytes << " bytes from client[" << client->id << "] {" << client->ip << "}.." << std::endl; self->parseCallback(RECV,(void*)buff); } } while(recvBytes > 0); std::cout << "Client " << client->id << " {" << client->ip << "} Disconnected...\n"; self->CloseClient(client); return NULL; }
bool WServer::readConfigurationProperty(const std::string& name, std::string& value) const { WServer *self = const_cast<WServer *>(this); return self->configuration().readConfigurationProperty(name, value); }
std::string WString::resolveKey() const { std::string result; WLocalizedStrings *ls = 0; WApplication *app = WApplication::instance(); if (app) ls = app->localizedStrings_; if (!ls) { WServer *server = WServer::instance(); if (server) ls = server->localizedStrings(); } if(ls) { //Check weather language or template if(impl_->isLanguage) { //Weather plural or singular if(impl_->n_ == -1) { //Weather module id was provided if(impl_->moduleAuthorId_ == -1) //get<1> = moduleId { if(ls->resolveKey(impl_->key_, result)) //get<0> = key(language key) return result; } else { if(ls->resolveKey(impl_->key_, impl_->moduleAuthorId_, result)) return result; } } else { if(impl_->moduleAuthorId_ == -1) { if(ls->resolvePluralKey(impl_->key_, result, impl_->n_)) return result; } else { if(ls->resolvePluralKey(impl_->key_, impl_->moduleAuthorId_, result, impl_->n_)) return result; } } } else { if(ls->resolveTemplateKey(impl_->key_, impl_->moduleAuthorId_, result)) { return result; } else if(ls->resolveTemplateKey(impl_->key_, impl_->moduleAuthorId_, result)) { return result; } } } if(impl_->isLanguage) { if(impl_->moduleAuthorId_ == -1) return "??" + impl_->key_ + "??"; else return "??" + impl_->key_ + "(" + boost::lexical_cast<std::string>(impl_->moduleAuthorId_) + ")??"; } else { return "???" + impl_->key_ + "(" + boost::lexical_cast<std::string>(impl_->moduleAuthorId_) + ")???"; } }