aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
Commit message (Expand)AuthorAge
* Fix ATC rail reversingorwell962018-08-12
* Add off-track train flag, fixes wagon object property reset on reversingorwell962018-07-04
* Implement trains blocking sectionsorwell962018-06-29
* Fix final bugs and to-do's (u.a.save/load system)orwell962018-06-14
* Mainly make collisions and coupling workorwell962018-06-14
* Implement collisions. (does not work yet, still code errors)orwell962018-06-14
* Implement a reverse path lookup for trains instead of an occupations window s...orwell962018-06-14
* Fix path_dir to actually be an angle, path item deletion and orientation of w...orwell962018-06-14
* Bugfixes part 1orwell962018-06-14
* Occupation System, new train steps, still incompleteorwell962018-06-14
* Adapt wagons to new path systemorwell962018-06-14
* Restructure path systemorwell962018-06-14
* Add bord computer to trainsorwell962018-01-09
* Change controls for trains (again)orwell962018-01-07
* Decrease the amount of garbage saved in save filesorwell962018-01-07
* Remove path invalidation statement.orwell962017-12-18
* Do not spam the server chat with messages from /at_sync_ndb and trains going ...orwell962017-12-18
* Rewrite rail connection system...orwell962017-12-18
* remove superfluous parameterorwell962017-11-27
* Add modifiable wagon extentsorwell962017-11-23
* Fix multiple track types not working simultaneouslyorwell962017-11-22
* Do not punch signsorwell962017-11-14
* Fix entity damageorwell962017-11-02
* Punch non-player objects when they get overridden by a train.orwell962017-10-25
* Fix subway train placerorwell962017-10-25
* Some workaround fixes for Linuxworks serverorwell962017-10-25
* Implement multi-occupation in detector.on_node table to finally fix collisionsorwell962017-10-25
* Replace many math.floor(x+0.5) calls (or math.floor calls that should be thos...orwell962017-10-25
* Fix coupling and collisions in certain casesorwell962017-10-25
* Do not crash when train_pos is nil while checking wagon entity loadingorwell962017-10-11
* Remove zip release files, move mod to root, exclude assets from Makefile (#92)rubenwardy2017-09-20
* Restructure mod directoryorwell962017-01-04
* Add Automatic Train Control systemorwell962017-01-04
* unify update_trainpart_properties and check_trainpartloadorwell962017-01-02
* Do not duplicate definitions of 'print' in every fileorwell962017-01-02
* spawn couple on train collisionorwell962016-12-31
* remove train type concept and calculate train's capabilities based on used wa...orwell962016-12-22
* Turning mod into a modpack and separating the trains from the core modorwell962016-12-20
ass="hl opt">= std::string("Connection error: ") + ctx->errstr; redisFree(ctx); throw DatabaseException(err); } if (conf.exists("redis_password")) { tmp = conf.get("redis_password"); redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "AUTH %s", tmp.c_str())); if (!reply) throw DatabaseException("Redis authentication failed"); if (reply->type == REDIS_REPLY_ERROR) { std::string err = "Redis authentication failed: " + std::string(reply->str, reply->len); freeReplyObject(reply); throw DatabaseException(err); } freeReplyObject(reply); } } Database_Redis::~Database_Redis() { redisFree(ctx); } void Database_Redis::beginSave() { redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "MULTI")); if (!reply) { throw DatabaseException(std::string( "Redis command 'MULTI' failed: ") + ctx->errstr); } freeReplyObject(reply); } void Database_Redis::endSave() { redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "EXEC")); if (!reply) { throw DatabaseException(std::string( "Redis command 'EXEC' failed: ") + ctx->errstr); } freeReplyObject(reply); } bool Database_Redis::saveBlock(const v3s16 &pos, const std::string &data) { std::string tmp = i64tos(getBlockAsInteger(pos)); redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "HSET %s %s %b", hash.c_str(), tmp.c_str(), data.c_str(), data.size())); if (!reply) { warningstream << "saveBlock: redis command 'HSET' failed on " "block " << PP(pos) << ": " << ctx->errstr << std::endl; freeReplyObject(reply); return false; } if (reply->type == REDIS_REPLY_ERROR) { warningstream << "saveBlock: saving block " << PP(pos) << " failed: " << std::string(reply->str, reply->len) << std::endl; freeReplyObject(reply); return false; } freeReplyObject(reply); return true; } void Database_Redis::loadBlock(const v3s16 &pos, std::string *block) { std::string tmp = i64tos(getBlockAsInteger(pos)); redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "HGET %s %s", hash.c_str(), tmp.c_str())); if (!reply) { throw DatabaseException(std::string( "Redis command 'HGET %s %s' failed: ") + ctx->errstr); } switch (reply->type) { case REDIS_REPLY_STRING: { *block = std::string(reply->str, reply->len); // std::string copies the memory so this won't cause any problems freeReplyObject(reply); return; } case REDIS_REPLY_ERROR: { std::string errstr(reply->str, reply->len); freeReplyObject(reply); errorstream << "loadBlock: loading block " << PP(pos) << " failed: " << errstr << std::endl; throw DatabaseException(std::string( "Redis command 'HGET %s %s' errored: ") + errstr); } case REDIS_REPLY_NIL: { *block = ""; // block not found in database freeReplyObject(reply); return; } } errorstream << "loadBlock: loading block " << PP(pos) << " returned invalid reply type " << reply->type << ": " << std::string(reply->str, reply->len) << std::endl; freeReplyObject(reply); throw DatabaseException(std::string( "Redis command 'HGET %s %s' gave invalid reply.")); } bool Database_Redis::deleteBlock(const v3s16 &pos) { std::string tmp = i64tos(getBlockAsInteger(pos)); redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "HDEL %s %s", hash.c_str(), tmp.c_str())); if (!reply) { throw DatabaseException(std::string( "Redis command 'HDEL %s %s' failed: ") + ctx->errstr); } else if (reply->type == REDIS_REPLY_ERROR) { warningstream << "deleteBlock: deleting block " << PP(pos) << " failed: " << std::string(reply->str, reply->len) << std::endl; freeReplyObject(reply); return false; } freeReplyObject(reply); return true; } void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst) { redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "HKEYS %s", hash.c_str())); if (!reply) { throw DatabaseException(std::string( "Redis command 'HKEYS %s' failed: ") + ctx->errstr); } switch (reply->type) { case REDIS_REPLY_ARRAY: dst.reserve(reply->elements); for (size_t i = 0; i < reply->elements; i++) { assert(reply->element[i]->type == REDIS_REPLY_STRING); dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str))); } break; case REDIS_REPLY_ERROR: throw DatabaseException(std::string( "Failed to get keys from database: ") + std::string(reply->str, reply->len)); } freeReplyObject(reply); } #endif // USE_REDIS