Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Nether PVP Arena
- Master program
- --]]
- -- Load dependencies
- dofile("/common/all")
- program.load("../mcnet/message", "../mcnet/names", "../mcnet/device")
- program.load("../mcnet/devices/server")
- program.load("msg", "devices/master")
- -- Create master
- local configPath = "/master.conf"
- local defaultConfig = {
- name = "master",
- domain = "netherpvp",
- detectTimeout = 1
- }
- local config = common.loadStore(configPath, defaultConfig)
- local master = game.Master:new{
- -- MCNet
- name = config.name,
- domain = config.domain,
- -- Game
- winScore = 3,
- startTimeout = 3
- }
- print(" Address: "..mcnet.address.format(master.address))
- print(" Computer ID: "..tostring(os.computerID()))
- print()
- -- Register handlers
- master:on("registeredServant", function(cellId, cellName)
- print("Registered ", cellName, " at ", cellId)
- end)
- master:on("unregisteredServant", function(cellId, cellName)
- print("Unregistered ", cellName, " at ", cellId)
- end)
- master:on("startGame", function()
- print("New game started")
- end)
- master:on("startRound", function()
- print("New round started")
- end)
- master:on("scoreChanged", function(color, score)
- print("Score change for ", color..": ", score)
- end)
- master:on("stopGame", function()
- print("Game stopped")
- end)
- master:on("char", function(char)
- if char == "q" then
- -- Confirm quit
- write("Confirm quit? [y/n] > ")
- local event, char = os.pullEvent("char")
- -- Check response
- local response = (string.lower(char) == "y" and "y") or "n"
- print(response)
- if (response == "y") then
- master:stop()
- end
- end
- end)
- master:on("error", function(errorType, errorMessage)
- print("[ERROR] "..errorMessage)
- end)
- -- Main
- master:start(config.detectTimeout)
- print("Waiting for start signal...")
- print(" Press Q to quit")
- print()
- -- TODO Remote control
- master:startGame()
- while master.isRunning do
- master:trigger(os.pullEvent())
- end
- print()
- print("Stopped")
- print()
Advertisement
Add Comment
Please, Sign In to add comment