-
Notifications
You must be signed in to change notification settings - Fork 32
/
client.lua
47 lines (40 loc) · 945 Bytes
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- client to connect to telnet
host = 'localhost'
port = 4000
timeout = 0.001
local socket = require 'socket'
function client_connect(port)
client = assert(socket.connect(host, port))
client:settimeout(timeout)
print("tcp no delay", client:setoption('tcp-nodelay', true))
end
-- Get data from Evennia
function data_in_smallworld()
local msg, err = client:receive()
local text = {}
while not err do
text[#text+1] = msg
msg, err = client:receive()
end
sleep(0.0005) -- Do NOT overpower the server.
return text
end
function data_in_tutorialworld()
local msg, err = client:receive()
local text = {}
while not err do
msg = string.gsub(msg, '%[.-m', ' ')
text[#text+1] = string.gsub(msg, '{.', '')
msg, err = client:receive()
end
return text
end
if TUTORIAL_WORLD then
data_in = data_in_tutorialworld
else
data_in = data_in_smallworld
end
-- Send data to Evennia
function data_out(data)
client:send(data .. '\n')
end