SHOW:
|
|
- or go back to the newest paste.
1 | --KSC Computing. | |
2 | local Account = {ID=0,name="",balance=0} | |
3 | local Accounts = {} | |
4 | local function wait(x) | |
5 | local start = os.time() | |
6 | while os.time()>start+x do end | |
7 | end | |
8 | ||
9 | if fs.exists("karma/") == false then | |
10 | fs.makeDir("karma/") | |
11 | end | |
12 | local function CStrip(str,chrs) | |
13 | local data = str | |
14 | for i,chr in ipairs(chrs) do | |
15 | data = string.gsub(data,'%'..chr,'') | |
16 | end | |
17 | return(data) | |
18 | end | |
19 | local function Save() | |
20 | - | table.insert(Accounts,data) |
20 | + | |
21 | savefile = fs.open("karma/accounts","w") | |
22 | savefile.writeLine(alen) | |
23 | for i=1,alen do | |
24 | local savedata = textutils.serialise(Accounts[i]) | |
25 | savedata = CStrip(savedata,{'{','}',' ','\n'}) | |
26 | savedata = string.sub(1,-2) | |
27 | savefile.writeLine(savedata) | |
28 | end | |
29 | savefile.close() | |
30 | --rfile = fs.open("karma/accounts","r") | |
31 | --for i,line in ipairs(rfile) do print(rfile.readLine()) end | |
32 | --rfile.close() | |
33 | end | |
34 | ||
35 | Interest = {SID=0,RID=0,Date = 0,Amount = 0,Rate = 0} | |
36 | Interests = {} | |
37 | local function FindID(id) | |
38 | for i,account in ipairs(Accounts) do | |
39 | if account.ID == id then | |
40 | return(i) | |
41 | end | |
42 | end | |
43 | end | |
44 | ||
45 | local function AccountOpen(name,id,balance) | |
46 | local newaccount = {} | |
47 | setmetatable(newaccount,{__index=Account}) | |
48 | newaccount.ID=id | |
49 | newaccount.name = name | |
50 | if balance == nil then | |
51 | newaccount.balance = 0 | |
52 | else | |
53 | newaccount.balance = balance | |
54 | end | |
55 | return(newaccount) | |
56 | end | |
57 | if fs.exists("karma/accounts") == true then | |
58 | accountfile = fs.open("karma/accounts","r") | |
59 | local alen = accountfile.readLine() | |
60 | - | local function AccountOpen(name,id) |
60 | + | |
61 | data = {} | |
62 | for value in string.gmatch(line,"([^,]+)") do | |
63 | table.insert(data,value) | |
64 | end | |
65 | - | newaccount.balance = 0 |
65 | + | table.insert(Accounts,AccountOpen(data[2],data[1],data[3])) |
66 | print(data,line) | |
67 | sleep(1) | |
68 | end | |
69 | accountfile.close() | |
70 | end | |
71 | local function AccountDeposit(ID,amount) | |
72 | Accounts[FindID(ID)].balance= Accounts[FindID(ID)].balance+amount | |
73 | end | |
74 | local function AccountWithdraw(ID,amount) | |
75 | Accounts[FindID(ID)].balance=Accounts[FindID(ID)].balance-amount | |
76 | end | |
77 | local function InterestOpen(SID,RID,Amount,Rate) | |
78 | local opened = {} | |
79 | setmetatable(opened,{__index=Interest}) | |
80 | opened.SID = SID | |
81 | opened.RID = RID | |
82 | opened.Date = os.day() | |
83 | opened.Amount = Amount | |
84 | opened.Rate = Rate | |
85 | return(opened) | |
86 | end | |
87 | running = true | |
88 | local modem = peripheral.wrap("top") | |
89 | modem.open(248) | |
90 | local function spam(channel,message,x) | |
91 | for i=1,tonumber(x) do modem.transmit(channel,248,tostring(message)) end | |
92 | print(channel,message) | |
93 | end | |
94 | local console = "" | |
95 | while running == true do --INTERACTOR | |
96 | local event,p1,p2,p3,p4,p5 = os.pullEvent() | |
97 | term.clear() | |
98 | term.setCursorPos(1,1) | |
99 | term.write("KSC MAINSERVER") | |
100 | term.setCursorPos(1,3) | |
101 | term.write("STATUS:ACTIVE") | |
102 | term.setCursorPos(1,4) | |
103 | --print(event,p1,p2,p3,p4,p5) | |
104 | term.setCursorPos(2,6) | |
105 | if console == "" then | |
106 | term.write("<>") | |
107 | else | |
108 | term.write(">"..console.."<") | |
109 | end | |
110 | term.setCursorPos(1,7) | |
111 | term.write(CStrip(textutils.serialise(Accounts),{'{','}',' '})) | |
112 | if event == "modem_message" then | |
113 | message = {} | |
114 | for word in string.gmatch(p4,"([^%s]+)") do | |
115 | table.insert(message,word) | |
116 | end | |
117 | if message[1] == "K912" then --K912 is temp | |
118 | if message[2] == "lsa" then | |
119 | term.write("LISA") | |
120 | elseif message[2] == "new" then | |
121 | table.insert(Accounts,AccountOpen(message[3],p3)) | |
122 | spam(p3,"Account Opened",10) | |
123 | Save() | |
124 | elseif message[2] == "TRQ" then | |
125 | spam(p3,"TRS",10) | |
126 | spam(tonumber(message[4]),"TRQ "..message[3].." "..message[5].." "..message[6],1) | |
127 | elseif message[2] == "VwA" then | |
128 | for i,account in ipairs(Accounts) do | |
129 | if p3 == account[1] then | |
130 | spam(p3,"VwA "..tostring(Accounts[tonumber(message[3])].balance),5) | |
131 | break | |
132 | end | |
133 | end | |
134 | elseif message[2] == "NTQ" then | |
135 | spam(message[3],"NTQ",1) | |
136 | elseif message[2] == "FTQ" then | |
137 | AccountWithdraw(message[3],message[4]) | |
138 | AccountDeposit(p3,message[4]) | |
139 | AccountWithdraw(p3,message[5]) | |
140 | AccountDeposit(message[3],message[5]) | |
141 | end | |
142 | end | |
143 | elseif event == "key" then | |
144 | if p1 == 14 then | |
145 | if string.len(console) >0 then | |
146 | console = string.sub(console,1,-2) | |
147 | end | |
148 | elseif p1 == 207 then | |
149 | running = false | |
150 | elseif p1 == 28 then | |
151 | cmessage = {} | |
152 | for word in string.gmatch(console,"([^%s]+)") do table.insert(cmessage,word) end | |
153 | if string.lower(cmessage[1]) == "sv" then | |
154 | Save() | |
155 | elseif string.lower(cmessage[1]) == "up" then | |
156 | spam(1119,cmessage[2],3) | |
157 | elseif string.lower(cmessage[1]) == "konami" then | |
158 | spam(cmessage[2],"Konami 00100100",4) | |
159 | elseif string.lower(cmessage[1]) == "nw" then | |
160 | table.insert(Accounts,AccountOpen(cmessage[2],tonumber(cmessage[3]))) | |
161 | Save() | |
162 | end | |
163 | console = "" | |
164 | end | |
165 | elseif event == "char" then | |
166 | console = console..p1 | |
167 | - | term.setCursorPos(7,4) |
167 | + | |
168 | ||
169 | end | |
170 | term.setCursorPos(8,3) | |
171 | term.write("INACTIVE") | |
172 | term.setCursorPos(1,8) | |
173 | --COMMANDS: | |
174 | -- wdl ID Amount | |
175 | -- dip ID Amount | |
176 | -- new Name |