Beispiel #1
0
func lobbyHandler(w http.ResponseWriter, r *http.Request) {
	auth_err := checkAuth(w, r)
	if auth_err != nil {
		return
	}
	t, err := loadTemplate("lobby.html")
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	session, _ := store.Get(r, "canibus")
	userName := session.Values["user"].(string)
	user, _ := core.GetUserByName(userName)
	if user.GetDeviceId() != 0 {
		leaveDevice(user)
	}
	data := LobbyTemplate{}
	data.Host = r.Host
	data.Config = core.GetConfig()
	data.NumOfUsers = core.NumberOfUsers()
	exec_err := t.Execute(w, data)
	if exec_err != nil {
		fmt.Println("Lobby Error: ", exec_err)
	}
}
Beispiel #2
0
func candevicesHandler(w http.ResponseWriter, r *http.Request) {
	config := core.GetConfig()
	drivers := config.GetDrivers()
	var data []CanDeviceJSON
	for i := range drivers {
		dev := CanDeviceJSON{}
		dev.Id = drivers[i].GetId()
		dev.DeviceType = drivers[i].DeviceType()
		dev.DeviceDesc = drivers[i].DeviceDesc()
		hax := drivers[i].GetHackSession()
		if hax == nil {
			dev.HackSession = "Idle"
		} else {
			dev.HackSession = hax.GetState()
		}
		dev.Year = drivers[i].GetYear()
		dev.Make = drivers[i].GetMake()
		dev.Model = drivers[i].GetModel()
		data = append(data, dev)
	}
	j, err := json.Marshal(data)
	if err != nil {
		logger.Log("Could not convert candevices to json")
		return
	}
	fmt.Fprintf(w, "%s", j)
}
Beispiel #3
0
func InitDrivers() {
	var conf = core.GetConfig()
	var drivers = conf.GetDrivers()
	for i := range drivers {
		drivers[i].Init()
	}
}
Beispiel #4
0
func addSimHandler(w http.ResponseWriter, r *http.Request) {
	config := core.GetConfig()
	dev := &candevice.Simulator{}
	newId := config.AppendDriver(dev)
	data := CanDeviceJSON{}
	data.Id = newId
	data.DeviceType = dev.DeviceType()
	data.HackSession = "Idle"
	j, err := json.Marshal(data)
	if err != nil {
		logger.Log("Could not convert candevices to json")
		return
	}
	fmt.Fprintf(w, "%s", j)
}