예제 #1
0
파일: command.go 프로젝트: ilahsa/go
///======================================
///生产者 ,产生图验图片
func putFile(session *link.Session, req map[string]string) error {
	file := req["file"]
	seq := req["seq"]
	fileid := GetMd5String(file)
	vf := &VerifyObj{Id: getId(), P: session, C: nil, FileId: fileid, File: file, Status: 1, Result: "0", Seq: seq, PPutUnix: time.Now().Unix()}
	QueueInstance.Enqueue(vf)
	VFMapInstance.Put(vf)
	ULogger.Infof("putfile 进队列 %v\n", vf)
	//记录p端的操作
	if session.State == nil {
		userId := session.Conn().RemoteAddr().String()
		user := &User{UserType: "P", Id: userId, WorkTime: time.Now().Format("2006-01-02 15:04:05")}
		session.State = user
		Exec(`insert into user_activities(user_id,active_time,active_type,user_type,other_info) values(?,now(),'begin','production',?)`, userId, userId)
	}
	return nil
}
예제 #2
0
파일: command.go 프로젝트: ilahsa/go
///c端开始答题
func cStart(session *link.Session, req map[string]string) error {
	userid := req["userid"]
	password := req["password"]
	seq := req["seq"]
	ULogger.Infof("user %s start answer", userid)
	ret := map[string]string{
		"action": "res_cstart",
		"seq":    seq,
		"result": "0",
	}
	if session.State != nil && session.State.(*User).UserType == "C" {
		ULogger.Error("have logined ", userid)
		session.Close()
	}

	if b := Login(userid, password); !b {
		ULogger.Errorf("cstart failed ,userid is %s password is %s", userid, password)

		by, _ := json.Marshal(ret)
		session.Send(link.Bytes(by))
		ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
		session.Close()
		return nil
	} else {
		user := &User{UserType: "C", Id: userid, WorkTime: time.Now().Format("2006-01-02 15:04:05")}
		session.State = user

		ret["result"] = "1"

		by, _ := json.Marshal(ret)

		session.Send(link.Bytes(by))
		ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
		//c端开始答题
		Exec(`insert into user_activities(user_id,active_time,active_type,user_type,other_info) values(?,now(),'begin','customer',?)`, userid, session.Conn().RemoteAddr().String())
		VFMapInstance.AddSession(session)
	}

	return nil
}