X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FVendServer.py;h=c93fda021a782d0cbbee1444ab9048596f8a7523;hp=dd2cd7d93088255b481905877a8075e54f826122;hb=bf6527c2a53d2cdbc7f721006a62cbff377f9ff8;hpb=973badd04666c604b2a83c775d026ab51d569330 diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index dd2cd7d..c93fda0 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -196,7 +196,7 @@ 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), @@ -204,7 +204,7 @@ def setup_idlers(v): 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"), + PipeIdler(v, "/usr/bin/getent", "passwd"), FortuneIdler(v), ClockIdler(v), StringIdler(v), @@ -348,9 +348,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) @@ -458,14 +457,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 +532,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 +708,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 +747,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)