Esempio n. 1
0
// Save saves state to the given writer.
// This state can be fed to Load() in a new instance of the server.
// At present, saved state is all global metadata.
func Save(raw io.Writer) (err error) {

	// Get encoder.
	w := json.NewEncoder(raw)

	// Write version.
	version := struct{ Version string }{Version: "1"}
	if err = w.Encode(version); err != nil {
		return
	}

	// Write state.
	core.Sync(nil, nil, func(hook bool) {
		if hook {
			return
		}

		core.Global.DataRange("", func(name, value string) {
			if err != nil {
				return
			}

			var data struct{ Name, Value string }
			data.Name = name
			data.Value = value
			err = w.Encode(data)
		})
	})

	return
}
Esempio n. 2
0
// Burst to a locally linked server.
func link_burst(l *local) {
	core.Sync(
		func(u *core.User, hook bool) {
			if !hook {
				send_uid(l, u)
			}
		},
		func(ch *core.Channel, hook bool) {
			b := bytes.NewBuffer(make([]byte, 0, 512))
			user := bytes.NewBuffer(make([]byte, 0, 50))
			if !hook {
				it := ch.Users()
				for {
					fmt.Fprintf(b, "SJOIN %d #%s +n :", 0, ch.Name())
					for ; it != nil; it = it.ChanNext() {
						user.WriteString(it.User().ID())
						user.Write([]byte(" "))
						if b.Len()+user.Len() > 509 {
							break
						}
						user.WriteTo(b)
						user.Reset()
					}
					b.Write([]byte("\r\n"))
					b.WriteTo(l)
					b.Reset()

					if it == nil {
						break
					}
				}
			}
		},
		func(hook bool) {
			// We currently *assume* this is called after all the other
			// hooks.
			if !hook {
				l.burst_sent = true
			}
		})
}