forked from mcclure/emu-coop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
coop.lua
85 lines (67 loc) · 2.47 KB
/
coop.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class = require "pl.class"
pretty = require "pl.pretty"
List = require "pl.list"
stringx = require "pl.stringx"
tablex = require "pl.tablex"
require "version"
require "util"
require "modes.index"
require "dialog"
require "pipe"
require "driver"
-- PROGRAM
if emu.emulating() then
local spec = nil -- Mode specification
local usableModes = {} -- Mode files that can be loaded in this version of coop.lua
for i,v in ipairs(modes) do
if versionMatches(version.modeFormat, v.format) then
table.insert(usableModes, v)
else
print("Could not load a game mode because it is not compatible with this version of the emulator. The game's name was: " .. tostring(v.name))
end
end
local specOptions = {} -- Mode files that match the currently running ROM
for i,v in ipairs(usableModes) do
if performTest(v.match) then
table.insert(specOptions, v)
end
end
if #specOptions == 1 then -- The current game's mode file has been found
spec = specOptions[1]
elseif #specOptions > 1 then -- More than one mode file was found that could be this game
spec = selectDialog(specOptions, "multiple matches")
else -- No matches
spec = selectDialog(usableModes, "no matches")
end
if spec then -- If user did not hit cancel
print("Playing " .. spec.name)
local data = ircDialog()
if data then -- If user did not hit cancel
local failed = false
function scrub(invalid) errorMessage(invalid .. " not valid") failed = true end
if failed then -- NOTHING
elseif not nonempty(data.server) then scrub("Server")
elseif not nonzero(data.port) then scrub("Port")
elseif not nonempty(data.nick) then scrub("Nick")
elseif not nonempty(data.partner) then scrub("Partner nick")
end
function connect()
local socket = require "socket"
local server = socket.tcp()
result, err = server:connect(data.server, data.port)
if not result then errorMessage("Could not connect to IRC: " .. err) failed = true return end
statusMessage("Connecting to server...")
opts.hpshare = data.hpshare
opts.magicshare = data.magicshare
opts.deathshare = data.deathshare
opts.sfx = data.sfx
mainDriver = GameDriver(spec, data.forceSend) -- Notice: This is a global, specs can use it
IrcPipe(data, mainDriver):wake(server)
end
if not failed then connect() end
if failed then gui.register(printMessage) end
end
end
else
refuseDialog()
end