Trying to fix bug with fifo and network players
[progcomp2013.git] / qchess / qchess.cgi
index 752fabf..035dce0 100755 (executable)
@@ -71,6 +71,10 @@ def open_fifo(name, mode, timeout=None):
                        raise w.exception
                return w.result
 
+def force_quit():
+       os.remove(path+client+".in")
+       os.remove(path+client+".out")
+
 def quit():
        
        if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
@@ -105,7 +109,7 @@ def quit():
 
 
 def main(argv):
-       print "Content-Type: text/plain\r\n\r\n"
+       print "Content-Type: text/plain\r\n" #Removed the second new line. Makes parsing everything easier ~BG3
        
        global client
        form = cgi.FieldStorage()
@@ -137,7 +141,11 @@ def main(argv):
                x = int(form["x"].value)
                y = int(form["y"].value)
        except:
-               
+               if request == "force_quit":
+                       force_quit()
+                       quit()
+                       return 0
+
                if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
                        if request == "quit":
                                print "Quit."
@@ -149,13 +157,17 @@ def main(argv):
                elif request == "start":
                        print "New game."
                        args = path+"qchess.py --no-graphics"
-                       if mode == None or mode == "bishop":
+                       if mode == "black":
+                               args += " @internal:AgentBishop @fifo:../qchess-cgi-data/"+client
+                       elif mode == None or mode == "bishop":
                                args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop"
-                       if mode == "random":
+                       elif mode == "random":
                                args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentRandom"
                        elif mode == "eigengame":
                                args += " --server=progcomp.ucc.asn.au @fifo:../qchess-cgi-data/"+client
 
+                       args += " --log=@../qchess-cgi-data/"+client+".log";
+
                        os.system("echo '"+args+"' | at now")
 
                #       subprocess.Popen(args)

UCC git Repository :: git.ucc.asn.au