示例#1
0
文件: woe.go 项目: beoran/woe
func runSupervisor() (status int) {
	monolog.Setup("woe.log", true, false)
	defer monolog.Close()
	enableDisableLogs()
	monolog.Info("Starting WOE supervisor.")
	for server_restart {
		// wd  , _ := os.Getwd()
		exe := fmt.Sprintf("%s", os.Args[0])
		argp := fmt.Sprintf("-l=%s", *server_tcpip)
		argel := fmt.Sprintf("-el=%s", *enable_logs)
		argdl := fmt.Sprintf("-dl=%s", *disable_logs)
		cmd := exec.Command(exe, "-s=true", argp, argel, argdl)
		monolog.Info("Starting server %s at %s.", exe, *server_tcpip)
		cmd.Stderr = os.Stderr
		cmd.Stdout = os.Stdout
		monolog.Debug("Server command line: %s.", cmd.Args)
		err := cmd.Run()
		monolog.Info("Server at %s shut down.", *server_tcpip)
		if err != nil {
			monolog.Error("Server shut down with error %s!", err)
			server_restart = false
			return 1
		}
	}
	return 0
}
示例#2
0
文件: server.go 项目: beoran/woe
func (me *Server) SetupWorld() (err error) {
	me.World, err = world.LoadWorld(me.DataPath(), "WOE")

	if err != nil {
		monolog.Error("Could not load world WOE: %s", err)
		return err
	}

	if me.World == nil {
		monolog.Info("Creating new default world...")
		me.World = world.NewWorld("WOE", DEFAULT_MOTD, me.DataPath())
		err := me.World.Save(me.DataPath())
		if err != nil {
			monolog.Error("Could not save world: %v", err)
			return err
		} else {
			monolog.Info("Saved default world.")
		}
	}
	return nil
}
示例#3
0
文件: woe.go 项目: beoran/woe
func runServer() (status int) {
	monolog.Setup("woe.log", true, false)
	defer monolog.Close()
	enableDisableLogs()
	monolog.Info("Starting WOE server...")
	monolog.Info("Server will run at %s.", *server_tcpip)
	woe, err := server.NewServer(*server_tcpip)
	if err != nil {
		monolog.Error("Could not initialize server!")
		monolog.Error(err.Error())
		panic(err)
	}
	monolog.Info("Server at %s init ok.", *server_tcpip)
	defer woe.Close()
	status, err = woe.Serve()
	if err != nil {
		monolog.Error("Error while running WOE server!")
		monolog.Error(err.Error())
		panic(err)
	}
	monolog.Info("Server shut down without error indication.", *server_tcpip)
	return status
}
示例#4
0
文件: character.go 项目: beoran/woe
// Load an character from a sitef file for the given account.
func (account *Account) LoadCharacter(dirname string, id string) (character *Character, err error) {

	character, aname, err := LoadCharacter(dirname, id)
	if character == nil {
		return character, err
	}

	if aname != account.Name {
		err := fmt.Errorf("Account doesn't match! %s %s", aname, account.Name)
		monolog.Error("%s", err.Error())
		return nil, err
	}

	character.Account = account
	return character, nil
}
示例#5
0
文件: account.go 项目: beoran/woe
// Load an account from a sitef file.
func LoadAccount(dirname string, name string) (account *Account, err error) {

	path := SavePathFor(dirname, "account", name)

	records, err := sitef.ParseFilename(path)
	if err != nil {
		return nil, err
	}

	if len(records) < 1 {
		return nil, errors.New("No record found!")
	}

	record := records[0]
	monolog.Info("Loading Account record: %s %v", path, record)

	account = new(Account)
	account.Name = record.Get("name")
	account.Hash = record.Get("hash")
	account.Algo = record.Get("algo")
	account.Email = record.Get("email")
	account.Points = record.GetIntDefault("points", 0)
	account.Privilege = Privilege(record.GetIntDefault("privilege",
		int(PRIVILEGE_NORMAL)))

	nchars := record.GetIntDefault("characters", 0)
	account.characters = make([]*Character, 0, nchars)
	monolog.Info("Try to load %d characters:\n", nchars)
	for index := 0; index < nchars; index++ {

		chid := record.GetArrayIndex("characters", index)
		monolog.Info("Loading character: %d %s\n", index, chid)

		ch, err := account.LoadCharacter(dirname, chid)
		if err != nil {
			monolog.Error("Could not load character %s: %s", chid, err.Error())
			// return nil, err
		} else {
			account.characters = append(account.characters, ch)
		}
	}

	/* Todo: load characters here... */
	monolog.Info("Loaded Account: %s %v", path, account)
	return account, nil
}
示例#6
0
文件: dialog.go 项目: beoran/woe
func (me *Client) NewAccountDialog(login string) bool {
	for me.account == nil {
		me.Printf("\nWelcome, %s! Creating new account...\n", login)
		pass1 := me.AskPassword()

		if pass1 == nil {
			return false
		}

		pass2 := me.AskRepeatPassword()

		if pass1 == nil {
			return false
		}

		if string(pass1) != string(pass2) {
			me.Printf("\nPasswords do not match! Please try again!\n")
			continue
		}

		email := me.AskEmail()
		if email == nil {
			return false
		}

		me.account = world.NewAccount(login, string(pass1), string(email), 7)
		err := me.account.Save(me.server.DataPath())

		if err != nil {
			monolog.Error("Could not save account %s: %v", login, err)
			me.Printf("\nFailed to save your account!\nPlease contact a WOE administrator!\n")
			return false
		}

		monolog.Info("Created new account %s", login)
		me.Printf("\nSaved your account.\n")
		return true
	}
	return false
}
示例#7
0
文件: server.go 项目: beoran/woe
func NewServer(address string) (server *Server, err error) {
	listener, err := net.Listen("tcp", address)
	if err != nil {
		return nil, err
	}

	monolog.Info("Server listening on %s.", address)

	clients := make(map[int]*Client)
	tickers := make(map[string]*Ticker)

	server = &Server{address, listener, clients, tickers, true, nil, STATUS_RESTART}
	err = server.SetupWorld()
	if err != nil {
		monolog.Error("Could not set up or load world!")
		return nil, err
	}

	monolog.Info("Server world set up.")
	server.AddDefaultTickers()
	monolog.Info("Tickers set up.")

	return server, err
}
示例#8
0
文件: sitef.go 项目: beoran/woe
func ParseReader(read io.Reader) (RecordList, error) {
	var records RecordList
	record := NewRecord()
	var err Error
	lineno := 0
	scanner := bufio.NewScanner(read)
	var key bytes.Buffer
	var value bytes.Buffer

	for scanner.Scan() {
		lineno++
		line := scanner.Text()
		// End of record?
		if (len(line) < 1) || line[0] == '-' {
			// Append last record if needed.
			if len(key.String()) > 0 {
				record.Put(key.String(), value.String())
			}
			// save the record and make a new one
			records = append(records, record)
			record = NewRecord()
			// comment?
		} else if line[0] == '#' {
			continue
			// continue value?
		} else if line[0] == '\t' || line[0] == ' ' || line[0] == '+' {

			/* Add a newline unless + is used */
			if line[0] != '+' {
				value.WriteRune('\n')
			}

			// continue the value, skipping the first character
			value.WriteString(line[1:])
			// new key
		} else if strings.ContainsRune(line, ':') {
			// save the previous key/value pair if needed
			if len(key.String()) > 0 {
				record.Put(key.String(), value.String())
			}

			key.Reset()
			value.Reset()

			parts := strings.SplitN(line, ":", 2)

			key.WriteString(parts[0])
			if len(parts) > 1 {
				value.WriteString(parts[1])
			}
			// Not a key. Be lenient and assume this is a continued value.
		} else {
			value.WriteString(line)
		}
	}

	// Append last record if needed.
	if len(key.String()) > 0 {
		record.Put(key.String(), value.String())
	}

	if len(record.order) > 0 {
		records = append(records, record)
	}

	if serr := scanner.Err(); serr != nil {
		err.lineno = lineno
		err.error = serr.Error()
		monolog.Error("Sitef parse error: %d %s", lineno, serr.Error)
		return records, err
	}

	return records, nil

}
示例#9
0
文件: raku.go 项目: beoran/woe
func (me *Lexer) Error(message string, args ...interface{}) {
	value := fmt.Sprintf(message, args...)
	monolog.Error("Lex Error: %s", value)
	me.Emit(TokenError, Value(value))
}