Esempio n. 1
0
func (s *Server) Setup() error {
	helpers.Logger.Debugf("#%d: Connecting to %s", s.LobbyId, s.Info.Host)

	var err error
	s.rcon, err = TF2RconWrapper.NewTF2RconConnection(s.Info.Host, s.Info.RconPassword)
	if err != nil {
		return err
	}

	// kick players
	helpers.Logger.Debugf("#%d: Kicking all players", s.LobbyId)
	kickErr := s.KickAll()

	if kickErr != nil {
		return kickErr
	}

	s.rcon.Query("mp_tournament 1; mp_tournament_readymode 1")
	// change map,
	helpers.Logger.Debugf("#%d: Changing Map", s.LobbyId)
	err = s.rcon.ChangeMap(s.Map)

	if err != nil {
		return err
	}

	time.Sleep(10 * time.Second) // wait for map to change

	err = s.rcon.Reconnect(2 * time.Minute)
	if err != nil {
		return err
	}

	helpers.Logger.Debugf("#%d: Creating listener", s.LobbyId)
	eventlistener := &TF2RconWrapper.EventListener{
		PlayerConnected:     s.PlayerConnected,
		PlayerDisconnected:  s.PlayerDisconnected,
		PlayerGlobalMessage: s.PlayerGlobalMessage,
		GameOver:            s.GameOver,
		CVarChange:          s.CVarChange,
		TournamentStarted:   s.TournamentStarted,
		RconCommand:         s.RconCommand,
	}

	s.source = Listener.AddSource(eventlistener, s.rcon)
	database.SetSecret(s.source.Secret, s.Info.ID)

	s.rcon.AddTag("TF2Stadium")
	s.rcon.Query("tftrue_no_hats 0; mp_timelimit 0; mp_tournament 1; mp_tournament_restart")

	helpers.Logger.Debugf("#%d: Setting whitelist", s.LobbyId)
	s.execWhitelist()

	helpers.Logger.Debugf("#%d: Configured", s.LobbyId)
	return nil
}
Esempio n. 2
0
File: rpc.go Progetto: N1xx1/Pauling
func (_ *Pauling) VerifyInfo(info *models.ServerRecord, nop *Noreply) error {
	c, err := rconwrapper.NewTF2RconConnection(info.Host, info.RconPassword)
	if c != nil {
		_, err = c.Query("tftrue_gamedesc")
		if err != nil {
			err = errors.New("TFTrue isn't installed on the server.")
		}
		c.Close()
	}
	return err
}
Esempio n. 3
0
func (s *Server) VerifyInfo() error {
	if config.Constants.ServerMockUp {
		return nil
	}

	var err error
	s.Rcon, err = TF2RconWrapper.NewTF2RconConnection(s.Info.Host, s.Info.RconPassword)

	if err != nil {
		return helpers.NewTPError(err.Error(), -1)
	}
	return nil
}
Esempio n. 4
0
func (s *Server) StartVerifier(ticker *time.Ticker) {
	var err error
	var count int

	s.Rcon.Close()
	s.Rcon, err = TF2RconWrapper.NewTF2RconConnection(s.Info.Host, s.Info.RconPassword)
	for err != nil && count != 5 {
		time.Sleep(1 * time.Second)
		Logger.Critical(err.Error())
		count++
		s.Rcon, err = TF2RconWrapper.NewTF2RconConnection(s.Info.Host, s.Info.RconPassword)
	}
	if count == 5 {
		PushEvent(EventDisconectedFromServer, s.LobbyId)
		return
	}
	s.ServerListener = RconListener.CreateServerListener(s.Rcon)
	go s.LogListener()

	for {
		select {
		case <-ticker.C:
			if !s.Verify() {
				ticker.Stop()
				s.Rcon.Close()
				return
			}
		case <-s.StopVerifier:
			Logger.Debug("Stopping logger for lobby %d", s.LobbyId)
			s.Rcon.Query("[tf2stadium.com] Lobby Ended.")
			ticker.Stop()
			RconListener.Close(s.Rcon)
			s.Rcon.Close()
			return
		}
	}
}
Esempio n. 5
0
func main() {
	var addr, pwd string

	flag.StringVar(&addr, "addr", "", "Server Address")
	flag.StringVar(&pwd, "pwd", "", "Server RCON Password")

	flag.Parse()

	reader := bufio.NewReader(os.Stdin)
	isCLI := stdinIsatty()

	if addr == "" {
		addr = readParameter(reader, "Please enter server address: ", false)
	}

	if pwd == "" {
		pwd = readParameter(reader, "Please enter RCON password: "******"RCON> ")
		}

		query, readErr := reader.ReadString('\n')
		if readErr != nil {
			break
		}

		reply, err := conn.Query(query)
		if err != nil {
			if err == rcon.ErrUnknownCommand {
				log.Println("Unknown Command")
				continue
			}

			log.Fatal(err.Error())
		}
		fmt.Printf("%s\n", reply)
	}
}
Esempio n. 6
0
func (s *Server) Setup() error {
	if config.Constants.ServerMockUp {
		return nil
	}

	Logger.Debug("#%d: Connecting to %s", s.LobbyId, s.Info.Host)

	s.Rcon, _ = TF2RconWrapper.NewTF2RconConnection(s.Info.Host, s.Info.RconPassword)

	// kick players
	Logger.Debug("#%d: Kicking all players", s.LobbyId)
	kickErr := s.KickAll()

	if kickErr != nil {
		return kickErr
	}

	Logger.Debug("#%d: Setting whitelist, changing map", s.LobbyId)
	// whitelist
	_, err := s.Rcon.Query(fmt.Sprintf("tftrue_whitelist_id %d", s.Whitelist))
	if err == TF2RconWrapper.UnknownCommandError {
		var whitelist string

		switch s.Whitelist {
		case 3250:
			whitelist = "etf2l_whitelist_9v9.txt"
		case 4498:
			whitelist = "etf2l_whitelist_6v6.txt"
		case 3312:
			whitelist = "etf2l_whitelist_ultiduo.txt"
		case 3759:
			whitelist = "etf2l_whitelist_bball.txt"

		case 3951:
			whitelist = "item_whitelist_ugc_HL.txt"
		case 4559:
			whitelist = "item_whitelist_ugc_6v6.txt"
		case 3771:
			whitelist = "item_whitelist_ugc_4v4.txt"

		case 3688:
			whitelist = "esea/item_whitelist.txt"
			// case 4034:

			// case 3872:
		}
		s.Rcon.Query("mp_tournament_whitelist " + whitelist)
	}

	filePath, _ := filepath.Abs("./configs/" + ConfigName(s.Map, s.Type, s.League))

	f, err := os.Open(filePath)
	if err != nil {
		//Logger.Debug("%s %s", filePath, err.Error())
		return errors.New("Config doesn't exist.")
	}
	f.Close()

	// change map
	mapErr := s.Rcon.ChangeMap(s.Map)

	if mapErr != nil {
		return mapErr
	}

	// run config
	s.ExecConfig()

	return nil
}
Esempio n. 7
0
func (s *Server) Setup() error {
	if config.Constants.ServerMockUp {
		return nil
	}

	helpers.Logger.Debug("[Server.Setup]: Setting up server -> [" + s.Info.Host + "] from lobby [" + fmt.Sprint(s.LobbyId) + "]")

	// connect to rcon if not connected before
	if s.Rcon == nil {
		var err error
		s.Rcon, err = TF2RconWrapper.NewTF2RconConnection(s.Info.Host, s.Info.RconPassword)

		if err != nil {
			return err
		}
	}

	// changing server password
	passErr := s.Rcon.ChangeServerPassword(s.ServerPassword)

	if passErr != nil {
		return passErr
	}

	// kick players
	helpers.Logger.Debug("[Server.Setup]: Connected to server, getting players...")
	kickErr := s.KickAll()

	if kickErr != nil {
		return kickErr
	} else {
		helpers.Logger.Debug("[Server.Setup]: Players kicked, running config!")
	}

	// run config
	config := NewServerConfig()
	config.League = s.League
	config.Type = s.Type
	config.Map = s.Map
	cfg, cfgErr := config.Get()

	if cfgErr == nil {
		config.Data = cfg
		configErr := s.ExecConfig(config)

		if configErr != nil {
			return configErr
		}
	} else {
		return cfgErr
	}

	// change map
	mapErr := s.Rcon.ChangeMap(s.Map)

	if mapErr != nil {
		return mapErr
	}

	return nil
}