Exemple #1
0
func main() {
	if !*logOnStdout {
		logFile, _ := os.OpenFile(*logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
		log.SetOutput(logFile)
	}
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

	cnfg, err := config.ReadDefault(*configFileName)
	if err != nil {
		log.Println("Fail to find", *configFileName, err)
		return
	}
	configSection := "db"
	if cnfg.HasSection(configSection) {
		f := func(key string) string {
			value, err := cnfg.String(configSection, key)
			if err != nil {
				log.Println("Config file", *configFileName, "Failt to find key", key, err)
				return ""
			}
			return value
		}
		err = ephenationdb.SetConnection(f)
		if err != nil {
			log.Println("main: open DB:", err)
			return
		}
	} else {
		log.Println("Config file", configFileName, "missing, or no section 'db'")
	}
	db := ephenationdb.New()
	chunkdata(db.C("chunkdata"))
}
func main() {
	flag.Parse()
	cnfg, err := config.ReadDefault(*configFileName)
	if err != nil {
		log.Println("Fail to find", *configFileName, err)
		return
	}
	if cnfg.HasSection("sql") {
		server, err := cnfg.String("sql", "DatabaseServer")
		if err != nil {
			log.Println(*configFileName, "DatabaseServer:", err)
			return
		}
		name, err := cnfg.String("sql", "DatabaseName")
		if err != nil {
			log.Println(*configFileName, "DatabaseName:", err)
			return
		}
		login, err := cnfg.String("sql", "DatabaseLogin")
		if err != nil {
			log.Println(*configFileName, "DatabaseLogin:"******"sql", "DatabasePassword")
		if err != nil {
			log.Println(*configFileName, "DatabasePassword:"******"Config file", configFileName, "missing, or no section 'sql'")
	}
	if encryptionSalt, err = cnfg.String("login", "salt"); err != nil {
		encryptionSalt = "" // Effectively no salt
	}
	if *convertChunkFiles {
		ConvertFiles()
		return
	}
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile() // Also done from special command /shutdown
	}
	if !*logOnStdout {
		logFile, _ := os.OpenFile(*logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
		log.SetOutput(logFile)
	}
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

	if *dumpsql {
		DumpSQL()
		os.Exit(0)
	}
	if *tflag {
		DoTest()
		return
	}
	log.Printf("Pheenadv world server\n")
	if *verboseFlag > 0 {
		log.Printf("Verbose flag set to %d\n", *verboseFlag)
	}
	if *inhibitCreateChunks {
		log.Println("No chunks will be created or saved")
	}
	runtime.GOMAXPROCS(*procFlag)
	rand.Seed(time.Now().UnixNano())
	host, err := os.Hostname()
	if err != nil {
		panic(err)
	}
	log.Printf("Start world server on %s\n", host)
	if *allowTestUser {
		log.Printf("Testusers without password allowed\n")
	}
	err = SetupListenForClients_WLuBlWLqWLa(*ipPort)
	if err != nil {
		log.Printf("%v, server abort\n", err)
		os.Exit(1)
	}
	go chunkdb.Poll_Bl() // Will terminate if there is no access to the SQL DB
	go ProcAutosave_RLu()
	go ProcPurgeOldChunks_WLw()
	go CatchSig()
	ManageMonsters_WLwWLuWLqWLmBlWLc() // Will not return
}
func main() {
	flag.Parse()

	if !*logOnStdout {
		logFile, _ := os.OpenFile(*logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
		log.SetOutput(logFile)
	}
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

	cnfg, err := config.ReadDefault(*configFileName)
	if err != nil {
		log.Println("Fail to find", *configFileName, err)
		return
	}
	configSection := "db"
	if cnfg.HasSection(configSection) {
		f := func(key string) string {
			value, err := cnfg.String(configSection, key)
			if err != nil {
				log.Println("Config file", *configFileName, "Failt to find key", key, err)
				return ""
			}
			return value
		}
		err = ephenationdb.SetConnection(f)
		if err != nil {
			log.Println("main: open DB:", err)
			// Continue without DB. Only test users can connect.
		}
	} else {
		log.Println("Config file", *configFileName, "missing section", configSection)
	}
	if encryptionSalt, err = cnfg.String("login", "salt"); err != nil {
		encryptionSalt = "" // Effectively no salt
	}

	if *createuser != "" {
		CreateUser(*createuser)
		return
	}

	if *convertChunkFiles {
		ConvertFiles()
		return
	}
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile() // Also done from special command /shutdown
	}
	if *tflag {
		DoTest()
		return
	}
	log.Printf("Pheenadv world server\n")
	if *verboseFlag > 0 {
		log.Printf("Verbose flag set to %d\n", *verboseFlag)
	}
	if *inhibitCreateChunks {
		log.Println("No chunks will be created or saved")
	}
	runtime.GOMAXPROCS(*procFlag)
	rand.Seed(time.Now().UnixNano())
	host, err := os.Hostname()
	if err != nil {
		panic(err)
	}
	log.Printf("Start world server on %s\n", host)
	if *allowTestUser {
		log.Printf("Testusers without password allowed\n")
	}
	err = SetupListenForClients_WLuBlWLqWLa(*ipPort)
	if err != nil {
		log.Printf("%v, server abort\n", err)
		os.Exit(1)
	}
	go ProcAutosave_RLu()
	go ProcPurgeOldChunks_WLw()
	go CatchSig()
	ManageMonsters_WLwWLuWLqWLmBlWLc() // Will not return
}