Example #1
0
func (Data *Data) Manage_newball(requete *list.Element, Tab_wd *owm.All_data) {
	ball := new(ballon.Ball)
	ball.Stats = new(ballon.StatsBall)
	rqt := requete.Value.(*protocol.Request)
	var newball protocol.New_ball
	var mess ballon.Message
	user := Data.User.Value.(*users.User)

	if user.NbrBallSend < 10 {
		newball = requete.Value.(*protocol.Request).Spec.(protocol.New_ball)
		ball.Id_ball = Data.Lst_ball.Id_max
		Data.Lst_ball.Id_max++
		ball.FlagC = true
		ball.Edited = true
		ball.Title = newball.Title
		ball.Messages = list.New()
		ball.Itinerary = list.New()
		ball.Followers = list.New()
		ball.Checkpoints = list.New()
		mess.Id = 0
		mess.Size = (int32)(len(newball.Message))
		mess.Content = newball.Message
		mess.Type = 1
		ball.Messages.PushFront(mess)
		ball.Date = time.Now()
		ball.Possessed = nil
		ball.Followers.PushFront(Data.User)
		ball.Creator = Data.User
		ball.InitCoord(rqt.Coord.Lon, rqt.Coord.Lat, int16(0), Tab_wd, true)
		eball := Data.Lst_ball.Blist.PushBack(ball)
		user := Data.User.Value.(*users.User)
		user.Followed.PushBack(eball)
		user.NbrBallSend++
		// Begin Stats
		user.Stats.NbrMessage++
		user.Stats.NbrBallCreate++
		user.Stats.NbrSend++
		user.Stats.NbrFollow++
		Data.Lst_users.GlobalStat.NbrBallCreate++
		Data.Lst_users.GlobalStat.NbrSend++
		Data.Lst_users.GlobalStat.NbrFollow++
		Data.Lst_users.GlobalStat.NbrMessage++
		ball.Stats.CreationDate = time.Now()
		ball.Stats.CoordCreated = new(ballon.Coordinate)
		ball.Stats.CoordCreated.Lon = rqt.Coord.Lon
		ball.Stats.CoordCreated.Lat = rqt.Coord.Lat
		ball.Stats.NbrFollow++
		// End Stats
		answer := Data.Manage_ack(rqt.Rtype, ball.Id_ball, int32(1))
		Data.Lst_asw.PushBack(answer)
	} else {
		answer := Data.Manage_ack(rqt.Rtype, 0, int32(0))
		Data.Lst_asw.PushBack(answer)
	}
}