A small question about getting lua libraries and such

Discussion about Mods for Prison Architect

Moderator: NBJeff

ronnie4444
level1
level1
Posts: 36
Joined: Thu Jan 01, 2015 4:49 pm

A small question about getting lua libraries and such

Postby ronnie4444 » Fri Jan 23, 2015 7:36 pm

Hiyya.

I've been working on a small mod that needs external lua libraries (websocket and copas, to be exact), and unfortunately Prison Architect doesn't recognize the "require" term. This is a built-in lua function to grab external libraries, to clarify, but unfortunately Prison Architect doesn't like it for some reason.

Thanks,
//Ron

EDIT: Here's the code...

object_MultiplayerBlockServer:

Code: Select all

function Create()
   otherPrisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y + 1 )
   myprisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y - 1 )
end

nextTimeout = 0.1
timer = 0

function Updateprisoner(xx,yy)
   otherPrisoner.Pos.x = xx
   otherPrisoner.Pos.y = yy
end

function OpenServer()
   local copas = require("copas")
   local ws = require("websocket").server.copas.listen
   {
      port = 12343,
      
      protocols = {
         
         echo = function(ws)
            while true do
               local x,y = ws:receive()
               ws:send(myprisoner.Pos.x,myprisoner.Pos.y)
               Updateprisoner(x,y)
            end
         end
      }
   }
end

function CheckTrigger()
   local triggerTime = this.TriggerTime
   if triggerTime == nil or tonumber(triggerTime) == 0 then
      return 5
   end
   if triggerTime ~= this.LastTriggered then
      OpenServer()
   end
end

function Update(TimePassed)
   timer = timer + TimePassed
   if timer > nextTimeOut then
      nextTimeout = CheckTrigger()
      timer = 0
   end
end


object_MultiplayerBlockClient:

Code: Select all

function Create()
   otherPrisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y - 1)
   myprisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y + 1 )
end

function Updateprisoner(xx,yy)
   otherPrisoner.Pos.x = xx
   otherPrisoner.Pos.y = yy
end

function CheckTrigger()
   local triggerTime = this.TriggerTime
   if triggerTime == nil or tonumber(triggerTime) == 0 then
      return 5
   end
   if triggerTime ~= this.LastTriggered then
      StartClient()
   end
end

function StartClient()
   local websocket = require("websocket")
   local client = websocket.client.copas({timeout=2})
   
   local ok,err = client:connect('localhost:12343',myprisoner.Pos.x, myprisoner.Pos.y)
   while true do
      local x,y = client:receive()
      Updateprisoner(x,y)
      local ok = client:send(myprisoner.Pos.x, myprisoner.Pos.y)
   end
end

function Update(TimePassed)
   timer = timer + TimePassed
   if timer > nextTimeOut then
      nextTimeout = CheckTrigger()
      timer = 0
   end
end


EDIT: The idea of this mod is to make a multiplayer server (for 2 people, the person hosting the server and the person using the client) that will tell the client where said 'myprisoner' is, and the client will move 'otherprisoner' to the coordinates. Likewise, the client will tell the server where the client myprisoner is, and the server will move the server-side otherprisoner to the coordinates given by the client.
Puman
level1
level1
Posts: 48
Joined: Fri Aug 29, 2014 1:21 pm

Re: A small question about getting lua libraries and such

Postby Puman » Mon Feb 02, 2015 11:27 pm

They have blocked the inclusion of external libraries for good reasons (letting modders do whatever they want to your computer for example, like opening up a web socket to a malicious external server).
seronis
level1
level1
Posts: 42
Joined: Fri Dec 05, 2014 1:32 am

Re: A small question about getting lua libraries and such

Postby seronis » Tue Feb 03, 2015 12:35 am

For -a- reason. Not a good one. Dont Starve still allows modders to include socket handling. Hell socket handling is one of the most basic things modders enjoy having access to and is used in many MANY games to provide legitimate features.
brickviking
level0
Posts: 1
Joined: Tue Feb 10, 2015 11:20 am

Re: A small question about getting lua libraries and such

Postby brickviking » Tue Feb 17, 2015 5:08 am

I hate to necro this thread, but including "require" in this scenario (especially for network connections) would open up the game to so much abuse from malignant modders it wouldn't be funny. Leaving out the ability to arbitrarily connect anywhere means that users are fractionally safer. What did puzzle me though, is the embedding of email commands into the primary executable, they seem to form part of the libcurl.

If Introversion ever decide to make this a multiplayer-for-real game, then they'll have to address that issue for themselves.

(Post 1)
seronis
level1
level1
Posts: 42
Joined: Fri Dec 05, 2014 1:32 am

Re: A small question about getting lua libraries and such

Postby seronis » Tue Feb 17, 2015 3:24 pm

DontStarve has had require available since it officially supported modding. Know how many malicious mods have been made?

ZERO

The ability to have networking in a mod is always a benifit. Guarding against 'what if' is an asininely stupid concept. The code is VISIBLE for crying out loud. You cant hide what your mod does since we're not distributing binaries, we are distributing the source and the game compiles it at bootup/runtime.
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Re: A small question about getting lua libraries and such

Postby elDiablo » Tue Feb 17, 2015 4:09 pm

The reason we did this is because we could see situations where malicious mods could be distributed to a large number of people. The game would then run the mod, and bad things could happen. We chose to be cautious and disable everything, rather than guess what would be needed and allow some things which could be bad.

We want people to make mods, and do things with the game we hadn't thought of, and so if people want sockets (and require and all that) we can look at adding them back in. It's just that we'll want to do it in a safe way.
seronis
level1
level1
Posts: 42
Joined: Fri Dec 05, 2014 1:32 am

Re: A small question about getting lua libraries and such

Postby seronis » Tue Feb 17, 2015 4:57 pm

Since the source of any mod is bare and visible ALL MODS ARE SAFE. The only way having those features would be unsafe is if there was no way to confirm what a mod was doing because it had to be compiled by the modder prior to uploading.

Kerbal space program has precompiled mods. They just require the source code to be linked in the forum post so people can verify it if they want.

The Sims has precompiled mods. They dont require any source on the various forums where mods are distributed.

There are still basically zero malicious mods for any of those games. Honestly just make EVERYTHING available that is possible. The limits arent making anything safer, only more limited.
Sumurai8
level2
level2
Posts: 92
Joined: Fri Feb 06, 2015 1:08 am

Re: A small question about getting lua libraries and such

Postby Sumurai8 » Wed Feb 18, 2015 9:58 pm

I personally dislike the idea that modders would be able to do anything on my computer if I download something from the steam workshop without me knowing anything about that.

You could do something like this:

- Require that the modder adds something to their manifest file if they want 'require(..)' to work.
- If the user activates the mod in-game, a confirmation message will display that notifies the user of something like "This mod can include external code. You should make sure the code of this mod is safe."
- Only activate the require(..) function when this special variable is in the manifest file.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 1 guest