Beispiel #1
0
func (Lobby) ServerVerify(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)

	if reqerr != nil {
		return reqerr.Encode()
	}

	var args struct {
		Server  *string `json:"server"`
		Rconpwd *string `json:"rconpwd"`
	}

	if err := chelpers.GetParams(data, &args); err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	var count int
	db.DB.Table("server_records").Where("host = ?", *args.Server).Count(&count)
	if count != 0 {
		return helpers.NewTPError("A lobby is already using this server.", -1).Encode()
	}

	info := models.ServerRecord{
		Host:         *args.Server,
		RconPassword: *args.Rconpwd,
	}
	err := models.VerifyInfo(info)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	return chelpers.EmptySuccessJS
}
Beispiel #2
0
func (Lobby) ServerVerify(so *wsevent.Client, args struct {
	Server  *string `json:"server"`
	Rconpwd *string `json:"rconpwd"`
}) interface{} {

	if !validAddress.MatchString(*args.Server) {
		return helpers.NewTPError("Invalid Server Address", -1)
	}

	var count int
	db.DB.Table("server_records").Where("host = ?", *args.Server).Count(&count)
	if count != 0 {
		return helpers.NewTPError("A lobby is already using this server.", -1)
	}

	info := &models.ServerRecord{
		Host:         *args.Server,
		RconPassword: *args.Rconpwd,
	}
	db.DB.Save(info)
	defer db.DB.Where("host = ?", info.Host).Delete(models.ServerRecord{})

	err := models.VerifyInfo(*info)
	if err != nil {
		return helpers.NewTPErrorFromError(err)
	}

	return chelpers.EmptySuccessJS
}
Beispiel #3
0
func LobbyCreate(so socketio.Socket) func(string) string {
	return chelpers.FilterRequest(so, lobbyCreateFilters,
		func(params map[string]interface{}) string {

			player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))

			mapName := params["mapName"].(string)
			lobbytypestring := params["type"].(string)
			league := params["league"].(string)
			server := params["server"].(string)
			rconPwd := params["rconpwd"].(string)
			whitelist := int(params["whitelist"].(uint))
			mumble := params["mumbleRequired"].(bool)

			var playermap = map[string]models.LobbyType{
				"debug":      models.LobbyTypeDebug,
				"sixes":      models.LobbyTypeSixes,
				"highlander": models.LobbyTypeHighlander,
			}

			lobbytype, _ := playermap[lobbytypestring]

			randBytes := make([]byte, 6)
			rand.Read(randBytes)
			serverPwd := base64.URLEncoding.EncodeToString(randBytes)

			//TODO what if playermap[lobbytype] is nil?
			info := models.ServerRecord{
				Host:           server,
				RconPassword:   rconPwd,
				ServerPassword: serverPwd}
			err := models.VerifyInfo(info)
			if err != nil {
				return err.Error()
			}

			lob := models.NewLobby(mapName, lobbytype, league, info, whitelist, mumble)
			lob.CreatedBySteamID = player.SteamId
			lob.Save()
			err = lob.SetupServer()

			if err != nil {
				bytes, _ := err.(*helpers.TPError).ErrorJSON().Encode()
				return string(bytes)
			}

			lob.State = models.LobbyStateWaiting
			lob.Save()
			lobby_id := simplejson.New()
			lobby_id.Set("id", lob.ID)
			bytes, _ := chelpers.BuildSuccessJSON(lobby_id).Encode()
			return string(bytes)
		})
}
Beispiel #4
0
func ServerVerify(so socketio.Socket) func(string) string {
	return chelpers.FilterRequest(so, serverVerifyFilters,
		func(params map[string]interface{}) string {
			info := models.ServerRecord{
				Host:         params["server"].(string),
				RconPassword: params["rconpwd"].(string),
			}
			err := models.VerifyInfo(info)
			if err != nil {
				bytes, _ := chelpers.BuildFailureJSON(err.Error(), -1).Encode()
				return string(bytes)
			}

			bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
			return string(bytes)

		})
}