Esempio n. 1
0
File: sitef.go Progetto: beoran/woe
func (me *Record) PutValue(key string, value reflect.Value) {

	monolog.Debug("PutValue: %s %v", key, value)

	stringer, ok := value.Interface().(fmt.Stringer)
	if ok {
		me.Put(key, stringer.String())
		return
	}

	switch value.Kind() {
	case reflect.Int, reflect.Int32, reflect.Int64:
		me.Putf(key, "%d", value.Int())
	case reflect.Uint, reflect.Uint32, reflect.Uint64:
		me.Putf(key, "%d", value.Uint())
	case reflect.Float32, reflect.Float64:
		me.Putf(key, "%f", value.Float())
	case reflect.String:
		me.Putf(key, "%s", value.String())
	case reflect.Struct:
		me.PutStruct(key+".", value.Interface())
	default:
		me.Put(key, "???")
	}

	monolog.Debug("Put: key %s value %s, result %v", key, value, me)

}
Esempio n. 2
0
File: raku.go Progetto: beoran/woe
func (me *Parser) Expect(types ...TokenType) bool {
	monolog.Debug("Expecting: ", types, " from ", me.now.AstType, " have ", me.LookaheadType(), " \n")
	for _, t := range types {
		if me.LookaheadType() == t {
			monolog.Debug("Found: ", t, "\n")
			return true
		}
	}
	monolog.Debug("Not found.\n")
	return false
}
Esempio n. 3
0
File: server.go Progetto: beoran/woe
// Returns the data path of the server
func (me *Server) DataPath() string {
	//
	cwd, err := os.Getwd()
	monolog.Debug("Current direcory: %s (%v).", cwd, err)

	if err != nil {
		cwd = "."
	}

	fp := filepath.Join(cwd, "data", "var")
	monolog.Debug("Data path: %s (%v). ", fp, err)

	return fp
}
Esempio n. 4
0
File: sitef.go Progetto: beoran/woe
func (me Record) GetValue(key string, value reflect.Value) (err error) {
	/*stringer, ok := value.Interface().(fmt.Stringer)
	  if ok {
	      me.Gut(key, stringer.String())
	      return
	  }*/
	monolog.Debug("GetValue: %s %v", key, value)

	switch value.Kind() {
	case reflect.Int, reflect.Int32, reflect.Int64:
		value.SetInt(int64(me.GetIntDefault(key, 0)))
	case reflect.Uint, reflect.Uint32, reflect.Uint64:
		value.SetUint(uint64(me.GetIntDefault(key, 0)))
	case reflect.Float32, reflect.Float64:
		f, err := me.GetFloat(key)
		if err != nil {
			return err
		}
		value.SetFloat(f)
	case reflect.String:
		s, ok := me.MayGet(key)
		if !ok {
			return fmt.Errorf("Could not get string for key %s", key)
		}
		value.SetString(s)
	case reflect.Struct:
		me.GetStruct(key+".", value.Addr().Interface())
	default:
		monolog.Warning("Don't know what to do with %v", value)
	}
	return nil
}
Esempio n. 5
0
File: woe.go Progetto: 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
}
Esempio n. 6
0
// Save a character as a sitef file.
func (me *Character) Save(dirname string) (err error) {
	path := SavePathFor(dirname, "character", me.ID)

	rec := sitef.NewRecord()
	me.SaveSirec(rec)
	monolog.Debug("Saving Character record: %s %v", path, rec)
	return sitef.SaveRecord(path, *rec)
}
Esempio n. 7
0
File: sitef.go Progetto: beoran/woe
func WriteField(writer io.Writer, key string, value string) {
	monolog.Debug("WriteField %s:%s", key, value)
	replacer := strings.NewReplacer("\n", "\n\t")
	writer.Write([]byte(key))
	writer.Write([]byte{':'})
	writer.Write([]byte(replacer.Replace(value)))
	writer.Write([]byte{'\n'})
}
Esempio n. 8
0
File: being.go Progetto: beoran/woe
func init() {
	KinEntityList = make(EntitylikeSlice, len(KinList))
	for i := range KinList {
		e := KinList[i]
		monolog.Debug("KinList: %s", e.Name)
		KinEntityList[i] = &e
	}
}
Esempio n. 9
0
File: being.go Progetto: beoran/woe
func init() {
	JobEntityList = make(EntitylikeSlice, len(JobList))
	for i := range JobList {
		e := JobList[i]
		monolog.Debug("JobList: %s", e.Name)
		JobEntityList[i] = &e
	}
}
Esempio n. 10
0
func (me *Client) HasTerminal(name string) bool {
	monolog.Debug("Client %d supports terminals? %s %v", me.id, name, me.info.terminals)
	for index := range me.info.terminals {
		if me.info.terminals[index] == name {
			return true
		}
	}
	return false
}
Esempio n. 11
0
File: world.go Progetto: beoran/woe
// Save an account as a sitef file.
func (me *World) Save(dirname string) (err error) {
	path := SavePathFor(dirname, "world", me.Name)

	rec := sitef.NewRecord()
	rec.Put("name", me.Name)
	rec.Put("motd", me.MOTD)
	monolog.Debug("Saving World record: %s %v", path, rec)
	return sitef.SaveRecord(path, *rec)
}
Esempio n. 12
0
File: raku.go Progetto: beoran/woe
func (me *Lexer) ReadReaderOnce() (bool, error) {
	buffer := make([]byte, 1024)

	n, err := me.Reader.Read(buffer)
	monolog.Debug("read %v %d %v\n", buffer[:n], n, err)
	if n > 0 {
		me.buffer = append(me.buffer, buffer[:n]...)
		monolog.Debug("append  %s", me.buffer)
	}

	if err == io.EOF {
		return true, nil
	} else if err != nil {
		me.Error("Error reading from reader: %s", err)
		return true, err
	}
	return false, nil
}
Esempio n. 13
0
File: raku.go Progetto: beoran/woe
func (me *Lexer) SkipIn(set string) bool {
	for strings.ContainsRune(set, me.Next()) {
		monolog.Debug("SkipIn: %s %c\n", set, me.Peek())
		if me.Peek() == '\000' {
			return false
		}
	}
	return true
}
Esempio n. 14
0
File: sitef.go Progetto: beoran/woe
func WriteRecord(writer io.Writer, record Record) {
	monolog.Debug("WriteRecord %v", record)

	for index := 0; index < len(record.order); index++ {
		key := record.order[index]
		value := record.dict[key]
		WriteField(writer, key, value)
	}
	writer.Write([]byte{'-', '-', '-', '-', '\n'})
}
Esempio n. 15
0
File: raku.go Progetto: beoran/woe
func (me *Lexer) Start() {
	if err := me.ReadReader(); err == nil || err == io.EOF {
		rule := LexNormal
		for rule != nil {
			monolog.Debug("Lexer Rule: %s\n", GetFunctionName(rule))
			rule = rule(me)
		}
	} else {
		me.Error("Could not read in input buffer: %s", err)
	}
	close(me.Output)
}
Esempio n. 16
0
// Save an account as a sitef file.
func (me *Account) Save(dirname string) (err error) {
	path := SavePathFor(dirname, "account", me.Name)

	rec := sitef.NewRecord()
	rec.Put("name", me.Name)
	rec.Put("hash", me.Hash)
	rec.Put("algo", me.Algo)
	rec.Put("email", me.Email)
	rec.PutInt("points", me.Points)
	rec.PutInt("privilege", int(me.Privilege))
	rec.PutInt("characters", len(me.characters))
	for i, chara := range me.characters {
		key := fmt.Sprintf("characters[%d]", i)
		rec.Put(key, chara.ID)

	}
	monolog.Debug("Saving Acccount record: %s %v", path, rec)
	return sitef.SaveRecord(path, *rec)
}
Esempio n. 17
0
File: sitef.go Progetto: beoran/woe
func (me *Record) Putf(key string, format string, values ...interface{}) {
	me.Put(key, fmt.Sprintf(format, values...))
	monolog.Debug("After putf: %s %v", key, me.order)
}