X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FVendServer.py;h=3c4290818603bf18b6a087706b91a7821fa422ff;hp=dd2cd7d93088255b481905877a8075e54f826122;hb=43d3383a86478b56de1933a31eb7b6d6a03e449b;hpb=973badd04666c604b2a83c775d026ab51d569330 diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index dd2cd7d..3c42908 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -17,6 +17,7 @@ from MessageKeeper import MessageKeeper from HorizScroll import HorizScroll from random import random, seed from Idler import GreetingIdler,TrainIdler,GrayIdler,StringIdler,ClockIdler,FortuneIdler,FileIdler,PipeIdler +from SnackConfig import get_snacks, get_snack import socket from posix import geteuid @@ -104,9 +105,20 @@ def scroll_options(username, mk, welcome = False): c = c.strip() (slot_num, price, slot_name) = c.split(' ', 2) if slot_name == 'dead': continue - choices += '%s8-%s (%sc) '%(slot_num, slot_name, price) + choices += '%s-(%sc)-%s8 '%(slot_name, price, slot_num) + +# we don't want to print snacks for now since it'll be too large +# and there's physical bits of paper in the machine anyway - matt +# try: +# snacks = get_snacks() +# except: +# snacks = {} +# +# for slot, ( name, price ) in snacks.items(): +# choices += '%s8-%s (%sc) ' % ( slot, name, price ) + choices += '55-DOOR ' - choices += 'OR A SNACK. ' + choices += 'OR ANOTHER SNACK. ' choices += '99 TO READ AGAIN. ' choices += 'CHOICE? ' msg.append((choices, False, None)) @@ -196,15 +208,15 @@ def setup_idlers(v): GrayIdler(v,one="/",zero="\\"), ClockIdler(v), GrayIdler(v,one="X",zero="O"), - FileIdler(v, '/usr/share/common-licenses/GPL-2'), + FileIdler(v, '/usr/share/common-licenses/GPL-2',affinity=2), GrayIdler(v,one="*",zero="-",reorder=1), StringIdler(v, text=str(math.pi) + " "), ClockIdler(v), GrayIdler(v,one="/",zero="\\",reorder=1), StringIdler(v, text=str(math.e) + " "), GrayIdler(v,one="X",zero="O",reorder=1), - StringIdler(v, text=" I want some pizza - please call Pizza Hut Shenton Park on +61 8 9381 9979 - and order as Quinn - I am getting really hungry", repeat=False), - PipeIdler(v, "/usr/bin/ypcat", "passwd"), + StringIdler(v, text=" I want some pizza - please call Pizza Hut Shenton Park on +61 8 9381 9979 [now closed? - MSH] - and order as Quinn - I am getting really hungry", repeat=False), + PipeIdler(v, "/usr/bin/getent", "passwd"), FortuneIdler(v), ClockIdler(v), StringIdler(v), @@ -348,9 +360,8 @@ def handle_get_selection_key(state, event, params, v, vstatus): vstatus.cur_user = '' vstatus.cur_selection = '' - reset_idler(v, vstatus) - vstatus.mk.set_messages([(center('BYE!'), False, 1.5)]) + reset_idler(v, vstatus, 2) return vstatus.cur_selection += chr(key + ord('0')) vstatus.mk.set_message('SELECT: '+vstatus.cur_selection) @@ -397,8 +408,14 @@ def make_selection(v, vstatus): else: v.display('GOT COKE!') else: - v.display(vstatus.cur_selection+' - $1.00') - if ((os.system('su - "%s" -c "dispense snack"'%(vstatus.username)) >> 8) == 0): + # first see if it's a named slot + try: + price, shortname, name = get_snack( vstatus.cur_selection ) + except: + price, shortname, name = get_snack( '--' ) + dollarprice = "$%.2f" % ( price / 100.0 ) + v.display(vstatus.cur_selection+' - %s'%dollarprice) + if ((os.system('su - "%s" -c "dispense %s"'%(vstatus.username, shortname)) >> 8) == 0): v.vend(vstatus.cur_selection) v.display('THANK YOU') else: @@ -458,14 +475,54 @@ def handle_getting_uid_key(state, event, params, v, vstatus): if len(vstatus.cur_user) == 5: uid = int(vstatus.cur_user) + if uid == 0: + logging.info('user '+vstatus.cur_user+' has a bad PIN') + pfalken=""" +CARRIER DETECTED + +CONNECT 128000 + +Welcome to Picklevision Sytems, Sunnyvale, CA + +Greetings Professor Falken. + + + + +Shall we play a game? + + +Please choose from the following menu: + +1. Tic-Tac-Toe +2. Chess +3. Checkers +4. Backgammon +5. Poker +6. Toxic and Biochemical Warfare +7. Global Thermonuclear War + +7 [ENTER] + +Wouldn't you prefer a nice game of chess? + +""".replace('\n',' ') + vstatus.mk.set_messages([(pfalken, False, 10)]) + vstatus.cur_user = '' + vstatus.cur_pin = '' + + reset_idler(v, vstatus, 10) + + return + if not has_good_pin(uid): logging.info('user '+vstatus.cur_user+' has a bad PIN') vstatus.mk.set_messages( - [(' '*10+'INVALID PIN SETUP'+' '*10, False, 3)]) + [(' '*10+'INVALID PIN SETUP'+' '*11, False, 3)]) vstatus.cur_user = '' vstatus.cur_pin = '' - reset_idler(v, vstatus, 5) + reset_idler(v, vstatus, 3) return @@ -493,7 +550,8 @@ def handle_idle_key(state, event, params, v, vstatus): def handle_idle_tick(state, event, params, v, vstatus): ### State idling - idle_step(vstatus) + if vstatus.mk.done(): + idle_step(vstatus) if vstatus.time_of_next_idler and time() > vstatus.time_of_next_idler: vstatus.time_of_next_idler = time() + 30 @@ -668,6 +726,14 @@ def create_state_table(vstatus): def get_state_table_handler(vstatus, state, event, counter): return vstatus.state_table[(state,event,counter)] +def time_to_next_update(vstatus): + idle_update = vstatus.time_of_next_idlestep - time() + if not vstatus.mk.done() and vstatus.mk.next_update is not None: + mk_update = vstatus.mk.next_update - time() + if mk_update < idle_update: + idle_update = mk_update + return idle_update + def run_forever(rfh, wfh, options, cf): v = VendingMachine(rfh, wfh) vstatus = VendState(v) @@ -699,7 +765,8 @@ def run_forever(rfh, wfh, options, cf): logging.error('Database error: '+str(e)) - e = v.next_event(vstatus.time_of_next_idlestep-time()) + timeout = time_to_next_update(vstatus) + e = v.next_event(timeout) (event, params) = e run_handler(event, params, v, vstatus)