def say(request): req =simplejson.loads(request.body) content = req['content'] cmd = req['cmd'] target = req['target'] uid = request.user.id if not cmd: return HttpResponse(simplejson.dumps({'success':False}), mimetype = 'application/json') chat = Chat() pattern1 = re.compile(r'<') content_t = re.sub(pattern1, '<', content) pattern2 = re.compile(r'>') content_t = re.sub(pattern2, '>', content_t) chat.username_id = request.user.id #................................................................ if cmd == "chat": insertMsg(content_t,uid,datetime.datetime.now(),cmd,-1,'pub',ifPCInGame(uid)) return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json') #..............................OK.................................. if cmd == "GPCL": #get pc list bValue = updateOnlineList(request) target_t = uid content_t = getPcList(request) insertMsg( content_t, request.user.id, datetime.datetime.now(),"OLPC",uid,"pri",ifPCInGame(uid)) return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json') #..............................OK.................................. if cmd == "CRTG": # create game bValue = updateOnlineList(request) g = createGame(uid, get_client_ip(request)) debugLog("CRTG: createGame() return value="+str(g)) if g["gid"]>0: try: grinfo = getGIRNDByUid(uid, request.user.username) rCRTG = insertMsg( simplejson.dumps(grinfo),uid, datetime.datetime.now(), "CRTG", uid, "pri", g["gid"]) except Exception,data: debugLog("CRTG error:"+str(Exception)+":"+str(data)) else: rCRTG = insertMsg( g["errmsg"],uid, datetime.datetime.now(), "CRTG", uid, "pri", -1) return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json')
debugLog("CRTG error:"+str(Exception)+":"+str(data)) else: rCRTG = insertMsg( g["errmsg"],uid, datetime.datetime.now(), "CRTG", uid, "pri", -1) return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json') #..............................OK.................................. if cmd == "JOIN": # join game jGid = req['gid'] bValue = updateOnlineList(request) jg = joinGame(int(jGid), uid, get_client_ip(request)) if jg =="": grinfo = getGIRNDByUid(uid, request.user.username) insertMsg( simplejson.dumps(grinfo), uid, datetime.datetime.now(),"JOIN",0,"gam",jGid) else: insertMsg( "", uid, datetime.datetime.now(),"JOIN",uid,"pri",0) return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json') #.............................nearly.OK.................................. if cmd == "STRT": # start game crntGid = ifPCInGame(uid) if crntGid >0: sg = startGame(crntGid) if sg["errmsg"]: insertMsg( sg["errmsg"], uid, datetime.datetime.now(),"STRT",target_t,"pri",0) return HttpResponse(simplejson.dumps({'success':False}), mimetype = 'application/json')