virtual std::string toString(){ std::string str="UCB-V Policy with amp="; str+=dtos(amp); str+=" zeta="; str+=dtos(zeta); return str; }
p1_const(register Constp cp) #endif { int type = cp->vtype; expptr vleng = cp->vleng; union Constant *c = &cp->Const; char cdsbuf0[64], cdsbuf1[64]; char *cds0, *cds1; switch (type) { case TYINT1: case TYSHORT: case TYLONG: #ifdef TYQUAD0 case TYQUAD: #endif case TYLOGICAL: case TYLOGICAL1: case TYLOGICAL2: fprintf(pass1_file, "%d: %d %ld\n", P1_CONST, type, c->ci); break; #ifndef NO_LONG_LONG case TYQUAD: fprintf(pass1_file, "%d: %d %llx\n", P1_CONST, type, c->cq); break; #endif case TYREAL: case TYDREAL: fprintf(pass1_file, "%d: %d %s\n", P1_CONST, type, cp->vstg ? c->cds[0] : cds(dtos(c->cd[0]), cdsbuf0)); break; case TYCOMPLEX: case TYDCOMPLEX: if (cp->vstg) { cds0 = c->cds[0]; cds1 = c->cds[1]; } else { cds0 = cds(dtos(c->cd[0]), cdsbuf0); cds1 = cds(dtos(c->cd[1]), cdsbuf1); } fprintf(pass1_file, "%d: %d %s %s\n", P1_CONST, type, cds0, cds1); break; case TYCHAR: if (vleng && !ISICON (vleng)) err("p1_const: bad vleng\n"); else fprintf(pass1_file, "%d: %d %lx\n", P1_CONST, type, cpexpr((expptr)cp)); break; default: erri ("p1_const: bad constant type '%d'", type); break; } /* switch */ } /* p1_const */
int main() { startDaemon(); Fan fan("/sys/devices/platform/applesmc.768", "fan1"); Sensor coreOne( "/sys/devices/platform/applesmc.768/subsystem/devices/coretemp.0", "temp2"); Sensor coreTwo( "/sys/devices/platform/applesmc.768/subsystem/devices/coretemp.0", "temp3"); Load load("/proc", "stat"); fan.writeContent(fan.getPath() + "/" + fan.getName() + "_manual", "1"); #if FANMINSPEED fan.setFanMinSpeed(FANMINSPEED); #endif #if FANMAXSPEED fan.setFanMaxSpeed(FANMAXSPEED); #endif int loadFactor = (fan.getFanMaxSpeed() - fan.getFanMinSpeed()) / (LOADSCALETO - LOACSCALEFROM); int sensorFacotor = (fan.getFanMaxSpeed() - fan.getFanMinSpeed()) / (SENSORSCALETO - SENSORSCALEFROM); while (1) { double loadAverage = 0; double sensorAverage = 0; for (int i = 0; i < AVERAGECOUNT; i++) { loadAverage += load.getAverage(); sensorAverage += (coreOne.getTemp() + coreTwo.getTemp()); sleep(SLEEPTIME); } loadAverage = loadAverage / AVERAGECOUNT; sensorAverage = sensorAverage / ((2 * AVERAGECOUNT) * 100000); logToFile(DAEMON_LOG, dtos(loadAverage).c_str()); logToFile(DAEMON_LOG, dtos(sensorAverage).c_str()); if (loadAverage > LOACSCALEFROM) { fan.setSpeed( fan.getFanMinSpeed() + loadFactor * (loadAverage - LOACSCALEFROM)); } else { fan.setSpeed( fan.getFanMinSpeed() + sensorFacotor * (sensorAverage - SENSORSCALEFROM)); } } return (0); }
// Login request (http://mc.kev009.com/wiki/Protocol#Login_Request_.280x01.29) int PacketHandler::login_request(User *user) { //Check that we have enought data in the buffer if(!user->buffer.haveData(12)) { return PACKET_NEED_MORE_DATA; } int32_t version; std::string player, passwd; int64_t mapseed; int8_t dimension; user->buffer >> version >> player >> passwd >> mapseed >> dimension; if(!user->buffer) { return PACKET_NEED_MORE_DATA; } user->buffer.removePacket(); LOG(INFO, "Packets", "Player " + dtos(user->UID) + " login v." + dtos(version) + " : " + player + ":" + passwd); user->nick = player; // If version is not 2 or 3 if(version != PROTOCOL_VERSION) { user->kick(Mineserver::get()->config()->sData("strings.wrong_protocol")); return PACKET_OK; } // If userlimit is reached if((int)User::all().size() >= Mineserver::get()->config()->iData("system.user_limit")) { user->kick(Mineserver::get()->config()->sData("strings.server_full")); return PACKET_OK; } char* kickMessage = NULL; if ((static_cast<Hook2<bool,const char*,char**>*>(Mineserver::get()->plugin()->getHook("PlayerLoginPre")))->doUntilFalse(player.c_str(), &kickMessage)) { user->kick(std::string(kickMessage)); } else { user->sendLoginInfo(); (static_cast<Hook1<bool,const char*>*>(Mineserver::get()->plugin()->getHook("PlayerLoginPost")))->doAll(player.c_str()); } return PACKET_OK; }
OutputBuffer* appendd (OutputBuffer *buf, double d) { char *str = dtos(d); append(buf, str); free(str); return buf; }
void Chat::handleChatMsg(User* user, std::string msg, const std::string& timeStamp) { if(user->isAbleToCommunicate("chat") == false) { return; } // Check for Admins or Server Console if (user->UID == SERVER_CONSOLE_UID) { Mineserver::get()->screen()->log(LOG_CHAT, user->nick + " " + msg); msg = timeStamp + " " + MC_COLOR_RED + user->nick + MC_COLOR_WHITE + " " + msg; } else if(IS_ADMIN(user->permissions)) { Mineserver::get()->screen()->log(LOG_CHAT, "<"+ user->nick + "> " + msg); msg = timeStamp + " <"+ MC_COLOR_DARK_MAGENTA + user->nick + MC_COLOR_WHITE + "> " + msg; } else { Mineserver::get()->screen()->log(LOG_CHAT, "<"+ user->nick + "> " + dtos(user->UID) + " " + msg); msg = timeStamp + " <"+ user->nick + "> " + msg; } this->sendMsg(user, msg, ALL); }
OutputBuffer* appendd (OutputBuffer *buf, double d) { char *str = dtos(d); #ifdef OUTPUT_DEBUG printf("appendd: %f -> %s\n", d, str); #endif append(buf, str); free(str); return buf; }
prconr(FILEP fp, Constp x, int k) #endif { char *x0, *x1; char cdsbuf0[64], cdsbuf1[64]; if (k > 1) { if (x->vstg) { x0 = x->Const.cds[0]; x1 = x->Const.cds[1]; } else { x0 = cds(dtos(x->Const.cd[0]), cdsbuf0); x1 = cds(dtos(x->Const.cd[1]), cdsbuf1); } fprintf(fp, "\t%s %s\n", x0, x1); } else fprintf(fp, "\t%s\n", x->vstg ? x->Const.cds[0] : cds(dtos(x->Const.cd[0]), cdsbuf0)); }
PLUGIN_API_EXPORT void CALLCONVERSION msJavaPlugin_init(mineserver_pointer_struct* mineserver) { if (mineserver->plugin.getPluginVersion(PLUGIN_NAME) > 0) { std::string msg = PLUGIN_NAME " is already loaded v." + dtos(mineserver->plugin.getPluginVersion(PLUGIN_NAME)); mineserver->logger.log(LogType::LOG_ERROR, PLUGIN_NAME, msg.c_str()); return; } mineserver->plugin.setPluginVersion(PLUGIN_NAME, PLUGIN_VERSION); new MSJavaPlugin(mineserver); }
void OpenGLRender::overlayDisplay() { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, screenW, 0, screenH, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); //Lighting should not affect objects in the overlay checkLighting(false); //Only display debug text if user turned it on if(!debug) { //glTranslatef(cam.getPosX(),cam.getPosY()-1,cam.getPosZ()+1); //glTranslatef(0,0,0); glColor3f(1.0f,1.0f,1.0f); overlayLineCount = 0; rasterStringToOverlay("("+itos(cam->getLookAt().x)+","+ dtos(cam->getLookAt().y)+","+ itos(cam->getLookAt().z)+")"); rasterStringToOverlay(itos(mouseX) + "," + itos(mouseY)); if(selectedID != -1) { rasterStringToOverlay("Box Data:"); rasterStringToOverlay(" Box Height: "+itos(manager->getActorByID(selectedID)->getLocation().y)); rasterStringToOverlay(" Box ID: "+itos(selectedID)); } } //Draw the cursor int xTex = 25, yTex = 59; glBindTexture(GL_TEXTURE_2D, testTex[cursorTex]); glBegin(GL_QUADS); glTexCoord2f(1,1); glVertex3f(mouseX+xTex, screenH-mouseY,0); glTexCoord2f(0,1); glVertex3f(mouseX, screenH-mouseY,0); glTexCoord2f(0,0); glVertex3f(mouseX, screenH-mouseY-yTex,0); glTexCoord2f(1,0); glVertex3f(mouseX+xTex, screenH-mouseY-yTex,0); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); checkLighting(true); glPopMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glPopMatrix(); perspective(); }
UnicodeString& ChoiceFormat::toPattern(UnicodeString& result) const { result.remove(); for (int32_t i = 0; i < fCount; ++i) { if (i != 0) { result += VERTICAL_BAR; } UnicodeString buf; if (uprv_isPositiveInfinity(fChoiceLimits[i])) { result += INFINITY; } else if (uprv_isNegativeInfinity(fChoiceLimits[i])) { result += MINUS; result += INFINITY; } else { result += dtos(fChoiceLimits[i], buf); } if (fClosures[i]) { result += LESS_THAN; } else { result += LESS_EQUAL; } // Append fChoiceFormats[i], using quotes if there are special // characters. Single quotes themselves must be escaped in // either case. const UnicodeString& text = fChoiceFormats[i]; UBool needQuote = text.indexOf(LESS_THAN) >= 0 || text.indexOf(LESS_EQUAL) >= 0 || text.indexOf(LESS_EQUAL2) >= 0 || text.indexOf(VERTICAL_BAR) >= 0; if (needQuote) { result += SINGLE_QUOTE; } if (text.indexOf(SINGLE_QUOTE) < 0) { result += text; } else { for (int32_t j = 0; j < text.length(); ++j) { UChar c = text[j]; result += c; if (c == SINGLE_QUOTE) { result += c; } } } if (needQuote) { result += SINGLE_QUOTE; } } return result; }
PLUGIN_API_EXPORT void CALLCONVERSION flatpermissions_init(mineserver_pointer_struct* mineserver_temp) { mineserver = mineserver_temp; if(mineserver->plugin.getPluginVersion(pluginName.c_str())>0){ std::string msg = "flatpermission is already loaded, v. "+dtos(mineserver->plugin.getPluginVersion(pluginName.c_str())); mineserver->logger.log(6, "plugin.flatpermissions", msg.c_str()); return; } std::string msg = "Loaded "+pluginName+"!"; mineserver->logger.log(6, "plugin.flatpermissions", msg.c_str()); mineserver->plugin.setPluginVersion(pluginName.c_str(), PLUGIN_VERSION); mineserver->plugin.addCallback("PlayerLoginPost", (void*)loginPost); }
int main () { int num = -1234567890; printf("number: %d\n", num); printf("string: %s\n", itos(num)); double real = -25.93333333; printf("number: %f\n", real); printf("string: %s\n", dtos(real)); double zero = 0.0; printf("number: %f\n", zero); printf("string: %s\n", dtos(zero)); OutputBuffer *buf = createBuffer(); append(buf, "number: "); appendi(buf, num); append(buf, "\nfloat: "); appendd(buf, real); append(buf, "\nzero: "); appendd(buf, zero); append(buf, "\n"); printf("buffer:\n\n%s\n", readBuffer(buf, 0)); destroyBuffer(buf); }
PLUGIN_API_EXPORT void CALLCONVERSION passiveMobs_init(mineserver_pointer_struct* mineserver_temp) { mineserver = mineserver_temp; if (mineserver->plugin.getPluginVersion(pluginName.c_str()) > 0) { std::string msg = atoi(pluginName.c_str())+ " is already loaded v."+dtos(mineserver->plugin.getPluginVersion(pluginName.c_str())); mineserver->logger.log(6, "plugin.passiveMobs", msg.c_str()); return; } std::string msg = "Loaded "+pluginName+"!"; mineserver->logger.log(6, "plugin.passiveMobs", msg.c_str()); mineserver->plugin.setPluginVersion(pluginName.c_str(), PLUGIN_PASSIVEMOBS_VERSION); mineserver->plugin.addCallback("Timer200", (void *)timer200Function); mineserver->plugin.addCallback("gotAttacked", (void *)gotAttacked); }
realpart(register Addrp p) #endif { register Addrp q; if (p->tag == TADDR && p->uname_tag == UNAM_CONST && ISCOMPLEX (p->vtype)) return (Addrp)mkrealcon (p -> vtype + TYREAL - TYCOMPLEX, p->user.kludge.vstg1 ? p->user.Const.cds[0] : cds(dtos(p->user.Const.cd[0]),CNULL)); q = (Addrp) cpexpr((expptr) p); if( ISCOMPLEX(p->vtype) ) q = mkfield (q, "r", p -> vtype + TYREAL - TYCOMPLEX); return(q); }
void Application::generate_profiler_text() { vec2 position = vec2(100, 100); vec2 delta = vec2(0, -20); for (map<string, double>::const_iterator i = profile_entries.begin(); i != profile_entries.end(); ++i, position = position + delta) { const string &tag = i->first; const double &elapsed = i->second; string text = fitToFieldSize(tag + ":", ' ', 16, JUSTIFY_LEFT) + dtos(elapsed) + "ms"; queue_text_for_draw(position, text); } profile_entries.clear(); }
PLUGIN_API_EXPORT void CALLCONVERSION nether_init(mineserver_pointer_struct* mineserver_temp) { mineserver = mineserver_temp; if (mineserver->plugin.getPluginVersion(pluginName.c_str()) > 0) { std::string msg = "nether is already loaded v."+dtos(mineserver->plugin.getPluginVersion(pluginName.c_str())); mineserver->logger.log(LOG_INFO, "plugin.nether", msg.c_str()); return; } std::string msg = "Loaded "+pluginName+"!"; mineserver->logger.log(LOG_INFO, "plugin.nether", msg.c_str()); mineserver->plugin.setPluginVersion(pluginName.c_str(), PLUGIN_NETHER_VERSION); mineserver->plugin.addCallback("Timer200", reinterpret_cast<voidF>(timer200Function)); mineserver->plugin.addCallback("BlockPlacePre", reinterpret_cast<voidF>(blockPlacePreFunction)); }
PLUGIN_API_EXPORT void CALLCONVERSION command_init(mineserver_pointer_struct* mineserver_temp) { mineserver = mineserver_temp; itemexchange = ItemExchange(); if (mineserver->plugin.getPluginVersion(pluginName.c_str()) > 0) { std::string msg = "itemexchange is already loaded v."+dtos(mineserver->plugin.getPluginVersion(pluginName.c_str())); mineserver->logger.log(LOG_INFO, "plugin.itemexchange", msg.c_str()); return; } std::string msg = "Loaded "+pluginName+"!"; mineserver->logger.log(LOG_INFO, "plugin.itemexchange", msg.c_str()); mineserver->plugin.setPluginVersion(pluginName.c_str(), PLUGIN_ITEMEXCHANGE_VERSION); mineserver->plugin.addCallback("PlayerChatCommand", (void *)command_handler); }
PLUGIN_API_EXPORT void CALLCONVERSION ircchat_init(mineserver_pointer_struct* mineserver_temp) { mineserver = mineserver_temp; ircthread = new IrcThread(); pthread_create(&(ircthread->irc_thread), NULL, &thread_init, NULL); if (mineserver->plugin.getPluginVersion(pluginName.c_str()) > 0) { std::string msg = "ircchat is already loaded v."+dtos(mineserver->plugin.getPluginVersion(pluginName.c_str())); mineserver->logger.log(LOG_INFO, "plugin.ircchat", msg.c_str()); return; } std::string msg = "Loaded "+pluginName+"!"; mineserver->logger.log(LOG_INFO, "plugin.ircchat", msg.c_str()); mineserver->plugin.setPluginVersion(pluginName.c_str(), PLUGIN_IRCCHAT_VERSION); mineserver->plugin.addCallback("PlayerChatPre", (void *)message_handler); }
imagpart(register Addrp p) #endif { register Addrp q; if( ISCOMPLEX(p->vtype) ) { if (p->tag == TADDR && p->uname_tag == UNAM_CONST) return mkrealcon (p -> vtype + TYREAL - TYCOMPLEX, p->user.kludge.vstg1 ? p->user.Const.cds[1] : cds(dtos(p->user.Const.cd[1]),CNULL)); q = (Addrp) cpexpr((expptr) p); q = mkfield (q, "i", p -> vtype + TYREAL - TYCOMPLEX); return( (expptr) q ); } else /* Cast an integer type onto a Double Real type */ return( mkrealcon( ISINT(p->vtype) ? TYDREAL : p->vtype , "0")); }
bool Chat::sendUserlist(User* user) { this->sendMsg(user, MC_COLOR_BLUE + "[ " + dtos(User::all().size()) + " players online ]", USER); for(unsigned int i = 0; i < User::all().size(); i++) { std::string playerDesc = "> " + User::all()[i]->nick; if(User::all()[i]->muted) { playerDesc += MC_COLOR_YELLOW + " (muted)"; } if(User::all()[i]->dnd) { playerDesc += MC_COLOR_YELLOW + " (dnd)"; } this->sendMsg(user, playerDesc, USER); } return true; }
void showPosition(User *user, std::string command, std::deque<std::string> args) { if(args.size() == 1) { User *tUser = getUserByNick(args[0]); if(tUser != NULL) Chat::get().sendMsg(user, COLOR_MAGENTA + args[0] + " is at: " + dtos(tUser->pos.x) + " " + dtos(tUser->pos.y) + " " + dtos(tUser->pos.z), Chat::USER); else reportError(user, "User " + args[0] + " not found (see /players)"); } else { Chat::get().sendMsg(user, COLOR_MAGENTA + "You are at: " + dtos(user->pos.x) + " " + dtos(user->pos.y) + " " + dtos(user->pos.z), Chat::USER); } }
putconst(register Constp p) #endif { register Addrp q; struct Literal *litp, *lastlit; int k, len, type; int litflavor; double cd[2]; ftnint nblanks; char *strp; char cdsbuf0[64], cdsbuf1[64], *ds[2]; if (p->tag != TCONST) badtag("putconst", p->tag); q = ALLOC(Addrblock); q->tag = TADDR; type = p->vtype; q->vtype = ( type==TYADDR ? tyint : type ); q->vleng = (expptr) cpexpr(p->vleng); q->vstg = STGCONST; /* Create the new label for the constant. This is wasteful of labels because when the constant value already exists in the literal pool, this label gets thrown away and is never reclaimed. It might be cleaner to move this down past the first switch() statement below */ q->memno = newlabel(); q->memoffset = ICON(0); q -> uname_tag = UNAM_CONST; /* Copy the constant info into the Addrblock; do this by copying the largest storage elts */ q -> user.Const = p -> Const; q->user.kludge.vstg1 = p->vstg; /* distinguish string from binary fp */ /* check for value in literal pool, and update pool if necessary */ k = 1; switch(type) { case TYCHAR: if (halign) { strp = p->Const.ccp; nblanks = p->Const.ccp1.blanks; len = p->vleng->constblock.Const.ci; litflavor = LIT_CHAR; goto loop; } else q->memno = BAD_MEMNO; break; case TYCOMPLEX: case TYDCOMPLEX: k = 2; if (p->vstg) cd[1] = atof(ds[1] = p->Const.cds[1]); else ds[1] = cds(dtos(cd[1] = p->Const.cd[1]), cdsbuf1); case TYREAL: case TYDREAL: litflavor = LIT_FLOAT; if (p->vstg) cd[0] = atof(ds[0] = p->Const.cds[0]); else ds[0] = cds(dtos(cd[0] = p->Const.cd[0]), cdsbuf0); goto loop; case TYLOGICAL1: case TYLOGICAL2: case TYLOGICAL: type = tylogical; goto lit_int_flavor; case TYLONG: type = tyint; case TYSHORT: case TYINT1: #ifdef TYQUAD case TYQUAD: #endif lit_int_flavor: litflavor = LIT_INT; /* Scan the literal pool for this constant value. If this same constant has been assigned before, use the same label. Note that this routine does NOT consider two differently-typed constants with the same bit pattern to be the same constant */ loop: lastlit = litpool + nliterals; for(litp = litpool ; litp<lastlit ; ++litp) /* Remove this type checking to ensure that all bit patterns are reused */ if(type == litp->littype) switch(litflavor) { case LIT_CHAR: if (len == (int)litp->litval.litival2[0] && nblanks == litp->litval.litival2[1] && !memcmp(strp, litp->cds[0], len)) { q->memno = litp->litnum; frexpr((expptr)p); q->user.Const.ccp1.ccp0 = litp->cds[0]; return(q); } break; case LIT_FLOAT: if(cd[0] == litp->litval.litdval[0] && !strcmp(ds[0], litp->cds[0]) && (k == 1 || cd[1] == litp->litval.litdval[1] && !strcmp(ds[1], litp->cds[1]))) { ret: q->memno = litp->litnum; frexpr((expptr)p); return(q); } break; case LIT_INT: if(p->Const.ci == litp->litval.litival) goto ret; break; } /* If there's room in the literal pool, add this new value to the pool */ if(nliterals < maxliterals) { ++nliterals; /* litp now points to the next free elt */ litp->littype = type; litp->litnum = q->memno; switch(litflavor) { case LIT_CHAR: litp->litval.litival2[0] = len; litp->litval.litival2[1] = nblanks; q->user.Const.ccp = litp->cds[0] = memcpy(gmem(len,0), strp, len); break; case LIT_FLOAT: litp->litval.litdval[0] = cd[0]; litp->cds[0] = copys(ds[0]); if (k == 2) { litp->litval.litdval[1] = cd[1]; litp->cds[1] = copys(ds[1]); } break; case LIT_INT: litp->litval.litival = p->Const.ci; break; } /* switch (litflavor) */ } else many("literal constants", 'L', maxliterals); break; case TYADDR: break; default: badtype ("putconst", p -> vtype); break; } /* switch */ if (type != TYCHAR || halign) frexpr((expptr)p); return( q ); }
void HeavenGen::generateWithNoise(int x, int z, int map) { // Debug.. #ifdef PRINT_MAPGEN_TIME #ifdef WIN32 DWORD t_begin, t_end; t_begin = timeGetTime(); #else struct timeval start, end; gettimeofday(&start, NULL); #endif #endif // Populate blocks in chunk int32_t currentHeight; int32_t ymax; uint16_t ciel; uint8_t* curBlock; uint8_t* curData; uint8_t col[2] = {0, 8}; heavenblocks.assign(16 * 16 * 128, 0); double xBlockpos = x << 4; double zBlockpos = z << 4; for (int bX = 0; bX < 16; bX++) { for (int bZ = 0; bZ < 16; bZ++) { double h = (int8_t)((Randomgen.GetValue(xBlockpos + bX, 0 , zBlockpos + bZ) * 20)); double n = (int8_t)((Randomgen2.GetValue(xBlockpos + bX, 0, zBlockpos + bZ) * 10) + 64); heightmap[(bZ << 4) + bX] = (uint8_t)(h + n); int32_t bYbX = ((bZ << 7) + (bX << 11)); for (int bY = 0; bY < 128; bY++) { curData = &blockdata[bYbX >> 1]; curBlock = &heavenblocks[bYbX++]; if (bY > n - h && bY < n) { *curBlock = BLOCK_WOOL; *curData = (bYbX & 1) ? col[rand() % 2] : col[rand() % 2] << 4; continue; } *curBlock = BLOCK_AIR; } } } #ifdef PRINT_MAPGEN_TIME #ifdef WIN32 t_end = timeGetTime(); Mineserver::get()->logger()->log("Mapgen: " + dtos(t_end - t_begin) + "ms"); #else gettimeofday(&end, NULL); Mineserver::get()->logger()->log("Mapgen: " + dtos(end.tv_usec - start.tv_usec)); #endif #endif }
bool Mineserver::run() { uint32_t starttime = (uint32_t)time(0); uint32_t tick = (uint32_t)time(0); // load plugins if (config()->has("system.plugins") && (config()->type("system.plugins") == CONFIG_NODE_LIST)) { std::list<std::string> tmp = config()->mData("system.plugins")->keys(); for (std::list<std::string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it) { std::string path = config()->sData("system.path.plugins"); std::string name = config()->sData("system.plugins." + (*it)); std::string alias = *it; if (name[0] == '_') { path = ""; alias = name; name = name.substr(1); } plugin()->loadPlugin(name, path, alias); } } // Initialize map for (int i = 0; i < (int)m_map.size(); i++) { physics(i)->enabled = (config()->bData("system.physics.enabled")); m_map[i]->init(i); if (config()->bData("map.generate_spawn.enabled")) { LOG2(INFO, "Generating spawn area..."); int size = config()->iData("map.generate_spawn.size"); bool show_progress = config()->bData("map.generate_spawn.show_progress"); #ifdef __FreeBSD__ show_progress = false; #endif #ifdef WIN32 DWORD t_begin = 0, t_end = 0; #else clock_t t_begin = 0, t_end = 0; #endif for (int x = -size; x <= size; x++) { if (show_progress) { #ifdef WIN32 t_begin = timeGetTime(); #else t_begin = clock(); #endif } for (int z = -size; z <= size; z++) { m_map[i]->loadMap(x, z); } if (show_progress) { #ifdef WIN32 t_end = timeGetTime(); LOG2(INFO, dtos((x + size + 1) *(size * 2 + 1)) + "/" + dtos((size * 2 + 1) *(size * 2 + 1)) + " done. " + dtos((t_end - t_begin) / (size * 2 + 1)) + "ms per chunk"); #else t_end = clock(); LOG2(INFO, dtos((x + size + 1) *(size * 2 + 1)) + "/" + dtos((size * 2 + 1) *(size * 2 + 1)) + " done. " + dtos(((t_end - t_begin) / (CLOCKS_PER_SEC / 1000)) / (size * 2 + 1)) + "ms per chunk"); #endif } } } #ifdef DEBUG LOG(DEBUG, "Map", "Spawn area ready!"); #endif } // Initialize packethandler packetHandler()->init(); // Load ip from config const std::string ip = config()->sData("net.ip"); // Load port from config const int port = config()->iData("net.port"); #ifdef WIN32 WSADATA wsaData; int iResult; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) { LOG2(ERROR, std::string("WSAStartup failed with error: " + iResult)); return false; } #endif struct sockaddr_in addresslisten; int reuse = 1; m_eventBase = reinterpret_cast<event_base*>(event_init()); #ifdef WIN32 m_socketlisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); #else m_socketlisten = socket(AF_INET, SOCK_STREAM, 0); #endif if (m_socketlisten < 0) { LOG2(ERROR, "Failed to create listen socket"); return false; } memset(&addresslisten, 0, sizeof(addresslisten)); addresslisten.sin_family = AF_INET; addresslisten.sin_addr.s_addr = inet_addr(ip.c_str()); addresslisten.sin_port = htons(port); setsockopt(m_socketlisten, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse)); // Bind to port if (bind(m_socketlisten, (struct sockaddr*)&addresslisten, sizeof(addresslisten)) < 0) { LOG2(ERROR, "Failed to bind to " + ip + ":" + dtos(port)); return false; } if (listen(m_socketlisten, 5) < 0) { LOG2(ERROR, "Failed to listen to socket"); return false; } setnonblock(m_socketlisten); event_set(&m_listenEvent, m_socketlisten, EV_WRITE | EV_READ | EV_PERSIST, accept_callback, NULL); event_add(&m_listenEvent, NULL); LOG2(INFO, "Listening on: "); if (ip == "0.0.0.0") { // Print all local IPs char name[255]; gethostname(name, sizeof(name)); struct hostent* hostinfo = gethostbyname(name); int ipIndex = 0; while (hostinfo && hostinfo->h_addr_list[ipIndex]) { const std::string ip(inet_ntoa(*(struct in_addr*)hostinfo->h_addr_list[ipIndex++])); LOG2(INFO, ip + ":" + dtos(port)); } } else { LOG2(INFO, ip + ":" + dtos(port)); } timeval loopTime; loopTime.tv_sec = 0; loopTime.tv_usec = 200000; // 200ms m_running = true; event_base_loopexit(m_eventBase, &loopTime); // Create our Server Console user so we can issue commands time_t timeNow = time(NULL); while (m_running && event_base_loop(m_eventBase, 0) == 0) { event_base_loopexit(m_eventBase, &loopTime); // Run 200ms timer hook static_cast<Hook0<bool>*>(plugin()->getHook("Timer200"))->doAll(); // Alert any block types that care about timers for (size_t i = 0 ; i < plugin()->getBlockCB().size(); ++i) { const BlockBasicPtr blockcb = plugin()->getBlockCB()[i]; if (blockcb != NULL) { blockcb->timer200(); } } //Update physics every 200ms for (std::vector<Map*>::size_type i = 0 ; i < m_map.size(); i++) { physics(i)->update(); } //Every 10 seconds.. timeNow = time(0); if (timeNow - starttime > 10) { starttime = (uint32_t)timeNow; //Map saving on configurable interval if (m_saveInterval != 0 && timeNow - m_lastSave >= m_saveInterval) { //Save for (std::vector<Map*>::size_type i = 0; i < m_map.size(); i++) { m_map[i]->saveWholeMap(); } m_lastSave = timeNow; } // If users, ping them if (!User::all().empty()) { // Send server time Packet pkt; pkt << (int8_t)PACKET_TIME_UPDATE << (int64_t)m_map[0]->mapTime; (*User::all().begin())->sendAll(pkt); } //Check for tree generation from saplings for (size_t i = 0; i < m_map.size(); ++i) { m_map[i]->checkGenTrees(); } // TODO: Run garbage collection for chunk storage dealie? // Run 10s timer hook static_cast<Hook0<bool>*>(plugin()->getHook("Timer10000"))->doAll(); } // Every second if (timeNow - tick > 0) { tick = (uint32_t)timeNow; // Loop users for (std::set<User*>::const_iterator it = users().begin(); it != users().end(); ++it) { // No data received in 30s, timeout if ((*it)->logged && timeNow - (*it)->lastData > 30) { LOG2(INFO, "Player " + (*it)->nick + " timed out"); delete *it; } else if (!(*it)->logged && timeNow - (*it)->lastData > 100) { delete (*it); } else { if (m_damage_enabled) { (*it)->checkEnvironmentDamage(); } (*it)->pushMap(); (*it)->popMap(); } } for (std::vector<Map*>::size_type i = 0 ; i < m_map.size(); i++) { m_map[i]->mapTime += 20; if (m_map[i]->mapTime >= 24000) { m_map[i]->mapTime = 0; } } for (std::set<User*>::const_iterator it = users().begin(); it != users().end(); ++it) { (*it)->pushMap(); (*it)->popMap(); } // Check for Furnace activity furnaceManager()->update(); // Run 1s timer hook static_cast<Hook0<bool>*>(plugin()->getHook("Timer1000"))->doAll(); } // Underwater check / drowning // ToDo: this could be done a bit differently? - Fador // -- User::all() == users() - louisdx for (std::set<User*>::const_iterator it = users().begin(); it != users().end(); ++it) { (*it)->isUnderwater(); if ((*it)->pos.y < 0) { (*it)->sethealth((*it)->health - 5); } } } #ifdef WIN32 closesocket(m_socketlisten); #else close(m_socketlisten); #endif saveAll(); event_base_free(m_eventBase); return true; }
bool client_write(User *user) { //If there is data in the output buffer, crypt it before writing if (!user->buffer.getWriteEmpty()) { std::vector<char> buf; user->buffer.getWriteData(buf); //More glue - Fador if(user->crypted) { //We might have to write some data uncrypted ToDo: fix if(user->uncryptedLeft) { user->bufferCrypted.addToWrite((uint8_t *)buf.data(),user->uncryptedLeft); } int p_len = buf.size()-user->uncryptedLeft, f_len = 0; if(p_len) { uint8_t *buffer = (uint8_t *)malloc(p_len+1); EVP_EncryptUpdate(&user->en, (uint8_t *)buffer, &p_len, (const uint8_t *)buf.data()+user->uncryptedLeft, buf.size()-user->uncryptedLeft); int written = p_len + f_len; user->bufferCrypted.addToWrite((uint8_t *)buffer,written); free(buffer); } user->uncryptedLeft = 0; } else { user->bufferCrypted.addToWrite((uint8_t *)buf.data(),buf.size()); user->uncryptedLeft = 0; } //free(outBuf); user->buffer.clearWrite(buf.size()); } //We have crypted data ready to be written if(!user->bufferCrypted.getWriteEmpty()) { std::vector<char> buf; user->bufferCrypted.getWriteData(buf); //Try to write the whole buffer const int written = send(user->fd, buf.data(), buf.size(), 0); //Handle errors if (written == SOCKET_ERROR) { #ifdef WIN32 #define ERROR_NUMBER WSAGetLastError() if ((ERROR_NUMBER != WSATRY_AGAIN && ERROR_NUMBER != WSAEINTR && ERROR_NUMBER != WSAEWOULDBLOCK)) #else #define ERROR_NUMBER errno if ((errno != EAGAIN && errno != EINTR)) #endif { LOG2(ERROR, "Error writing to client, tried to write " + dtos(buf.size()) + " bytes, code: " + dtos(ERROR_NUMBER)); //delete user; user->logged = false; ServerInstance->usersToRemove().insert(user); return false; } } else { //Remove written amount from the buffer user->bufferCrypted.clearWrite(written); } //If we couldn't write everything at once, add EV_WRITE event calling this function again.. if (!user->bufferCrypted.getWriteEmpty()) { event_add(user->getWriteEvent(), nullptr); return false; } } return true; }
// Physics loop bool Physics::update() { if(!enabled) { return true; } // Check if needs to be updated if(simList.empty()) { return true; } clock_t starttime = clock(); std::vector<sint32> toRemove; std::vector<vec> toAdd; Screen::get()->log("Simulating " + dtos(simList.size()) + " items!"); uint32 listSize = simList.size(); // Iterate each simulation for(uint32 simIt = 0; simIt < listSize; simIt++) { vec pos = simList[simIt].blocks[0].pos; // Blocks uint8 block, meta; Map::get()->getBlock(pos, &block, &meta); simList[simIt].blocks[0].id = block; simList[simIt].blocks[0].meta = meta; // Water simulation if(simList[simIt].type == TYPE_WATER) { if(isWaterBlock(block)) { sint32 it = 0; //for(sint32 it=simList[simIt].blocks.size()-1; it>=0; it--) { bool havesource = false; // Search for water source if this is not the source if(simList[simIt].blocks[it].id != BLOCK_STATIONARY_WATER) { for(int i = 0; i < 6; i++) { vec local(pos); switch(i) { case 0: local += vec( 0, 1, 0); break; //y++ case 1: local += vec( 1, 0, 0); break; //x++ case 2: local += vec(-1, 0, 0); break; //x-- case 3: local += vec( 0, 0, 1); break; //z++ case 4: local += vec( 0, 0, -1); break; //z-- case 5: local += vec( 0, -1, 0); break; //y-- } // Search neighboring water blocks for source current if (Map::get()->getBlock(local, &block, &meta) && isWaterBlock(block)) { // is this the source block if(i != 5 && (block == BLOCK_STATIONARY_WATER || (meta&0x07) < (simList[simIt].blocks[it].meta&0x07) || i == 0)) { havesource = true; } //Else we have to search for source to this block also else if(i == 5 || (meta&0x07) > (simList[simIt].blocks[it].meta&0x07)) { toAdd.push_back(local); } } } } //Stationary water block is the source else { havesource = true; } //If no source, dry block away if(!havesource) { //This block will change so add surrounding blocks to simulation for(uint32 i = 0; i < toAdd.size(); i++) { addSimulation(toAdd[i]); } //If not dried out yet if(!(simList[simIt].blocks[it].meta&0x8) && (simList[simIt].blocks[it].meta&0x07) < M7) { // Set new water level block = BLOCK_WATER; meta = simList[simIt].blocks[it].meta+1; Map::get()->setBlock(pos, block, meta); Map::get()->sendBlockChange(pos, block, meta); toRemove.push_back(simIt); addSimulation(pos); // Update simulation meta information // simList[simIt].blocks[it].meta = meta; } //Else this block has dried out else { //Clear and remove simulation Map::get()->setBlock(pos, BLOCK_AIR, 0); Map::get()->sendBlockChange(pos, BLOCK_AIR, 0); toRemove.push_back(simIt); //If below this block has another waterblock, simulate it also if(Map::get()->getBlock(pos - vec(0, 1, 0), &block, &meta) && isWaterBlock(block)) addSimulation(pos - vec(0, 1, 0)); } } //Have source! else { toAdd.clear(); vec belowPos(pos - vec(0, 1, 0)); // If below is free to fall if(Map::get()->getBlock(belowPos, &block, &meta) && mayFallThrough(block)) { // Set new fallblock there block = BLOCK_WATER; meta = M_FALLING; Map::get()->setBlock(belowPos, block, meta); Map::get()->sendBlockChange(belowPos, block, meta); // Change simulation-block to current block toRemove.push_back(simIt); addSimulation(belowPos); } //Else if spreading to sides //If water level is at minimum, dont simulate anymore else if((simList[simIt].blocks[it].meta&M7) != M7) { for(int i = 0; i < 4; i++) { vec local(pos); switch(i) { case 0: local += vec( 1, 0, 0); break; case 1: local += vec(-1, 0, 0); break; case 2: local += vec( 0, 0, 1); break; case 3: local += vec( 0, 0, -1); break; } if(Map::get()->getBlock(local, &block, &meta) && mayFallThrough(block)) { //Decrease water level each turn if(!isWaterBlock(block) || meta > (simList[simIt].blocks[it].meta&0x07)+1) { meta = (simList[simIt].blocks[it].meta&0x07)+1; Map::get()->setBlock(local, BLOCK_WATER, meta); Map::get()->sendBlockChange(local, BLOCK_WATER, meta); addSimulation(local); } } } // End for i=0:3 //Remove this block from simulation toRemove.push_back(simIt); } //Water level at minimum else { //Remove this block from simulation toRemove.push_back(simIt); } } } } //Block has changes else { //Remove this block from simulation toRemove.push_back(simIt); } } else { //Remove this block from simulation toRemove.push_back(simIt); } } std::vector<int>::reverse_iterator rit; for ( rit = toRemove.rbegin() ; rit < toRemove.rend(); ++rit ) { simList.erase(simList.begin()+*rit); } clock_t endtime = clock()-starttime; Screen::get()->log("Exit simulation, took " + dtos(endtime*1000/CLOCKS_PER_SEC) + " ms, " + dtos(simList.size()) + " items left"); return true; }
void NetherGen::generateWithNoise(int x, int z, int map) { // Debug.. #ifdef PRINT_MAPGEN_TIME #ifdef WIN32 DWORD t_begin, t_end; t_begin = timeGetTime(); #else struct timeval start, end; gettimeofday(&start, NULL); #endif #endif sChunk* chunk = ServerInstance->map(map)->getChunk(x, z); // Populate blocks in chunk int32_t currentHeight; int32_t ymax; uint16_t ciel; uint8_t* curBlock; double xBlockpos = x << 4; double zBlockpos = z << 4; for (int bX = 0; bX < 16; bX++) { for (int bZ = 0; bZ < 16; bZ++) { double ciel2 = (Randomciel.GetValue(xBlockpos + bX, 0 , zBlockpos + bZ) * 1.5); ciel = 128 - (uint16_t)(abs(ciel2 * ciel2 * ciel2 * ciel2 * ciel2 * ciel2)); // Cubed! Get some good stalagtites! heightmap[(bZ << 4) + bX] = ymax = currentHeight = (uint8_t)((Randomgen.GetValue(xBlockpos + bX, 0, zBlockpos + bZ) * 15) + 64); int32_t stoneHeight = (int32_t)(currentHeight * 0.94); int32_t bYbX = ((bZ << 7) + (bX << 11)); if (ymax < seaLevel) { ymax = seaLevel; } for (int bY = 0; bY < 128; bY++) { int index = bX + (bZ << 4) + (bY << 8); curBlock = &(chunk->blocks[index]); if (bY >= 126) { *curBlock = BLOCK_BEDROCK; continue; } if (bY == 0) { *curBlock = BLOCK_BEDROCK; continue; } if (bY > ciel) { *curBlock = BLOCK_NETHERSTONE; continue; } if (bY < currentHeight) { if (bY < stoneHeight) { *curBlock = BLOCK_NETHERSTONE; // Add caves // cave.AddCaves(*curBlock, xBlockpos + bX, bY, zBlockpos + bZ, map); } else { *curBlock = BLOCK_NETHERSTONE; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { *curBlock = BLOCK_SLOW_SAND; // FF } else if (bY < seaLevel - 1) { *curBlock = BLOCK_GRAVEL; // FF } else { *curBlock = BLOCK_NETHERSTONE; // FF } } else { if (bY <= seaLevel) { *curBlock = BLOCK_STATIONARY_LAVA; // FF } else { *curBlock = BLOCK_AIR; // FF } } } } } #ifdef PRINT_MAPGEN_TIME #ifdef WIN32 t_end = timeGetTime(); ServerInstance->logger()->log("Mapgen: " + dtos(t_end - t_begin) + "ms"); #else gettimeofday(&end, NULL); ServerInstance->logger()->log("Mapgen: " + dtos(end.tv_usec - start.tv_usec)); #endif #endif }
int Mineserver::run(int argc, char *argv[]) { uint32 starttime = (uint32)time(0); uint32 tick = (uint32)time(0); // Init our Screen screen()->init(VERSION); screen()->log("Welcome to Mineserver v" + VERSION); updatePlayerList(); initConstants(); std::string file_config; file_config.assign(CONFIG_FILE); std::string file_commands; file_commands.assign(COMMANDS_FILE); if (argc > 1) { file_config.assign(argv[1]); } // Initialize conf Mineserver::get()->conf()->load(file_config); Mineserver::get()->conf()->load(file_commands, COMMANDS_NAME_PREFIX); // Write PID to file std::ofstream pid_out((Mineserver::get()->conf()->sValue("pid_file")).c_str()); if (!pid_out.fail()) { #ifdef WIN32 pid_out << _getpid(); #else pid_out << getpid(); #endif } pid_out.close(); // Load MOTD Mineserver::get()->chat()->checkMotd(Mineserver::get()->conf()->sValue("motd_file")); // Set physics enable state according to config Mineserver::get()->physics()->enabled = (Mineserver::get()->conf()->bValue("liquid_physics")); // Initialize map Mineserver::get()->map()->init(); if (Mineserver::get()->conf()->bValue("map_generate_spawn")) { Mineserver::get()->screen()->log("Generating spawn area..."); int size = Mineserver::get()->conf()->iValue("map_generate_spawn_size"); bool show_progress = Mineserver::get()->conf()->bValue("map_generate_spawn_show_progress"); #ifdef WIN32 DWORD t_begin,t_end; #else clock_t t_begin,t_end; #endif for (int x=-size;x<=size;x++) { #ifdef WIN32 if(show_progress) { t_begin = timeGetTime(); } #else if(show_progress) { t_begin = clock(); } #endif for (int z = -size; z <= size; z++) { Mineserver::get()->map()->loadMap(x, z); } if(show_progress) { #ifdef WIN32 t_end = timeGetTime (); Mineserver::get()->screen()->log(dtos((x+size+1)*(size*2+1)) + "/" + dtos((size*2+1)*(size*2+1)) + " done. " + dtos((t_end-t_begin)/(size*2+1)) + "ms per chunk"); #else t_end = clock(); Mineserver::get()->screen()->log(dtos((x+size+1)*(size*2+1)) + "/" + dtos((size*2+1)*(size*2+1)) + " done. " + dtos(((t_end-t_begin)/(CLOCKS_PER_SEC/1000))/(size*2+1)) + "ms per chunk"); #endif } } #ifdef _DEBUG Mineserver::get()->screen()->log("Spawn area ready!"); #endif } // Initialize packethandler Mineserver::get()->packetHandler()->init(); // Load ip from config std::string ip = Mineserver::get()->conf()->sValue("ip"); // Load port from config int port = Mineserver::get()->conf()->iValue("port"); // Initialize plugins Mineserver::get()->plugin()->init(); #ifdef WIN32 WSADATA wsaData; int iResult; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if(iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); Mineserver::get()->screen()->end(); return EXIT_FAILURE; } #endif struct sockaddr_in addresslisten; int reuse = 1; m_eventBase = (event_base*)event_init(); #ifdef WIN32 m_socketlisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); #else m_socketlisten = socket(AF_INET, SOCK_STREAM, 0); #endif if(m_socketlisten < 0) { Mineserver::get()->screen()->log(LOG_ERROR, "Failed to create listen socket"); Mineserver::get()->screen()->end(); return 1; } memset(&addresslisten, 0, sizeof(addresslisten)); addresslisten.sin_family = AF_INET; addresslisten.sin_addr.s_addr = inet_addr(ip.c_str()); addresslisten.sin_port = htons(port); setsockopt(m_socketlisten, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse)); //Bind to port if(bind(m_socketlisten, (struct sockaddr*)&addresslisten, sizeof(addresslisten)) < 0) { Mineserver::get()->screen()->log(LOG_ERROR, "Failed to bind"); return 1; } if(listen(m_socketlisten, 5) < 0) { Mineserver::get()->screen()->log(LOG_ERROR, "Failed to listen to socket"); Mineserver::get()->screen()->end(); return 1; } setnonblock(m_socketlisten); event_set(&m_listenEvent, m_socketlisten, EV_WRITE|EV_READ|EV_PERSIST, accept_callback, NULL); event_add(&m_listenEvent, NULL); if(ip == "0.0.0.0") { // Print all local IPs char name[255]; gethostname ( name, sizeof(name)); struct hostent* hostinfo = gethostbyname(name); Mineserver::get()->screen()->log("Listening on: "); int ipIndex = 0; while(hostinfo && hostinfo->h_addr_list[ipIndex]) { std::string ip(inet_ntoa(*(struct in_addr*)hostinfo->h_addr_list[ipIndex++])); Mineserver::get()->screen()->log(" " + ip + ":" + dtos(port)); } } else { std::string myip(ip); Mineserver::get()->screen()->log("Listening on " + myip + ":" + dtos(port)); } //std::cout << std::endl; timeval loopTime; loopTime.tv_sec = 0; loopTime.tv_usec = 200000; //200ms m_running = true; event_base_loopexit(m_eventBase, &loopTime); // Create our Server Console user so we can issue commands User* serverUser = new User(-1, SERVER_CONSOLE_UID); serverUser->changeNick("[Server]"); while(m_running && event_base_loop(m_eventBase, 0) == 0) { // Append current command and check if user entered return if(Mineserver::get()->screen()->hasCommand()) { // Now handle this command as normal Mineserver::get()->chat()->handleMsg(serverUser, Mineserver::get()->screen()->getCommand().c_str()); } if(time(0)-starttime > 10) { starttime = (uint32)time(0); //If users, ping them if(User::all().size() > 0) { //0x00 package uint8 data = 0; User::all()[0]->sendAll(&data, 1); //Send server time Packet pkt; pkt << (sint8)PACKET_TIME_UPDATE << (sint64)Mineserver::get()->map()->mapTime; User::all()[0]->sendAll((uint8*)pkt.getWrite(), pkt.getWriteLen()); } // TODO: Run garbage collection for chunk storage dealie? } //Every second if(time(0)-tick > 0) { tick = (uint32)time(0); //Loop users for(unsigned int i = 0; i < User::all().size(); i++) { User::all()[i]->pushMap(); User::all()[i]->popMap(); //Minecart hacks!! /* if(User::all()[i]->attachedTo) { Packet pkt; pkt << PACKET_ENTITY_VELOCITY << (sint32)User::all()[i]->attachedTo << (sint16)10000 << (sint16)0 << (sint16)0; //pkt << PACKET_ENTITY_RELATIVE_MOVE << (sint32)User::all()[i]->attachedTo << (sint8)100 << (sint8)0 << (sint8)0; User::all()[i]->sendAll((uint8*)pkt.getWrite(), pkt.getWriteLen()); } */ } map()->mapTime+=20; if (map()->mapTime >= 24000) { map()->mapTime = 0; } map()->checkGenTrees(); // Check for Furnace activity Mineserver::get()->furnaceManager()->update(); } // Physics simulation every 200ms Mineserver::get()->physics()->update(); // Underwater check / drowning int i = 0; int s = User::all().size(); for(i=0;i<s;i++) { User::all()[i]->isUnderwater(); } // event_set(&m_listenEvent, m_socketlisten, EV_WRITE|EV_READ|EV_PERSIST, accept_callback, NULL); // event_add(&m_listenEvent, NULL); event_base_loopexit(m_eventBase, &loopTime); } #ifdef WIN32 closesocket(m_socketlisten); #else close(m_socketlisten); #endif // Remove the PID file #ifdef WIN32 _unlink((Mineserver::get()->conf()->sValue("pid_file")).c_str()); #else unlink((Mineserver::get()->conf()->sValue("pid_file")).c_str()); #endif // End our NCurses session screen()->end(); /* Free memory */ delete m_map; delete m_chat; delete m_plugin; delete m_screen; delete m_physics; delete m_conf; delete m_furnaceManager; delete m_packetHandler; delete m_mapGen; delete m_logger; return EXIT_SUCCESS; }
void MapGen::generateWithNoise(int x, int z, int map) { // Debug.. #ifdef PRINT_MAPGEN_TIME #ifdef WIN32 DWORD t_begin,t_end; t_begin = timeGetTime (); #else struct timeval start, end; gettimeofday(&start, NULL); #endif #endif sChunk *chunk = Mineserver::get()->map(map)->chunks.getChunk(x,z); // Winterland Block topBlock = BLOCK_GRASS; if(winterEnabled) topBlock = BLOCK_SNOW; // Populate blocks in chunk int32_t currentHeight; int32_t ymax; uint8_t *curBlock; double xBlockpos = x<<4; double zBlockpos = z<<4; for(int bX = 0; bX < 16; bX++) { for(int bZ = 0; bZ < 16; bZ++) { heightmap[(bZ<<4)+bX] = ymax = currentHeight = (uint8_t)((ridgedMultiNoise.GetValue(xBlockpos+bX,0, zBlockpos+bZ) * 15) + 64); int32_t stoneHeight = (int32_t)(currentHeight * 0.94); int32_t bYbX = ((bZ << 7) + (bX << 11)); if(ymax < seaLevel) ymax = seaLevel; for(int bY = 0; bY <= ymax; bY++) { curBlock = &(chunk->blocks[bYbX++]); // Place bedrock if(bY == 0) { *curBlock = BLOCK_BEDROCK; continue; } if(bY < currentHeight) { if (bY < stoneHeight) { *curBlock = BLOCK_STONE; // Add caves if(addCaves) cave.AddCaves(*curBlock, xBlockpos + bX, bY, zBlockpos + bZ); } else *curBlock = BLOCK_DIRT; } else if(currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) *curBlock = BLOCK_SAND; // FF else if (bY < seaLevel - 1) *curBlock = BLOCK_GRAVEL; // FF else *curBlock = topBlock; // FF } else { if (bY <= seaLevel) *curBlock = BLOCK_WATER; // FF else *curBlock = BLOCK_AIR; // FF } } } } #ifdef PRINT_MAPGEN_TIME #ifdef WIN32 t_end = timeGetTime (); Mineserver::get()->logger()->log("Mapgen: " + dtos(t_end-t_begin) + "ms"); #else gettimeofday(&end, NULL); Mineserver::get()->logger()->log("Mapgen: " + dtos(end.tv_usec - start.tv_usec)); #endif #endif }