// The 'name' argument is not the nick name shown, it is the login name used to
// authenticate the player.
func (up *user) CmdLogin_WLwWLuWLqBlWLc(email string) {
	// fmt.Printf("CmdLogin: New player %v\n", email)
	// It may be that there is no license for this player. But we can only give one type of error
	// message, which means wrong email or password.
	validTestUser := false
	remote := up.conn.RemoteAddr().String()
	addr := strings.Split(remote, ":") // The format is expected to be NNN.NNN.NNN.NNN:NNNN.
	if *allowTestUser && strings.HasPrefix(email, CnfgTestPlayerNamePrefix) {
		if len(addr) == 2 {
			ip := addr[0]
			cnfg, err := config.ReadDefault(*configFileName)
			if err == nil && cnfg.HasSection("login") {
				testplayersallowed, _ := cnfg.Bool("login", "testplayer")
				testiplist, err := cnfg.String("login", "testip")
				if testplayersallowed && err == nil && strings.Contains(testiplist, ip) {
					validTestUser = true
				} else if err != nil {
					validTestUser = true // Allow testuser if no "testip" key.
				}
			} else {
				validTestUser = true // Allow testuser if no config file or no "Login" section
			}
		}
	} else {
		log.Println("Denied testuser from", remote)
	}
	if validTestUser {
		// This test player is allowed login without password, but it is never saved
		uid := up.pl.New_WLwWLc(email)
		up.uid = uid
		up.loginAck_WLuWLqBlWLa()
		up.pl.adminLevel = 9
	} else {
		lic := license.Load_Bl(email)
		up.Lock()
		up.lic = lic
		up.challenge = make([]byte, LoginChallengeLength)
		cryptrand.Read(up.challenge)
		if lic != nil && len(lic.Names) > 0 {
			uid, ok := up.pl.Load_WLwBlWLc(lic.Names[0])
			if ok {
				up.uid = uid
			} else {
				up.lic = nil // Failed to load player data, have fail login (do not know avatar name)
			}
		} else if lic == nil {
			if *verboseFlag > 0 {
				log.Printf("Login failed or no license for '%v'\n", email)
			}
		} else if len(lic.Names) == 0 {
			log.Printf("No avatar for email '%v'\n", email)
			up.lic = nil // Force the next login phase to fail.
		}
		up.connState = PlayerConnStatePass
		up.Unlock()
		// Request a password, even though the license may be incorrect.
		up.writeBlocking_Bl([]byte{3 + LoginChallengeLength, 0, client_prot.CMD_REQ_PASSWORD})
		up.writeBlocking_Bl(up.challenge)
	}
}
Beispiel #2
0
func LoadConfig(confName string) (*MergedConfig, error) {
	var err error
	for _, confPath := range ConfPaths {
		conf, err := config.ReadDefault(path.Join(confPath, confName))
		if err == nil {
			return &MergedConfig{conf, ""}, nil
		}
	}
	if err == nil {
		err = errors.New("not found")
	}
	return nil, err
}
Beispiel #3
0
func LoadClientVersionInformation(file string) (int, int) {
	cnfg, err := config.ReadDefault(*configFileName)
	if err == nil && cnfg.HasSection("client") {
		major, err := cnfg.Int("client", "major")
		if err != nil {
			log.Println(*configFileName, "major:", err)
			return 0, 0
		}
		minor, err := cnfg.Int("client", "minor")
		if err != nil {
			log.Println(*configFileName, "minor:", err)
			return 0, 0
		}
		return major, minor
	}
	return 0, 0
}
Beispiel #4
0
func parseMessagesFile(path string) (messageConfig *config.Config, error error) {
	messageConfig, error = config.ReadDefault(path)
	return
}
Beispiel #5
0
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
}