Skip to content

Commit 280c134

Browse files
committed
Fixes for CC Tweaked
1 parent 26daaf6 commit 280c134

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
# Pythonized ComputerCraft API
22

3-
1. Create module named `examplemod.py`:
3+
1. Enable localhost in mod server config
4+
5+
In case of singleplayer it's located inside your saves folder.
6+
In case of multiplayer check your server folder.
7+
8+
Edit `computercraft-server.toml`
9+
10+
```toml
11+
[[http.rules]]
12+
host = "127.0.0.0/8"
13+
action = "allow" # change here deny to allow
14+
```
15+
16+
2. Create module named `examplemod.py`:
417

518
```python
619
async def hello(api):
720
await api.print('Hello world!')
821
```
922

10-
2. Start a server:
23+
3. Start a server:
1124

1225
```bash
1326
python -m computercraft.server examplemod
1427
```
1528

16-
3. In minecraft, open up any computer and type:
29+
4. In minecraft, open up any computer and type:
1730

1831
```bash
1932
wget http://127.0.0.1:8080/ py

computercraft/back.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ local function event_queue(task_id, event)
6767
end
6868

6969
local function fetch_fn()
70-
local r = http.post(url..'start/'..os.getComputerID()..'/'..args[1]..'/')
70+
local r = http.post(url..'start/'..os.getComputerID()..'/'..args[1]..'/', '')
7171
if (r == nil or r.getResponseCode() ~= 200) then
7272
print('Failed to start program '..args[1])
7373
return
7474
end
7575
while true do
76-
r = http.post(url..'gettask/'..os.getComputerID()..'/', answer)
76+
r = http.post(url..'gettask/'..os.getComputerID()..'/', '')
7777
if (r == nil or r.getResponseCode() ~= 200) then
7878
print('Connection broken')
7979
return

computercraft/server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ async def taskresult(self, request):
193193
def backdoor(request):
194194
with open(LUA_FILE, 'r') as f:
195195
fcont = f.read()
196+
h = request.host
197+
if ':' not in h:
198+
# fix for malformed Host header
199+
h += ':{}'.format(request.app['port'])
196200
fcont = fcont.replace(
197201
"local url = 'http://127.0.0.1:4343/'",
198-
"local url = '{}://{}/'".format(request.scheme, request.host)
202+
"local url = '{}://{}/'".format(request.scheme, h)
199203
)
200204
return web.Response(text=fcont)
201205

@@ -214,16 +218,16 @@ def main():
214218
parser = argparse.ArgumentParser()
215219
parser.add_argument('module', help='Module used as source for programs')
216220
parser.add_argument('--host')
217-
parser.add_argument('--port', type=int)
221+
parser.add_argument('--port', type=int, default=8080)
218222
args = parser.parse_args()
219223

220224
app_kw = {}
221225
if args.host is not None:
222226
app_kw['host'] = args.host
223-
if args.port is not None:
224-
app_kw['port'] = args.port
227+
app_kw['port'] = args.port
225228

226229
app = CCApplication()
230+
app['port'] = args.port
227231
app.initialize(args.module)
228232
web.run_app(app, **app_kw)
229233

0 commit comments

Comments
 (0)