func data(w http.ResponseWriter, r *http.Request) {
	if um.Usermap[r.FormValue("id")] != nil {
		if um.Usermap[r.FormValue("id")].UserContext != nil {
			if um.Usermap[r.FormValue("id")].UserContext.Dataqueue == nil {
				um.Usermap[r.FormValue("id")].UserContext.Dataqueue = pq.NewPriorityQueue()
			}
		} else {
			return
		}
	} else {
		return
	}
	body := r.FormValue("body")
	fmt.Println("got message: ", body)
	um.Usermap[r.FormValue("id")].UserContext.Dataqueue.Push(
		&pq.Item{
			Value:    body,
			Priority: defaultpriority,
		})

	fmt.Println("handler returning")
}
Exemple #2
0
func InsertUser(id string, name string) error {

	if _, ok := Usermap[id]; !ok {

		u := &User{Id: id, Name: name}

		u.UserContext = &Context{}
		// Set up the data queue
		u.UserContext.Dataqueue = pq.NewPriorityQueue()

		u.UserState = &State{}
		// Set up the draw state
		u.UserState.DrawState = draw.NewDrawState()

		bg := &character.MainCharacter{}
		bg.IdMC = "background"
		bg.CoordMC = &geom.Coord{X: 0, Y: 0}
		bg.ImageMC = image.Images["resources/Nice-blue-background-Desktop-Wallpaper.jpg"]
		bg.SizeMC = &bg.ImageMC.Size
		bg.ZMC = 0
		bg.PreviousLoc = bg.SizeMC
		bg.DirtyMC = true
		fmt.Printf("%+v\n", bg.Size())
		u.UserState.DrawState.Add(bg)

		mc := &character.MainCharacter{}
		mc.IdMC = "Kirby"
		mc.CoordMC = &geom.Coord{X: 20, Y: 20}
		mc.ImageMC = image.Images["resources/iceKing.png"]
		mc.SizeMC = &mc.ImageMC.Size
		mc.ZMC = 2
		mc.PreviousLoc = mc.SizeMC
		mc.DirtyMC = false
		u.UserState.DrawState.Add(mc)

		p := object.NewPanel()
		p.SetCoord(&geom.Coord{X: 100.0, Y: 100.0})
		p.PanelId = "HoldsPaula"

		mc2 := &character.MainCharacter{}
		mc2.IdMC = "Paula"
		mc2.CoordMC = &geom.Coord{}
		mc2.ImageMC = image.Images["resources/paula.jpg"]
		mc2.SizeMC = &mc2.ImageMC.Size
		mc2.ZMC = 5
		mc2.PreviousLoc = mc2.SizeMC
		mc2.DirtyMC = true

		p.AddObject(mc2)

		u.UserState.DrawState.Add(p)

		b := gamestate.NewBoard()
		b.InitialFill()
		for _, bo := range b.GetObjects() {
			u.UserState.DrawState.Add(bo)
		}

		// Initialize the game state (TODO)
		u.UserState.GameState = "Not Implemented"

		Usermap[id] = u
		log.Println("User Added!", id)
		time.Sleep(1 * time.Second)
		go CheckForData(id)
		return nil
	} else {
		return fmt.Errorf("User Already Exists: %s: %s", id, name)
	}
	return nil
}