mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Changed command splitting logic from json data to lua tables
This commit is contained in:
1 parent
d07112e85e
commit
be73f2f3a5
1 file changed
+23
-16
@@ -646,8 +646,8 @@ function instanceManagement() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// messageInterface Management
|
// messageInterface Management
|
||||||
setInterval(function(){let command=commandBuffer.pop();if(command){messageInterfaceInternal(command[0],command[1])}},10);
|
setInterval(function(){let command=commandBuffer.pop();if(command){messageInterfaceInternal(command[0],command[1])}},50);
|
||||||
|
|
||||||
// Mod uploading and management -----------------------------------------------
|
// Mod uploading and management -----------------------------------------------
|
||||||
// get mod names and hashes
|
// get mod names and hashes
|
||||||
// string: instance, function: callback
|
// string: instance, function: callback
|
||||||
@@ -832,19 +832,21 @@ function instanceManagement() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// if we got some confirmed orders
|
// if we got some confirmed orders
|
||||||
//console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
// console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
||||||
//if (!(confirmedOrders.length>0)){return;}
|
//if (!(confirmedOrders.length>0)){return;}
|
||||||
let cmd="[";
|
let cmd="local t={";
|
||||||
for(let i=0;i<confirmedOrders.length;i++)
|
for(let i=0;i<confirmedOrders.length;i++)
|
||||||
{
|
{
|
||||||
cmd+='{"'+confirmedOrders[i].name+'"'+":"+confirmedOrders[i].count+"},";
|
cmd+='["'+confirmedOrders[i].name+'"]='+confirmedOrders[i].count+',';
|
||||||
if(cmd.length>8000)//450 //ITS SMALL SO FACTORIO DOESNT SPILT IT INTO MULTIPLE PACKETS
|
if(cmd.length>320) // Factorio max packet size is 508
|
||||||
{
|
{
|
||||||
messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");
|
messageInterface("/silent-command remote.call('clusterio', 'runcode', '"+cmd.slice(0, -1)+"}"+ " for k, item in pairs(t) do GiveItemsToStorage(k, item) end')");
|
||||||
cmd="[";
|
cmd="local t={";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(cmd=="[")){messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");}
|
if (!(cmd==="local t={")){
|
||||||
|
messageInterface("/silent-command remote.call('clusterio', 'runcode', '"+cmd.slice(0, -1)+"}"+ " for k, item in pairs(t) do GiveItemsToStorage(k, item) end')");
|
||||||
|
}
|
||||||
confirmedOrders=[];
|
confirmedOrders=[];
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@@ -868,17 +870,22 @@ function instanceManagement() {
|
|||||||
}
|
}
|
||||||
inventoryFrame["signal-unixtime"] = Math.floor(Date.now()/1000);
|
inventoryFrame["signal-unixtime"] = Math.floor(Date.now()/1000);
|
||||||
// console.log("RCONing inventory! " + JSON.stringify(inventoryFrame));
|
// console.log("RCONing inventory! " + JSON.stringify(inventoryFrame));
|
||||||
let cmd="{";
|
let first = true;
|
||||||
for (var key in inventoryFrame)
|
let cmd="local s={";
|
||||||
|
for (let key in inventoryFrame)
|
||||||
{
|
{
|
||||||
cmd+='"'+key+'"'+":"+inventoryFrame[key]+",";
|
cmd+='["'+key+'"]='+inventoryFrame[key]+",";
|
||||||
if(cmd.length>400)//450 //ITS SMALL SO FACTORIO DOESNT SPILT IT INTO MULTIPLE PACKETS
|
if(first && cmd.length>300 || !first && cmd.length > 320) // Factorio max packet size is 508
|
||||||
{
|
{
|
||||||
messageInterface("/silent-command remote.call('clusterio', 'receiveInventory', '"+cmd.slice(0, -1)+"}"+ "')");
|
messageInterface("/silent-command remote.call('clusterio', 'runcode', '"+(first ? 'global.ticksSinceMasterPinged=0 ':'')+cmd.slice(0, -1)+"}"+ " for name,count in pairs(s) do global.invdata[name]=count end')");
|
||||||
cmd="{";
|
cmd="local s={";
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(cmd=="[")){messageInterface("/silent-command remote.call('clusterio', 'receiveInventory', '"+cmd.slice(0, -1)+"}"+ "')");}
|
if (!(cmd==="local s={")){
|
||||||
|
messageInterface("/silent-command remote.call('clusterio', 'runcode', '"+(first ? 'global.ticksSinceMasterPinged=0 ':'')+cmd.slice(0, -1)+"}"+ " for name,count in pairs(s) do global.invdata[name]=count end')");
|
||||||
|
}
|
||||||
|
messageInterface("/silent-command remote.call('clusterio', 'runcode', 'UpdateInvCombinators()')");
|
||||||
} catch (e){
|
} catch (e){
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user