summaryrefslogtreecommitdiff
path: root/client/data/net.lua
diff options
context:
space:
mode:
authorU-DESKTOP-FOJ6TK1\Alex <alex@cogarr.net>2025-02-12 17:25:25 -0600
committerU-DESKTOP-FOJ6TK1\Alex <alex@cogarr.net>2025-02-12 17:25:25 -0600
commitb1c3386ca4032ac5925969d759ae2e5bc015d1f8 (patch)
tree74e7d8797afea9df12222e149e865134ddec9479 /client/data/net.lua
parent0aae46ecc38005236210f7e243f02cac39ab1dc3 (diff)
downloadhome_text_adventure-master.tar.gz
home_text_adventure-master.tar.bz2
home_text_adventure-master.zip
Final commitHEADmaster
Diffstat (limited to 'client/data/net.lua')
-rw-r--r--client/data/net.lua296
1 files changed, 150 insertions, 146 deletions
diff --git a/client/data/net.lua b/client/data/net.lua
index c3eec15..b624184 100644
--- a/client/data/net.lua
+++ b/client/data/net.lua
@@ -1,146 +1,150 @@
-
-local snet = {}
-local room = require("room")
-local item = require("item")
-local house = require("house")
-local socket = net.newsocket(net.REQ)
-
---Some server in the cloud, running the same stuff in server/*
-socket:connect("tcp://34.73.161.231:5555")
-
-function snet.ask_for_homes(location,index)
- socket:send(function(stream)
- stream:writestring("get_houses")
- stream:writestring(location)
- stream:writeint(index)
- end)
- local stream = socket:block_recv()
- local num_homes = stream:readint()
- local ret = {}
- printf("Found %d homes",num_homes)
- for i = 1,num_homes do
- local home_name = stream:readstring()
- local nice_name = string.match(home_name,"(.*).lua")
- print(nice_name)
- ret[#ret + 1] = nice_name
- end
- return ret
- --print("got homes:",stream:readstring())
-end
-
-function snet.ask_for_all_homes(location)
- socket:send(function(stream)
- stream:writestring("get_all_houses")
- stream:writestring(location)
- end)
- local stream = socket:block_recv()
- local ret = {}
- for i = 1,stream:readint() do
- local home_name = stream:readstring()
- local nice_name = string.match(home_name,"(.*).lua")
- ret[#ret + 1] = nice_name
- end
- return ret
-end
-
-function snet.house_exists(location,housename)
- socket:send(function(stream)
- stream:writestring("house_exists")
- stream:writestring(location)
- stream:writestring(housename)
- end)
- local stream = socket:block_recv()
- return stream:readint() == 1
-end
-
-function snet.settle_at(myid,location,name)
- socket:send(function(stream)
- stream:writestring("settle")
- stream:writestring(location)
- stream:writestring(name)
- stream:writedouble(myid)
- end)
- local stream = socket:block_recv()
-
-end
-
-function snet.is_name_available(name,loc_name)
- socket:send(function(stream)
- stream:writestring("is_name_avaliable")
- stream:writestring(name)
- stream:writestring(loc_name)
- end)
- local stream = socket:block_recv()
- return stream:readint() == 1
-end
-
-function snet.claim_house(name,loc_name,playerid)
- socket:send(function(stream)
- stream:writestring("claim_house")
- stream:writestring(name)
- stream:writestring(loc_name)
- stream:writestring(tostring(playerid))
- end)
- local stream = socket:block_recv()
-end
-
-function snet.write_house(player_id,housedata)
- socket:send(function(stream)
- stream:writestring("write_house")
- stream:writestring(tostring(player_id))
- stream:writestring(housedata)
- end)
- local stream = socket:block_recv()
- print("Done getting stream back")
-end
-
-function snet.get_house(loc_name,housename)
- socket:send(function(stream)
- stream:writestring("get_house")
- stream:writestring(loc_name)
- stream:writestring(housename)
- end)
- local stream = socket:block_recv()
- print("Got house back")
- local housedata = stream:readstring()
- local this_house = assert(loadstring(housedata,housename))()
- setmetatable(this_house,house.meta)
- print("house loaded correctly",house)
- for room_name,this_room in pairs(this_house.rooms) do
- print("setting item metas for ",this_room,":",type(this_room),"---",this_room.items)
- for i,this_item in pairs(this_room.items) do
- print(string.format("Setting item metas for %q %q",tostring(i),tostring(this_item)))
- --print("setting item metas for",i,":",this_item)
- setmetatable(this_item,item.meta)
- end
- print("Setting meta table for this room")
- setmetatable(this_room,room.meta)
- print("done setting meta table")
- end
- print("returning house")
- return this_house
-end
-
-function snet.do_i_own(loc_name,housename,playerid)
- print("doing do_i_own")
- socket:send(function(stream)
- print("Starting to write to stream")
- stream:writestring("do_i_own")
- print("one")
- stream:writestring(loc_name)
- print("two",housename)
- stream:writestring(housename)
- print("three",playerid)
- --print("three",tostring(playerid))
- stream:writestring(tostring(playerid))
- print("Wrote everything to send")
- end)
- print("Done with sending")
- local stream = socket:block_recv()
- local ret = stream:readint()
- print("got back:",ret)
- print("Done with do_i_own")
- return ret == 1
-end
-
-return snet
+
+local snet = {}
+local room = require("room")
+local item = require("item")
+local house = require("house")
+local socket = net.newsocket(net.REQ)
+
+--Some server in the cloud, running the same stuff in server/*
+socket:connect("tcp://34.73.161.231:80")
+
+function snet.ask_for_homes(location,index)
+ socket:send(function(stream)
+ stream:writestring("get_houses")
+ stream:writestring(location)
+ stream:writeint(index)
+ end)
+ local stream = socket:block_recv()
+ local num_homes = stream:readint()
+ local ret = {}
+ printf("Found %d homes",num_homes)
+ for i = 1,num_homes do
+ local home_name = stream:readstring()
+ local nice_name = string.match(home_name,"(.*).lua")
+ print(nice_name)
+ ret[#ret + 1] = nice_name
+ end
+ return ret
+ --print("got homes:",stream:readstring())
+end
+
+function snet.ask_for_all_homes(location)
+ socket:send(function(stream)
+ stream:writestring("get_all_houses")
+ stream:writestring(location)
+ end)
+ local stream = socket:block_recv()
+ local ret = {}
+ for i = 1,stream:readint() do
+ local home_name = stream:readstring()
+ local nice_name = string.match(home_name,"(.*).lua")
+ ret[#ret + 1] = nice_name
+ end
+ return ret
+end
+
+function snet.house_exists(location,housename)
+ socket:send(function(stream)
+ stream:writestring("house_exists")
+ stream:writestring(location)
+ stream:writestring(housename)
+ end)
+ local stream = socket:block_recv()
+ return stream:readint() == 1
+end
+
+function snet.settle_at(myid,location,name)
+ socket:send(function(stream)
+ stream:writestring("settle")
+ stream:writestring(location)
+ stream:writestring(name)
+ stream:writedouble(myid)
+ end)
+ local stream = socket:block_recv()
+
+end
+
+function snet.is_name_available(name,loc_name)
+ socket:send(function(stream)
+ stream:writestring("is_name_avaliable")
+ stream:writestring(name)
+ stream:writestring(loc_name)
+ end)
+ local stream = socket:block_recv()
+ return stream:readint() == 1
+end
+
+function snet.claim_house(name,loc_name,playerid)
+ socket:send(function(stream)
+ stream:writestring("claim_house")
+ stream:writestring(name)
+ stream:writestring(loc_name)
+ stream:writestring(tostring(playerid))
+ end)
+ local stream = socket:block_recv()
+end
+
+function snet.write_house(player_id,housedata)
+ socket:send(function(stream)
+ stream:writestring("write_house")
+ stream:writestring(tostring(player_id))
+ stream:writestring(housedata)
+ end)
+ local stream = socket:block_recv()
+ print("Done getting stream back")
+end
+
+function snet.get_house(loc_name,housename)
+ socket:send(function(stream)
+ stream:writestring("get_house")
+ stream:writestring(loc_name)
+ stream:writestring(housename)
+ end)
+ local stream = socket:block_recv()
+ print("Got house back")
+ local housedata = stream:readstring()
+ local this_house = assert(loadstring(housedata,housename))()
+ setmetatable(this_house,house.meta)
+ print("house loaded correctly",house)
+ for room_name,this_room in pairs(this_house.rooms) do
+ if this_room ~= "exit" then
+ print("setting item metas for ",this_room,":",type(this_room),"---",this_room.items)
+ for i,this_item in pairs(this_room.items) do
+ print(string.format("Setting item metas for %q %q",tostring(i),tostring(this_item)))
+ --print("setting item metas for",i,":",this_item)
+ setmetatable(this_item,item.meta)
+ end
+ print("Setting meta table for this room")
+ setmetatable(this_room,room.meta)
+ print("done setting meta table")
+ end
+ end
+ print("returning house")
+ return this_house
+end
+
+function snet.do_i_own(loc_name,housename,playerid)
+ print("doing do_i_own")
+ socket:send(function(stream)
+ print("Starting to write to stream")
+ stream:writestring("do_i_own")
+ print("one")
+ stream:writestring(loc_name)
+ print("two",housename)
+ stream:writestring(housename)
+ print("three",playerid)
+ --print("three",tostring(playerid))
+ stream:writestring(tostring(playerid))
+ print("Wrote everything to send")
+ end)
+ print("Done with sending")
+ local stream = socket:block_recv()
+ local ret = stream:readint()
+ print("got back:",ret)
+ print("Done with do_i_own")
+ return ret == 1
+end
+
+set_hints("look","go","settle","goto")
+
+return snet