mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Initial stab at making the master server dole out resources more fairly when running a deficit.
This commit is contained in:
1 parent
49887012f7
commit
ce6ab38a72
1 file changed
+15
-2
@@ -197,7 +197,10 @@ app.post("/api/place", function(req, res) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// endpoint to remove items from DB when client orders items
|
// endpoint to remove items from DB when client orders items
|
||||||
|
_doleDivisionFactor = {}; //If the server regularly can't fulfill requests, this number grows until it can. Then it slowly shrinks back down.
|
||||||
app.post("/api/remove", function(req, res) {
|
app.post("/api/remove", function(req, res) {
|
||||||
|
const doleDivisionRetardation = 10; //lower rates will equal more dramatic swings
|
||||||
|
const maxDoleDivision = 250; //a higher cap will divide the store more ways, but will take longer to recover as supplies increase
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
// save items we get
|
// save items we get
|
||||||
@@ -214,9 +217,18 @@ app.post("/api/remove", function(req, res) {
|
|||||||
console.log('failure count not find ' + object.name);
|
console.log('failure count not find ' + object.name);
|
||||||
} else {
|
} else {
|
||||||
if (doc) {
|
if (doc) {
|
||||||
|
const originalCount = object.count || 0;
|
||||||
|
object.count /= ((_doleDivisionFactor[object.name]||0)+doleDivisionRetardation)/doleDivisionRetardation;
|
||||||
|
object.count = Math.round(object.count);
|
||||||
|
|
||||||
|
console.info(`Serving ${object.count}/${originalCount} ${object.name} from ${doc.count} ${object.name} with dole division factor ${(_doleDivisionFactor[object.name]||0)} (real=${((_doleDivisionFactor[object.name]||0)+doleDivisionRetardation)/doleDivisionRetardation}), item is ${Number(doc.count) > Number(object.count)?'stocked':'short'}.`);
|
||||||
|
|
||||||
// Update existing items if item name already exists
|
// Update existing items if item name already exists
|
||||||
if(Number(doc.count) > Number(object.count)) {
|
if(Number(doc.count) > Number(object.count)) {
|
||||||
console.log("removed: " + object.name + " " + object.count + " . " + doc.count + " and sent to " + object.instanceID + " | " + object.instanceName);
|
//If successful,
|
||||||
|
_doleDivisionFactor[object.name] = Math.max((_doleDivisionFactor[object.name]||0)||1, 1) - 1;
|
||||||
|
|
||||||
|
//console.log("removed: " + object.name + " " + object.count + " . " + doc.count + " and sent to " + object.instanceID + " | " + object.instanceName);
|
||||||
objectUpdate = {
|
objectUpdate = {
|
||||||
"name": object.name,
|
"name": object.name,
|
||||||
"count": Number(doc.count) - Number(object.count),
|
"count": Number(doc.count) - Number(object.count),
|
||||||
@@ -226,7 +238,8 @@ app.post("/api/remove", function(req, res) {
|
|||||||
// res.send("successier");
|
// res.send("successier");
|
||||||
res.send(object);
|
res.send(object);
|
||||||
} else {
|
} else {
|
||||||
console.log('failure out of ' + object.name + " | " + object.count + " from " + object.instanceID + " ("+object.instanceName+")");
|
_doleDivisionFactor[object.name] = Math.min(maxDoleDivision, Math.max((_doleDivisionFactor[object.name]||0)||1, 1) * 2);
|
||||||
|
//console.log('failure out of ' + object.name + " | " + object.count + " from " + object.instanceID + " ("+object.instanceName+")");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('failure ' + object.name);
|
console.log('failure ' + object.name);
|
||||||
|
|||||||
Reference in new issue
Block a user