9 procedures[name.lower()] = proc
31 while argstr
and argstr[0]==
'"':
32 end=argstr.find(
'"', 1)
34 arg += qadd + argstr[1:end]
36 argstr = argstr[end+1:]
42 space = argstr.find(
' ')
45 argstr = argstr[space+1:]
61 newstr = arg.replace(
'"',
'""')
62 if not newstr
or space!=-1
or quote!=-1:
63 ret +=
'"' + newstr +
'"'
73 running_cmds[key] = continuation
78 if running_cmds.has_key(key):
79 func = running_cmds[key]
87 def run(cmd, args, continuation, id=None, cp=-1):
89 cp = VS.getCurrentPlayer()
92 if not isinstance(id,str):
94 print "running: "+cmd+
", "+
str(args)+
"; id: "+id
95 VS.sendCustom(cp, cmd,
joinArgs(args), id)
98 def respond(args, continuation, id, cp=-1):
99 run(
"response", args, continuation, id, cp)
109 lines = text.split(
'\n')
113 VS.IOmessage(0,
"game",self.
cpstr,l)
117 cp = VS.getCurrentPlayer();
119 print "======= Processing message "+
str(id)+
" ======="
122 print "Command: "+cmd
125 if cmd==
'reloadlib' and local
and len(args)>=1:
126 reload(__import__(args[0]))
127 VS.IOmessage(0,
"game",
"p"+
str(cp),
"Reloaded "+
str(args[0]))
131 def localresponse(args):
135 run(args[0], args[1:], localresponse, id, cp)
136 elif (cmd==
'response'):
140 if ret
and isinstance(ret, tuple)
and len(ret)==2:
141 respond(ret[0], ret[1], id, cp)
146 elif procedures.has_key(cmd):
147 ret = procedures[cmd](local, cmd, args, id)
148 if ret
and isinstance(ret, tuple)
and len(ret)==2:
149 respond(ret[0], ret[1], id, cp)
156 print "Command "+
repr(cmd)+
" does not exist. Available functions:"
157 print procedures.keys()
163 writer.write(
"An error occurred when processing custom command: \n"
164 +
str(cmd)+
" "+argstr +
"\n")
166 print "-------------------------- " +
str(id)+
" -------"